diff options
Diffstat (limited to 'smtreeview.cpp')
-rw-r--r-- | smtreeview.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/smtreeview.cpp b/smtreeview.cpp new file mode 100644 index 0000000..411857a --- /dev/null +++ b/smtreeview.cpp @@ -0,0 +1,51 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include <QSettings> +#include <QHeaderView> +#include <QAction> +#include <QActionGroup> + +#include "smtreeview.h" + +SmTreeView::SmTreeView(const QString &hSetting, QWidget *parent) : QTreeView(parent), mHeaderSetting(hSetting){ + header()->setSectionResizeMode(QHeaderView::ResizeToContents); +} + +#include <QDebug> + +void SmTreeView::readHeaderConfig(){ + QSettings s; + QByteArray headerPos = s.value(mHeaderSetting).toByteArray(); + if(!headerPos.isEmpty()){ + header()->restoreState(headerPos); + } + QHeaderView *hv = header(); + QHash<int, QAction*> headerActions; + foreach(QAction *a, mHeaderGroup->actions()){ + headerActions.insert(a->data().toInt(), a); + } + for(int i = 0; i < hv->count(); ++i){ + if(!hv->isSectionHidden(i)){ + qDebug() << mHeaderSetting << headerActions.value(i) << "checked" << headerActions.value(i)->isCheckable(); + headerActions.value(i)->setChecked(true); + } + } +} + +void SmTreeView::writeHeaderConfig(){ + QSettings s; + s.setValue(mHeaderSetting, header()->saveState()); +} + +void SmTreeView::toggleHeader(QObject *action){ + QAction *a = qobject_cast<QAction*>(action); + int logicalIndex = a->data().toInt(); + QHeaderView *hv = header(); + hv->setSectionHidden(logicalIndex, !a->isChecked()); + qDebug() << mHeaderSetting << a->text() << "toggled" << a->isChecked(); +} |