From 89b0e4c069c9089b2adf367480212bcbd3948116 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 22 Apr 2015 12:37:39 +0200 Subject: [PATCH] TreeModel: API cleanup - rename index{From->For}Item - rename item{From->For}Index - remove ununsed setColumnCount Change-Id: I1cce9657e476dd1e8ffa9f7cdb2e646fab6884ab Reviewed-by: Eike Ziller --- src/libs/extensionsystem/pluginview.cpp | 2 +- src/libs/utils/treemodel.cpp | 31 ++++++++----------- src/libs/utils/treemodel.h | 5 ++- .../cmakeprojectmanager/cmakesettingspage.cpp | 2 +- src/plugins/debugger/breakhandler.cpp | 2 +- src/plugins/debugger/debuggeroptionspage.cpp | 4 +-- .../debugger/debuggertooltipmanager.cpp | 4 +-- src/plugins/debugger/registerhandler.cpp | 2 +- src/plugins/debugger/watchhandler.cpp | 14 ++++----- src/plugins/projectexplorer/kitmodel.cpp | 6 ++-- .../projectexplorer/projectwizardpage.cpp | 4 +-- .../projectexplorer/toolchainoptionspage.cpp | 4 +-- 12 files changed, 37 insertions(+), 43 deletions(-) diff --git a/src/libs/extensionsystem/pluginview.cpp b/src/libs/extensionsystem/pluginview.cpp index c5437c9de32..a0b87a51cfb 100644 --- a/src/libs/extensionsystem/pluginview.cpp +++ b/src/libs/extensionsystem/pluginview.cpp @@ -385,7 +385,7 @@ void PluginView::setFilter(const QString &filter) PluginSpec *PluginView::pluginForIndex(const QModelIndex &index) const { const QModelIndex &sourceIndex = m_sortModel->mapToSource(index); - auto item = dynamic_cast(m_model->itemFromIndex(sourceIndex)); + auto item = dynamic_cast(m_model->itemForIndex(sourceIndex)); return item ? item->m_spec: 0; } diff --git a/src/libs/utils/treemodel.cpp b/src/libs/utils/treemodel.cpp index 4390dd5e737..76aed344c34 100644 --- a/src/libs/utils/treemodel.cpp +++ b/src/libs/utils/treemodel.cpp @@ -783,7 +783,7 @@ void TreeItem::setFlags(Qt::ItemFlags flags) QModelIndex TreeItem::index() const { QTC_ASSERT(m_model, return QModelIndex()); - return m_model->indexFromItem(this); + return m_model->indexForItem(this); } void TreeItem::setModel(TreeModel *model) @@ -887,7 +887,7 @@ QModelIndex TreeModel::parent(const QModelIndex &idx) const if (!idx.isValid()) return QModelIndex(); - const TreeItem *item = itemFromIndex(idx); + const TreeItem *item = itemForIndex(idx); QTC_ASSERT(item, return QModelIndex()); const TreeItem *parent = item->parent(); if (!parent || parent == m_root) @@ -911,7 +911,7 @@ int TreeModel::rowCount(const QModelIndex &idx) const return m_root->rowCount(); if (idx.column() > 0) return 0; - const TreeItem *item = itemFromIndex(idx); + const TreeItem *item = itemForIndex(idx); QTC_ASSERT(item, return 0); return item->rowCount(); } @@ -926,7 +926,7 @@ int TreeModel::columnCount(const QModelIndex &idx) const bool TreeModel::setData(const QModelIndex &idx, const QVariant &data, int role) { - TreeItem *item = itemFromIndex(idx); + TreeItem *item = itemForIndex(idx); bool res = item ? item->setData(idx.column(), data, role) : false; if (res) emit dataChanged(idx, idx); @@ -935,7 +935,7 @@ bool TreeModel::setData(const QModelIndex &idx, const QVariant &data, int role) QVariant TreeModel::data(const QModelIndex &idx, int role) const { - TreeItem *item = itemFromIndex(idx); + TreeItem *item = itemForIndex(idx); return item ? item->data(idx.column(), role) : QVariant(); } @@ -949,7 +949,7 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation, bool TreeModel::hasChildren(const QModelIndex &idx) const { - TreeItem *item = itemFromIndex(idx); + TreeItem *item = itemForIndex(idx); return !item || item->hasChildren(); } @@ -957,7 +957,7 @@ Qt::ItemFlags TreeModel::flags(const QModelIndex &idx) const { if (!idx.isValid()) return 0; - TreeItem *item = itemFromIndex(idx); + TreeItem *item = itemForIndex(idx); return item ? item->flags(idx.column()) : (Qt::ItemIsEnabled|Qt::ItemIsSelectable); } @@ -966,7 +966,7 @@ bool TreeModel::canFetchMore(const QModelIndex &idx) const { if (!idx.isValid()) return false; - TreeItem *item = itemFromIndex(idx); + TreeItem *item = itemForIndex(idx); return item ? item->canFetchMore() : false; } @@ -974,7 +974,7 @@ void TreeModel::fetchMore(const QModelIndex &idx) { if (!idx.isValid()) return; - TreeItem *item = itemFromIndex(idx); + TreeItem *item = itemForIndex(idx); if (item) item->fetchMore(); } @@ -997,25 +997,20 @@ void TreeModel::setHeader(const QStringList &displays) m_columnCount = displays.size(); } -void TreeModel::setColumnCount(int columnCount) -{ - m_columnCount = columnCount; -} - QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const { CHECK_INDEX(parent); if (!hasIndex(row, column, parent)) return QModelIndex(); - const TreeItem *item = itemFromIndex(parent); + const TreeItem *item = itemForIndex(parent); QTC_ASSERT(item, return QModelIndex()); if (row >= item->rowCount()) return QModelIndex(); return createIndex(row, column, (void*)(item->child(row))); } -TreeItem *TreeModel::itemFromIndex(const QModelIndex &idx) const +TreeItem *TreeModel::itemForIndex(const QModelIndex &idx) const { CHECK_INDEX(idx); TreeItem *item = idx.isValid() ? static_cast(idx.internalPointer()) : m_root; @@ -1024,7 +1019,7 @@ TreeItem *TreeModel::itemFromIndex(const QModelIndex &idx) const return item; } -QModelIndex TreeModel::indexFromItem(const TreeItem *item) const +QModelIndex TreeModel::indexForItem(const TreeItem *item) const { QTC_ASSERT(item, return QModelIndex()); if (item == m_root) @@ -1065,7 +1060,7 @@ void TreeModel::removeItem(TreeItem *item) int pos = parent->m_children.indexOf(item); QTC_ASSERT(pos != -1, return); - QModelIndex idx = indexFromItem(parent); + QModelIndex idx = indexForItem(parent); beginRemoveRows(idx, pos, pos); item->m_parent = 0; parent->m_children.removeAt(pos); diff --git a/src/libs/utils/treemodel.h b/src/libs/utils/treemodel.h index 03d79170798..1ce85ef3343 100644 --- a/src/libs/utils/treemodel.h +++ b/src/libs/utils/treemodel.h @@ -276,12 +276,11 @@ public: TreeItem *rootItem() const; void setRootItem(TreeItem *item); - TreeItem *itemFromIndex(const QModelIndex &) const; - QModelIndex indexFromItem(const TreeItem *needle) const; + TreeItem *itemForIndex(const QModelIndex &) const; + QModelIndex indexForItem(const TreeItem *needle) const; void removeItems(); void setHeader(const QStringList &displays); - void setColumnCount(int columnCount); UntypedTreeLevelItems untypedLevelItems(int level = 0, TreeItem *start = 0) const; UntypedTreeLevelItems untypedLevelItems(TreeItem *start) const; diff --git a/src/plugins/cmakeprojectmanager/cmakesettingspage.cpp b/src/plugins/cmakeprojectmanager/cmakesettingspage.cpp index 295b0bf4cea..bb9ba4305bf 100644 --- a/src/plugins/cmakeprojectmanager/cmakesettingspage.cpp +++ b/src/plugins/cmakeprojectmanager/cmakesettingspage.cpp @@ -226,7 +226,7 @@ CMakeToolTreeItem *CMakeToolItemModel::cmakeToolItem(const Core::Id &id) const CMakeToolTreeItem *CMakeToolItemModel::cmakeToolItem(const QModelIndex &index) const { - TreeItem *item = itemFromIndex(index); + TreeItem *item = itemForIndex(index); if (item->level() == 2) return static_cast(item); return 0; diff --git a/src/plugins/debugger/breakhandler.cpp b/src/plugins/debugger/breakhandler.cpp index ee60ba1062f..28d3ed71ac9 100644 --- a/src/plugins/debugger/breakhandler.cpp +++ b/src/plugins/debugger/breakhandler.cpp @@ -534,7 +534,7 @@ void BreakHandler::updateMarkers() Breakpoint BreakHandler::findBreakpointByIndex(const QModelIndex &index) const { - TreeItem *item = itemFromIndex(index); + TreeItem *item = itemForIndex(index); return Breakpoint(item && item->parent() == rootItem() ? static_cast(item) : 0); } diff --git a/src/plugins/debugger/debuggeroptionspage.cpp b/src/plugins/debugger/debuggeroptionspage.cpp index 6d4f9417217..32653c25c6a 100644 --- a/src/plugins/debugger/debuggeroptionspage.cpp +++ b/src/plugins/debugger/debuggeroptionspage.cpp @@ -151,7 +151,7 @@ QModelIndex DebuggerItemModel::lastIndex() const { TreeItem *manualGroup = rootItem()->lastChild(); TreeItem *lastItem = manualGroup->lastChild(); - return lastItem ? indexFromItem(lastItem) : QModelIndex(); + return lastItem ? indexForItem(lastItem) : QModelIndex(); } DebuggerItem *DebuggerItemModel::currentDebugger() const @@ -183,7 +183,7 @@ void DebuggerItemModel::apply() void DebuggerItemModel::setCurrentIndex(const QModelIndex &index) { - TreeItem *treeItem = itemFromIndex(index); + TreeItem *treeItem = itemForIndex(index); m_currentTreeItem = treeItem && treeItem->level() == 2 ? static_cast(treeItem) : 0; } diff --git a/src/plugins/debugger/debuggertooltipmanager.cpp b/src/plugins/debugger/debuggertooltipmanager.cpp index b3c64958a72..14ae377d044 100644 --- a/src/plugins/debugger/debuggertooltipmanager.cpp +++ b/src/plugins/debugger/debuggertooltipmanager.cpp @@ -264,7 +264,7 @@ public: { if (!idx.isValid()) return; - auto item = dynamic_cast(itemFromIndex(idx)); + auto item = dynamic_cast(itemForIndex(idx)); if (!item) return; QByteArray iname = item->iname; @@ -473,7 +473,7 @@ public: void reexpand(const QModelIndex &idx) { - TreeItem *item = model.itemFromIndex(idx); + TreeItem *item = model.itemForIndex(idx); QTC_ASSERT(item, return); QByteArray iname = item->data(0, LocalsINameRole).toByteArray(); bool shouldExpand = model.m_expandedINames.contains(iname); diff --git a/src/plugins/debugger/registerhandler.cpp b/src/plugins/debugger/registerhandler.cpp index 545631c90f8..da667a2e07d 100644 --- a/src/plugins/debugger/registerhandler.cpp +++ b/src/plugins/debugger/registerhandler.cpp @@ -603,7 +603,7 @@ void RegisterHandler::setNumberFormat(const QByteArray &name, RegisterFormat for RegisterItem *reg = m_registerByName.value(name, 0); QTC_ASSERT(reg, return); reg->m_format = format; - QModelIndex index = indexFromItem(reg); + QModelIndex index = indexForItem(reg); emit dataChanged(index, index); } diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index cc27ae30c1d..59675a068f8 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -904,9 +904,9 @@ QVariant WatchModel::data(const QModelIndex &idx, int role) const if (role == BaseTreeView::ExtraIndicesForColumnWidth) { QModelIndexList l; foreach (TreeItem *item, m_watchRoot->children()) - l.append(indexFromItem(item)); + l.append(indexForItem(item)); foreach (TreeItem *item, m_returnRoot->children()) - l.append(indexFromItem(item)); + l.append(indexForItem(item)); return QVariant::fromValue(l); } return WatchModelBase::data(idx, role); @@ -917,7 +917,7 @@ bool WatchModel::setData(const QModelIndex &idx, const QVariant &value, int role if (!idx.isValid()) return false; // Triggered by ModelTester. - WatchItem *item = static_cast(itemFromIndex(idx)); + WatchItem *item = static_cast(itemForIndex(idx)); QTC_ASSERT(item, return false); switch (role) { @@ -1189,7 +1189,7 @@ void WatchModel::reinsertAllData() parent->insertChild(row, newItem); if (m_expandedINames.contains(parent->iname)) { emit inameIsExpanded(parent->iname); - emit itemIsExpanded(indexFromItem(parent)); + emit itemIsExpanded(indexForItem(parent)); } showEditValue(newItem); // FIXME: Needed? } @@ -1258,7 +1258,7 @@ void WatchModel::reexpandItems() { foreach (const QByteArray &iname, m_expandedINames) { if (WatchItem *item = findItem(iname)) { - emit itemIsExpanded(indexFromItem(item)); + emit itemIsExpanded(indexForItem(item)); emit inameIsExpanded(iname); } else { // Can happen. We might have stepped into another frame @@ -1534,7 +1534,7 @@ WatchModelBase *WatchHandler::model() const const WatchItem *WatchHandler::watchItem(const QModelIndex &idx) const { - return static_cast(m_model->itemFromIndex(idx)); + return static_cast(m_model->itemForIndex(idx)); } void WatchHandler::fetchMore(const QByteArray &iname) const @@ -1723,7 +1723,7 @@ void WatchHandler::resetLocation() void WatchHandler::setCurrentItem(const QByteArray &iname) { if (WatchItem *item = m_model->findItem(iname)) { - QModelIndex idx = m_model->indexFromItem(item); + QModelIndex idx = m_model->indexForItem(item); emit m_model->currentIndexRequested(idx); } } diff --git a/src/plugins/projectexplorer/kitmodel.cpp b/src/plugins/projectexplorer/kitmodel.cpp index eb3c68c6dfa..5296dcd1470 100644 --- a/src/plugins/projectexplorer/kitmodel.cpp +++ b/src/plugins/projectexplorer/kitmodel.cpp @@ -143,14 +143,14 @@ Kit *KitModel::kit(const QModelIndex &index) KitNode *KitModel::kitNode(const QModelIndex &index) { - TreeItem *n = itemFromIndex(index); + TreeItem *n = itemForIndex(index); return n && n->level() == 2 ? static_cast(n) : 0; } QModelIndex KitModel::indexOf(Kit *k) const { KitNode *n = findWorkingCopy(k); - return n ? indexFromItem(n) : QModelIndex(); + return n ? indexForItem(n) : QModelIndex(); } void KitModel::setDefaultKit(const QModelIndex &index) @@ -191,7 +191,7 @@ void KitModel::isAutoDetectedChanged() } if (oldParent && oldParent != newParent) { - beginMoveRows(indexFromItem(oldParent), idx, idx, indexFromItem(newParent), newParent->children().size()); + beginMoveRows(indexForItem(oldParent), idx, idx, indexForItem(newParent), newParent->children().size()); TreeItem *n = oldParent->children().at(idx); removeItem(n); newParent->appendChild(n); diff --git a/src/plugins/projectexplorer/projectwizardpage.cpp b/src/plugins/projectexplorer/projectwizardpage.cpp index 464df95ce24..2b157e29d82 100644 --- a/src/plugins/projectexplorer/projectwizardpage.cpp +++ b/src/plugins/projectexplorer/projectwizardpage.cpp @@ -383,7 +383,7 @@ bool ProjectWizardPage::expandTree(const QModelIndex &root) void ProjectWizardPage::setBestNode(AddNewTree *tree) { - QModelIndex index = tree ? m_model->indexFromItem(tree) : QModelIndex(); + QModelIndex index = tree ? m_model->indexForItem(tree) : QModelIndex(); m_ui->projectComboBox->setCurrentIndex(index); while (index.isValid()) { @@ -395,7 +395,7 @@ void ProjectWizardPage::setBestNode(AddNewTree *tree) FolderNode *ProjectWizardPage::currentNode() const { QModelIndex index = m_ui->projectComboBox->view()->currentIndex(); - TreeItem *item = m_model->itemFromIndex(index); + TreeItem *item = m_model->itemForIndex(index); return item ? static_cast(item)->node() : 0; } diff --git a/src/plugins/projectexplorer/toolchainoptionspage.cpp b/src/plugins/projectexplorer/toolchainoptionspage.cpp index 45e59926df4..8c985e21d63 100644 --- a/src/plugins/projectexplorer/toolchainoptionspage.cpp +++ b/src/plugins/projectexplorer/toolchainoptionspage.cpp @@ -357,7 +357,7 @@ void ToolChainOptionsWidget::createToolChain(ToolChainFactory *factory) m_manualRoot->appendChild(item); - m_toolChainView->setCurrentIndex(m_model.indexFromItem(item)); + m_toolChainView->setCurrentIndex(m_model.indexForItem(item)); } void ToolChainOptionsWidget::updateState() @@ -377,7 +377,7 @@ void ToolChainOptionsWidget::updateState() ToolChainTreeItem *ToolChainOptionsWidget::currentTreeItem() { QModelIndex index = m_toolChainView->currentIndex(); - TreeItem *item = m_model.itemFromIndex(index); + TreeItem *item = m_model.itemForIndex(index); return item && item->level() == 2 ? static_cast(item) : 0; }