PDA

View Full Version : fast alternative for hiding of rows of QTableView



kerim
7th April 2011, 08:13
hi folks,

i am writing a software that displays logfile data within a QTableView.
in some cases the displayed file content can be several 100 MB of size.

I allready managed to put the whole content into the tableview by subclassing QAbstractTableModel in one go, so that works fine.

but now the problem and would like to get some ideas in regard to this, hope u can help:

there shall be filtering functionalities like: "find all rows that match a certain pattern"

i thought maybe hiding the appropriate rows could be an option to display the result, but that turned out to be quite slow:


QModelIndex start = tableModel->index(0, 0);
QModelIndexList list = tableModel->match(start,
Qt::DisplayRole,
"*DEBUG*",
-1,
Qt::MatchWildcard);

ui->tableView->setUpdatesEnabled(false);
for(ushort idx=0; idx<list.size();idx++)
{
int row = list[idx].row();
ui->tableView->hideRow(row);
}
ui->tableView->setUpdatesEnabled(true);


i know that the parameters for tableModel::match(...) do certainly have an effect on speed, but i think its more the amount of rows within the table.

so, any ideas how this kind of filtering could be implemented without having a bottle neck as this?
hiding rows is not mandatory, so if u have other ideas how to display results i would appreciate.

thnx alot.
greets.

ChrisW67
7th April 2011, 08:17
QSortFilterProxyModel is made for this sort of thing.

kerim
7th April 2011, 09:19
ok, that looks good, but:

within that qt-example u mention i changed the initial data to be 1000 times bigger (that is far less than i have) and what happens is,
that the filtering functionality gets slow too: whenever one changes the filter it takes several seconds for the results view to be updated,
so i am curious if this QSortFilterProxyModel is not just a kind of wrapper for the initial attempt of filtering (see my code above).

the speed issue is still there i think.

kerim
7th April 2011, 15:11
i would like to ask few question about filtering via QSortFilterProxyModel:

in regard to the example from http://doc.qt.nokia.com/latest/itemviews-customsortfiltermodel.html

1. is it possible to be notified when the proxyfilter has finished filtering ? i would like the user to be informed that its working in the background and need to know when it has finished.

2. after having finished i would like the user to be able to click on the view that contains the filter results and have the source-view containing the model-data to jump to the row the user has selected. how do i do that!?

thnx alot.

Added after 39 minutes:

ok, i figured out how to do point 2:


// //////////////////////////////////
void MainWindow::on_tableView_2_pressed(QModelIndex index)
// //////////////////////////////////
{
ui->tableView->setCurrentIndex( proxyModel->mapToSource(index) );
}

but the currentIndex is not alway the topmost index within my source-view,
means the relevant row within my source-view is not always the topmost row within the scroll-area.
how do i achive that ??

it would be nice if someone has an idea how to achive point 1 :(

Added after 8 minutes:

:rolleyes: ok, again for those interested:


// //////////////////////////////////
void MainWindow::on_tableView_2_pressed(QModelIndex index)
// //////////////////////////////////
{
ui->tableView->setCurrentIndex( proxyModel->mapToSource(index) );
ui->tableView->scrollTo(proxyModel->mapToSource(index), QAbstractItemView::PositionAtTop);
}
does the magic.

but still dont know how to achive point 1, help is appreciated.