Changeset 101692 in vbox for trunk/src/VBox
- Timestamp:
- Oct 31, 2023 4:08:48 PM (13 months ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/settings
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsSelector.cpp
r101691 r101692 35 35 #include <QLayout> 36 36 #include <QPainter> 37 #include <QSortFilterProxyModel> 37 38 #include <QTabWidget> 38 39 #include <QToolButton> … … 245 246 /** Returns item with certain @a strLink. */ 246 247 QModelIndex findItem(const QString &strLink); 247 248 /** Sorts the contents of model by @a iColumn and @a enmOrder. */249 virtual void sort(int iColumn = 0, Qt::SortOrder enmOrder = Qt::AscendingOrder) RT_OVERRIDE;250 248 251 249 private: … … 438 436 } 439 437 440 void UISelectorDelegate::paint(QPainter *pPainter, const QStyleOptionViewItem &option, const QModelIndex & index) const438 void UISelectorDelegate::paint(QPainter *pPainter, const QStyleOptionViewItem &option, const QModelIndex &proxyIndex) const 441 439 { 442 440 /* Sanity checks: */ 443 441 AssertPtrReturnVoid(pPainter); 442 AssertReturnVoid(proxyIndex.isValid()); 443 444 /* Acquire model: */ 445 const QSortFilterProxyModel *pProxyModel = qobject_cast<const QSortFilterProxyModel*>(proxyIndex.model()); 446 AssertPtrReturnVoid(pProxyModel); 447 const UISelectorModel *pModel = qobject_cast<const UISelectorModel*>(pProxyModel->sourceModel()); 448 AssertPtrReturnVoid(pModel); 449 450 /* Acquire model index: */ 451 const QModelIndex index = pProxyModel->mapToSource(proxyIndex); 444 452 AssertReturnVoid(index.isValid()); 445 446 /* Acquire model: */447 const UISelectorModel *pModel = qobject_cast<const UISelectorModel*>(index.model());448 453 449 454 /* Acquire item properties: */ … … 725 730 } 726 731 727 void UISelectorModel::sort(int /* iColumn */, Qt::SortOrder enmOrder)728 {729 /* Prepare empty list for sorted items: */730 QList<UISelectorTreeViewItem*> sortedItems;731 732 /* For each of items: */733 const int iItemCount = m_pRootItem->childCount();734 for (int iItemPos = 0; iItemPos < iItemCount; ++iItemPos)735 {736 /* Get iterated item/id: */737 UISelectorTreeViewItem *pItem = m_pRootItem->childItem(iItemPos);738 const int iID = pItem->id();739 740 /* Gather suitable position in the list of sorted items: */741 int iInsertPosition = 0;742 for (; iInsertPosition < sortedItems.size(); ++iInsertPosition)743 {744 /* Get sorted item/id: */745 UISelectorTreeViewItem *pSortedItem = sortedItems.at(iInsertPosition);746 const int iSortedID = pSortedItem->id();747 748 /* Apply sorting rule: */749 if ( ((enmOrder == Qt::AscendingOrder) && (iID < iSortedID))750 || ((enmOrder == Qt::DescendingOrder) && (iID > iSortedID)))751 break;752 }753 754 /* Insert iterated item into sorted position: */755 sortedItems.insert(iInsertPosition, pItem);756 }757 758 /* Update corresponding model-indexes: */759 m_pRootItem->setChildren(sortedItems);760 beginMoveRows(root(), 0, iItemCount - 1, root(), 0);761 endMoveRows();762 }763 764 732 Qt::ItemFlags UISelectorModel::flags(const QModelIndex &specifiedIndex) const 765 733 { … … 790 758 { 791 759 /* Sanity check: */ 792 UISelectorModel *pModel = qobject_cast<UISelectorModel*>(model()); 760 QSortFilterProxyModel *pProxyModel = qobject_cast<QSortFilterProxyModel*>(model()); 761 AssertPtrReturn(pProxyModel, QITreeView::minimumSizeHint()); 762 UISelectorModel *pModel = qobject_cast<UISelectorModel*>(pProxyModel->sourceModel()); 793 763 AssertPtrReturn(pModel, QITreeView::minimumSizeHint()); 794 764 … … 820 790 { 821 791 /* Configure tree-view: */ 792 setSortingEnabled(true); 793 sortByColumn(0, Qt::AscendingOrder); 822 794 setFrameShape(QFrame::NoFrame); 823 795 viewport()->setAutoFillBackground(false); … … 925 897 , m_pTreeView(0) 926 898 , m_pModel(0) 899 , m_pModelProxy(0) 927 900 { 928 901 prepare(); … … 990 963 { 991 964 int iID = -1; 992 const QModelIndex index = m_pTreeView->currentIndex(); 965 const QModelIndex proxyIndex = m_pTreeView->currentIndex(); 966 const QModelIndex index = m_pModelProxy->mapToSource(proxyIndex); 993 967 if (index.isValid()) 994 968 iID = m_pModel->data(index, UISelectorModel::R_ItemId).toString().toInt(); … … 1008 982 { 1009 983 const QModelIndex index = m_pModel->findItem(iID); 1010 if (index.isValid()) 1011 m_pTreeView->setCurrentIndex(index); 1012 } 1013 1014 void UISettingsSelectorTreeView::sltHandleCurrentChanged(const QModelIndex &index, 984 const QModelIndex proxyIndex = m_pModelProxy->mapFromSource(index); 985 if (proxyIndex.isValid()) 986 m_pTreeView->setCurrentIndex(proxyIndex); 987 } 988 989 void UISettingsSelectorTreeView::sltHandleCurrentChanged(const QModelIndex &proxyIndex, 1015 990 const QModelIndex & /* previousIndex */) 1016 991 { 992 const QModelIndex index = m_pModelProxy->mapToSource(proxyIndex); 1017 993 if (index.isValid()) 1018 994 { … … 1033 1009 if (m_pModel) 1034 1010 { 1035 m_pTreeView->setModel(m_pModel); 1036 m_pTreeView->setRootIndex(m_pModel->root()); 1011 /* Create proxy-model: */ 1012 m_pModelProxy = new QSortFilterProxyModel(m_pTreeView); 1013 if (m_pModelProxy) 1014 { 1015 /* Configure proxy-model: */ 1016 m_pModelProxy->setSortRole(UISelectorModel::R_ItemId); 1017 m_pModelProxy->setSourceModel(m_pModel); 1018 m_pTreeView->setModel(m_pModelProxy); 1019 } 1020 const QModelIndex proxyIndex = m_pModelProxy->mapFromSource(m_pModel->root()); 1021 m_pTreeView->setRootIndex(proxyIndex); 1037 1022 } 1038 1023 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsSelector.h
r101691 r101692 41 41 class QAction; 42 42 class QActionGroup; 43 class QSortFilterProxyModel; 43 44 class QTabWidget; 44 45 class QTreeWidget; … … 184 185 185 186 /** Holds the tree-view instance. */ 186 UISelectorTreeView *m_pTreeView;187 UISelectorTreeView *m_pTreeView; 187 188 /** Holds the model instance. */ 188 UISelectorModel *m_pModel; 189 UISelectorModel *m_pModel; 190 /** Holds the proxy-model instance. */ 191 QSortFilterProxyModel *m_pModelProxy; 189 192 }; 190 193
Note:
See TracChangeset
for help on using the changeset viewer.