mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
selection: move dive selection, current dive and dc through signals
To reduce access of global variables. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
616dbd9671
commit
72a15c46d9
10 changed files with 47 additions and 36 deletions
|
@ -202,7 +202,7 @@ void setSelection(const std::vector<dive *> &selection, dive *currentDive, int c
|
||||||
auto selectedDives = setSelectionCore(selection, currentDive, currentDc);
|
auto selectedDives = setSelectionCore(selection, currentDive, currentDc);
|
||||||
|
|
||||||
// Send the new selection to the UI.
|
// Send the new selection to the UI.
|
||||||
emit diveListNotifier.divesSelected(selectedDives, current_dive);
|
emit diveListNotifier.divesSelected(selectedDives, current_dive, currentDc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set selection, but try to keep the current dive. If current dive is not in selection,
|
// Set selection, but try to keep the current dive. If current dive is not in selection,
|
||||||
|
|
|
@ -111,7 +111,8 @@ signals:
|
||||||
void tripChanged(dive_trip *trip, TripField field);
|
void tripChanged(dive_trip *trip, TripField field);
|
||||||
|
|
||||||
// Selection changes
|
// Selection changes
|
||||||
void divesSelected(const QVector<dive *> &dives, dive *currentDive);
|
// currentDC == -1 -> keep current dive computer
|
||||||
|
void divesSelected(const QVector<dive *> &dives, dive *currentDive, int currentDC);
|
||||||
void tripSelected(dive_trip *trip, dive *currentDive);
|
void tripSelected(dive_trip *trip, dive *currentDive);
|
||||||
|
|
||||||
// Dive site signals. Add and delete events are sent per dive site and
|
// Dive site signals. Add and delete events are sent per dive site and
|
||||||
|
|
|
@ -225,7 +225,7 @@ void DiveListView::reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
// If items were selected, inform the selection model
|
// If items were selected, inform the selection model
|
||||||
void DiveListView::diveSelectionChanged(const QVector<QModelIndex> &indices, QModelIndex currentDive)
|
void DiveListView::diveSelectionChanged(const QVector<QModelIndex> &indices, QModelIndex currentDive, int currentDC)
|
||||||
{
|
{
|
||||||
// This is the entry point for programmatical selection changes.
|
// This is the entry point for programmatical selection changes.
|
||||||
// Set a flag so that selection changes are not further processed,
|
// Set a flag so that selection changes are not further processed,
|
||||||
|
@ -258,7 +258,14 @@ void DiveListView::diveSelectionChanged(const QVector<QModelIndex> &indices, QMo
|
||||||
}
|
}
|
||||||
setAnimated(oldAnimated);
|
setAnimated(oldAnimated);
|
||||||
|
|
||||||
selectionChangeDone();
|
// This is truly sad, but taking the list of selected indices and turning them
|
||||||
|
// into dives turned out to be unreasonably slow. Therefore, let's access
|
||||||
|
// the core list directly.
|
||||||
|
std::vector<dive *> selected = getDiveSelection();
|
||||||
|
selectDiveSitesOnMap(selected);
|
||||||
|
struct dive *current = currentDive.data(DiveTripModelBase::DIVE_ROLE).value<struct dive *>();
|
||||||
|
emit divesSelected(selected, current, currentDC);
|
||||||
|
|
||||||
programmaticalSelectionChange = false;
|
programmaticalSelectionChange = false;
|
||||||
|
|
||||||
// Set the currently activated row.
|
// Set the currently activated row.
|
||||||
|
@ -305,7 +312,14 @@ void DiveListView::tripSelected(QModelIndex trip, QModelIndex currentDive)
|
||||||
// funny side-effects).
|
// funny side-effects).
|
||||||
selectionModel()->setCurrentIndex(currentDive, QItemSelectionModel::Current);
|
selectionModel()->setCurrentIndex(currentDive, QItemSelectionModel::Current);
|
||||||
|
|
||||||
selectionChangeDone();
|
// This is truly sad, but taking the list of selected indices and turning them
|
||||||
|
// into dives turned out to be unreasonably slow. Therefore, let's access
|
||||||
|
// the core list directly.
|
||||||
|
std::vector<dive *> selection = getDiveSelection();
|
||||||
|
selectDiveSitesOnMap(selection);
|
||||||
|
struct dive *current = currentDive.data(DiveTripModelBase::DIVE_ROLE).value<struct dive *>();
|
||||||
|
emit divesSelected(selection, current, -1);
|
||||||
|
|
||||||
programmaticalSelectionChange = false;
|
programmaticalSelectionChange = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,7 +429,7 @@ void DiveListView::currentChanged(const QModelIndex ¤t, const QModelIndex&
|
||||||
scrollTo(current);
|
scrollTo(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::selectionChangeDone()
|
void DiveListView::selectDiveSitesOnMap(const std::vector<dive *> &dives)
|
||||||
{
|
{
|
||||||
#ifdef MAP_SUPPORT
|
#ifdef MAP_SUPPORT
|
||||||
// When receiving the divesSelected signal the main window will
|
// When receiving the divesSelected signal the main window will
|
||||||
|
@ -425,21 +439,15 @@ void DiveListView::selectionChangeDone()
|
||||||
// the dive-site selection is controlled by the filter not
|
// the dive-site selection is controlled by the filter not
|
||||||
// by the selected dives.
|
// by the selected dives.
|
||||||
if (!DiveFilter::instance()->diveSiteMode()) {
|
if (!DiveFilter::instance()->diveSiteMode()) {
|
||||||
// This is truly sad, but taking the list of selected indices and turning them
|
|
||||||
// into dive sites turned out to be unreasonably slow. Therefore, let's access
|
|
||||||
// the core list directly. In my tests, this went down from 700 to 0 ms!
|
|
||||||
QVector<dive_site *> selectedSites;
|
QVector<dive_site *> selectedSites;
|
||||||
selectedSites.reserve(amount_selected);
|
selectedSites.reserve(dives.size());
|
||||||
int i;
|
for (dive *d: dives) {
|
||||||
dive *d;
|
if (!d->hidden_by_filter && d->dive_site && !selectedSites.contains(d->dive_site))
|
||||||
for_each_dive(i, d) {
|
|
||||||
if (d->selected && !d->hidden_by_filter && d->dive_site && !selectedSites.contains(d->dive_site))
|
|
||||||
selectedSites.push_back(d->dive_site);
|
selectedSites.push_back(d->dive_site);
|
||||||
}
|
}
|
||||||
MapWidget::instance()->setSelected(selectedSites);
|
MapWidget::instance()->setSelected(selectedSites);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
emit divesSelected();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::selectTripItems(QModelIndex index)
|
void DiveListView::selectTripItems(QModelIndex index)
|
||||||
|
@ -524,7 +532,8 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS
|
||||||
// Display the new, processed, selection
|
// Display the new, processed, selection
|
||||||
QTreeView::selectionChanged(selectionModel()->selection(), newDeselected);
|
QTreeView::selectionChanged(selectionModel()->selection(), newDeselected);
|
||||||
|
|
||||||
selectionChangeDone();
|
selectDiveSitesOnMap(selection);
|
||||||
|
emit divesSelected(selection, newCurrent, -1);
|
||||||
|
|
||||||
programmaticalSelectionChange = false;
|
programmaticalSelectionChange = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,8 @@ public:
|
||||||
void loadImages();
|
void loadImages();
|
||||||
void loadWebImages();
|
void loadWebImages();
|
||||||
signals:
|
signals:
|
||||||
void divesSelected();
|
// currentDC = -1: don't change dc number.
|
||||||
|
void divesSelected(const std::vector<dive *> &dives, dive *currentDive, int currentDC);
|
||||||
public
|
public
|
||||||
slots:
|
slots:
|
||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
|
@ -51,13 +52,13 @@ slots:
|
||||||
void renumberDives();
|
void renumberDives();
|
||||||
void addDivesToTrip();
|
void addDivesToTrip();
|
||||||
void shiftTimes();
|
void shiftTimes();
|
||||||
void diveSelectionChanged(const QVector<QModelIndex> &indices, QModelIndex currentDive);
|
void diveSelectionChanged(const QVector<QModelIndex> &indices, QModelIndex currentDive, int currentDC);
|
||||||
void tripSelected(QModelIndex trip, QModelIndex currentDive);
|
void tripSelected(QModelIndex trip, QModelIndex currentDive);
|
||||||
private:
|
private:
|
||||||
void rowsInserted(const QModelIndex &parent, int start, int end) override;
|
void rowsInserted(const QModelIndex &parent, int start, int end) override;
|
||||||
void reset() override;
|
void reset() override;
|
||||||
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override;
|
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override;
|
||||||
void selectionChangeDone();
|
void selectDiveSitesOnMap(const std::vector<dive *> &dives);
|
||||||
void selectTripItems(QModelIndex index);
|
void selectTripItems(QModelIndex index);
|
||||||
DiveTripModelBase::Layout currentLayout;
|
DiveTripModelBase::Layout currentLayout;
|
||||||
QModelIndex contextMenuIndex;
|
QModelIndex contextMenuIndex;
|
||||||
|
|
|
@ -176,7 +176,7 @@ MainWindow::MainWindow() :
|
||||||
if (!QIcon::hasThemeIcon("window-close")) {
|
if (!QIcon::hasThemeIcon("window-close")) {
|
||||||
QIcon::setThemeName("subsurface");
|
QIcon::setThemeName("subsurface");
|
||||||
}
|
}
|
||||||
connect(diveList.get(), &DiveListView::divesSelected, this, &MainWindow::selectionChanged);
|
connect(diveList.get(), &DiveListView::divesSelected, this, &MainWindow::divesSelected);
|
||||||
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainWindow::readSettings);
|
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainWindow::readSettings);
|
||||||
for (int i = 0; i < NUM_RECENT_FILES; i++) {
|
for (int i = 0; i < NUM_RECENT_FILES; i++) {
|
||||||
actionsRecent[i] = new QAction(this);
|
actionsRecent[i] = new QAction(this);
|
||||||
|
@ -331,10 +331,10 @@ void MainWindow::updateAutogroup()
|
||||||
ui.actionAutoGroup->setChecked(divelog.autogroup);
|
ui.actionAutoGroup->setChecked(divelog.autogroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::selectionChanged()
|
void MainWindow::divesSelected(const std::vector<dive *> &selection, dive *currentDive, int currentDC)
|
||||||
{
|
{
|
||||||
mainTab->updateDiveInfo();
|
mainTab->updateDiveInfo();
|
||||||
if (current_dive)
|
if (currentDive)
|
||||||
enableDisableOtherDCsActions();
|
enableDisableOtherDCsActions();
|
||||||
profile->plotCurrentDive();
|
profile->plotCurrentDive();
|
||||||
#ifdef MAP_SUPPORT
|
#ifdef MAP_SUPPORT
|
||||||
|
|
|
@ -129,7 +129,7 @@ slots:
|
||||||
void on_actionReplanDive_triggered();
|
void on_actionReplanDive_triggered();
|
||||||
void on_action_Check_for_Updates_triggered();
|
void on_action_Check_for_Updates_triggered();
|
||||||
|
|
||||||
void selectionChanged();
|
void divesSelected(const std::vector<dive *> &selection, dive *currentDive, int currentDC);
|
||||||
void initialUiSetup();
|
void initialUiSetup();
|
||||||
|
|
||||||
void on_actionImportDiveLog_triggered();
|
void on_actionImportDiveLog_triggered();
|
||||||
|
|
|
@ -1370,7 +1370,7 @@ QModelIndex DiveTripModelTree::diveToIdx(const dive *d) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveTripModelTree::divesSelected(const QVector<dive *> &divesIn, dive *currentDive)
|
void DiveTripModelTree::divesSelected(const QVector<dive *> &divesIn, dive *currentDive, int currentDC)
|
||||||
{
|
{
|
||||||
QVector <dive *> dives = visibleDives(divesIn);
|
QVector <dive *> dives = visibleDives(divesIn);
|
||||||
|
|
||||||
|
@ -1382,7 +1382,7 @@ void DiveTripModelTree::divesSelected(const QVector<dive *> &divesIn, dive *curr
|
||||||
processByTrip(dives, [this, &indices] (dive_trip *trip, const QVector<dive *> &divesInTrip)
|
processByTrip(dives, [this, &indices] (dive_trip *trip, const QVector<dive *> &divesInTrip)
|
||||||
{ divesSelectedTrip(trip, divesInTrip, indices); });
|
{ divesSelectedTrip(trip, divesInTrip, indices); });
|
||||||
|
|
||||||
emit selectionChanged(indices, diveToIdx(currentDive));
|
emit selectionChanged(indices, diveToIdx(currentDive), currentDC);
|
||||||
|
|
||||||
// The current dive has changed. Transform the current dive into an index and pass it on to the view.
|
// The current dive has changed. Transform the current dive into an index and pass it on to the view.
|
||||||
currentChanged(currentDive);
|
currentChanged(currentDive);
|
||||||
|
@ -1659,7 +1659,7 @@ QModelIndex DiveTripModelList::diveToIdx(const dive *d) const
|
||||||
return createIndex(it - items.begin(), 0);
|
return createIndex(it - items.begin(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveTripModelList::divesSelected(const QVector<dive *> &divesIn, dive *currentDive)
|
void DiveTripModelList::divesSelected(const QVector<dive *> &divesIn, dive *currentDive, int currentDC)
|
||||||
{
|
{
|
||||||
QVector<dive *> dives = visibleDives(divesIn);
|
QVector<dive *> dives = visibleDives(divesIn);
|
||||||
|
|
||||||
|
@ -1679,7 +1679,7 @@ void DiveTripModelList::divesSelected(const QVector<dive *> &divesIn, dive *curr
|
||||||
indices.append(createIndex(j, 0, noParent));
|
indices.append(createIndex(j, 0, noParent));
|
||||||
}
|
}
|
||||||
|
|
||||||
emit selectionChanged(indices, diveToIdx(currentDive));
|
emit selectionChanged(indices, diveToIdx(currentDive), currentDC);
|
||||||
|
|
||||||
// The current dive has changed. Transform the current dive into an index and pass it on to the view.
|
// The current dive has changed. Transform the current dive into an index and pass it on to the view.
|
||||||
currentChanged(currentDive);
|
currentChanged(currentDive);
|
||||||
|
@ -1697,7 +1697,7 @@ void DiveTripModelList::tripSelected(dive_trip *trip, dive *currentDive)
|
||||||
for (int i = 0; i < trip->dives.nr; ++i)
|
for (int i = 0; i < trip->dives.nr; ++i)
|
||||||
dives.push_back(trip->dives.dives[i]);
|
dives.push_back(trip->dives.dives[i]);
|
||||||
|
|
||||||
divesSelected(dives, currentDive);
|
divesSelected(dives, currentDive, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple sorting helper for sorting against a criterium and if
|
// Simple sorting helper for sorting against a criterium and if
|
||||||
|
|
|
@ -78,13 +78,13 @@ protected slots:
|
||||||
void reset();
|
void reset();
|
||||||
signals:
|
signals:
|
||||||
// The propagation of selection changes is complex.
|
// The propagation of selection changes is complex.
|
||||||
// The control flow of dive-selection goes:
|
// The control flow of programmatical dive-selection goes:
|
||||||
// Commands/DiveListNotifier ---(dive */dive_trip *)---> DiveTripModel ---(QModelIndex)---> DiveListView
|
// Commands/DiveListNotifier ---(dive */dive_trip *)---> DiveTripModel ---(QModelIndex)---> DiveListView
|
||||||
// i.e. The command objects send changes in terms of pointer-to-dives, which the DiveTripModel transforms
|
// i.e. The command objects send changes in terms of pointer-to-dives, which the DiveTripModel transforms
|
||||||
// into QModelIndexes according to the current view (tree/list). Finally, the DiveListView transforms these
|
// into QModelIndexes according to the current view (tree/list). Finally, the DiveListView transforms these
|
||||||
// indices into local indices according to current sorting/filtering and instructs the QSelectionModel to
|
// indices into local indices according to current sorting/filtering and instructs the QSelectionModel to
|
||||||
// perform the appropriate actions.
|
// perform the appropriate actions.
|
||||||
void selectionChanged(const QVector<QModelIndex> &indices, QModelIndex currentDive);
|
void selectionChanged(const QVector<QModelIndex> &indices, QModelIndex currentDive, int currentDC);
|
||||||
void tripSelected(QModelIndex trip, QModelIndex currentDive);
|
void tripSelected(QModelIndex trip, QModelIndex currentDive);
|
||||||
protected:
|
protected:
|
||||||
dive *oldCurrent;
|
dive *oldCurrent;
|
||||||
|
@ -116,7 +116,7 @@ public slots:
|
||||||
void divesChanged(const QVector<dive *> &dives);
|
void divesChanged(const QVector<dive *> &dives);
|
||||||
void diveChanged(dive *d);
|
void diveChanged(dive *d);
|
||||||
void divesTimeChanged(timestamp_t delta, const QVector<dive *> &dives);
|
void divesTimeChanged(timestamp_t delta, const QVector<dive *> &dives);
|
||||||
void divesSelected(const QVector<dive *> &dives, dive *currentDive);
|
void divesSelected(const QVector<dive *> &dives, dive *currentDive, int currentDC);
|
||||||
void tripSelected(dive_trip *trip, dive *currentDive);
|
void tripSelected(dive_trip *trip, dive *currentDive);
|
||||||
void tripChanged(dive_trip *trip, TripField);
|
void tripChanged(dive_trip *trip, TripField);
|
||||||
void filterReset();
|
void filterReset();
|
||||||
|
@ -195,7 +195,7 @@ public slots:
|
||||||
void divesTimeChanged(timestamp_t delta, const QVector<dive *> &dives);
|
void divesTimeChanged(timestamp_t delta, const QVector<dive *> &dives);
|
||||||
// Does nothing in list view.
|
// Does nothing in list view.
|
||||||
//void divesMovedBetweenTrips(dive_trip *from, dive_trip *to, bool deleteFrom, bool createTo, const QVector<dive *> &dives);
|
//void divesMovedBetweenTrips(dive_trip *from, dive_trip *to, bool deleteFrom, bool createTo, const QVector<dive *> &dives);
|
||||||
void divesSelected(const QVector<dive *> &dives, dive *currentDive);
|
void divesSelected(const QVector<dive *> &dives, dive *currentDive, int currentDC);
|
||||||
void tripSelected(dive_trip *trip, dive *currentDive);
|
void tripSelected(dive_trip *trip, dive *currentDive);
|
||||||
void filterReset();
|
void filterReset();
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ void MultiFilterSortModel::resetModel(DiveTripModelBase::Layout layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate selection into local indices and re-emit signal
|
// Translate selection into local indices and re-emit signal
|
||||||
void MultiFilterSortModel::selectionChangedSlot(const QVector<QModelIndex> &indices, QModelIndex currentDive)
|
void MultiFilterSortModel::selectionChangedSlot(const QVector<QModelIndex> &indices, QModelIndex currentDive, int currentDC)
|
||||||
{
|
{
|
||||||
QVector<QModelIndex> indicesLocal;
|
QVector<QModelIndex> indicesLocal;
|
||||||
indicesLocal.reserve(indices.size());
|
indicesLocal.reserve(indices.size());
|
||||||
|
@ -43,7 +43,7 @@ void MultiFilterSortModel::selectionChangedSlot(const QVector<QModelIndex> &indi
|
||||||
indicesLocal.push_back(local);
|
indicesLocal.push_back(local);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit selectionChanged(indicesLocal, mapFromSource(currentDive));
|
emit selectionChanged(indicesLocal, mapFromSource(currentDive), currentDC);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate selection into local indices and re-emit signal
|
// Translate selection into local indices and re-emit signal
|
||||||
|
|
|
@ -18,10 +18,10 @@ public:
|
||||||
|
|
||||||
void resetModel(DiveTripModelBase::Layout layout);
|
void resetModel(DiveTripModelBase::Layout layout);
|
||||||
signals:
|
signals:
|
||||||
void selectionChanged(const QVector<QModelIndex> &indices, QModelIndex currentDive);
|
void selectionChanged(const QVector<QModelIndex> &indices, QModelIndex currentDive, int currentDC);
|
||||||
void tripSelected(QModelIndex trip, QModelIndex currentDive);
|
void tripSelected(QModelIndex trip, QModelIndex currentDive);
|
||||||
private slots:
|
private slots:
|
||||||
void selectionChangedSlot(const QVector<QModelIndex> &indices, QModelIndex currentDive);
|
void selectionChangedSlot(const QVector<QModelIndex> &indices, QModelIndex currentDive, int currentDC);
|
||||||
void tripSelectedSlot(QModelIndex trip, QModelIndex currentDive);
|
void tripSelectedSlot(QModelIndex trip, QModelIndex currentDive);
|
||||||
private:
|
private:
|
||||||
MultiFilterSortModel(QObject *parent = 0);
|
MultiFilterSortModel(QObject *parent = 0);
|
||||||
|
|
Loading…
Reference in a new issue