VirtualBox

Changeset 76297 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Dec 19, 2018 4:32:48 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699. Refactoring on file system model/item/view classes. episode 2

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
5 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r76211 r76297  
    859859        src/guestctrl/UIFileManagerPanel.h \
    860860        src/guestctrl/UIFileManagerSessionPanel.h \
    861         src/guestctrl/UIFileManagerModel.h \
     861        src/guestctrl/UICustomFileSystemModel.h \
    862862        src/guestctrl/UIFileManagerTable.h \
    863863        src/guestctrl/UIGuestControlInterface.h \
     
    10151015        src/guestctrl/UIFileManagerPanel.h \
    10161016        src/guestctrl/UIFileManagerSessionPanel.h \
    1017         src/guestctrl/UIFileManagerModel.h \
     1017        src/guestctrl/UICustomFileSystemModel.h \
    10181018        src/guestctrl/UIFileManagerTable.h \
    10191019        src/guestctrl/UIGuestControlInterface.h \
     
    15881588        src/guestctrl/UIFileManagerPanel.cpp \
    15891589        src/guestctrl/UIFileManagerSessionPanel.cpp \
    1590         src/guestctrl/UIFileManagerModel.cpp \
     1590        src/guestctrl/UICustomFileSystemModel.cpp \
    15911591        src/guestctrl/UIFileManagerTable.cpp \
    15921592        src/guestctrl/UIGuestControlInterface.cpp \
     
    17671767        src/guestctrl/UIFileManagerPanel.cpp \
    17681768        src/guestctrl/UIFileManagerSessionPanel.cpp \
    1769         src/guestctrl/UIFileManagerModel.cpp \
     1769        src/guestctrl/UICustomFileSystemModel.cpp \
    17701770        src/guestctrl/UIFileManagerTable.cpp \
    17711771        src/guestctrl/UIGuestControlInterface.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UICustomFileSystemModel.cpp

    r76296 r76297  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIFileManagerModel class implementation.
     3 * VBox Qt GUI - UICustomFileSystemModel class implementation.
    44 */
    55
     
    2626/* GUI includes: */
    2727# include "UIErrorString.h"
    28 # include "UIFileManagerModel.h"
     28# include "UICustomFileSystemModel.h"
    2929# include "UIFileManagerTable.h"
    3030# include "UIFileManager.h"
     
    3333#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3434
    35 const char* UIFileManagerModel::strUpDirectoryString = "..";
    36 
    37 UIGuestControlFileProxyModel::UIGuestControlFileProxyModel(QObject *parent /* = 0 */)
     35const char* UICustomFileSystemModel::strUpDirectoryString = "..";
     36
     37UICustomFileSystemProxyModel::UICustomFileSystemProxyModel(QObject *parent /* = 0 */)
    3838    :QSortFilterProxyModel(parent)
    3939    , m_fListDirectoriesOnTop(false)
     
    4141}
    4242
    43 void UIGuestControlFileProxyModel::setListDirectoriesOnTop(bool fListDirectoriesOnTop)
     43void UICustomFileSystemProxyModel::setListDirectoriesOnTop(bool fListDirectoriesOnTop)
    4444{
    4545    m_fListDirectoriesOnTop = fListDirectoriesOnTop;
    4646}
    4747
    48 bool UIGuestControlFileProxyModel::listDirectoriesOnTop() const
     48bool UICustomFileSystemProxyModel::listDirectoriesOnTop() const
    4949{
    5050    return m_fListDirectoriesOnTop;
    5151}
    5252
    53 bool UIGuestControlFileProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
     53bool UICustomFileSystemProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
    5454{
    5555    UIFileTableItem *pLeftItem = static_cast<UIFileTableItem*>(left.internalPointer());
     
    7373
    7474        /* If the sort column is QDateTime than handle it correctly: */
    75         if (sortColumn() == UIFileManagerModelColumn_ChangeTime)
    76         {
    77             QVariant dataLeft = pLeftItem->data(UIFileManagerModelColumn_ChangeTime);
    78             QVariant dataRight = pRightItem->data(UIFileManagerModelColumn_ChangeTime);
     75        if (sortColumn() == UICustomFileSystemModelColumn_ChangeTime)
     76        {
     77            QVariant dataLeft = pLeftItem->data(UICustomFileSystemModelColumn_ChangeTime);
     78            QVariant dataRight = pRightItem->data(UICustomFileSystemModelColumn_ChangeTime);
    7979            QDateTime leftDateTime = dataLeft.toDateTime();
    8080            QDateTime rightDateTime = dataRight.toDateTime();
     
    8282        }
    8383        /* When we show human readble sizes in size column sorting gets confused, so do it here: */
    84         else if(sortColumn() == UIFileManagerModelColumn_Size)
    85         {
    86             qulonglong leftSize = pLeftItem->data(UIFileManagerModelColumn_Size).toULongLong();
    87             qulonglong rightSize = pRightItem->data(UIFileManagerModelColumn_Size).toULongLong();
     84        else if(sortColumn() == UICustomFileSystemModelColumn_Size)
     85        {
     86            qulonglong leftSize = pLeftItem->data(UICustomFileSystemModelColumn_Size).toULongLong();
     87            qulonglong rightSize = pRightItem->data(UICustomFileSystemModelColumn_Size).toULongLong();
    8888            return (leftSize < rightSize);
    8989
     
    9393}
    9494
    95 UIFileManagerModel::UIFileManagerModel(QObject *parent)
     95UICustomFileSystemModel::UICustomFileSystemModel(QObject *parent)
    9696    : QAbstractItemModel(parent)
    9797    , m_pParent(qobject_cast<UIFileManagerTable*>(parent))
     
    100100}
    101101
    102 UIFileTableItem* UIFileManagerModel::rootItem() const
     102UIFileTableItem* UICustomFileSystemModel::rootItem() const
    103103{
    104104    if (!m_pParent)
     
    107107}
    108108
    109 UIFileManagerModel::~UIFileManagerModel()
     109UICustomFileSystemModel::~UICustomFileSystemModel()
    110110{}
    111111
    112 int UIFileManagerModel::columnCount(const QModelIndex &parent) const
     112int UICustomFileSystemModel::columnCount(const QModelIndex &parent) const
    113113{
    114114    if (parent.isValid())
     
    123123}
    124124
    125 bool UIFileManagerModel::setData(const QModelIndex &index, const QVariant &value, int role)
     125bool UICustomFileSystemModel::setData(const QModelIndex &index, const QVariant &value, int role)
    126126{
    127127    if (index.isValid() && role == Qt::EditRole)
     
    148148}
    149149
    150 QVariant UIFileManagerModel::data(const QModelIndex &index, int role) const
     150QVariant UICustomFileSystemModel::data(const QModelIndex &index, int role) const
    151151{
    152152    if (!index.isValid())
     
    159159    {
    160160        /* dont show anything but the name for up directories: */
    161         if (item->isUpDirectory() && index.column() != UIFileManagerModelColumn_Name)
     161        if (item->isUpDirectory() && index.column() != UICustomFileSystemModelColumn_Name)
    162162            return QVariant();
    163163        /* Format date/time column: */
     
    169169        }
    170170        /* Decide whether to show human-readable file object sizes: */
    171         if (index.column() == UIFileManagerModelColumn_Size)
     171        if (index.column() == UICustomFileSystemModelColumn_Size)
    172172        {
    173173            if (m_fShowHumanReadableSizes)
     
    207207}
    208208
    209 Qt::ItemFlags UIFileManagerModel::flags(const QModelIndex &index) const
     209Qt::ItemFlags UICustomFileSystemModel::flags(const QModelIndex &index) const
    210210{
    211211    if (!index.isValid())
     
    220220}
    221221
    222 QVariant UIFileManagerModel::headerData(int section, Qt::Orientation orientation,
     222QVariant UICustomFileSystemModel::headerData(int section, Qt::Orientation orientation,
    223223                               int role) const
    224224{
     
    233233}
    234234
    235 QModelIndex UIFileManagerModel::index(UIFileTableItem* item)
     235QModelIndex UICustomFileSystemModel::index(UIFileTableItem* item)
    236236{
    237237    if (!item)
     
    240240}
    241241
    242 QModelIndex UIFileManagerModel::index(int row, int column, const QModelIndex &parent)
     242QModelIndex UICustomFileSystemModel::index(int row, int column, const QModelIndex &parent)
    243243            const
    244244{
     
    263263
    264264
    265 QModelIndex UIFileManagerModel::parent(const QModelIndex &index) const
     265QModelIndex UICustomFileSystemModel::parent(const QModelIndex &index) const
    266266{
    267267    if (!index.isValid())
     
    277277}
    278278
    279 int UIFileManagerModel::rowCount(const QModelIndex &parent) const
     279int UICustomFileSystemModel::rowCount(const QModelIndex &parent) const
    280280{
    281281    if (parent.column() > 0)
     
    291291}
    292292
    293 void UIFileManagerModel::signalUpdate()
     293void UICustomFileSystemModel::signalUpdate()
    294294{
    295295    emit layoutChanged();
    296296}
    297297
    298 QModelIndex UIFileManagerModel::rootIndex() const
     298QModelIndex UICustomFileSystemModel::rootIndex() const
    299299{
    300300    if (!rootItem())
     
    304304}
    305305
    306 void UIFileManagerModel::beginReset()
     306void UICustomFileSystemModel::beginReset()
    307307{
    308308    beginResetModel();
    309309}
    310310
    311 void UIFileManagerModel::endReset()
     311void UICustomFileSystemModel::endReset()
    312312{
    313313    endResetModel();
    314314}
    315315
    316 void UIFileManagerModel::setShowHumanReadableSizes(bool fShowHumanReadableSizes)
     316void UICustomFileSystemModel::setShowHumanReadableSizes(bool fShowHumanReadableSizes)
    317317{
    318318    m_fShowHumanReadableSizes = fShowHumanReadableSizes;
    319319}
    320320
    321 bool UIFileManagerModel::showHumanReadableSizes() const
     321bool UICustomFileSystemModel::showHumanReadableSizes() const
    322322{
    323323    return m_fShowHumanReadableSizes;
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UICustomFileSystemModel.h

    r76296 r76297  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIFileManagerModel class declaration.
     3 * VBox Qt GUI - UICustomFileSystemModel class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef ___UIFileManagerModel_h___
    19 #define ___UIFileManagerModel_h___
     18#ifndef ___UICustomFileSystemModel_h___
     19#define ___UICustomFileSystemModel_h___
    2020
    2121/* Qt includes: */
     
    3030class UIFileManagerTable;
    3131
    32 enum UIFileManagerModelColumn
     32enum UICustomFileSystemModelColumn
    3333{
    34     UIFileManagerModelColumn_Name = 0,
    35     UIFileManagerModelColumn_Size,
    36     UIFileManagerModelColumn_ChangeTime,
    37     UIFileManagerModelColumn_Owner,
    38     UIFileManagerModelColumn_Permissions,
    39     UIFileManagerModelColumn_Max
     34    UICustomFileSystemModelColumn_Name = 0,
     35    UICustomFileSystemModelColumn_Size,
     36    UICustomFileSystemModelColumn_ChangeTime,
     37    UICustomFileSystemModelColumn_Owner,
     38    UICustomFileSystemModelColumn_Permissions,
     39    UICustomFileSystemModelColumn_Max
    4040};
    4141
    4242/** A QSortFilterProxyModel extension used in file tables. Modifies some
    4343 *  of the base class behavior like lessThan(..) */
    44 class UIGuestControlFileProxyModel : public QSortFilterProxyModel
     44class UICustomFileSystemProxyModel : public QSortFilterProxyModel
    4545{
    4646
     
    4949public:
    5050
    51     UIGuestControlFileProxyModel(QObject *parent = 0);
     51    UICustomFileSystemProxyModel(QObject *parent = 0);
    5252
    5353    void setListDirectoriesOnTop(bool fListDirectoriesOnTop);
     
    6363};
    6464
    65 /** UIFileManagerModel serves as the model for a file structure.
     65/** UICustomFileSystemModel serves as the model for a file structure.
    6666 *  it supports a tree level hierarchy which can be displayed with
    6767 *  QTableView and/or QTreeView. Note the file structure data is not
    6868 *  kept by the model but rather by the containing widget which also servers
    6969 *  as the interface to functionality that this model provides.*/
    70 class UIFileManagerModel : public QAbstractItemModel
     70class UICustomFileSystemModel : public QAbstractItemModel
    7171{
    7272
     
    7575public:
    7676
    77     explicit UIFileManagerModel(QObject *parent = 0);
    78     ~UIFileManagerModel();
     77    explicit UICustomFileSystemModel(QObject *parent = 0);
     78    ~UICustomFileSystemModel();
    7979
    8080    QVariant       data(const QModelIndex &index, int role) const /* override */;
     
    110110
    111111
    112 #endif /* !___UIFileManagerModel_h___ */
     112#endif /* !___UICustomFileSystemModel_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.cpp

    r76177 r76297  
    2929# include "UIActionPool.h"
    3030# include "UIFileManager.h"
    31 # include "UIFileManagerModel.h"
     31# include "UICustomFileSystemModel.h"
    3232# include "UIFileManagerHostTable.h"
    3333# include "UIToolBar.h"
     
    105105        const QFileInfo &entryInfo = entryList.at(i);
    106106        if (entryInfo.baseName().isEmpty() || entryInfo.baseName() == "." ||
    107             entryInfo.baseName() == UIFileManagerModel::strUpDirectoryString)
     107            entryInfo.baseName() == UICustomFileSystemModel::strUpDirectoryString)
    108108            continue;
    109109        statistics.m_totalSize += entryInfo.size();
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.h

    r76177 r76297  
    2626
    2727/** This class scans the host file system by using the Qt API
    28     and connects to the UIFileManagerModel*/
     28    and connects to the UICustomFileSystemModel*/
    2929class UIFileManagerHostTable : public UIFileManagerTable
    3030{
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp

    r76296 r76297  
    4747# include "UIFileManagerTable.h"
    4848# include "UIFileManager.h"
    49 # include "UIFileManagerModel.h"
     49# include "UICustomFileSystemModel.h"
    5050# include "UIToolBar.h"
    5151
     
    586586    if (!isDirectory())
    587587        return false;
    588     if (data(0) == UIFileManagerModel::strUpDirectoryString)
     588    if (data(0) == UICustomFileSystemModel::strUpDirectoryString)
    589589        return true;
    590590    return false;
     
    762762
    763763
    764     m_pModel = new UIFileManagerModel(this);
     764    m_pModel = new UICustomFileSystemModel(this);
    765765    if (!m_pModel)
    766766        return;
    767767
    768     m_pProxyModel = new UIGuestControlFileProxyModel(this);
     768    m_pProxyModel = new UICustomFileSystemProxyModel(this);
    769769    if (!m_pProxyModel)
    770770        return;
     
    863863    const QString startPath("/");
    864864    QVector<QVariant> headData;
    865     headData.resize(UIFileManagerModelColumn_Max);
     865    headData.resize(UICustomFileSystemModelColumn_Max);
    866866    m_pRootItem = new UIFileTableItem(headData, 0, FileObjectType_Directory);
    867867    UIFileTableItem* startItem = new UIFileTableItem(createTreeItemData(startPath, 4096, QDateTime(),
     
    910910    if (isDirectoryMap)
    911911    {
    912         if (!map.contains(UIFileManagerModel::strUpDirectoryString)  && !isStartDir)
     912        if (!map.contains(UICustomFileSystemModel::strUpDirectoryString)  && !isStartDir)
    913913        {
    914914            QVector<QVariant> data;
    915             UIFileTableItem *item = new UIFileTableItem(createTreeItemData(UIFileManagerModel::strUpDirectoryString, 4096,
     915            UIFileTableItem *item = new UIFileTableItem(createTreeItemData(UICustomFileSystemModel::strUpDirectoryString, 4096,
    916916                                                                           QDateTime(), QString(), QString())
    917917                                                        , parent, FileObjectType_Directory);
    918918            item->setIsOpened(false);
    919             map.insert(UIFileManagerModel::strUpDirectoryString, item);
     919            map.insert(UICustomFileSystemModel::strUpDirectoryString, item);
    920920        }
    921         else if (map.contains(UIFileManagerModel::strUpDirectoryString)  && isStartDir)
     921        else if (map.contains(UICustomFileSystemModel::strUpDirectoryString)  && isStartDir)
    922922        {
    923             map.remove(UIFileManagerModel::strUpDirectoryString);
     923            map.remove(UICustomFileSystemModel::strUpDirectoryString);
    924924        }
    925925    }
     
    12811281    if (m_pRootItem)
    12821282    {
    1283         m_pRootItem->setData(UIFileManager::tr("Name"), UIFileManagerModelColumn_Name);
    1284         m_pRootItem->setData(UIFileManager::tr("Size"), UIFileManagerModelColumn_Size);
    1285         m_pRootItem->setData(UIFileManager::tr("Change Time"), UIFileManagerModelColumn_ChangeTime);
    1286         m_pRootItem->setData(UIFileManager::tr("Owner"), UIFileManagerModelColumn_Owner);
    1287         m_pRootItem->setData(UIFileManager::tr("Permissions"), UIFileManagerModelColumn_Permissions);
     1283        m_pRootItem->setData(UIFileManager::tr("Name"), UICustomFileSystemModelColumn_Name);
     1284        m_pRootItem->setData(UIFileManager::tr("Size"), UICustomFileSystemModelColumn_Size);
     1285        m_pRootItem->setData(UIFileManager::tr("Change Time"), UICustomFileSystemModelColumn_ChangeTime);
     1286        m_pRootItem->setData(UIFileManager::tr("Owner"), UICustomFileSystemModelColumn_Owner);
     1287        m_pRootItem->setData(UIFileManager::tr("Permissions"), UICustomFileSystemModelColumn_Permissions);
    12881288    }
    12891289    if (m_pWarningLabel)
     
    14321432{
    14331433    QVector<QVariant> data;
    1434     data.resize(UIFileManagerModelColumn_Max);
    1435     data[UIFileManagerModelColumn_Name]        = strName;
    1436     data[UIFileManagerModelColumn_Size]        = (qulonglong)size;
    1437     data[UIFileManagerModelColumn_ChangeTime]  = changeTime;
    1438     data[UIFileManagerModelColumn_Owner]       = strOwner;
    1439     data[UIFileManagerModelColumn_Permissions] = strPermissions;
     1434    data.resize(UICustomFileSystemModelColumn_Max);
     1435    data[UICustomFileSystemModelColumn_Name]        = strName;
     1436    data[UICustomFileSystemModelColumn_Size]        = (qulonglong)size;
     1437    data[UICustomFileSystemModelColumn_ChangeTime]  = changeTime;
     1438    data[UICustomFileSystemModelColumn_Owner]       = strOwner;
     1439    data[UICustomFileSystemModelColumn_Permissions] = strPermissions;
    14401440    return data;
    14411441}
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.h

    r76296 r76297  
    4747class UIActionPool;
    4848class UIFileTableItem;
    49 class UIFileManagerModel;
    50 class UIGuestControlFileProxyModel;
     49class UICustomFileSystemModel;
     50class UICustomFileSystemProxyModel;
    5151class UIGuestControlFileView;
    5252class UIToolBar;
     
    161161
    162162/** A UIFileTableItem instance is a tree node representing a file object (file, directory, etc). The tree contructed
    163     by these instances is the data source for the UIFileManagerModel. */
     163    by these instances is the data source for the UICustomFileSystemModel. */
    164164class UIFileTableItem
    165165{
     
    240240/** This class serves a base class for file table. Currently a guest version
    241241 *  and a host version are derived from this base. Each of these children
    242  *  populates the UIFileManagerModel by scanning the file system
     242 *  populates the UICustomFileSystemModel by scanning the file system
    243243 *  differently. The file structre kept in this class as a tree. */
    244244class UIFileManagerTable : public QIWithRetranslateUI<QWidget>
     
    342342    CGuestFsObjInfo  guestFsObjectInfo(const QString& path, CGuestSession &comGuestSession) const;
    343343    void             setSelectionDependentActionsEnabled(bool fIsEnabled);
    344     /** Creates a QList out of the parameters wrt. UIFileManagerModelColumn enum */
     344    /** Creates a QList out of the parameters wrt. UICustomFileSystemModelColumn enum */
    345345    QVector<QVariant>  createTreeItemData(const QString &strName, ULONG64 size, const QDateTime &changeTime,
    346346                                        const QString &strOwner, const QString &strPermissions);
     
    395395    bool            checkIfDeleteOK();
    396396
    397     UIFileManagerModel      *m_pModel;
     397    UICustomFileSystemModel      *m_pModel;
    398398    UIGuestControlFileView       *m_pView;
    399     UIGuestControlFileProxyModel *m_pProxyModel;
     399    UICustomFileSystemProxyModel *m_pProxyModel;
    400400
    401401    QGridLayout     *m_pMainLayout;
     
    404404    QILabel         *m_pWarningLabel;
    405405
    406     friend class     UIFileManagerModel;
     406    friend class     UICustomFileSystemModel;
    407407};
    408408
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