VirtualBox

Changeset 76312 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 20, 2018 1:02:13 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699. More refactoring on file system model classes to achieve decoupling

Location:
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UICustomFileSystemModel.cpp

    r76309 r76312  
    2828# include "UICustomFileSystemModel.h"
    2929# include "UIFileManagerTable.h"
    30 # include "UIFileManager.h"
    3130# include "VBoxGlobal.h"
    3231
     
    284283UICustomFileSystemModel::UICustomFileSystemModel(QObject *parent)
    285284    : QAbstractItemModel(parent)
    286     , m_pParent(qobject_cast<UIFileManagerTable*>(parent))
    287285    , m_fShowHumanReadableSizes(false)
    288286{
     
    324322        if (index.column() == 0 && value.canConvert(QMetaType::QString))
    325323        {
    326             UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
    327             if (!item || !m_pParent)
     324            UIFileTableItem *pItem = static_cast<UIFileTableItem*>(index.internalPointer());
     325            if (!pItem)
    328326                return false;
    329             if (m_pParent->renameItem(item, value.toString()))
    330             {
    331                 item->setData(value, index.column());
    332                 emit dataChanged(index, index);
    333             }
    334             else
    335             {
    336                 if (m_pParent)
    337                     m_pParent->emitLogOutput(QString(item->path()).append(" could not be renamed"), FileManagerLogType_Error);
    338             }
     327            QString strOldName = pItem->name();
     328            pItem->setData(value, index.column());
     329            emit dataChanged(index, index);
     330            emit sigItemRenamed(pItem, strOldName, value.toString());
    339331            return true;
    340332        }
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UICustomFileSystemModel.h

    r76309 r76312  
    2525/* COM includes: */
    2626#include "COMEnums.h"
    27 
    28 /* Forward declarations: */
    29 class UIFileManagerTable;
    3027
    3128enum UICustomFileSystemModelColumn
     
    126123
    127124    UICustomFileSystemProxyModel(QObject *parent = 0);
    128 
    129125    void setListDirectoriesOnTop(bool fListDirectoriesOnTop);
    130126    bool listDirectoriesOnTop() const;
     
    141137/** UICustomFileSystemModel serves as the model for a file structure.
    142138 *  it supports a tree level hierarchy which can be displayed with
    143  *  QTableView and/or QTreeView. .*/
     139 *  QTableView and/or QTreeView.*/
    144140class UICustomFileSystemModel : public QAbstractItemModel
    145141{
    146142
    147143    Q_OBJECT;
     144
     145signals:
     146
     147    void sigItemRenamed(UIFileTableItem *pItem, QString strOldName, QString strNewName);
    148148
    149149public:
     
    181181    UIFileTableItem    *m_pRootItem;
    182182    void setupModelData(const QStringList &lines, UIFileTableItem *parent);
    183     UIFileManagerTable *m_pParent;
    184183    bool                m_fShowHumanReadableSizes;
    185 
    186184};
    187185
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp

    r76309 r76312  
    583583    if (!m_pModel)
    584584        return;
     585    connect(m_pModel, &UICustomFileSystemModel::sigItemRenamed,
     586            this, &UIFileManagerTable::sltHandleItemRenameAttempt);
    585587
    586588    m_pProxyModel = new UICustomFileSystemProxyModel(this);
     
    917919void UIFileManagerTable::sltRename()
    918920{
    919     if (!m_pView)
     921    if (!m_pView || !m_pModel)
    920922        return;
    921923    QItemSelectionModel *selectionModel =  m_pView->selectionModel();
     
    10171019    performSelectionSearch(strText);
    10181020}
     1021
     1022void UIFileManagerTable::sltHandleItemRenameAttempt(UIFileTableItem *pItem, QString strOldName, QString strNewName)
     1023{
     1024    if (!pItem)
     1025        return;
     1026    /* Attempt to chage item name in the file system: */
     1027    if (!renameItem(pItem, strNewName))
     1028    {
     1029        /* Restore the previous name. relist the view: */
     1030        pItem->setData(strOldName, static_cast<int>(UICustomFileSystemModelColumn_Name));
     1031        relist();
     1032        sigLogOutput(QString(pItem->path()).append(" could not be renamed"), FileManagerLogType_Error);
     1033    }
     1034}
     1035
    10191036
    10201037void UIFileManagerTable::sltCreateFileViewContextMenu(const QPoint &point)
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.h

    r76309 r76312  
    190190    void sltRefresh();
    191191    void sltDelete();
     192    /** Calls the edit on the data item over m_pView. This causes setData(..) call on the model. After setting
     193     *  user entered text as the name of the item m_pModel signals. This signal is handled by sltHandleItemRenameAttempt which
     194     *  tries to rename the corresponding file object by calling renameItem(...). If this rename fails the old name of the
     195     *  model item is restored and view is refreshed by sltHandleItemRenameAttempt. */
    192196    void sltRename();
    193197    void sltCopy();
     
    280284    void sltLocationComboCurrentChange(const QString &strLocation);
    281285    void sltSearchTextChanged(const QString &strText);
     286    /** m_pModel signals when an tree item is renamed. we try to apply this rename to the file system.
     287     *  if the file system rename fails we restore the old name of the item. See the comment of
     288     *  sltRename() for more details. */
     289    void sltHandleItemRenameAttempt(UIFileTableItem *pItem, QString strOldName, QString strNewName);
    282290
    283291private:
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette