From f46a2d56bc12fd23c9d12dac0c47e944b2ecc27f Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 29 May 2013 11:51:33 -0300 Subject: Reimplement the Sort method to change from Tree / List, and remember selection. Things are working as they should, but I hit on -probably- a Qt bug that makes painting on the table view a bit weird ( it only updates the painting by moving the mouse around ). I'll try to fake the mouse movements in a couple of commits after this one. There's also a few columns that are not being correctly sorted, probably something to do with the SortRole. Signed-off-by: Tomaz Canabrava --- qt-ui/divelistview.cpp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 0e3f62793..4944c5f02 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -29,32 +29,24 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec void DiveListView::headerClicked(int i ) { - QModelIndexList oldSelection = selectionModel()->selectedRows(); + QItemSelection oldSelection = selectionModel()->selection(); QList currentSelectedDives; - Q_FOREACH(const QModelIndex& index , oldSelection){ + Q_FOREACH(const QModelIndex& index , oldSelection.indexes()){ struct dive *d = (struct dive *) index.data(TreeItemDT::DIVE_ROLE).value(); - if (d){ + if (d){ // can also be a trip, so test. currentSelectedDives.push_back(d); } } - if (i == (int) TreeItemDT::NR){ - reload(DiveTripModel::TREE); - }else{ - reload(DiveTripModel::LIST); - } - - QModelIndexList newSelection; - QItemSelection newSelection2; + reload( i == (int) TreeItemDT::NR ? DiveTripModel::TREE : DiveTripModel::LIST); + selectionModel()->clearSelection(); Q_FOREACH(struct dive *d, currentSelectedDives){ QModelIndexList match = model()->match(model()->index(0,0), TreeItemDT::DIVE_ROLE, QVariant::fromValue(d), 1, Qt::MatchRecursive); - if (match.count() == 0){ - qDebug() << "Well, this shouldn't happen."; - }else{ - newSelection << match.first(); - } + selectionModel()->select(match.first(), QItemSelectionModel::Select | QItemSelectionModel::Rows); } + + sortByColumn(i); } void DiveListView::reload(DiveTripModel::Layout layout) @@ -122,8 +114,8 @@ void DiveListView::toggleColumnVisibilityByIndex() void DiveListView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command) { - if (mouseClickSelection) - QTreeView::setSelection(rect, command); + //if (mouseClickSelection) + QTreeView::setSelection(rect, command); } void DiveListView::mousePressEvent(QMouseEvent* event) -- cgit v1.2.3-70-g09d2