diff options
Diffstat (limited to 'smtreemodel.cpp')
-rw-r--r-- | smtreemodel.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/smtreemodel.cpp b/smtreemodel.cpp index 8b51bab..bcd1a8a 100644 --- a/smtreemodel.cpp +++ b/smtreemodel.cpp @@ -136,6 +136,26 @@ QModelIndex SmTreeModel::find(const QVariant &value, int column, const QModelInd return QModelIndex(); } +QModelIndex SmTreeModel::findRecursive(const QVariant &value, int column, const QModelIndex &parent) const{ + SmTreeItem *parentItem = 0; + if(!parent.isValid()){ + return QModelIndex(); + }else{ + parentItem = static_cast<SmTreeItem*>(parent.internalPointer()); + } + for(int i = 0; i < parentItem->childCount(); ++i){ + SmTreeItem *child = parentItem->child(i); + if(child->childCount()){ + return findRecursive(value, column, createIndex(i, column, child)); + } + if(child->data(column) == value){ + return createIndex(i, column, child); + } + } + QModelIndex next = index(parent.row() + 1, column, parent.parent()); + return findRecursive(value, column, next); +} + bool SmTreeModel::setRoot(SmTreeItem *rootItem){ if(mRootItem){ beginResetModel(); @@ -159,13 +179,7 @@ void SmTreeModel::reparent(const QModelIndex &idx, const QModelIndex &newParent) if(!idx.isValid()){ return; } - SmTreeItem *parentItem = 0; SmTreeItem *item = static_cast<SmTreeItem*>(idx.internalPointer()); - if(newParent == QModelIndex()){ - parentItem = root(); - }else{ - parentItem = static_cast<SmTreeItem*>(newParent.internalPointer()); - } QList<QVariant> data; for(int i = 0; i < item->columnCount(); ++i){ data << item->data(i); |