# HG changeset patch # User sheepluva # Date 1335965614 -7200 # Node ID a0052cd32508c409a96a5018cc59d10e16652320 # Parent 6b44c0f11476d8e99fd011d7bafa89e083410d0f rooms list + reorder filter chain for better performance (sorting and full-text search are now last step, not first) + automatically restore custom column widths and sort settings... diff -r 6b44c0f11476 -r a0052cd32508 QTfrontend/ui/page/pageroomslist.cpp --- a/QTfrontend/ui/page/pageroomslist.cpp Wed May 02 14:30:22 2012 +0200 +++ b/QTfrontend/ui/page/pageroomslist.cpp Wed May 02 15:33:34 2012 +0200 @@ -152,7 +152,13 @@ connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onFilterChanged())); connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection); + // save header state on change + connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), + this, SLOT(saveHeaderState())); + connect(roomsList->horizontalHeader(), SIGNAL(sectionResized), + this, SLOT(saveHeaderState())); + // sorting connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), this, SLOT(onSortIndicatorChanged(int, Qt::SortOrder))); } @@ -490,6 +496,10 @@ void PageRoomsList::setModel(RoomsListModel * model) { + // filter chain: + // model -> stateFilteredModel -> schemeFilteredModel -> + // -> weaponsFilteredModel -> roomsModel (search filter+sorting) + if (roomsModel == NULL) { roomsModel = new QSortFilterProxyModel(this); @@ -514,28 +524,32 @@ schemeFilteredModel->setFilterCaseSensitivity(Qt::CaseInsensitive); weaponsFilteredModel->setFilterCaseSensitivity(Qt::CaseInsensitive); - stateFilteredModel->setSourceModel(roomsModel); schemeFilteredModel->setSourceModel(stateFilteredModel); weaponsFilteredModel->setSourceModel(schemeFilteredModel); + roomsModel->setSourceModel(weaponsFilteredModel); - roomsList->setModel(schemeFilteredModel); + // let the table view display the last model in the filter chain + roomsList->setModel(roomsModel); } - roomsModel->setSourceModel(model); + stateFilteredModel->setSourceModel(model); roomsList->hideColumn(RoomsListModel::StateColumn); QHeaderView * h = roomsList->horizontalHeader(); + if (!restoreHeaderState()) + { + h->resizeSection(RoomsListModel::PlayerCountColumn, 32); + h->resizeSection(RoomsListModel::TeamCountColumn, 32); + h->resizeSection(RoomsListModel::OwnerColumn, 100); + h->resizeSection(RoomsListModel::MapColumn, 100); + h->resizeSection(RoomsListModel::SchemeColumn, 100); + h->resizeSection(RoomsListModel::WeaponsColumn, 100); + } + h->setSortIndicatorShown(true); - h->setResizeMode(RoomsListModel::NameColumn, QHeaderView::Stretch); - h->resizeSection(RoomsListModel::PlayerCountColumn, 32); - h->resizeSection(RoomsListModel::TeamCountColumn, 32); - h->resizeSection(RoomsListModel::OwnerColumn, 100); - h->resizeSection(RoomsListModel::MapColumn, 100); - h->resizeSection(RoomsListModel::SchemeColumn, 100); - h->resizeSection(RoomsListModel::WeaponsColumn, 100); } @@ -580,3 +594,18 @@ weaponsFilteredModel->setFilterWildcard( QString("*%1*").arg(CBWeapons->currentText())); } + + +bool PageRoomsList::restoreHeaderState() +{ + if (!m_gameSettings->contains("roomslist_header")) + return false; + return roomsList->horizontalHeader()->restoreState( + m_gameSettings->value("roomslist_header").toByteArray()); +} + +void PageRoomsList::saveHeaderState() +{ + m_gameSettings->setValue( + "roomslist_header", roomsList->horizontalHeader()->saveState()); +} diff -r 6b44c0f11476 -r a0052cd32508 QTfrontend/ui/page/pageroomslist.h --- a/QTfrontend/ui/page/pageroomslist.h Wed May 02 14:30:22 2012 +0200 +++ b/QTfrontend/ui/page/pageroomslist.h Wed May 02 15:33:34 2012 +0200 @@ -77,6 +77,7 @@ void onJoinConfirmation(const QString &); void onSortIndicatorChanged(int logicalIndex, Qt::SortOrder order); void onFilterChanged(); + void saveHeaderState(); private: QSettings * m_gameSettings; @@ -87,6 +88,7 @@ AmmoSchemeModel * ammoSchemeModel; + bool restoreHeaderState(); }; #endif