summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-11-28 09:17:30 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-28 15:28:15 -0800
commit3264255a7a2466f1a7d093cf3c26ae564e846472 (patch)
tree072fcd2db06419a82d8e2f67c91379e5b14235b7
parentc1102a38f359b9c155183a39fb059870d63e1d6d (diff)
downloadsubsurface-3264255a7a2466f1a7d093cf3c26ae564e846472.tar.gz
Make it possible to hide some columns on the Cylinders Equipment pane.
This patch makes it possible to hide some columns on the Cylinders Equipment pane. The 'remove' and 'type' are impossible to hide, since they are the most important ones for a non-tech diver. Fixes #281 Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/maintab.cpp43
-rw-r--r--qt-ui/maintab.h3
-rw-r--r--qt-ui/models.h2
3 files changed, 46 insertions, 2 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 8c0f6849a..0400aa7ed 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -20,6 +20,7 @@
#include <QCompleter>
#include <QDebug>
#include <QSet>
+#include <QSettings>
#include <QTableView>
#include <QPalette>
@@ -109,6 +110,48 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui.scrollArea_3->viewport()->setPalette(p);
ui.scrollArea_4->viewport()->setPalette(p);
}
+ ui.cylinders->view()->horizontalHeader()->setContextMenuPolicy(Qt::ActionsContextMenu);
+
+ QSettings s;
+ s.beginGroup("cylinders_dialog");
+ for(int i = 0; i < CylindersModel::COLUMNS; i++){
+ if ((i == CylindersModel::REMOVE) || (i == CylindersModel::TYPE))
+ continue;
+ bool checked = s.value(QString("column%1_hidden").arg(i)).toBool();
+ QAction *action = new QAction(cylindersModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString(), ui.cylinders->view());
+ action->setCheckable(true);
+ action->setData(i);
+ action->setChecked(!checked);
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(toggleTriggeredColumn()));
+ ui.cylinders->view()->setColumnHidden(i, checked);
+ ui.cylinders->view()->horizontalHeader()->addAction(action);
+ }
+}
+
+MainTab::~MainTab()
+{
+ QSettings s;
+ s.beginGroup("cylinders_dialog");
+ for(int i = 0; i < CylindersModel::COLUMNS; i++){
+ if ((i == CylindersModel::REMOVE) || (i == CylindersModel::TYPE))
+ continue;
+ s.setValue(QString("column%1_hidden").arg(i), ui.cylinders->view()->isColumnHidden(i));
+ }
+}
+
+void MainTab::toggleTriggeredColumn()
+{
+ QAction *action = qobject_cast<QAction*>(sender());
+ int col = action->data().toInt();
+ QTableView *view = ui.cylinders->view();
+
+ if(action->isChecked()){
+ view->showColumn(col);
+ if(view->columnWidth(col) <= 15)
+ view->setColumnWidth(col, 80);
+ }
+ else
+ view->hideColumn(col);
}
void MainTab::addDiveStarted()
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index 233aa9439..5750fb378 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -51,6 +51,7 @@ public:
enum EditMode { NONE, DIVE, TRIP, ADD, MANUALLY_ADDED_DIVE };
MainTab(QWidget *parent);
+ ~MainTab();
void clearStats();
void clearInfo();
void clearEquipment();
@@ -82,7 +83,7 @@ public slots:
void editWeightWidget(const QModelIndex& index);
void addDiveStarted();
void enableEdition(EditMode newEditMode = NONE);
-
+ void toggleTriggeredColumn();
private:
Ui::MainTab ui;
WeightModel *weightModel;
diff --git a/qt-ui/models.h b/qt-ui/models.h
index d7b2eedd2..9dd7b2bf6 100644
--- a/qt-ui/models.h
+++ b/qt-ui/models.h
@@ -80,7 +80,7 @@ private:
class CylindersModel : public CleanerTableModel {
Q_OBJECT
public:
- enum Column {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH};
+ enum Column {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH, COLUMNS};
explicit CylindersModel(QObject* parent = 0);
static CylindersModel *instance();