- Timestamp:
- Apr 22, 2019 11:21:29 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIFormEditorWidget.cpp
r78244 r78246 21 21 #include <QHeaderView> 22 22 #include <QItemEditorFactory> 23 #include <QSortFilterProxyModel> 23 24 #include <QStyledItemDelegate> 24 25 #include <QVBoxLayout> … … 153 154 QString valueToString() const; 154 155 156 /** Returns whether the row is visible. */ 157 bool isVisible() const; 158 155 159 /** Returns value cast to bool. */ 156 160 bool toBool() const; … … 221 225 /** Returns the child item with @a iIndex. */ 222 226 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 */; 223 230 224 231 /** Returns flags for item with certain @a index. */ … … 271 278 272 279 280 /** QSortFilterProxyModel subclass used as the Form Editor proxy-model. */ 281 class UIFormEditorProxyModel : public QSortFilterProxyModel 282 { 283 Q_OBJECT; 284 285 public: 286 287 /** Constructs the Form Editor proxy-model passing @a pParent to the base-class. */ 288 UIFormEditorProxyModel(QObject *pParent = 0); 289 290 protected: 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 273 297 /********************************************************************************************************************************* 274 298 * Class UIFormEditorCell implementation. * … … 308 332 { 309 333 return m_cells.at(UIFormEditorDataType_Value)->text(); 334 } 335 336 bool UIFormEditorRow::isVisible() const 337 { 338 return m_comValue.GetVisible(); 310 339 } 311 340 … … 524 553 /* Return corresponding row: */ 525 554 return m_dataList[iIndex]; 555 } 556 557 QModelIndex 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(); 526 566 } 527 567 … … 763 803 764 804 /********************************************************************************************************************************* 805 * Class UIFormEditorProxyModel implementation. * 806 *********************************************************************************************************************************/ 807 808 UIFormEditorProxyModel::UIFormEditorProxyModel(QObject *pParent /* = 0 */) 809 : QSortFilterProxyModel(pParent) 810 { 811 } 812 813 bool 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 /********************************************************************************************************************************* 765 830 * Class UIFormEditorWidget implementation. * 766 831 *********************************************************************************************************************************/ … … 827 892 m_pTableModel = new UIFormEditorModel(m_pTableView); 828 893 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 } 830 903 831 904 /* We certainly have abstract item delegate: */
Note:
See TracChangeset
for help on using the changeset viewer.