summaryrefslogtreecommitdiffstats
path: root/archivemodel.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2013-06-14 15:14:58 +0200
committerArno <am@disconnect.de>2013-06-14 15:14:58 +0200
commitdeee95ecd5d92b93956061d4e6ae63246b8bc928 (patch)
tree8a12b93a118e78b431e526aa2178651f346d3200 /archivemodel.cpp
parent35f5a0c5e13df3a0a41ef990b886a98ce2374a5c (diff)
downloadSheMov-deee95ecd5d92b93956061d4e6ae63246b8bc928.tar.gz
SheMov-deee95ecd5d92b93956061d4e6ae63246b8bc928.tar.bz2
SheMov-deee95ecd5d92b93956061d4e6ae63246b8bc928.zip
Filter recursive
Well, well... Recursion isn't that bad at all. Filter experimental ArchiveView recursive by the following rules: * check children _and_ parents for filter * if any child _or_ parent matches, accept the current row, parents and children. The column is converted to a QString and matched by QRegExp, so don't try to match numbers or anything else.
Diffstat (limited to 'archivemodel.cpp')
-rw-r--r--archivemodel.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/archivemodel.cpp b/archivemodel.cpp
index 9ef2eac..a6c3c4a 100644
--- a/archivemodel.cpp
+++ b/archivemodel.cpp
@@ -99,6 +99,38 @@ bool ArchiveModel::setData(const QModelIndex &idx, const QVariant &value, int ro
return false;
}
+bool ArchiveModel::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 ArchiveModel::removeNode(const QModelIndex &idx){
if(!idx.isValid()){
return false;
@@ -182,6 +214,17 @@ void ArchiveModel::collectorFinished(){
setRoot(item);
}
+bool ArchiveModel::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;
+}
+
void ArchiveModel::emitDatabaseError(const QSqlError &e){
QString databaseText = e.databaseText().isEmpty() ? tr("(none)") : e.databaseText();
QString driverText = e.driverText().isEmpty() ? tr("(none)") : e.driverText();