mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
selection: pass down selection to tab widgets
On selection change, pass down selection (including current dive and dc) to the tab widgets. Ultimately, this should remove access to global variables. A number of new accesses are marked as TODO. They shall be removed in due course. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
908da77863
commit
cded7ef5fe
16 changed files with 62 additions and 55 deletions
|
@ -333,7 +333,7 @@ void MainWindow::updateAutogroup()
|
|||
|
||||
void MainWindow::divesSelected(const std::vector<dive *> &selection, dive *currentDive, int currentDC)
|
||||
{
|
||||
mainTab->updateDiveInfo();
|
||||
mainTab->updateDiveInfo(selection, currentDive, currentDC);
|
||||
if (currentDive)
|
||||
enableDisableOtherDCsActions();
|
||||
profile->plotCurrentDive();
|
||||
|
@ -827,7 +827,8 @@ void MainWindow::on_actionPreviousDC_triggered()
|
|||
unsigned nrdc = number_of_computers(current_dive);
|
||||
dc_number = (dc_number + nrdc - 1) % nrdc;
|
||||
profile->plotCurrentDive();
|
||||
mainTab->updateDiveInfo();
|
||||
// TODO: remove
|
||||
mainTab->updateDiveInfo(getDiveSelection(), current_dive, dc_number);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionNextDC_triggered()
|
||||
|
@ -835,7 +836,8 @@ void MainWindow::on_actionNextDC_triggered()
|
|||
unsigned nrdc = number_of_computers(current_dive);
|
||||
dc_number = (dc_number + 1) % nrdc;
|
||||
profile->plotCurrentDive();
|
||||
mainTab->updateDiveInfo();
|
||||
// TODO: remove
|
||||
mainTab->updateDiveInfo(getDiveSelection(), current_dive, dc_number);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionFullScreen_triggered(bool checked)
|
||||
|
|
|
@ -11,7 +11,7 @@ class TabBase : public QWidget {
|
|||
|
||||
public:
|
||||
using QWidget::QWidget;
|
||||
virtual void updateData() = 0;
|
||||
virtual void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) = 0;
|
||||
virtual void clear() = 0;
|
||||
virtual void updateUi(QString titleColor);
|
||||
};
|
||||
|
|
|
@ -137,13 +137,13 @@ void TabDiveEquipment::toggleTriggeredColumn()
|
|||
}
|
||||
}
|
||||
|
||||
void TabDiveEquipment::updateData()
|
||||
void TabDiveEquipment::updateData(const std::vector<dive *> &, dive *currentDive, int currentDC)
|
||||
{
|
||||
cylindersModel->updateDive(current_dive, dc_number);
|
||||
weightModel->updateDive(current_dive);
|
||||
cylindersModel->updateDive(currentDive, currentDC);
|
||||
weightModel->updateDive(currentDive);
|
||||
|
||||
if (current_dive && current_dive->suit)
|
||||
ui.suit->setText(QString(current_dive->suit));
|
||||
if (currentDive && currentDive->suit)
|
||||
ui.suit->setText(QString(currentDive->suit));
|
||||
else
|
||||
ui.suit->clear();
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class TabDiveEquipment : public TabBase {
|
|||
public:
|
||||
TabDiveEquipment(QWidget *parent = 0);
|
||||
~TabDiveEquipment();
|
||||
void updateData() override;
|
||||
void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) override;
|
||||
void clear() override;
|
||||
void closeWarning();
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@ TabDiveExtraInfo::~TabDiveExtraInfo()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void TabDiveExtraInfo::updateData()
|
||||
void TabDiveExtraInfo::updateData(const std::vector<dive *> &, dive *currentDive, int currentDC)
|
||||
{
|
||||
const struct divecomputer *currentdc = get_dive_dc(current_dive, dc_number);
|
||||
const struct divecomputer *currentdc = get_dive_dc(currentDive, currentDC);
|
||||
if (currentdc)
|
||||
extraDataModel->updateDiveComputer(currentdc);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class TabDiveExtraInfo : public TabBase {
|
|||
public:
|
||||
TabDiveExtraInfo(QWidget *parent = 0);
|
||||
~TabDiveExtraInfo();
|
||||
void updateData() override;
|
||||
void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) override;
|
||||
void clear() override;
|
||||
private:
|
||||
Ui::TabDiveExtraInfo *ui;
|
||||
|
|
|
@ -203,23 +203,18 @@ void TabDiveInformation::showCurrentWidget(bool show, int position)
|
|||
ui->diveInfoScrollAreaLayout->addWidget(ui->groupBox_current, 6, position, 1, 1);
|
||||
}
|
||||
|
||||
void TabDiveInformation::updateData()
|
||||
void TabDiveInformation::updateData(const std::vector<dive *> &, dive *currentDive, int currentDC)
|
||||
{
|
||||
if (!current_dive) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
int salinity_value;
|
||||
manualDive = is_manually_added_dc(¤t_dive->dc);
|
||||
manualDive = is_manually_added_dc(¤tDive->dc);
|
||||
updateWaterTypeWidget();
|
||||
updateProfile();
|
||||
updateWhen();
|
||||
ui->watertemp->setText(get_temperature_string(current_dive->watertemp, true));
|
||||
ui->airtemp->setText(get_temperature_string(current_dive->airtemp, true));
|
||||
ui->watertemp->setText(get_temperature_string(currentDive->watertemp, true));
|
||||
ui->airtemp->setText(get_temperature_string(currentDive->airtemp, true));
|
||||
ui->atmPressType->setItemText(1, get_depth_unit()); // Check for changes in depth unit (imperial/metric)
|
||||
ui->atmPressType->setCurrentIndex(0); // Set the atmospheric pressure combo box to mbar
|
||||
salinity_value = get_dive_salinity(current_dive);
|
||||
salinity_value = get_dive_salinity(currentDive);
|
||||
if (salinity_value) { // Set water type indicator (EN13319 = 1.020 g/l)
|
||||
if (prefs.salinityEditDefault) { //If edit-salinity is enabled then set correct water type in combobox:
|
||||
ui->waterTypeCombo->setCurrentIndex(updateSalinityComboIndex(salinity_value));
|
||||
|
@ -234,12 +229,12 @@ void TabDiveInformation::updateData()
|
|||
}
|
||||
checkDcSalinityOverWritten(); // If exclamation is needed (i.e. salinity overwrite by user), then show it
|
||||
|
||||
updateMode(current_dive);
|
||||
ui->visibility->setCurrentStars(current_dive->visibility);
|
||||
ui->wavesize->setCurrentStars(current_dive->wavesize);
|
||||
ui->current->setCurrentStars(current_dive->current);
|
||||
ui->surge->setCurrentStars(current_dive->surge);
|
||||
ui->chill->setCurrentStars(current_dive->chill);
|
||||
updateMode(currentDive);
|
||||
ui->visibility->setCurrentStars(currentDive->visibility);
|
||||
ui->wavesize->setCurrentStars(currentDive->wavesize);
|
||||
ui->current->setCurrentStars(currentDive->current);
|
||||
ui->surge->setCurrentStars(currentDive->surge);
|
||||
ui->chill->setCurrentStars(currentDive->chill);
|
||||
if (prefs.extraEnvironmentalDefault)
|
||||
showCurrentWidget(true, 2); // Show current star widget at 3rd position
|
||||
else
|
||||
|
|
|
@ -14,7 +14,7 @@ class TabDiveInformation : public TabBase {
|
|||
public:
|
||||
TabDiveInformation(QWidget *parent = 0);
|
||||
~TabDiveInformation();
|
||||
void updateData() override;
|
||||
void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) override;
|
||||
void clear() override;
|
||||
void updateUi(QString titleColor) override;
|
||||
private slots:
|
||||
|
|
|
@ -191,7 +191,7 @@ void TabDiveNotes::updateDiveSite(struct dive *d)
|
|||
ui.locationTags->show();
|
||||
}
|
||||
|
||||
void TabDiveNotes::updateData()
|
||||
void TabDiveNotes::updateData(const std::vector<dive *> &, dive *currentDive, int currentDC)
|
||||
{
|
||||
ui.location->refreshDiveSiteCache();
|
||||
|
||||
|
@ -246,25 +246,25 @@ void TabDiveNotes::updateData()
|
|||
ui.timeLabel->setVisible(true);
|
||||
ui.timeEdit->setVisible(true);
|
||||
/* and fill them from the dive */
|
||||
ui.rating->setCurrentStars(current_dive->rating);
|
||||
ui.rating->setCurrentStars(currentDive->rating);
|
||||
// reset labels in case we last displayed trip notes
|
||||
ui.LocationLabel->setText(tr("Location"));
|
||||
ui.NotesLabel->setText(tr("Notes"));
|
||||
ui.tagWidget->setText(get_taglist_string(current_dive->tag_list));
|
||||
bool isManual = is_manually_added_dc(¤t_dive->dc);
|
||||
ui.tagWidget->setText(get_taglist_string(currentDive->tag_list));
|
||||
bool isManual = is_manually_added_dc(¤tDive->dc);
|
||||
ui.depth->setVisible(isManual);
|
||||
ui.depthLabel->setVisible(isManual);
|
||||
ui.duration->setVisible(isManual);
|
||||
ui.durationLabel->setVisible(isManual);
|
||||
|
||||
updateNotes(current_dive);
|
||||
updateDiveSite(current_dive);
|
||||
updateDateTime(current_dive);
|
||||
ui.diveguide->setText(current_dive->diveguide);
|
||||
ui.buddy->setText(current_dive->buddy);
|
||||
updateNotes(currentDive);
|
||||
updateDiveSite(currentDive);
|
||||
updateDateTime(currentDive);
|
||||
ui.diveguide->setText(currentDive->diveguide);
|
||||
ui.buddy->setText(currentDive->buddy);
|
||||
}
|
||||
ui.duration->setText(render_seconds_to_string(current_dive->duration.seconds));
|
||||
ui.depth->setText(get_depth_string(current_dive->maxdepth, true));
|
||||
ui.duration->setText(render_seconds_to_string(currentDive->duration.seconds));
|
||||
ui.depth->setText(get_depth_string(currentDive->maxdepth, true));
|
||||
|
||||
ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty());
|
||||
/* unset the special value text for date and time, just in case someone dove at midnight */
|
||||
|
|
|
@ -17,7 +17,7 @@ class TabDiveNotes : public TabBase {
|
|||
Q_OBJECT
|
||||
public:
|
||||
TabDiveNotes(QWidget *parent = 0);
|
||||
void updateData() override;
|
||||
void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) override;
|
||||
void clear() override;
|
||||
void closeWarning();
|
||||
|
||||
|
|
|
@ -48,7 +48,8 @@ TabDivePhotos::~TabDivePhotos()
|
|||
|
||||
void TabDivePhotos::clear()
|
||||
{
|
||||
updateData();
|
||||
// TODO: clear model
|
||||
divePictureModel->updateDivePictures();
|
||||
}
|
||||
|
||||
void TabDivePhotos::contextMenuEvent(QContextMenuEvent *event)
|
||||
|
@ -159,8 +160,9 @@ void TabDivePhotos::removeAllPhotos()
|
|||
}
|
||||
}
|
||||
|
||||
void TabDivePhotos::updateData()
|
||||
void TabDivePhotos::updateData(const std::vector<dive *> &, dive *currentDive, int)
|
||||
{
|
||||
// TODO: pass dive
|
||||
divePictureModel->updateDivePictures();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class TabDivePhotos : public TabBase {
|
|||
public:
|
||||
TabDivePhotos(QWidget *parent = 0);
|
||||
~TabDivePhotos();
|
||||
void updateData() override;
|
||||
void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) override;
|
||||
void clear() override;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -59,7 +59,7 @@ void TabDiveStatistics::divesChanged(const QVector<dive *> &dives, DiveField fie
|
|||
|
||||
// TODO: make this more fine grained. Currently, the core can only calculate *all* statistics.
|
||||
if (field.duration || field.depth || field.mode || field.air_temp || field.water_temp)
|
||||
updateData();
|
||||
updateData(getDiveSelection(), current_dive, dc_number); // TODO: remember these data
|
||||
}
|
||||
|
||||
void TabDiveStatistics::cylinderChanged(dive *d)
|
||||
|
@ -67,10 +67,10 @@ void TabDiveStatistics::cylinderChanged(dive *d)
|
|||
// If the changed dive is not selected, do nothing
|
||||
if (!d->selected)
|
||||
return;
|
||||
updateData();
|
||||
updateData(getDiveSelection(), current_dive, dc_number); // TODO: remember these data
|
||||
}
|
||||
|
||||
void TabDiveStatistics::updateData()
|
||||
void TabDiveStatistics::updateData(const std::vector<dive *> &, dive *currentDive, int)
|
||||
{
|
||||
stats_t stats_selection;
|
||||
calculate_stats_selected(&stats_selection);
|
||||
|
@ -109,7 +109,7 @@ void TabDiveStatistics::updateData()
|
|||
}
|
||||
|
||||
|
||||
bool is_freedive = current_dive && current_dive->dc.divemode == FREEDIVE;
|
||||
bool is_freedive = currentDive && currentDive->dc.divemode == FREEDIVE;
|
||||
ui->divesAllText->setText(QString::number(stats_selection.selection_size));
|
||||
ui->totalTimeAllText->setText(get_dive_duration_string(stats_selection.total_time.seconds, tr("h"), tr("min"), tr("sec"), " ", is_freedive));
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class TabDiveStatistics : public TabBase {
|
|||
public:
|
||||
TabDiveStatistics(QWidget *parent = 0);
|
||||
~TabDiveStatistics();
|
||||
void updateData() override;
|
||||
void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) override;
|
||||
void clear() override;
|
||||
|
||||
private slots:
|
||||
|
|
|
@ -49,7 +49,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
|||
// call colorsChanged() for the initial setup now that the extraWidgets are loaded
|
||||
colorsChanged();
|
||||
|
||||
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainTab::updateDiveInfo);
|
||||
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainTab::settingsChanged);
|
||||
|
||||
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
||||
connect(closeKey, &QShortcut::activated, this, &MainTab::escDetected);
|
||||
|
@ -70,7 +70,13 @@ void MainTab::nextInputField(QKeyEvent *event)
|
|||
keyPressEvent(event);
|
||||
}
|
||||
|
||||
void MainTab::updateDiveInfo()
|
||||
void MainTab::settingsChanged()
|
||||
{
|
||||
// TODO: remember these
|
||||
updateDiveInfo(getDiveSelection(), current_dive, dc_number);
|
||||
}
|
||||
|
||||
void MainTab::updateDiveInfo(const std::vector<dive *> &selection, dive *currentDive, int currentDC)
|
||||
{
|
||||
// don't execute this while planning a dive
|
||||
if (DivePlannerPointsModel::instance()->isPlanner())
|
||||
|
@ -81,9 +87,9 @@ void MainTab::updateDiveInfo()
|
|||
for (TabBase *widget: extraWidgets)
|
||||
widget->setEnabled(enabled);
|
||||
|
||||
if (current_dive) {
|
||||
if (currentDive) {
|
||||
for (TabBase *widget: extraWidgets)
|
||||
widget->updateData();
|
||||
widget->updateData(selection, currentDive, currentDC);
|
||||
if (single_selected_trip()) {
|
||||
// Remember the tab selected for last dive but only if we're not on the dive site tab
|
||||
if (lastSelectedDive)
|
||||
|
|
|
@ -24,7 +24,9 @@ public:
|
|||
|
||||
public
|
||||
slots:
|
||||
void updateDiveInfo();
|
||||
// Always called with non-null currentDive
|
||||
void updateDiveInfo(const std::vector<dive *> &selection, dive *currentDive, int currentDC);
|
||||
void settingsChanged();
|
||||
void escDetected();
|
||||
void colorsChanged();
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue