diff options
-rw-r--r-- | desktop-widgets/divelistview.cpp | 68 | ||||
-rw-r--r-- | desktop-widgets/divelistview.h | 1 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 2 |
3 files changed, 30 insertions, 41 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); } } diff --git a/desktop-widgets/divelistview.h b/desktop-widgets/divelistview.h index 990d0446b..1853dab1d 100644 --- a/desktop-widgets/divelistview.h +++ b/desktop-widgets/divelistview.h @@ -34,7 +34,6 @@ signals: public slots: void settingsChanged(); - void reloadHeaderActions(); private slots: void toggleColumnVisibilityByIndex(); diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index dfe039c51..c4a234b72 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -219,8 +219,6 @@ MainWindow::MainWindow() : QMainWindow(), graphics->setEmptyState(); initialUiSetup(); readSettings(); - diveList->reload(); - diveList->reloadHeaderActions(); diveList->setFocus(); MapWidget::instance()->reload(); diveList->expand(diveList->model()->index(0, 0)); |