Originally Posted by
kerim
i was thinking about putting the patterns into a list and apply each of them successively to the source-table and keep in mind which rows of my source-table succeeded filtering previously for returning appropriate return value for
bool QSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
To copy to clipboard, switch view to plain text mode
Yes, you're right in the track. All you really need to do is to reimplement the filterAcceptsRow() and inside it get the source index:
QModelIndex sourceIndex
= sourceModel
()->index
( sourceRow,
0, sourceParent
);
QModelIndex sourceIndex = sourceModel()->index( sourceRow, 0, sourceParent );
To copy to clipboard, switch view to plain text mode
Get string value from the index:
QString value
= sourceIndex.
data().
toString();
QString value = sourceIndex.data().toString();
To copy to clipboard, switch view to plain text mode
And finally, check the value against each pattern:
foreach
( const QString &pattern, patterns
) { if( value.contains( pattern ) ) return true;
}
return false;
foreach( const QString &pattern, patterns ) {
if( value.contains( pattern ) ) return true;
}
return false;
To copy to clipboard, switch view to plain text mode
Originally Posted by
kerim
(another different annoying thing is that QSortFilterProxyModel has no signal that tells that filtering is done
?)
Yes it does, rowsRemoved() and rowsInserted() signals are emitted when ever the proxy model changes because of the filtering.
Added after 21 minutes:
Originally Posted by
kerim
i assume this is because the proxymodel lives in a different thread !?!?
besides getting some opinion from you on doing repetetive filtering requests, i
would also appreciate to get a hint if i am right by assuming the mentioned crashing
is caused by using proxyModel within different threads.
Yes, your are right.
Remember that most of Qt's classes are not thread-safe, this includes models and proxies.
Secondly, do remember that views can only live in main thread, because the painting must be done there.
Now, if you modify the model (or proxy model) from another thread the change will most likely trigger the view (which is connected to your model) to update itself.
When the view is being repainted it will read the underlying model. At that time you have two threads reading and changing the model at same time and there is nothing to protect against it, no mutexes or anything.
If you are going to use models in another thread then make sure that no other thread can access it. And don't attach a view to that model (or any proxy) either.
Bookmarks