ProjectExplorer: Simplify some kit aspect models

Change-Id: Ic494056102613f7a534b8da78540d4c951410cbe
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2024-10-04 14:24:03 +02:00
parent 2f0b7996d2
commit 87e0d5d46a
3 changed files with 5 additions and 54 deletions

View File

@@ -43,18 +43,6 @@ public:
, m_kit(kit) , 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() void reset()
{ {
clear(); clear();
@@ -83,12 +71,6 @@ class DebuggerItemSortModel : public SortModel
public: public:
DebuggerItemSortModel(QObject *parent) : SortModel(parent) {} DebuggerItemSortModel(QObject *parent) : SortModel(parent) {}
QModelIndex indexForId(const QVariant &id) const
{
return mapFromSource(
static_cast<DebuggerItemListModel *>(sourceModel())->indexForId(id));
}
void reset() { static_cast<DebuggerItemListModel *>(sourceModel())->reset(); } void reset() { static_cast<DebuggerItemListModel *>(sourceModel())->reset(); }
private: private:
@@ -177,7 +159,8 @@ private:
sortModel->reset(); sortModel->reset();
sortModel->sort(0); sortModel->sort(0);
const DebuggerItem * const item = DebuggerKitAspect::debugger(m_kit); 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 QVariant currentId() const

View File

@@ -36,18 +36,6 @@ public:
reset(); 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<ToolchainTreeItem *>(item);
return tcItem->bundle && tcItem->bundle->bundleId() == bundleId;
});
return item ? indexForItem(item) : QModelIndex();
}
void reset() void reset()
{ {
clear(); clear();
@@ -77,12 +65,6 @@ class ToolchainSortModel : public SortModel
public: public:
ToolchainSortModel(QObject *parent) : SortModel(parent) {} ToolchainSortModel(QObject *parent) : SortModel(parent) {}
QModelIndex indexForBundleId(Id bundleId) const
{
return mapFromSource(
static_cast<ToolchainListModel *>(sourceModel())->indexForBundleId(bundleId));
}
void reset() { static_cast<ToolchainListModel *>(sourceModel())->reset(); } void reset() { static_cast<ToolchainListModel *>(sourceModel())->reset(); }
private: private:
@@ -222,7 +204,7 @@ private:
int indexOf(QComboBox *cb, Id bundleId) int indexOf(QComboBox *cb, Id bundleId)
{ {
return static_cast<ToolchainSortModel *>(cb->model())->indexForBundleId(bundleId).row(); return cb->findData(bundleId.toSetting(), ToolchainTreeItem::BundleIdRole);
} }
QWidget *m_mainWidget = nullptr; QWidget *m_mainWidget = nullptr;

View File

@@ -39,15 +39,6 @@ public:
, m_kit(kit) , 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<QtVersionItem *>(item)->uniqueId() == id; });
return item ? indexForItem(item) : QModelIndex();
}
void reset() void reset()
{ {
clear(); clear();
@@ -71,12 +62,6 @@ class QtVersionSortModel : public SortModel
public: public:
QtVersionSortModel(QObject *parent) : SortModel(parent) {} QtVersionSortModel(QObject *parent) : SortModel(parent) {}
QModelIndex indexForId(int id) const
{
return mapFromSource(
static_cast<QtVersionListModel *>(sourceModel())->indexForQtId(id));
}
void reset() { static_cast<QtVersionListModel *>(sourceModel())->reset(); } void reset() { static_cast<QtVersionListModel *>(sourceModel())->reset(); }
private: private:
@@ -154,7 +139,8 @@ private:
const auto sortModel = static_cast<QtVersionSortModel *>(m_combo->model()); const auto sortModel = static_cast<QtVersionSortModel *>(m_combo->model());
sortModel->reset(); sortModel->reset();
sortModel->sort(0); 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: private: