OSDN Git Service

c19bf007aff183106db030a601ef284ab9eee634
[dennco/denncoCreator.git] / Source / utils / dcqtitemmodel.h
1 //  Copyright (c) 2012 Dennco Project
2 //
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.
7 //
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.
12 //
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/>.
15
16 //
17 //  Created by tkawata on Sep-30, 2012.
18 //
19 #ifndef DCQTITEMMODEL_H
20 #define DCQTITEMMODEL_H
21
22 #include <QAbstractItemModel>
23 #include <QVector>
24 #include <QStringList>
25
26 class DCQtItemModelItem
27 {
28 public:
29     DCQtItemModelItem(const QVector<QVariant> &data, DCQtItemModelItem *parent = 0);
30     virtual ~DCQtItemModelItem();
31
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);
43
44 private:
45     QList<DCQtItemModelItem*> mChildItems;
46     QVector<QVariant> mItemData;
47     DCQtItemModelItem *mParentItem;
48 };
49
50 class DCQtItemModel : public QAbstractItemModel
51 {
52     Q_OBJECT
53 public:
54     DCQtItemModel(const QStringList &headers, QObject *parent = 0);
55     virtual ~DCQtItemModel();
56
57     QVariant data(const QModelIndex &index, int role) const;
58     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
59
60     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
61     QModelIndex parent(const QModelIndex &index) const;
62
63     int rowCount(const QModelIndex &parent = QModelIndex()) const;
64     int columnCount(const QModelIndex &parent = QModelIndex()) const;
65
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);
69
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();
75
76     //
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);
80
81 protected:
82     DCQtItemModelItem *getItem(const QModelIndex &index) const;
83
84     DCQtItemModelItem *mRootItem;
85     QVector<bool> mReadOnlyAttrib;
86 signals:
87     
88 public slots:
89     
90 };
91
92 #endif // DCQTITEMMODEL_H