1 // Copyright (c) 2012 Dennco Project
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // Created by tkawata on Sep-30, 2012.
19 #ifndef DCQTITEMMODEL_H
20 #define DCQTITEMMODEL_H
22 #include <QAbstractItemModel>
24 #include <QStringList>
26 class DCQtItemModelItem
29 DCQtItemModelItem(const QVector<QVariant> &data, DCQtItemModelItem *parent = 0);
30 virtual ~DCQtItemModelItem();
32 DCQtItemModelItem *child(int number);
33 int childCount() const;
34 int columnCount() const;
35 QVariant data(int column) const;
36 bool insertChildren(int position, int count, int columns);
37 bool insertColumns(int position, int columns);
38 DCQtItemModelItem *parent();
39 bool removeChildren(int position, int count);
40 bool removeColumns(int position, int columns);
41 int childNumber() const;
42 bool setData(int column, const QVariant &value);
45 QList<DCQtItemModelItem*> mChildItems;
46 QVector<QVariant> mItemData;
47 DCQtItemModelItem *mParentItem;
50 class DCQtItemModel : public QAbstractItemModel
54 DCQtItemModel(const QStringList &headers, QObject *parent = 0);
55 virtual ~DCQtItemModel();
57 QVariant data(const QModelIndex &index, int role) const;
58 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
60 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
61 QModelIndex parent(const QModelIndex &index) const;
63 int rowCount(const QModelIndex &parent = QModelIndex()) const;
64 int columnCount(const QModelIndex &parent = QModelIndex()) const;
66 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
67 virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
68 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
70 bool insertColumns(int position, int columns, const QModelIndex &parent = QModelIndex());
71 bool removeColumns(int position, int columns, const QModelIndex &parent = QModelIndex());
72 bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex());
73 bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex());
74 bool removeAllItems();
77 bool insertStringList(const QStringList &stringList, const QModelIndex &parent = QModelIndex());
78 bool insertString(const QString &string, const QModelIndex &parent = QModelIndex());
79 void setReadOnly(int column, bool isReadOnly);
82 DCQtItemModelItem *getItem(const QModelIndex &index) const;
84 DCQtItemModelItem *mRootItem;
85 QVector<bool> mReadOnlyAttrib;
92 #endif // DCQTITEMMODEL_H