VirtualBox

Changeset 76309 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 20, 2018 8:59:24 AM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699. Moving the ownership of the data to file model.

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

Legend:

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

    r76303 r76309  
    5353UIFileTableItem::~UIFileTableItem()
    5454{
    55     qDeleteAll(m_childItems);
    56     m_childItems.clear();
     55    reset();
    5756}
    5857
     
    6362    m_childItems.append(item);
    6463    m_childMap.insert(item->name(), item);
     64}
     65
     66void UIFileTableItem::reset()
     67{
     68    qDeleteAll(m_childItems);
     69    m_childItems.clear();
     70    m_childMap.clear();
     71    m_bIsOpened = false;
    6572}
    6673
     
    280287    , m_fShowHumanReadableSizes(false)
    281288{
    282 }
    283 
    284 UIFileTableItem* UICustomFileSystemModel::rootItem() const
    285 {
    286     if (!m_pParent)
    287         return 0;
    288     return m_pParent->m_pRootItem;
     289    initializeTree();
     290}
     291
     292UIFileTableItem* UICustomFileSystemModel::rootItem()
     293{
     294    return m_pRootItem;
     295}
     296
     297const UIFileTableItem* UICustomFileSystemModel::rootItem() const
     298{
     299    return m_pRootItem;
    289300}
    290301
    291302UICustomFileSystemModel::~UICustomFileSystemModel()
    292 {}
     303{
     304    delete m_pRootItem;
     305}
    293306
    294307int UICustomFileSystemModel::columnCount(const QModelIndex &parent) const
     
    422435}
    423436
    424 QModelIndex UICustomFileSystemModel::index(int row, int column, const QModelIndex &parent)
    425             const
     437QModelIndex UICustomFileSystemModel::index(int row, int column, const QModelIndex &parent) const
    426438{
    427439    if (!hasIndex(row, column, parent))
    428440        return QModelIndex();
    429441
    430     UIFileTableItem *parentItem;
    431 
    432     if (!parent.isValid())
    433         parentItem = rootItem();
    434     else
     442    const UIFileTableItem* parentItem = rootItem();
     443
     444    if (parent.isValid())
    435445        parentItem = static_cast<UIFileTableItem*>(parent.internalPointer());
     446
    436447    if (!parentItem)
    437448        return QModelIndex();
     
    463474    if (parent.column() > 0)
    464475        return 0;
    465     UIFileTableItem *parentItem = 0;
    466     if (!parent.isValid())
    467         parentItem = rootItem();
    468     else
     476    const UIFileTableItem *parentItem = rootItem();
     477    if (parent.isValid())
    469478        parentItem = static_cast<UIFileTableItem*>(parent.internalPointer());
    470479    if (!parentItem)
     
    496505}
    497506
     507void UICustomFileSystemModel::reset()
     508{
     509    beginResetModel();
     510    m_pRootItem->reset();
     511    endResetModel();
     512}
     513
    498514void UICustomFileSystemModel::setShowHumanReadableSizes(bool fShowHumanReadableSizes)
    499515{
     
    505521    return m_fShowHumanReadableSizes;
    506522}
     523
     524void UICustomFileSystemModel::initializeTree()
     525{
     526    QVector<QVariant> headData;
     527    headData.resize(UICustomFileSystemModelColumn_Max);
     528    m_pRootItem = new UIFileTableItem(headData, 0, KFsObjType_Directory);
     529}
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UICustomFileSystemModel.h

    r76303 r76309  
    5353
    5454    void appendChild(UIFileTableItem *child);
    55 
     55    void reset();
    5656    UIFileTableItem *child(int row) const;
    5757    /** Searches for the child by path and returns it if found. */
     
    141141/** UICustomFileSystemModel serves as the model for a file structure.
    142142 *  it supports a tree level hierarchy which can be displayed with
    143  *  QTableView and/or QTreeView. Note the file structure data is not
    144  *  kept by the model but rather by the containing widget which also servers
    145  *  as the interface to functionality that this model provides.*/
     143 *  QTableView and/or QTreeView. .*/
    146144class UICustomFileSystemModel : public QAbstractItemModel
    147145{
     
    170168    void           beginReset();
    171169    void           endReset();
     170    void           reset();
     171
    172172    void           setShowHumanReadableSizes(bool fShowHumanReadableSizes);
    173173    bool           showHumanReadableSizes() const;
     174    UIFileTableItem* rootItem();
     175    const UIFileTableItem* rootItem() const;
    174176
    175177    static const char* strUpDirectoryString;
    176178
    177179private:
    178 
    179     UIFileTableItem* rootItem() const;
     180    void                initializeTree();
     181    UIFileTableItem    *m_pRootItem;
    180182    void setupModelData(const QStringList &lines, UIFileTableItem *parent);
    181183    UIFileManagerTable *m_pParent;
    182     UIFileTableItem    *m_pRootItem;
    183184    bool                m_fShowHumanReadableSizes;
    184185
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.cpp

    r76301 r76309  
    286286    if (m_comGuestSession.isNull())
    287287        return;
    288     if (!m_pRootItem || m_pRootItem->childCount() <= 0)
    289         return;
    290     UIFileTableItem *startDirItem = m_pRootItem->child(0);
     288    if (!rootItem() || rootItem()->childCount() <= 0)
     289        return;
     290    UIFileTableItem *startDirItem = rootItem()->child(0);
    291291    if (!startDirItem)
    292292        return;
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.cpp

    r76300 r76309  
    294294void UIFileManagerHostTable::goToHomeDirectory()
    295295{
    296     if (!m_pRootItem || m_pRootItem->childCount() <= 0)
    297         return;
    298     UIFileTableItem *startDirItem = m_pRootItem->child(0);
     296    if (!rootItem() || rootItem()->childCount() <= 0)
     297        return;
     298    UIFileTableItem *startDirItem = rootItem()->child(0);
    299299    if (!startDirItem)
    300300        return;
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp

    r76301 r76309  
    511511    :QIWithRetranslateUI<QWidget>(pParent)
    512512    , m_eFileOperationType(FileOperationType_None)
    513     , m_pRootItem(0)
    514513    , m_pLocationLabel(0)
    515514    , m_pPropertiesDialog(0)
     
    528527UIFileManagerTable::~UIFileManagerTable()
    529528{
    530     delete m_pRootItem;
    531529}
    532530
     
    534532{
    535533    if (m_pModel)
    536         m_pModel->beginReset();
    537     delete m_pRootItem;
    538     m_pRootItem = 0;
    539     if (m_pModel)
    540         m_pModel->endReset();
     534        m_pModel->reset();
     535
    541536    if (m_pLocationComboBox)
    542537    {
     
    680675void UIFileManagerTable::initializeFileTree()
    681676{
    682     if (m_pRootItem)
    683         reset();
    684 
    685     /* Root item: */
     677    if (m_pModel)
     678        m_pModel->reset();
     679    if (!rootItem())
     680        return;
     681
    686682    const QString startPath("/");
    687     QVector<QVariant> headData;
    688     headData.resize(UICustomFileSystemModelColumn_Max);
    689     m_pRootItem = new UIFileTableItem(headData, 0, KFsObjType_Directory);
    690683    UIFileTableItem* startItem = new UIFileTableItem(createTreeItemData(startPath, 4096, QDateTime(),
    691684                                                                        "" /* owner */, "" /* permissions */),
    692                                                      m_pRootItem, KFsObjType_Directory);
     685                                                     rootItem(), KFsObjType_Directory);
    693686    startItem->setPath(startPath);
    694     m_pRootItem->appendChild(startItem);
     687    rootItem()->appendChild(startItem);
    695688    startItem->setIsOpened(false);
    696689    populateStartDirectory(startItem);
     
    11021095void UIFileManagerTable::retranslateUi()
    11031096{
    1104     if (m_pRootItem)
    1105     {
    1106         m_pRootItem->setData(UIFileManager::tr("Name"), UICustomFileSystemModelColumn_Name);
    1107         m_pRootItem->setData(UIFileManager::tr("Size"), UICustomFileSystemModelColumn_Size);
    1108         m_pRootItem->setData(UIFileManager::tr("Change Time"), UICustomFileSystemModelColumn_ChangeTime);
    1109         m_pRootItem->setData(UIFileManager::tr("Owner"), UICustomFileSystemModelColumn_Owner);
    1110         m_pRootItem->setData(UIFileManager::tr("Permissions"), UICustomFileSystemModelColumn_Permissions);
     1097    UIFileTableItem *pRootItem = rootItem();
     1098    if (pRootItem)
     1099    {
     1100        pRootItem->setData(UIFileManager::tr("Name"), UICustomFileSystemModelColumn_Name);
     1101        pRootItem->setData(UIFileManager::tr("Size"), UICustomFileSystemModelColumn_Size);
     1102        pRootItem->setData(UIFileManager::tr("Change Time"), UICustomFileSystemModelColumn_ChangeTime);
     1103        pRootItem->setData(UIFileManager::tr("Owner"), UICustomFileSystemModelColumn_Owner);
     1104        pRootItem->setData(UIFileManager::tr("Permissions"), UICustomFileSystemModelColumn_Permissions);
    11111105    }
    11121106    if (m_pWarningLabel)
     
    11751169UIFileTableItem *UIFileManagerTable::getStartDirectoryItem()
    11761170{
    1177     if (!m_pRootItem)
     1171    UIFileTableItem* pRootItem = rootItem();
     1172    if (!pRootItem)
    11781173        return 0;
    1179     if (m_pRootItem->childCount() <= 0)
     1174    if (pRootItem->childCount() <= 0)
    11801175        return 0;
    1181     return m_pRootItem->child(0);
     1176    return pRootItem->child(0);
    11821177}
    11831178
     
    12501245}
    12511246
    1252 
    12531247QVector<QVariant> UIFileManagerTable::createTreeItemData(const QString &strName, ULONG64 size, const QDateTime &changeTime,
    12541248                                                            const QString &strOwner, const QString &strPermissions)
     
    12621256    data[UICustomFileSystemModelColumn_Permissions] = strPermissions;
    12631257    return data;
     1258}
     1259
     1260UIFileTableItem* UIFileManagerTable::rootItem()
     1261{
     1262    if (!m_pModel)
     1263        return 0;
     1264    return m_pModel->rootItem();
    12641265}
    12651266
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.h

    r76301 r76309  
    256256    QVector<QVariant>  createTreeItemData(const QString &strName, ULONG64 size, const QDateTime &changeTime,
    257257                                        const QString &strOwner, const QString &strPermissions);
    258 
    259     UIFileTableItem         *m_pRootItem;
     258    UIFileTableItem*   rootItem();
     259
     260
    260261    QILabel                 *m_pLocationLabel;
    261262    UIPropertiesDialog      *m_pPropertiesDialog;
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