Commit 89b0e4c0 authored by hjk's avatar hjk

TreeModel: API cleanup

- rename index{From->For}Item
- rename item{From->For}Index
- remove ununsed setColumnCount

Change-Id: I1cce9657e476dd1e8ffa9f7cdb2e646fab6884ab
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 9f269dfb
......@@ -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<PluginItem *>(m_model->itemFromIndex(sourceIndex));
auto item = dynamic_cast<PluginItem *>(m_model->itemForIndex(sourceIndex));
return item ? item->m_spec: 0;
}
......
......@@ -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<TreeItem*>(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);
......
......@@ -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;
......
......@@ -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<CMakeToolTreeItem *>(item);
return 0;
......
......@@ -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<BreakpointItem *>(item) : 0);
}
......
......@@ -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<DebuggerTreeItem *>(treeItem) : 0;
}
......
......@@ -264,7 +264,7 @@ public:
{
if (!idx.isValid())
return;
auto item = dynamic_cast<ToolTipWatchItem *>(itemFromIndex(idx));
auto item = dynamic_cast<ToolTipWatchItem *>(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);
......
......@@ -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);
}
......
......@@ -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<WatchItem *>(itemFromIndex(idx));
WatchItem *item = static_cast<WatchItem *>(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<WatchItem *>(m_model->itemFromIndex(idx));
return static_cast<WatchItem *>(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);
}
}
......
......@@ -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<KitNode *>(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);
......
......@@ -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<AddNewTree *>(item)->node() : 0;
}
......
......@@ -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<ToolChainTreeItem *>(item) : 0;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment