diff options
author | Arno <am@disconnect.de> | 2010-12-05 08:29:05 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-12-05 08:29:05 +0100 |
commit | 609e8d6f4ae179243d6f258205701561d94500f5 (patch) | |
tree | 057b5c21086d984c05b9d5e50cf5be59e167b5e6 /filestreewidget.cpp | |
parent | d1837c9c92c9f38a464f0473001db4e9a57d44e7 (diff) | |
download | SheMov-609e8d6f4ae179243d6f258205701561d94500f5.tar.gz SheMov-609e8d6f4ae179243d6f258205701561d94500f5.tar.bz2 SheMov-609e8d6f4ae179243d6f258205701561d94500f5.zip |
Selectable columns in FilesTreeView
Made columns shown in FilesTreeView selectable. Also, the order of
columns is saved and restored.
This was a difficult one. I even had to make a debug build of qt. But I
fixed a serious bug in FilesTreeModel::modeName: don't access the Hash
if modeName == -1.
Diffstat (limited to 'filestreewidget.cpp')
-rw-r--r-- | filestreewidget.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/filestreewidget.cpp b/filestreewidget.cpp index b017d7d..4ed9662 100644 --- a/filestreewidget.cpp +++ b/filestreewidget.cpp @@ -21,6 +21,7 @@ #include <QSettings> #include <QEvent> #include <QSettings> +#include <QHeaderView> #include "filestreewidget.h" #include "smglobals.h" @@ -275,7 +276,16 @@ void FilesTreeWidget::fileSelectionChanged(const QItemSelection &selected, const FilesTreeView::FilesTreeView(QWidget *parent) : QTreeView(parent), mHoverWin(new HoverWindow), mHover(false){ setAttribute(Qt::WA_Hover); - readConfig(); + +} + +void FilesTreeView::setModel(QAbstractItemModel *model){ + QTreeView::setModel(model); + for(int i = 0; i < header()->count(); ++i){ + header()->setSectionHidden(i, true); + } + readHeaderConfig(); + connect(header(), SIGNAL(sectionMoved(int,int,int)), this, SLOT(sectionHasMoved(int,int,int))); } void FilesTreeView::readConfig(){ @@ -284,6 +294,27 @@ void FilesTreeView::readConfig(){ mHoverWin->setWindowOpacity(s.value("ui/hoveropacity", 10).toFloat() / 10.0); } +void FilesTreeView::readHeaderConfig(){ + QSettings s; + QByteArray headerPos = s.value("ui/headerpos").toByteArray(); + if(!headerPos.isEmpty()){ + header()->restoreState(headerPos); + } +} + +void FilesTreeView::writeHeaderConfig(){ + QSettings s; + s.setValue("ui/headerpos", header()->saveState()); +} + +void FilesTreeView::toggleHeader(QObject *action){ + QAction *a = qobject_cast<QAction*>(action); + Q_ASSERT(a); + int logicalIndex = a->data().toInt(); + QHeaderView *hv = header(); + hv->setSectionHidden(logicalIndex, !a->isChecked()); +} + void FilesTreeView::contextMenuEvent(QContextMenuEvent *event){ QMenu ctxMenu; foreach(QAction *a, actions()){ @@ -350,6 +381,7 @@ bool FilesTreeView::exitHover(bool exitVal){ FilesTreeSortModel::FilesTreeSortModel(QObject *parent) : QSortFilterProxyModel(parent) {} +// left + right are from the sourceModel() !!!! bool FilesTreeSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const{ if(left.parent() == QModelIndex()){ return false; |