summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/divelistview.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-11-24 19:57:14 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-12-12 15:52:40 -0800
commit369c5b0dc656cbf4da2c8185debc355af4243cc5 (patch)
tree45d166b0af297a44158e5eae349b903a59026ebc /desktop-widgets/divelistview.cpp
parent712e4680cae91ca3ca7291bc7f5124d5a3578a4d (diff)
downloadsubsurface-369c5b0dc656cbf4da2c8185debc355af4243cc5.tar.gz
desktop: init dive list header actions in constructor
The main window called a function to init the header actions (i.e. the context menu) of the dive-list. There is no reason why this shouldn't be done in the constructor of the dive list, since it only accesses the QSettings, which are available at application startup. This improves modularity of the code (by a tiny, tiny bit). Moreover, the initialization function was at the same time the header-reloading function. That function can now be folded into the settings-changed function, since that is the only remaining user. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/divelistview.cpp')
-rw-r--r--desktop-widgets/divelistview.cpp68
1 files changed, 30 insertions, 38 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp
index 07f7435c0..14973cf0a 100644
--- a/desktop-widgets/divelistview.cpp
+++ b/desktop-widgets/divelistview.cpp
@@ -61,6 +61,32 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent),
for (int i = DiveTripModelBase::NR; i < DiveTripModelBase::COLUMNS; i++)
calculateInitialColumnWidth(i);
setColumnWidths();
+
+ QSettings s;
+ s.beginGroup("DiveListColumnState");
+ for (int i = 0; i < model()->columnCount(); i++) {
+ QString title = QString("%1").arg(model()->headerData(i, Qt::Horizontal).toString());
+ QString settingName = QString("showColumn%1").arg(i);
+ QAction *a = new QAction(title, header());
+ bool showHeaderFirstRun = !(i == DiveTripModelBase::MAXCNS ||
+ i == DiveTripModelBase::GAS ||
+ i == DiveTripModelBase::OTU ||
+ i == DiveTripModelBase::TEMPERATURE ||
+ i == DiveTripModelBase::TOTALWEIGHT ||
+ i == DiveTripModelBase::SUIT ||
+ i == DiveTripModelBase::CYLINDER ||
+ i == DiveTripModelBase::SAC ||
+ i == DiveTripModelBase::TAGS);
+ bool shown = s.value(settingName, showHeaderFirstRun).toBool();
+ a->setCheckable(true);
+ a->setChecked(shown);
+ a->setProperty("index", i);
+ a->setProperty("settingName", settingName);
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(toggleColumnVisibilityByIndex()));
+ header()->addAction(a);
+ setColumnHidden(i, !shown);
+ }
+ s.endGroup();
}
DiveListView::~DiveListView()
@@ -353,44 +379,10 @@ void DiveListView::reload()
void DiveListView::settingsChanged()
{
update();
- reloadHeaderActions();
-}
-
-void DiveListView::reloadHeaderActions()
-{
- // Populate the context menu of the headers that will show
- // the menu to show / hide columns.
- if (!header()->actions().size()) {
- QSettings s;
- s.beginGroup("DiveListColumnState");
- for (int i = 0; i < model()->columnCount(); i++) {
- QString title = QString("%1").arg(model()->headerData(i, Qt::Horizontal).toString());
- QString settingName = QString("showColumn%1").arg(i);
- QAction *a = new QAction(title, header());
- bool showHeaderFirstRun = !(i == DiveTripModelBase::MAXCNS ||
- i == DiveTripModelBase::GAS ||
- i == DiveTripModelBase::OTU ||
- i == DiveTripModelBase::TEMPERATURE ||
- i == DiveTripModelBase::TOTALWEIGHT ||
- i == DiveTripModelBase::SUIT ||
- i == DiveTripModelBase::CYLINDER ||
- i == DiveTripModelBase::SAC ||
- i == DiveTripModelBase::TAGS);
- bool shown = s.value(settingName, showHeaderFirstRun).toBool();
- a->setCheckable(true);
- a->setChecked(shown);
- a->setProperty("index", i);
- a->setProperty("settingName", settingName);
- connect(a, SIGNAL(triggered(bool)), this, SLOT(toggleColumnVisibilityByIndex()));
- header()->addAction(a);
- setColumnHidden(i, !shown);
- }
- s.endGroup();
- } else {
- for (int i = 0; i < model()->columnCount(); i++) {
- QString title = QString("%1").arg(model()->headerData(i, Qt::Horizontal).toString());
- header()->actions()[i]->setText(title);
- }
+
+ for (int i = 0; i < model()->columnCount(); i++) {
+ QString title = model()->headerData(i, Qt::Horizontal).toString();
+ header()->actions()[i]->setText(title);
}
}