summaryrefslogtreecommitdiffstats
path: root/qt-ui/divelistview.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-21 16:51:49 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-21 16:51:49 -0300
commit37ada91000dc14e0d154e1a3f4fd7f1f842ce956 (patch)
tree873b477780e321b852d6c37ae3cbb16396293381 /qt-ui/divelistview.cpp
parente7b84233af14723814f1340010bb86c6801f1e06 (diff)
downloadsubsurface-37ada91000dc14e0d154e1a3f4fd7f1f842ce956.tar.gz
Added code for handling of show / hide of columns.
The code also remembers to save in the config file. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r--qt-ui/divelistview.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 5c8a93ff0..248a29634 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -10,8 +10,10 @@
#include <QApplication>
#include <QHeaderView>
#include <QDebug>
+#include <QSettings>
#include <QKeyEvent>
#include <QSortFilterProxyModel>
+#include <QAction>
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false)
@@ -20,6 +22,7 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
setItemDelegateForColumn(TreeItemDT::RATING, new StarWidgetsDelegate());
QSortFilterProxyModel *model = new QSortFilterProxyModel(this);
setModel(model);
+ header()->setContextMenuPolicy(Qt::ActionsContextMenu);
}
void DiveListView::reload()
@@ -37,11 +40,41 @@ void DiveListView::reload()
else
setCurrentIndex(firstDiveOrTrip);
}
+ // Populate the context menu of the headers that will show
+ // the menu to show / hide columns.
+ if (!header()->actions().size()){
+ QAction *visibleAction = new QAction("Visible:", header());
+ header()->addAction(visibleAction);
+ 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());
+ QAction *a = new QAction(title, header());
+ a->setCheckable(true);
+ a->setChecked( s.value(title, true).toBool());
+ a->setProperty("index", i);
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(hideColumnByIndex()));
+ header()->addAction(a);
+ }
+ s.endGroup();
+ }
}
-void DiveListView::setModel(QAbstractItemModel* model)
+void DiveListView::hideColumnByIndex()
{
- QTreeView::setModel(model);
+ QAction *action = qobject_cast<QAction*>(sender());
+ if (!action)
+ return;
+
+ QSettings s;
+ s.beginGroup("DiveListColumnState");
+ s.setValue(action->text(), action->isChecked());
+ s.endGroup();
+
+ if (action->isChecked())
+ showColumn(action->property("index").toInt());
+ else
+ hideColumn(action->property("index").toInt());
}
void DiveListView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command)