1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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()
38 QModelIndex
ProjectModel::index(int row
, int column
,
39 const QModelIndex
& parent
) const
42 if(!hasIndex(row
, column
, parent
))
45 ProjectNode
* foundParent
= root
;
47 foundParent
= static_cast<ProjectNode
*>(parent
.internalPointer());
49 if(row
< foundParent
->numChildren() && row
>= 0)
50 return createIndex(row
, column
, foundParent
->child(row
));
55 QModelIndex
ProjectModel::parent(const QModelIndex
&child
) const
60 ProjectNode
* foundParent
= static_cast<ProjectNode
*>
61 (child
.internalPointer())->parent();
66 return createIndex(foundParent
->row(), 0, foundParent
);
69 int ProjectModel::rowCount(const QModelIndex
&parent
) const
75 return root
->numChildren();
77 if(parent
.column() != 0)
80 return static_cast<ProjectNode
*>(parent
.internalPointer())->numChildren();
83 int ProjectModel::columnCount(const QModelIndex
&parent
) const
88 QVariant
ProjectModel::data(const QModelIndex
&index
, int role
) const
93 if(role
!= Qt::DisplayRole
)
96 return static_cast<ProjectNode
*>
97 (index
.internalPointer())->data(index
.column());
100 QVariant
ProjectModel::headerData(int col
, Qt::Orientation orientation
,
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
,
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
++)