VirtualBox

Changeset 78246 in vbox for trunk


Ignore:
Timestamp:
Apr 22, 2019 11:21:29 AM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9434: Import Appliance wizard: Form Editor widget: Implementing filter proxy-model allowing to hide invisible form table items.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIFormEditorWidget.cpp

    r78244 r78246  
    2121#include <QHeaderView>
    2222#include <QItemEditorFactory>
     23#include <QSortFilterProxyModel>
    2324#include <QStyledItemDelegate>
    2425#include <QVBoxLayout>
     
    153154    QString valueToString() const;
    154155
     156    /** Returns whether the row is visible. */
     157    bool isVisible() const;
     158
    155159    /** Returns value cast to bool. */
    156160    bool toBool() const;
     
    221225    /** Returns the child item with @a iIndex. */
    222226    QITableViewRow *childItem(int iIndex) const;
     227
     228    /** Returns the index of the item in the model specified by the given @a iRow, @a iColumn and @a parentIdx. */
     229    virtual QModelIndex index(int iRow, int iColumn, const QModelIndex &parentIdx = QModelIndex()) const /* override */;
    223230
    224231    /** Returns flags for item with certain @a index. */
     
    271278
    272279
     280/** QSortFilterProxyModel subclass used as the Form Editor proxy-model. */
     281class UIFormEditorProxyModel : public QSortFilterProxyModel
     282{
     283    Q_OBJECT;
     284
     285public:
     286
     287    /** Constructs the Form Editor proxy-model passing @a pParent to the base-class. */
     288    UIFormEditorProxyModel(QObject *pParent = 0);
     289
     290protected:
     291
     292    /** Returns whether item in the row indicated by the given @a iSourceRow and @a srcParenIdx should be included in the model. */
     293    virtual bool filterAcceptsRow(int iSourceRow, const QModelIndex &srcParenIdx) const /* override */;
     294};
     295
     296
    273297/*********************************************************************************************************************************
    274298*   Class UIFormEditorCell implementation.                                                                                       *
     
    308332{
    309333    return m_cells.at(UIFormEditorDataType_Value)->text();
     334}
     335
     336bool UIFormEditorRow::isVisible() const
     337{
     338    return m_comValue.GetVisible();
    310339}
    311340
     
    524553    /* Return corresponding row: */
    525554    return m_dataList[iIndex];
     555}
     556
     557QModelIndex UIFormEditorModel::index(int iRow, int iColumn, const QModelIndex &parentIdx /* = QModelIndex() */) const
     558{
     559    /* No index for unknown items: */
     560    if (!hasIndex(iRow, iColumn, parentIdx))
     561        return QModelIndex();
     562
     563    /* Provide index users with packed item pointer: */
     564    UIFormEditorRow *pItem = iRow >= 0 && iRow < m_dataList.size() ? m_dataList.at(iRow) : 0;
     565    return pItem ? createIndex(iRow, iColumn, pItem) : QModelIndex();
    526566}
    527567
     
    763803
    764804/*********************************************************************************************************************************
     805*   Class UIFormEditorProxyModel implementation.                                                                                 *
     806*********************************************************************************************************************************/
     807
     808UIFormEditorProxyModel::UIFormEditorProxyModel(QObject *pParent /* = 0 */)
     809    : QSortFilterProxyModel(pParent)
     810{
     811}
     812
     813bool UIFormEditorProxyModel::filterAcceptsRow(int iSourceRow, const QModelIndex &sourceParent) const
     814{
     815    /* Acquire actual index of source model: */
     816    QModelIndex i = sourceModel()->index(iSourceRow, 0, sourceParent);
     817    if (i.isValid())
     818    {
     819        /* Get packed item pointer: */
     820        UIFormEditorRow *pItem = static_cast<UIFormEditorRow*>(i.internalPointer());
     821        /* Filter invisible items: */
     822        if (!pItem->isVisible())
     823            return false;
     824    }
     825    return true;
     826}
     827
     828
     829/*********************************************************************************************************************************
    765830*   Class UIFormEditorWidget implementation.                                                                                     *
    766831*********************************************************************************************************************************/
     
    827892            m_pTableModel = new UIFormEditorModel(m_pTableView);
    828893            if (m_pTableModel)
    829                 m_pTableView->setModel(m_pTableModel);
     894            {
     895                /* Create proxy-model: */
     896                UIFormEditorProxyModel *pProxyModel = new UIFormEditorProxyModel(m_pTableView);
     897                if (pProxyModel)
     898                {
     899                    pProxyModel->setSourceModel(m_pTableModel);
     900                    m_pTableView->setModel(pProxyModel);
     901                }
     902            }
    830903
    831904            /* We certainly have abstract item delegate: */
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