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);
|
||||
|
||||
// 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,
|
||||
|
|
|
@ -111,7 +111,8 @@ signals:
|
|||
void tripChanged(dive_trip *trip, TripField field);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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
|
||||
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.
|
||||
// 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);
|
||||
|
||||
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;
|
||||
|
||||
// Set the currently activated row.
|
||||
|
@ -305,7 +312,14 @@ void DiveListView::tripSelected(QModelIndex trip, QModelIndex currentDive)
|
|||
// funny side-effects).
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -415,7 +429,7 @@ void DiveListView::currentChanged(const QModelIndex ¤t, const QModelIndex&
|
|||
scrollTo(current);
|
||||
}
|
||||
|
||||
void DiveListView::selectionChangeDone()
|
||||
void DiveListView::selectDiveSitesOnMap(const std::vector<dive *> &dives)
|
||||
{
|
||||
#ifdef MAP_SUPPORT
|
||||
// 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
|
||||
// by the selected dives.
|
||||
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;
|
||||
selectedSites.reserve(amount_selected);
|
||||
int i;
|
||||
dive *d;
|
||||
for_each_dive(i, d) {
|
||||
if (d->selected && !d->hidden_by_filter && d->dive_site && !selectedSites.contains(d->dive_site))
|
||||
selectedSites.reserve(dives.size());
|
||||
for (dive *d: dives) {
|
||||
if (!d->hidden_by_filter && d->dive_site && !selectedSites.contains(d->dive_site))
|
||||
selectedSites.push_back(d->dive_site);
|
||||
}
|
||||
MapWidget::instance()->setSelected(selectedSites);
|
||||
}
|
||||
#endif
|
||||
emit divesSelected();
|
||||
}
|
||||
|
||||
void DiveListView::selectTripItems(QModelIndex index)
|
||||
|
@ -524,7 +532,8 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS
|
|||
// Display the new, processed, selection
|
||||
QTreeView::selectionChanged(selectionModel()->selection(), newDeselected);
|
||||
|
||||
selectionChangeDone();
|
||||
selectDiveSitesOnMap(selection);
|
||||
emit divesSelected(selection, newCurrent, -1);
|
||||
|
||||
programmaticalSelectionChange = false;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,8 @@ public:
|
|||
void loadImages();
|
||||
void loadWebImages();
|
||||
signals:
|
||||
void divesSelected();
|
||||
// currentDC = -1: don't change dc number.
|
||||
void divesSelected(const std::vector<dive *> &dives, dive *currentDive, int currentDC);
|
||||
public
|
||||
slots:
|
||||
void settingsChanged();
|
||||
|
@ -51,13 +52,13 @@ slots:
|
|||
void renumberDives();
|
||||
void addDivesToTrip();
|
||||
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);
|
||||
private:
|
||||
void rowsInserted(const QModelIndex &parent, int start, int end) override;
|
||||
void reset() override;
|
||||
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override;
|
||||
void selectionChangeDone();
|
||||
void selectDiveSitesOnMap(const std::vector<dive *> &dives);
|
||||
void selectTripItems(QModelIndex index);
|
||||
DiveTripModelBase::Layout currentLayout;
|
||||
QModelIndex contextMenuIndex;
|
||||
|
|
|
@ -176,7 +176,7 @@ MainWindow::MainWindow() :
|
|||
if (!QIcon::hasThemeIcon("window-close")) {
|
||||
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);
|
||||
for (int i = 0; i < NUM_RECENT_FILES; i++) {
|
||||
actionsRecent[i] = new QAction(this);
|
||||
|
@ -331,10 +331,10 @@ void MainWindow::updateAutogroup()
|
|||
ui.actionAutoGroup->setChecked(divelog.autogroup);
|
||||
}
|
||||
|
||||
void MainWindow::selectionChanged()
|
||||
void MainWindow::divesSelected(const std::vector<dive *> &selection, dive *currentDive, int currentDC)
|
||||
{
|
||||
mainTab->updateDiveInfo();
|
||||
if (current_dive)
|
||||
if (currentDive)
|
||||
enableDisableOtherDCsActions();
|
||||
profile->plotCurrentDive();
|
||||
#ifdef MAP_SUPPORT
|
||||
|
|
|
@ -129,7 +129,7 @@ slots:
|
|||
void on_actionReplanDive_triggered();
|
||||
void on_action_Check_for_Updates_triggered();
|
||||
|
||||
void selectionChanged();
|
||||
void divesSelected(const std::vector<dive *> &selection, dive *currentDive, int currentDC);
|
||||
void initialUiSetup();
|
||||
|
||||
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);
|
||||
|
||||
|
@ -1382,7 +1382,7 @@ void DiveTripModelTree::divesSelected(const QVector<dive *> &divesIn, dive *curr
|
|||
processByTrip(dives, [this, &indices] (dive_trip *trip, const QVector<dive *> &divesInTrip)
|
||||
{ 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.
|
||||
currentChanged(currentDive);
|
||||
|
@ -1659,7 +1659,7 @@ QModelIndex DiveTripModelList::diveToIdx(const dive *d) const
|
|||
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);
|
||||
|
||||
|
@ -1679,7 +1679,7 @@ void DiveTripModelList::divesSelected(const QVector<dive *> &divesIn, dive *curr
|
|||
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.
|
||||
currentChanged(currentDive);
|
||||
|
@ -1697,7 +1697,7 @@ void DiveTripModelList::tripSelected(dive_trip *trip, dive *currentDive)
|
|||
for (int i = 0; i < trip->dives.nr; ++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
|
||||
|
|
|
@ -78,13 +78,13 @@ protected slots:
|
|||
void reset();
|
||||
signals:
|
||||
// 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
|
||||
// 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
|
||||
// indices into local indices according to current sorting/filtering and instructs the QSelectionModel to
|
||||
// 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);
|
||||
protected:
|
||||
dive *oldCurrent;
|
||||
|
@ -116,7 +116,7 @@ public slots:
|
|||
void divesChanged(const QVector<dive *> &dives);
|
||||
void diveChanged(dive *d);
|
||||
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 tripChanged(dive_trip *trip, TripField);
|
||||
void filterReset();
|
||||
|
@ -195,7 +195,7 @@ public slots:
|
|||
void divesTimeChanged(timestamp_t delta, const QVector<dive *> &dives);
|
||||
// Does nothing in list view.
|
||||
//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 filterReset();
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ void MultiFilterSortModel::resetModel(DiveTripModelBase::Layout layout)
|
|||
}
|
||||
|
||||
// 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;
|
||||
indicesLocal.reserve(indices.size());
|
||||
|
@ -43,7 +43,7 @@ void MultiFilterSortModel::selectionChangedSlot(const QVector<QModelIndex> &indi
|
|||
indicesLocal.push_back(local);
|
||||
}
|
||||
|
||||
emit selectionChanged(indicesLocal, mapFromSource(currentDive));
|
||||
emit selectionChanged(indicesLocal, mapFromSource(currentDive), currentDC);
|
||||
}
|
||||
|
||||
// Translate selection into local indices and re-emit signal
|
||||
|
|
|
@ -18,10 +18,10 @@ public:
|
|||
|
||||
void resetModel(DiveTripModelBase::Layout layout);
|
||||
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);
|
||||
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);
|
||||
private:
|
||||
MultiFilterSortModel(QObject *parent = 0);
|
||||
|
|
Loading…
Reference in a new issue