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)
|
void MainWindow::divesSelected(const std::vector<dive *> &selection, dive *currentDive, int currentDC)
|
||||||
{
|
{
|
||||||
mainTab->updateDiveInfo();
|
mainTab->updateDiveInfo(selection, currentDive, currentDC);
|
||||||
if (currentDive)
|
if (currentDive)
|
||||||
enableDisableOtherDCsActions();
|
enableDisableOtherDCsActions();
|
||||||
profile->plotCurrentDive();
|
profile->plotCurrentDive();
|
||||||
|
@ -827,7 +827,8 @@ void MainWindow::on_actionPreviousDC_triggered()
|
||||||
unsigned nrdc = number_of_computers(current_dive);
|
unsigned nrdc = number_of_computers(current_dive);
|
||||||
dc_number = (dc_number + nrdc - 1) % nrdc;
|
dc_number = (dc_number + nrdc - 1) % nrdc;
|
||||||
profile->plotCurrentDive();
|
profile->plotCurrentDive();
|
||||||
mainTab->updateDiveInfo();
|
// TODO: remove
|
||||||
|
mainTab->updateDiveInfo(getDiveSelection(), current_dive, dc_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionNextDC_triggered()
|
void MainWindow::on_actionNextDC_triggered()
|
||||||
|
@ -835,7 +836,8 @@ void MainWindow::on_actionNextDC_triggered()
|
||||||
unsigned nrdc = number_of_computers(current_dive);
|
unsigned nrdc = number_of_computers(current_dive);
|
||||||
dc_number = (dc_number + 1) % nrdc;
|
dc_number = (dc_number + 1) % nrdc;
|
||||||
profile->plotCurrentDive();
|
profile->plotCurrentDive();
|
||||||
mainTab->updateDiveInfo();
|
// TODO: remove
|
||||||
|
mainTab->updateDiveInfo(getDiveSelection(), current_dive, dc_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionFullScreen_triggered(bool checked)
|
void MainWindow::on_actionFullScreen_triggered(bool checked)
|
||||||
|
|
|
@ -11,7 +11,7 @@ class TabBase : public QWidget {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using QWidget::QWidget;
|
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 clear() = 0;
|
||||||
virtual void updateUi(QString titleColor);
|
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);
|
cylindersModel->updateDive(currentDive, currentDC);
|
||||||
weightModel->updateDive(current_dive);
|
weightModel->updateDive(currentDive);
|
||||||
|
|
||||||
if (current_dive && current_dive->suit)
|
if (currentDive && currentDive->suit)
|
||||||
ui.suit->setText(QString(current_dive->suit));
|
ui.suit->setText(QString(currentDive->suit));
|
||||||
else
|
else
|
||||||
ui.suit->clear();
|
ui.suit->clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ class TabDiveEquipment : public TabBase {
|
||||||
public:
|
public:
|
||||||
TabDiveEquipment(QWidget *parent = 0);
|
TabDiveEquipment(QWidget *parent = 0);
|
||||||
~TabDiveEquipment();
|
~TabDiveEquipment();
|
||||||
void updateData() override;
|
void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) override;
|
||||||
void clear() override;
|
void clear() override;
|
||||||
void closeWarning();
|
void closeWarning();
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,9 @@ TabDiveExtraInfo::~TabDiveExtraInfo()
|
||||||
delete ui;
|
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)
|
if (currentdc)
|
||||||
extraDataModel->updateDiveComputer(currentdc);
|
extraDataModel->updateDiveComputer(currentdc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ class TabDiveExtraInfo : public TabBase {
|
||||||
public:
|
public:
|
||||||
TabDiveExtraInfo(QWidget *parent = 0);
|
TabDiveExtraInfo(QWidget *parent = 0);
|
||||||
~TabDiveExtraInfo();
|
~TabDiveExtraInfo();
|
||||||
void updateData() override;
|
void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) override;
|
||||||
void clear() override;
|
void clear() override;
|
||||||
private:
|
private:
|
||||||
Ui::TabDiveExtraInfo *ui;
|
Ui::TabDiveExtraInfo *ui;
|
||||||
|
|
|
@ -203,23 +203,18 @@ void TabDiveInformation::showCurrentWidget(bool show, int position)
|
||||||
ui->diveInfoScrollAreaLayout->addWidget(ui->groupBox_current, 6, position, 1, 1);
|
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;
|
int salinity_value;
|
||||||
manualDive = is_manually_added_dc(¤t_dive->dc);
|
manualDive = is_manually_added_dc(¤tDive->dc);
|
||||||
updateWaterTypeWidget();
|
updateWaterTypeWidget();
|
||||||
updateProfile();
|
updateProfile();
|
||||||
updateWhen();
|
updateWhen();
|
||||||
ui->watertemp->setText(get_temperature_string(current_dive->watertemp, true));
|
ui->watertemp->setText(get_temperature_string(currentDive->watertemp, true));
|
||||||
ui->airtemp->setText(get_temperature_string(current_dive->airtemp, 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->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
|
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 (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:
|
if (prefs.salinityEditDefault) { //If edit-salinity is enabled then set correct water type in combobox:
|
||||||
ui->waterTypeCombo->setCurrentIndex(updateSalinityComboIndex(salinity_value));
|
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
|
checkDcSalinityOverWritten(); // If exclamation is needed (i.e. salinity overwrite by user), then show it
|
||||||
|
|
||||||
updateMode(current_dive);
|
updateMode(currentDive);
|
||||||
ui->visibility->setCurrentStars(current_dive->visibility);
|
ui->visibility->setCurrentStars(currentDive->visibility);
|
||||||
ui->wavesize->setCurrentStars(current_dive->wavesize);
|
ui->wavesize->setCurrentStars(currentDive->wavesize);
|
||||||
ui->current->setCurrentStars(current_dive->current);
|
ui->current->setCurrentStars(currentDive->current);
|
||||||
ui->surge->setCurrentStars(current_dive->surge);
|
ui->surge->setCurrentStars(currentDive->surge);
|
||||||
ui->chill->setCurrentStars(current_dive->chill);
|
ui->chill->setCurrentStars(currentDive->chill);
|
||||||
if (prefs.extraEnvironmentalDefault)
|
if (prefs.extraEnvironmentalDefault)
|
||||||
showCurrentWidget(true, 2); // Show current star widget at 3rd position
|
showCurrentWidget(true, 2); // Show current star widget at 3rd position
|
||||||
else
|
else
|
||||||
|
|
|
@ -14,7 +14,7 @@ class TabDiveInformation : public TabBase {
|
||||||
public:
|
public:
|
||||||
TabDiveInformation(QWidget *parent = 0);
|
TabDiveInformation(QWidget *parent = 0);
|
||||||
~TabDiveInformation();
|
~TabDiveInformation();
|
||||||
void updateData() override;
|
void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) override;
|
||||||
void clear() override;
|
void clear() override;
|
||||||
void updateUi(QString titleColor) override;
|
void updateUi(QString titleColor) override;
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
@ -191,7 +191,7 @@ void TabDiveNotes::updateDiveSite(struct dive *d)
|
||||||
ui.locationTags->show();
|
ui.locationTags->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDiveNotes::updateData()
|
void TabDiveNotes::updateData(const std::vector<dive *> &, dive *currentDive, int currentDC)
|
||||||
{
|
{
|
||||||
ui.location->refreshDiveSiteCache();
|
ui.location->refreshDiveSiteCache();
|
||||||
|
|
||||||
|
@ -246,25 +246,25 @@ void TabDiveNotes::updateData()
|
||||||
ui.timeLabel->setVisible(true);
|
ui.timeLabel->setVisible(true);
|
||||||
ui.timeEdit->setVisible(true);
|
ui.timeEdit->setVisible(true);
|
||||||
/* and fill them from the dive */
|
/* 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
|
// reset labels in case we last displayed trip notes
|
||||||
ui.LocationLabel->setText(tr("Location"));
|
ui.LocationLabel->setText(tr("Location"));
|
||||||
ui.NotesLabel->setText(tr("Notes"));
|
ui.NotesLabel->setText(tr("Notes"));
|
||||||
ui.tagWidget->setText(get_taglist_string(current_dive->tag_list));
|
ui.tagWidget->setText(get_taglist_string(currentDive->tag_list));
|
||||||
bool isManual = is_manually_added_dc(¤t_dive->dc);
|
bool isManual = is_manually_added_dc(¤tDive->dc);
|
||||||
ui.depth->setVisible(isManual);
|
ui.depth->setVisible(isManual);
|
||||||
ui.depthLabel->setVisible(isManual);
|
ui.depthLabel->setVisible(isManual);
|
||||||
ui.duration->setVisible(isManual);
|
ui.duration->setVisible(isManual);
|
||||||
ui.durationLabel->setVisible(isManual);
|
ui.durationLabel->setVisible(isManual);
|
||||||
|
|
||||||
updateNotes(current_dive);
|
updateNotes(currentDive);
|
||||||
updateDiveSite(current_dive);
|
updateDiveSite(currentDive);
|
||||||
updateDateTime(current_dive);
|
updateDateTime(currentDive);
|
||||||
ui.diveguide->setText(current_dive->diveguide);
|
ui.diveguide->setText(currentDive->diveguide);
|
||||||
ui.buddy->setText(current_dive->buddy);
|
ui.buddy->setText(currentDive->buddy);
|
||||||
}
|
}
|
||||||
ui.duration->setText(render_seconds_to_string(current_dive->duration.seconds));
|
ui.duration->setText(render_seconds_to_string(currentDive->duration.seconds));
|
||||||
ui.depth->setText(get_depth_string(current_dive->maxdepth, true));
|
ui.depth->setText(get_depth_string(currentDive->maxdepth, true));
|
||||||
|
|
||||||
ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty());
|
ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty());
|
||||||
/* unset the special value text for date and time, just in case someone dove at midnight */
|
/* 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
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
TabDiveNotes(QWidget *parent = 0);
|
TabDiveNotes(QWidget *parent = 0);
|
||||||
void updateData() override;
|
void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) override;
|
||||||
void clear() override;
|
void clear() override;
|
||||||
void closeWarning();
|
void closeWarning();
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,8 @@ TabDivePhotos::~TabDivePhotos()
|
||||||
|
|
||||||
void TabDivePhotos::clear()
|
void TabDivePhotos::clear()
|
||||||
{
|
{
|
||||||
updateData();
|
// TODO: clear model
|
||||||
|
divePictureModel->updateDivePictures();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDivePhotos::contextMenuEvent(QContextMenuEvent *event)
|
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();
|
divePictureModel->updateDivePictures();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ class TabDivePhotos : public TabBase {
|
||||||
public:
|
public:
|
||||||
TabDivePhotos(QWidget *parent = 0);
|
TabDivePhotos(QWidget *parent = 0);
|
||||||
~TabDivePhotos();
|
~TabDivePhotos();
|
||||||
void updateData() override;
|
void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) override;
|
||||||
void clear() override;
|
void clear() override;
|
||||||
|
|
||||||
protected:
|
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.
|
// 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)
|
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)
|
void TabDiveStatistics::cylinderChanged(dive *d)
|
||||||
|
@ -67,10 +67,10 @@ void TabDiveStatistics::cylinderChanged(dive *d)
|
||||||
// If the changed dive is not selected, do nothing
|
// If the changed dive is not selected, do nothing
|
||||||
if (!d->selected)
|
if (!d->selected)
|
||||||
return;
|
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;
|
stats_t stats_selection;
|
||||||
calculate_stats_selected(&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->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));
|
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:
|
public:
|
||||||
TabDiveStatistics(QWidget *parent = 0);
|
TabDiveStatistics(QWidget *parent = 0);
|
||||||
~TabDiveStatistics();
|
~TabDiveStatistics();
|
||||||
void updateData() override;
|
void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) override;
|
||||||
void clear() override;
|
void clear() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
@ -49,7 +49,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
||||||
// call colorsChanged() for the initial setup now that the extraWidgets are loaded
|
// call colorsChanged() for the initial setup now that the extraWidgets are loaded
|
||||||
colorsChanged();
|
colorsChanged();
|
||||||
|
|
||||||
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainTab::updateDiveInfo);
|
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainTab::settingsChanged);
|
||||||
|
|
||||||
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
||||||
connect(closeKey, &QShortcut::activated, this, &MainTab::escDetected);
|
connect(closeKey, &QShortcut::activated, this, &MainTab::escDetected);
|
||||||
|
@ -70,7 +70,13 @@ void MainTab::nextInputField(QKeyEvent *event)
|
||||||
keyPressEvent(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
|
// don't execute this while planning a dive
|
||||||
if (DivePlannerPointsModel::instance()->isPlanner())
|
if (DivePlannerPointsModel::instance()->isPlanner())
|
||||||
|
@ -81,9 +87,9 @@ void MainTab::updateDiveInfo()
|
||||||
for (TabBase *widget: extraWidgets)
|
for (TabBase *widget: extraWidgets)
|
||||||
widget->setEnabled(enabled);
|
widget->setEnabled(enabled);
|
||||||
|
|
||||||
if (current_dive) {
|
if (currentDive) {
|
||||||
for (TabBase *widget: extraWidgets)
|
for (TabBase *widget: extraWidgets)
|
||||||
widget->updateData();
|
widget->updateData(selection, currentDive, currentDC);
|
||||||
if (single_selected_trip()) {
|
if (single_selected_trip()) {
|
||||||
// Remember the tab selected for last dive but only if we're not on the dive site tab
|
// Remember the tab selected for last dive but only if we're not on the dive site tab
|
||||||
if (lastSelectedDive)
|
if (lastSelectedDive)
|
||||||
|
|
|
@ -24,7 +24,9 @@ public:
|
||||||
|
|
||||||
public
|
public
|
||||||
slots:
|
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 escDetected();
|
||||||
void colorsChanged();
|
void colorsChanged();
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue