From a896d928412bc8f02131c8c6ab0d8c1ad4e4753f Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 3 Nov 2018 07:55:02 +0100 Subject: Put WizardTreeModel in separate file One class per file :) No functional changes, just code shuffle and reindention. --- wizardtreemodel.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 wizardtreemodel.cpp (limited to 'wizardtreemodel.cpp') 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 WizardTreeModel::fileData(const QModelIndex &idx) const{ + SmTreeItem *item = itemAt(idx); + QList 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(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; +} -- cgit v1.2.3-70-g09d2