diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-05-31 21:05:33 +0900 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-06-02 20:31:04 +0900 |
commit | e88a9aa83eacaa6a003ca440947fa20c9b598834 (patch) | |
tree | 4ac2b3afe0f9705c41fdc43f9aaf8987029841fc | |
parent | 9a65798daf3dc0e7991305ce759d42d40d2dc98c (diff) | |
download | subsurface-e88a9aa83eacaa6a003ca440947fa20c9b598834.tar.gz |
Once again try to fix the selection
Things got broken. Again. We no longer kept track of the selected dives in
our structures which broke statistics.
This attempts to fix that, but appears to still have a bug when selecting
trips. Sometimes this results in 0 dives being selected according to our
data structures, while Qt happily shows all dives of the trip as seected.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/divelistview.cpp | 28 | ||||
-rw-r--r-- | qt-ui/globe.cpp | 2 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 14 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 8 |
4 files changed, 48 insertions, 4 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 075f12d4a..5883ea615 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -210,7 +210,7 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex))); Q_FOREACH(const QModelIndex& index, newSelected.indexes()) { - if(index.column() != 0) + if (index.column() != 0) continue; const QAbstractItemModel *model = index.model(); @@ -218,16 +218,42 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS if (!dive) { // it's a trip! if (model->rowCount(index)) { QItemSelection selection; + struct dive *child = (struct dive*) model->data(index.child(0,0), TreeItemDT::DIVE_ROLE).value<void*>(); + while (child) { + select_dive(get_index_for_dive(child)); + child = child->next; + } selection.select(index.child(0,0), index.child(model->rowCount(index) -1 , 0)); selectionModel()->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows); selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::NoUpdate); if (!isExpanded(index)) expand(index); } + } else { + select_dive(get_index_for_dive(dive)); + } + } + Q_FOREACH(const QModelIndex& index, newDeselected.indexes()) { + if (index.column() != 0) + continue; + 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)) { + struct dive *child = (struct dive*) model->data(index.child(0,0), TreeItemDT::DIVE_ROLE).value<void*>(); + while (child) { + deselect_dive(get_index_for_dive(child)); + child = child->next; + } + } + } else { + deselect_dive(get_index_for_dive(dive)); } } 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))); + // now that everything is up to date, update the widgets + Q_EMIT currentDiveChanged(selected_dive); } diff --git a/qt-ui/globe.cpp b/qt-ui/globe.cpp index bf2369862..67a4fcd73 100644 --- a/qt-ui/globe.cpp +++ b/qt-ui/globe.cpp @@ -94,6 +94,8 @@ void GlobeGPS::centerOn(dive* dive) if (messageWidget->isVisible() && (!dive || dive_has_gps_location(dive))) { messageWidget->animatedHide(); } + if (!dive) + return; editingDiveCoords = 0; diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index e810dd6ee..55f11789f 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -272,6 +272,20 @@ void MainTab::updateDiveInfo(int dive) weightModel->clear(); addCylinder->setEnabled(false); addWeight->setEnabled(false); + ui->maximumDepthAllText->clear(); + ui->minimumDepthAllText->clear(); + ui->averageDepthAllText->clear(); + ui->maximumSacAllText->clear(); + ui->minimumSacAllText->clear(); + ui->averageSacAllText->clear(); + ui->divesAllText->clear(); + ui->maximumTemperatureAllText->clear(); + ui->minimumTemperatureAllText->clear(); + ui->averageTemperatureAllText->clear(); + ui->totalTimeAllText->clear(); + ui->averageTimeAllText->clear(); + ui->longestAllText->clear(); + ui->shortestAllText->clear(); } /* statisticsTab*/ /* we can access the stats_selection struct, but how do we ensure the relevant dives are selected diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index d3cd951d8..5a33bd4d5 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -63,9 +63,11 @@ void MainWindow::refreshDisplay() void MainWindow::current_dive_changed(int divenr) { - select_dive(divenr); - ui->globe->centerOn(get_dive(selected_dive)); - redrawProfile(); + if (amount_selected && divenr >= 0) { + select_dive(divenr); + ui->globe->centerOn(get_dive(selected_dive)); + redrawProfile(); + } ui->InfoWidget->updateDiveInfo(divenr); } |