From 87e0d5d46a697a9b737409a2d21438d88493e48b Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 4 Oct 2024 14:24:03 +0200 Subject: [PATCH] ProjectExplorer: Simplify some kit aspect models Change-Id: Ic494056102613f7a534b8da78540d4c951410cbe Reviewed-by: hjk --- src/plugins/debugger/debuggerkitaspect.cpp | 21 ++----------------- .../projectexplorer/toolchainkitaspect.cpp | 20 +----------------- src/plugins/qtsupport/qtkitaspect.cpp | 18 ++-------------- 3 files changed, 5 insertions(+), 54 deletions(-) diff --git a/src/plugins/debugger/debuggerkitaspect.cpp b/src/plugins/debugger/debuggerkitaspect.cpp index e70ab1430cd..5597e8fc204 100644 --- a/src/plugins/debugger/debuggerkitaspect.cpp +++ b/src/plugins/debugger/debuggerkitaspect.cpp @@ -43,18 +43,6 @@ public: , m_kit(kit) {} - QModelIndex indexForId(const QVariant &id) const - { - // The "None" item always comes last - const auto noneIndex = [this] { return index(rowCount() - 1, 0); }; - - if (id.isNull()) - return noneIndex(); - const TreeItem *const item = findItemAtLevel<1>( - [id](TreeItem *item) { return item->data(0, DebuggerTreeItem::IdRole) == id; }); - return item ? indexForItem(item) : noneIndex(); - } - void reset() { clear(); @@ -83,12 +71,6 @@ class DebuggerItemSortModel : public SortModel public: DebuggerItemSortModel(QObject *parent) : SortModel(parent) {} - QModelIndex indexForId(const QVariant &id) const - { - return mapFromSource( - static_cast(sourceModel())->indexForId(id)); - } - void reset() { static_cast(sourceModel())->reset(); } private: @@ -177,7 +159,8 @@ private: sortModel->reset(); sortModel->sort(0); const DebuggerItem * const item = DebuggerKitAspect::debugger(m_kit); - m_comboBox->setCurrentIndex(sortModel->indexForId(item ? item->id() : QVariant()).row()); + m_comboBox->setCurrentIndex( + m_comboBox->findData(item ? item->id() : QVariant(), DebuggerTreeItem::IdRole)); } QVariant currentId() const diff --git a/src/plugins/projectexplorer/toolchainkitaspect.cpp b/src/plugins/projectexplorer/toolchainkitaspect.cpp index 631a1cbccdd..aaac794c4d8 100644 --- a/src/plugins/projectexplorer/toolchainkitaspect.cpp +++ b/src/plugins/projectexplorer/toolchainkitaspect.cpp @@ -36,18 +36,6 @@ public: reset(); } - QModelIndex indexForBundleId(Id bundleId) const - { - if (!bundleId.isValid()) - return index(rowCount() - 1, 0); // The "none" item always comes last - const TreeItem *const item = findItemAtLevel<1>( - [bundleId](TreeItem *item) { - const auto tcItem = static_cast(item); - return tcItem->bundle && tcItem->bundle->bundleId() == bundleId; - }); - return item ? indexForItem(item) : QModelIndex(); - } - void reset() { clear(); @@ -77,12 +65,6 @@ class ToolchainSortModel : public SortModel public: ToolchainSortModel(QObject *parent) : SortModel(parent) {} - QModelIndex indexForBundleId(Id bundleId) const - { - return mapFromSource( - static_cast(sourceModel())->indexForBundleId(bundleId)); - } - void reset() { static_cast(sourceModel())->reset(); } private: @@ -222,7 +204,7 @@ private: int indexOf(QComboBox *cb, Id bundleId) { - return static_cast(cb->model())->indexForBundleId(bundleId).row(); + return cb->findData(bundleId.toSetting(), ToolchainTreeItem::BundleIdRole); } QWidget *m_mainWidget = nullptr; diff --git a/src/plugins/qtsupport/qtkitaspect.cpp b/src/plugins/qtsupport/qtkitaspect.cpp index 09bf54015a3..6910a87bbbe 100644 --- a/src/plugins/qtsupport/qtkitaspect.cpp +++ b/src/plugins/qtsupport/qtkitaspect.cpp @@ -39,15 +39,6 @@ public: , m_kit(kit) {} - QModelIndex indexForQtId(int id) const - { - if (id == -1) - return index(rowCount() - 1, 0); // The "No Qt" item always comes last - const TreeItem *const item = findItemAtLevel<1>( - [id](TreeItem *item) { return static_cast(item)->uniqueId() == id; }); - return item ? indexForItem(item) : QModelIndex(); - } - void reset() { clear(); @@ -71,12 +62,6 @@ class QtVersionSortModel : public SortModel public: QtVersionSortModel(QObject *parent) : SortModel(parent) {} - QModelIndex indexForId(int id) const - { - return mapFromSource( - static_cast(sourceModel())->indexForQtId(id)); - } - void reset() { static_cast(sourceModel())->reset(); } private: @@ -154,7 +139,8 @@ private: const auto sortModel = static_cast(m_combo->model()); sortModel->reset(); sortModel->sort(0); - m_combo->setCurrentIndex(sortModel->indexForId(QtKitAspect::qtVersionId(m_kit)).row()); + m_combo->setCurrentIndex( + m_combo->findData(QtKitAspect::qtVersionId(m_kit), QtVersionItem::IdRole)); } private: