summaryrefslogtreecommitdiffstats
path: root/smtreemodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'smtreemodel.cpp')
-rw-r--r--smtreemodel.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/smtreemodel.cpp b/smtreemodel.cpp
index b909fcd..b52859c 100644
--- a/smtreemodel.cpp
+++ b/smtreemodel.cpp
@@ -166,6 +166,49 @@ QModelIndex SmTreeModel::findRecursive(const QVariant &value, int column, const
return QModelIndex();
}
+bool SmTreeModel::matchRecursive(const QModelIndex &parent, const QRegExp &regex, int column) const {
+ if(!parent.isValid()){
+ return false;
+ }
+ // first try the parent itself
+ QString value = parent.data().toString();
+ if(value.isEmpty()){
+ return false;
+ }
+ if(value.contains(regex)){
+ return true;
+ }
+
+ // no match, check for children
+ SmTreeItem *item = static_cast<SmTreeItem*>(parent.internalPointer());
+ if(!item->childCount()){
+ //leaf, chech parents
+ return checkParents(item, regex, column);
+ }
+
+ // we have children, traverse them
+ bool retval = false;
+ for(int i = 0; i < item->childCount(); ++i){
+ QModelIndex newIdx = createIndex(i, column, item->child(i));
+ retval = matchRecursive(newIdx, regex, column);
+ if(retval){
+ break;
+ }
+ }
+ return retval;
+}
+
+bool SmTreeModel::checkParents(const SmTreeItem *item, const QRegExp &regex, int column) const {
+ while(item != root()){
+ QString value = item->data(column).toString();
+ if(value.contains(regex)){
+ return true;
+ }
+ item = item->parent();
+ }
+ return false;
+}
+
bool SmTreeModel::setRoot(SmTreeItem *rootItem){
if(mRootItem){
beginResetModel();