Theme Editor: Working on the project viewer infrastructure
[kugel-rb.git] / utils / themeeditor / projectmodel.cpp
blobaeca1c76a7ac3fbaac95eba8e630194115da8855
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 Robert Bieber
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #include "projectmodel.h"
24 #include "projectfiles.h"
26 ProjectModel::ProjectModel(QString config, QObject *parent) :
27 QAbstractItemModel(parent)
29 root = new ProjectRoot(config);
32 ProjectModel::~ProjectModel()
34 if(root)
35 delete root;
38 QModelIndex ProjectModel::index(int row, int column,
39 const QModelIndex& parent) const
42 if(!hasIndex(row, column, parent))
43 return QModelIndex();
45 ProjectNode* foundParent = root;
46 if(parent.isValid())
47 foundParent = static_cast<ProjectNode*>(parent.internalPointer());
49 if(row < foundParent->numChildren() && row >= 0)
50 return createIndex(row, column, foundParent->child(row));
51 else
52 return QModelIndex();
55 QModelIndex ProjectModel::parent(const QModelIndex &child) const
57 if(!child.isValid())
58 return QModelIndex();
60 ProjectNode* foundParent = static_cast<ProjectNode*>
61 (child.internalPointer())->parent();
63 if(foundParent == 0)
64 return QModelIndex();
66 return createIndex(foundParent->row(), 0, foundParent);
69 int ProjectModel::rowCount(const QModelIndex &parent) const
71 if(!root)
72 return 0;
74 if(!parent.isValid())
75 return root->numChildren();
77 if(parent.column() != 0)
78 return 0;
80 return static_cast<ProjectNode*>(parent.internalPointer())->numChildren();
83 int ProjectModel::columnCount(const QModelIndex &parent) const
85 return numColumns;
88 QVariant ProjectModel::data(const QModelIndex &index, int role) const
90 if(!index.isValid())
91 return QVariant();
93 if(role != Qt::DisplayRole)
94 return QVariant();
96 return static_cast<ProjectNode*>
97 (index.internalPointer())->data(index.column());
100 QVariant ProjectModel::headerData(int col, Qt::Orientation orientation,
101 int role) const
103 return QVariant();
106 Qt::ItemFlags ProjectModel::flags(const QModelIndex &index) const
108 return static_cast<ProjectNode*>
109 (index.internalPointer())->flags(index.column());
112 bool ProjectModel::setData(const QModelIndex &index, const QVariant &value,
113 int role)
115 return true;
118 /* Constructor and destructor for the root class */
119 ProjectRoot::ProjectRoot(QString config)
121 children.append(new ProjectFiles(this));
124 ProjectRoot::~ProjectRoot()
126 for(int i = 0; i < children.count(); i++)
127 delete children[i];