1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtCore module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QABSTRACTITEMMODEL_H
|
---|
43 | #define QABSTRACTITEMMODEL_H
|
---|
44 |
|
---|
45 | #include <QtCore/qvariant.h>
|
---|
46 | #include <QtCore/qobject.h>
|
---|
47 | #include <QtCore/qhash.h>
|
---|
48 |
|
---|
49 | QT_BEGIN_HEADER
|
---|
50 |
|
---|
51 | QT_BEGIN_NAMESPACE
|
---|
52 |
|
---|
53 | QT_MODULE(Core)
|
---|
54 |
|
---|
55 | class QAbstractItemModel;
|
---|
56 | class QPersistentModelIndex;
|
---|
57 |
|
---|
58 | class Q_CORE_EXPORT QModelIndex
|
---|
59 | {
|
---|
60 | friend class QAbstractItemModel;
|
---|
61 | friend class QProxyModel;
|
---|
62 | public:
|
---|
63 | inline QModelIndex() : r(-1), c(-1), p(0), m(0) {}
|
---|
64 | inline QModelIndex(const QModelIndex &other)
|
---|
65 | : r(other.r), c(other.c), p(other.p), m(other.m) {}
|
---|
66 | inline ~QModelIndex() { p = 0; m = 0; }
|
---|
67 | inline int row() const { return r; }
|
---|
68 | inline int column() const { return c; }
|
---|
69 | inline void *internalPointer() const { return p; }
|
---|
70 | inline qint64 internalId() const { return reinterpret_cast<qint64>(p); }
|
---|
71 | inline QModelIndex parent() const;
|
---|
72 | inline QModelIndex sibling(int row, int column) const;
|
---|
73 | inline QModelIndex child(int row, int column) const;
|
---|
74 | inline QVariant data(int role = Qt::DisplayRole) const;
|
---|
75 | inline Qt::ItemFlags flags() const;
|
---|
76 | inline const QAbstractItemModel *model() const { return m; }
|
---|
77 | inline bool isValid() const { return (r >= 0) && (c >= 0) && (m != 0); }
|
---|
78 | inline bool operator==(const QModelIndex &other) const
|
---|
79 | { return (other.r == r) && (other.p == p) && (other.c == c) && (other.m == m); }
|
---|
80 | inline bool operator!=(const QModelIndex &other) const
|
---|
81 | { return !(*this == other); }
|
---|
82 | inline bool operator<(const QModelIndex &other) const
|
---|
83 | {
|
---|
84 | if (r < other.r) return true;
|
---|
85 | if (r == other.r) {
|
---|
86 | if (c < other.c) return true;
|
---|
87 | if (c == other.c) {
|
---|
88 | if (p < other.p) return true;
|
---|
89 | if (p == other.p) return m < other.m;
|
---|
90 | }
|
---|
91 | }
|
---|
92 | return false; }
|
---|
93 | private:
|
---|
94 | inline QModelIndex(int row, int column, void *ptr, const QAbstractItemModel *model);
|
---|
95 | int r, c;
|
---|
96 | void *p;
|
---|
97 | const QAbstractItemModel *m;
|
---|
98 | };
|
---|
99 | Q_DECLARE_TYPEINFO(QModelIndex, Q_MOVABLE_TYPE);
|
---|
100 |
|
---|
101 | #ifndef QT_NO_DEBUG_STREAM
|
---|
102 | Q_CORE_EXPORT QDebug operator<<(QDebug, const QModelIndex &);
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | class QPersistentModelIndexData;
|
---|
106 |
|
---|
107 | class Q_CORE_EXPORT QPersistentModelIndex
|
---|
108 | {
|
---|
109 | public:
|
---|
110 | QPersistentModelIndex();
|
---|
111 | QPersistentModelIndex(const QModelIndex &index);
|
---|
112 | QPersistentModelIndex(const QPersistentModelIndex &other);
|
---|
113 | ~QPersistentModelIndex();
|
---|
114 | bool operator<(const QPersistentModelIndex &other) const;
|
---|
115 | bool operator==(const QPersistentModelIndex &other) const;
|
---|
116 | inline bool operator!=(const QPersistentModelIndex &other) const
|
---|
117 | { return !operator==(other); }
|
---|
118 | QPersistentModelIndex &operator=(const QPersistentModelIndex &other);
|
---|
119 | bool operator==(const QModelIndex &other) const;
|
---|
120 | bool operator!=(const QModelIndex &other) const;
|
---|
121 | QPersistentModelIndex &operator=(const QModelIndex &other);
|
---|
122 | operator const QModelIndex&() const;
|
---|
123 | int row() const;
|
---|
124 | int column() const;
|
---|
125 | void *internalPointer() const;
|
---|
126 | qint64 internalId() const;
|
---|
127 | QModelIndex parent() const;
|
---|
128 | QModelIndex sibling(int row, int column) const;
|
---|
129 | QModelIndex child(int row, int column) const;
|
---|
130 | QVariant data(int role = Qt::DisplayRole) const;
|
---|
131 | Qt::ItemFlags flags() const;
|
---|
132 | const QAbstractItemModel *model() const;
|
---|
133 | bool isValid() const;
|
---|
134 | private:
|
---|
135 | QPersistentModelIndexData *d;
|
---|
136 | friend uint qHash(const QPersistentModelIndex &);
|
---|
137 | #ifndef QT_NO_DEBUG_STREAM
|
---|
138 | friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &);
|
---|
139 | #endif
|
---|
140 | };
|
---|
141 | Q_DECLARE_TYPEINFO(QPersistentModelIndex, Q_MOVABLE_TYPE);
|
---|
142 |
|
---|
143 | inline uint qHash(const QPersistentModelIndex &index)
|
---|
144 | { return qHash(index.d); }
|
---|
145 |
|
---|
146 |
|
---|
147 | #ifndef QT_NO_DEBUG_STREAM
|
---|
148 | Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &);
|
---|
149 | #endif
|
---|
150 |
|
---|
151 | template<typename T> class QList;
|
---|
152 | typedef QList<QModelIndex> QModelIndexList;
|
---|
153 |
|
---|
154 | class QMimeData;
|
---|
155 | class QAbstractItemModelPrivate;
|
---|
156 | template <class Key, class T> class QMap;
|
---|
157 |
|
---|
158 |
|
---|
159 | class Q_CORE_EXPORT QAbstractItemModel : public QObject
|
---|
160 | {
|
---|
161 | Q_OBJECT
|
---|
162 |
|
---|
163 | friend class QPersistentModelIndexData;
|
---|
164 | friend class QAbstractItemViewPrivate;
|
---|
165 | public:
|
---|
166 |
|
---|
167 | explicit QAbstractItemModel(QObject *parent = 0);
|
---|
168 | virtual ~QAbstractItemModel();
|
---|
169 |
|
---|
170 | bool hasIndex(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
---|
171 | virtual QModelIndex index(int row, int column,
|
---|
172 | const QModelIndex &parent = QModelIndex()) const = 0;
|
---|
173 | virtual QModelIndex parent(const QModelIndex &child) const = 0;
|
---|
174 |
|
---|
175 | inline QModelIndex sibling(int row, int column, const QModelIndex &idx) const
|
---|
176 | { return index(row, column, parent(idx)); }
|
---|
177 |
|
---|
178 | virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0;
|
---|
179 | virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0;
|
---|
180 | virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
|
---|
181 |
|
---|
182 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0;
|
---|
183 | virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
---|
184 |
|
---|
185 | virtual QVariant headerData(int section, Qt::Orientation orientation,
|
---|
186 | int role = Qt::DisplayRole) const;
|
---|
187 | virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
|
---|
188 | int role = Qt::EditRole);
|
---|
189 |
|
---|
190 | virtual QMap<int, QVariant> itemData(const QModelIndex &index) const;
|
---|
191 | virtual bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles);
|
---|
192 |
|
---|
193 | virtual QStringList mimeTypes() const;
|
---|
194 | virtual QMimeData *mimeData(const QModelIndexList &indexes) const;
|
---|
195 | virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action,
|
---|
196 | int row, int column, const QModelIndex &parent);
|
---|
|
---|