aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-29 14:03:36 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-29 14:03:36 -0300
commit9cc04c1ca65424bb0c32aad17be80dd6887b4c65 (patch)
tree49409760398cdb22c2c4036677a2741fb0f4142c
parentf46a2d56bc12fd23c9d12dac0c47e944b2ecc27f (diff)
downloadsubsurface-9cc04c1ca65424bb0c32aad17be80dd6887b4c65.tar.gz
More work on bug 111, Sorting works as it should.
Sorting is now working as it should, changing from table to tree, keeping the selection from table to tree ( but there's a regression on tree to table conversion, I'll try to fix it in the following commit. ). this commit also cleans a lot of boilerplate code that I wrote to bypass a graphics bug, that I seem to have correctly fixed in this version. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
-rw-r--r--qt-ui/divelistview.cpp87
-rw-r--r--qt-ui/divelistview.h7
2 files changed, 32 insertions, 62 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 4944c5f02..5c2bfca70 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -32,24 +32,31 @@ void DiveListView::headerClicked(int i )
QItemSelection oldSelection = selectionModel()->selection();
QList<struct dive*> currentSelectedDives;
Q_FOREACH(const QModelIndex& index , oldSelection.indexes()){
+ if (index.column() != 0) // We only care about the dives, so, let's stick to rows and discard columns.
+ continue;
+
struct dive *d = (struct dive *) index.data(TreeItemDT::DIVE_ROLE).value<void*>();
- if (d){ // can also be a trip, so test.
+ if (d){
currentSelectedDives.push_back(d);
}
}
- reload( i == (int) TreeItemDT::NR ? DiveTripModel::TREE : DiveTripModel::LIST);
-
+ // clear the model, repopulate with new indexes.
+ reload( i == (int) TreeItemDT::NR ? DiveTripModel::TREE : DiveTripModel::LIST, false);
selectionModel()->clearSelection();
+
+ // repopulat the selections.
Q_FOREACH(struct dive *d, currentSelectedDives){
- QModelIndexList match = model()->match(model()->index(0,0), TreeItemDT::DIVE_ROLE, QVariant::fromValue<void*>(d), 1, Qt::MatchRecursive);
- selectionModel()->select(match.first(), QItemSelectionModel::Select | QItemSelectionModel::Rows);
+ QModelIndexList match = model()->match(model()->index(0,0), TreeItemDT::NR, d->number, 1, Qt::MatchRecursive);
+ QModelIndex idx = match.first();
+ selectionModel()->select( idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
}
-
+
+ // sort.
sortByColumn(i);
}
-void DiveListView::reload(DiveTripModel::Layout layout)
+void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
{
header()->setClickable(true);
connect(header(), SIGNAL(sectionPressed(int)), this, SLOT(headerClicked(int)), Qt::UniqueConnection);
@@ -58,10 +65,15 @@ void DiveListView::reload(DiveTripModel::Layout layout)
QAbstractItemModel *oldModel = m->sourceModel();
if (oldModel)
oldModel->deleteLater();
+
DiveTripModel *tripModel = new DiveTripModel(this);
tripModel->setLayout(layout);
m->setSourceModel(tripModel);
+
+ if(!forceSort)
+ return;
+
sortByColumn(0, Qt::DescendingOrder);
QModelIndex firstDiveOrTrip = m->index(0,0);
if (firstDiveOrTrip.isValid()) {
@@ -112,37 +124,6 @@ void DiveListView::toggleColumnVisibilityByIndex()
setColumnHidden(action->property("index").toInt(), !action->isChecked());
}
-void DiveListView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command)
-{
- //if (mouseClickSelection)
- QTreeView::setSelection(rect, command);
-}
-
-void DiveListView::mousePressEvent(QMouseEvent* event)
-{
- mouseClickSelection = true;
- QTreeView::mousePressEvent(event);
-}
-
-void DiveListView::mouseReleaseEvent(QMouseEvent* event)
-{
- mouseClickSelection = false;
- QTreeView::mouseReleaseEvent(event);
-}
-
-void DiveListView::keyPressEvent(QKeyEvent* event)
-{
- if (event->modifiers())
- mouseClickSelection = true;
- QTreeView::keyPressEvent(event);
-}
-
-void DiveListView::keyReleaseEvent(QKeyEvent* event)
-{
- mouseClickSelection = false;
- QWidget::keyReleaseEvent(event);
-}
-
void DiveListView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
{
if (!current.isValid())
@@ -163,21 +144,16 @@ void DiveListView::currentChanged(const QModelIndex& current, const QModelIndex&
void DiveListView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
{
- QList<QModelIndex> parents;
- Q_FOREACH(const QModelIndex& index, deselected.indexes()) {
- const QAbstractItemModel *model = index.model();
- struct dive *dive = (struct dive*) model->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
- if (!dive) { // it's a trip!
- if (model->rowCount(index)) {
- expand(index); // leave this - even if it looks like it shouldn't be here. looks like I've found a Qt bug.
- // the subselection is removed, but the painting is not. this cleans the area.
- }
- } else if (!parents.contains(index.parent())) {
- parents.push_back(index.parent());
- }
- }
+ QItemSelection newSelected = selected.size() ? selected : selectionModel()->selection();
+ QItemSelection newDeselected = deselected;
+
+ disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
+ disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
+
+ Q_FOREACH(const QModelIndex& index, newSelected.indexes()) {
+ if(index.column() != 0)
+ continue;
- Q_FOREACH(const QModelIndex& index, selected.indexes()) {
const QAbstractItemModel *model = index.model();
struct dive *dive = (struct dive*) model->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
if (!dive) { // it's a trip!
@@ -190,11 +166,10 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
expand(index);
}
}
- } else if (!parents.contains(index.parent())) {
- parents.push_back(index.parent());
}
}
- Q_FOREACH(const QModelIndex& index, parents)
- expand(index);
+ QTreeView::selectionChanged(selectionModel()->selection(), newDeselected);
+ connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
+ connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
}
diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h
index 99154d4ac..35c401a20 100644
--- a/qt-ui/divelistview.h
+++ b/qt-ui/divelistview.h
@@ -24,12 +24,7 @@ public:
DiveListView(QWidget *parent = 0);
void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
void currentChanged(const QModelIndex& current, const QModelIndex& previous);
- void mousePressEvent(QMouseEvent* event);
- void mouseReleaseEvent(QMouseEvent* event);
- void keyPressEvent(QKeyEvent* event);
- void keyReleaseEvent(QKeyEvent*);
- void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command);
- void reload(DiveTripModel::Layout layout = DiveTripModel::TREE);
+ void reload(DiveTripModel::Layout layout = DiveTripModel::TREE, bool forceSort = true);
public slots:
void toggleColumnVisibilityByIndex();