在此之前,我询问a question
关于我们需要表示多个列过滤,以表示适合多个过滤器模式的行。在处理近乎庞大的数据集时加快QSortFilterProxyModel过滤
现在,当处理大表(通过big
我的意思是大约200,000行和4列),如果我们有一个大的表(通常这是过滤器模式的前2个字符中最差),过滤会变得很慢。
那么你对此有何建议?
注:我有自己的高性能源数据模型基于this
例如巫喂约1秒
编辑1
我的该行数的视场改变我的方法(而不是QStandardItemModel
)从这个:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
if (/* filtering is enable*/) {
bool _res = sourceModel()->data(sourceModel()->index(source_row, 0, source_parent)).toString().contains(/*RegExp for column 0*/);
for (int col = 0; col < columnCount(); col++) {
_res &= sourceModel()->data(sourceModel()->index(source_row, col + 1, source_parent)).toString().contains(/*RegExp for column col + 1*/);
}
return _res;
}
return true;
}
要这样:
bool DataFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
if (_enable) {
return (sourceModel()->index(source_row, 0, source_parent.child(source_row, 0)).data().toString().contains(/*string for column 0*/))
&& sourceModel()->index(source_row, 1, source_parent.child(source_row, 1)).data().toString().contains(/*string for column 1*/))
&& sourceModel()->index(source_row, 2, source_parent.child(source_row, 2)).data().toString().contains(/*string for column 2*/))
&& sourceModel()->index(source_row, 3, source_parent.child(source_row, 3)).data().toString().contains(/*string for column 3*/));
}
return true;
}
查找工作Perfect.Now过滤工作就像一个魅力无延迟
1.剖析模型性能。 2.不要使用正则表达式进行过滤,编写自己的方法。 3.如果您确实需要大数据支持 - 请将内存中的SQLite作为模型和过滤的来源。 –
您可以抛弃QSortFilterProxyModel并将其替换为您自己的专用构建实现;由于您知道您的应用程序的特定需求,因此您可能可以将您的实现设计为比QSortFilterProxyModel更高效,而QSortFilterProxyModel必须是通用的,并且不能对与其交互的代码的行为作出任何假设。 –
@ JeremyFriesner.So你说我们应该忘记'QSortFilterProxyModel'.如果我们只需要过滤,在源数据模型(从QAbstractTableModel派生)中实现过滤是否是个好主意?如果没有,我会听你的建议。 – IMAN4K