diff options
author | Arno <arno@disconnect.de> | 2018-11-03 07:55:02 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2018-11-03 07:55:02 +0100 |
commit | a896d928412bc8f02131c8c6ab0d8c1ad4e4753f (patch) | |
tree | bb2d50f4675c3100b1a1a578988c41c3f5c6275f /wizardtreemodel.cpp | |
parent | 3bfc587c081df11a02fad65e9cf9a3174aba284a (diff) | |
download | SheMov-a896d928412bc8f02131c8c6ab0d8c1ad4e4753f.tar.gz SheMov-a896d928412bc8f02131c8c6ab0d8c1ad4e4753f.tar.bz2 SheMov-a896d928412bc8f02131c8c6ab0d8c1ad4e4753f.zip |
Put WizardTreeModel in separate file
One class per file :) No functional changes, just code shuffle and
reindention.
Diffstat (limited to 'wizardtreemodel.cpp')
-rw-r--r-- | wizardtreemodel.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/wizardtreemodel.cpp b/wizardtreemodel.cpp new file mode 100644 index 0000000..783fc4a --- /dev/null +++ b/wizardtreemodel.cpp @@ -0,0 +1,76 @@ +/* + 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 "wizardtreemodel.h" +#include "smglobals.h" +#include "smtreeitem.h" + +WizardTreeModel::WizardTreeModel(QStringList &headers, QObject *parent) : SmTreeModel(headers, parent){ + mFiletypeMap = SmGlobals::instance()->filetypeMap(); +} + +Qt::ItemFlags WizardTreeModel::flags(const QModelIndex &index) const{ + if(index.column() == FileType || index.column() == FilePart){ + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; + } + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QList<QVariant> WizardTreeModel::fileData(const QModelIndex &idx) const{ + SmTreeItem *item = itemAt(idx); + QList<QVariant> retval; + for(int i = 0; i < item->columnCount(); ++i){ + retval << item->data(i); + } + return retval; +} + +void WizardTreeModel::clear(){ + SmTreeItem *rootItem = new SmTreeItem(NumFields); + setRoot(rootItem); +} + +QVariant WizardTreeModel::data(const QModelIndex &index, int role) const{ + SmTreeItem *item = static_cast<SmTreeItem*>(index.internalPointer()); + if(role == Qt::TextAlignmentRole){ + if(index.column() == FileSize){ + return Qt::AlignRight; + } + return Qt::AlignLeft; + } + if(role == FileNameRole){ + return item->data(FileName); + } + if(role == FileSizeRole){ + return item->data(FileSize); + } + if(role == FileTypeRole){ + return item->data(FileType); + } + if(role == FullPathRole){ + return item->data(FullPath); + } + if(role == FilePartRole){ + return item->data(FilePart); + } + return SmTreeModel::data(index, role); +} + +bool WizardTreeModel::setData(const QModelIndex &index, const QVariant &value, int role){ + if(role == Qt::EditRole){ + SmTreeItem *item = itemAt(index); + if(index.column() == FileType){ + QVariant realVal = mFiletypeMap.key(value.toString()); + item->setData(index.column(), realVal); + }else{ + item->setData(index.column(), value); + } + emit dataChanged(index, index); + return true; + } + return false; +} |