Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "fileslistmodel.h"
- #include <qjson/serializer.h>
- #include <QtGui/QGuiApplication>
- #include <QtGui/QColor>
- #include <QtGui/QPalette>
- #include <cutecat/core/macros.h>
- FilesListModel::FilesListModel(ConfigArchsSet set): QAbstractItemModel()
- {
- foreach (QString arch, set.keys()) {
- _data << FLNodeGroup(arch, QList<FLNode>());
- foreach (QString target, set[arch].keys()) {
- ConfigFileEntry entry = set[arch][target];
- _data.last().nodes << FLNode(target, entry.symlinking, entry.path);
- }
- }
- }
- ConfigArchsSet FilesListModel::configArchsSet()
- {
- ConfigArchsSet set;
- foreach (FLNodeGroup group, _data) {
- set[group.arch] = ConfigFilesSet();
- foreach (FLNode node, group.nodes)
- set[group.arch][node.target] = ConfigFileEntry(node.source, node.symlinking);
- }
- return set;
- }
- QModelIndex FilesListModel::index(int row, int column, const QModelIndex& parent) const
- {
- if (!hasIndex(row, column, parent))
- return QModelIndex();
- if (!parent.isValid()) {
- return createIndex(row, column, new FLNodePointer(row));
- } else {
- return createIndex(row, column, new FLNodePointer(parent.row(), row));
- }
- }
- QModelIndex FilesListModel::parent(const QModelIndex& child) const
- {
- auto ptr = (FLNodePointer*) child.internalPointer();
- if (ptr->fileIndex == -1)
- return QModelIndex();
- else {
- return createIndex(ptr->archIndex, 0, new FLNodePointer(ptr->archIndex, -1));
- }
- }
- int FilesListModel::rowCount(const QModelIndex& parent) const
- {
- if (!parent.isValid())
- return _data.count();
- auto ptr = (FLNodePointer*) parent.internalPointer();
- if (ptr->fileIndex == -1) {
- return _data[parent.row()].nodes.count();
- } else {
- return 0;
- }
- }
- int FilesListModel::columnCount(const QModelIndex& parent) const
- {
- return COLUMNS_COUNT;
- }
- QVariant FilesListModel::data(const QModelIndex& index, int role) const
- {
- auto ptr = (FLNodePointer*) index.internalPointer();
- if (ptr->fileIndex == -1) {
- if (index.column() == COLUMN_TARGET) {
- switch (role) {
- case Qt::DisplayRole:
- return _data[ptr->archIndex].arch;
- default:
- return QVariant();
- }
- } else {
- return QVariant();
- }
- } else {
- if (index.column() == COLUMN_TARGET) {
- switch (role) {
- case Qt::DisplayRole:
- return _data[ptr->archIndex].nodes[ptr->fileIndex].target;
- default:
- return QVariant();
- }
- } else if (index.column() == COLUMN_SOURCE) {
- switch (role) {
- case Qt::DisplayRole: {
- FLNode node = _data[ptr->archIndex].nodes[ptr->fileIndex];
- return (node.symlinking ? "-> " : "= ") + node.source;
- }
- case Qt::ForegroundRole:
- return QGuiApplication::palette().color(QPalette::Disabled, QPalette::WindowText);
- default:
- return QVariant();
- }
- } else {
- return QVariant();
- }
- }
- }
- // bool FilesListModel::removeRows(int row, int count, const QModelIndex& parent)
- // {
- // if (!parent.isValid())
- // for (int i=0; i<count; i++)
- // _data.removeAt(row+i);
- // else
- // for (int i=0; i<count; i++)
- // _data[parent.row()].nodes.removeAt(row+i);
- // return true;
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement