/** * Returns the model index of an item in the tree. * \param row The row where the item is located * \param column The column where the item is located * \param parent The parent of the item * \return The model index of the item */ QModelIndex StationTreeModel::index( int row, int column, const QModelIndex &parent /*= QModelIndex()*/ ) const { if (!hasIndex(row, column, parent)) return QModelIndex(); ModelTreeItem* parentItem; if (!parent.isValid()) parentItem = (ModelTreeItem*)(_rootItem); else parentItem = static_cast<ModelTreeItem*>(parent.internalPointer()); ModelTreeItem* childItem = (ModelTreeItem*)(parentItem->child(row)); if (childItem) { QModelIndex newIndex = createIndex(row, column, childItem); // assign ModelIndex to BaseItem so it can communicate with the model BaseItem* item = childItem->getItem(); if ( item != nullptr ) item->setModelIndex(newIndex); return newIndex; } else return QModelIndex(); }