summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/divelistview.cpp29
-rw-r--r--qt-ui/divelistview.h3
-rw-r--r--qt-ui/mainwindow.cpp4
3 files changed, 19 insertions, 17 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index abd9d4ede..4957e3374 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -40,6 +40,10 @@ void DiveListView::reload()
else
setCurrentIndex(firstDiveOrTrip);
}
+}
+
+void DiveListView::reloadHeaderActions()
+{
// Populate the context menu of the headers that will show
// the menu to show / hide columns.
if (!header()->actions().size()) {
@@ -48,24 +52,23 @@ void DiveListView::reload()
QSettings s;
s.beginGroup("DiveListColumnState");
for(int i = 0; i < model()->columnCount(); i++) {
- QString title = QString("show %1").arg(model()->headerData( i, Qt::Horizontal).toString());
+ QString title = QString("show %1").arg(model()->headerData(i, Qt::Horizontal).toString());
+ QString settingName = QString("showColumn%1").arg(i);
QAction *a = new QAction(title, header());
+ bool shown = s.value(settingName, true).toBool();
a->setCheckable(true);
- a->setChecked( s.value(title, true).toBool());
+ a->setChecked(shown);
a->setProperty("index", i);
- connect(a, SIGNAL(triggered(bool)), this, SLOT(hideColumnByIndex()));
+ a->setProperty("settingName", settingName);
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(toggleColumnVisibilityByIndex()));
header()->addAction(a);
- if (a->isChecked())
- showColumn(true);
- else
- hideColumn(false);
+ setColumnHidden(i, !shown);
}
s.endGroup();
- s.sync();
}
}
-void DiveListView::hideColumnByIndex()
+void DiveListView::toggleColumnVisibilityByIndex()
{
QAction *action = qobject_cast<QAction*>(sender());
if (!action)
@@ -73,14 +76,10 @@ void DiveListView::hideColumnByIndex()
QSettings s;
s.beginGroup("DiveListColumnState");
- s.setValue(action->text(), action->isChecked());
+ s.setValue(action->property("settingName").toString(), action->isChecked());
s.endGroup();
s.sync();
-
- if (action->isChecked())
- showColumn(action->property("index").toInt());
- else
- hideColumn(action->property("index").toInt());
+ setColumnHidden(action->property("index").toInt(), !action->isChecked());
}
void DiveListView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command)
diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h
index 6cbcd8319..c1a33db51 100644
--- a/qt-ui/divelistview.h
+++ b/qt-ui/divelistview.h
@@ -31,7 +31,8 @@ public:
void reload();
public slots:
- void hideColumnByIndex();
+ void toggleColumnVisibilityByIndex();
+ void reloadHeaderActions();
Q_SIGNALS:
void currentDiveChanged(int divenr);
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 8e0e54eaa..4d0299d7e 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -44,6 +44,7 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow())
ui->ProfileWidget->setFocusProxy(ui->ListWidget);
ui->ListWidget->reload();
readSettings();
+ ui->ListWidget->reloadHeaderActions();
ui->ListWidget->setFocus();
ui->globe->reload();
instance = this;
@@ -432,7 +433,8 @@ void MainWindow::writeSettings()
settings.beginGroup("ListWidget");
for (i = TreeItemDT::NR; i < TreeItemDT::COLUMNS; i++)
- settings.setValue(QString("colwidth%1").arg(i), ui->ListWidget->columnWidth(i));
+ if (!ui->ListWidget->isColumnHidden(i))
+ settings.setValue(QString("colwidth%1").arg(i), ui->ListWidget->columnWidth(i));
settings.endGroup();
settings.beginGroup("Units");
SAVE_VALUE("feet", units.length);