aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-29 11:51:33 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-29 11:51:33 -0300
commitf46a2d56bc12fd23c9d12dac0c47e944b2ecc27f (patch)
treec9dd1915fca181ee7e189e2f847207c3b738232f
parentbb77f5a44e4c5d7a85e500437e69beb4ed38f264 (diff)
downloadsubsurface-f46a2d56bc12fd23c9d12dac0c47e944b2ecc27f.tar.gz
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 <tcanabrava@kde.org>
-rw-r--r--qt-ui/divelistview.cpp28
1 files changed, 10 insertions, 18 deletions
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<struct dive*> 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<void*>();
- 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<void*>(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)