source: trunk/src/gui/itemviews/qstandarditemmodel_p.h@ 100

Last change on this file since 100 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 6.3 KB
Line 
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 QtGui 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 QSTANDARDITEMMODEL_P_H
43#define QSTANDARDITEMMODEL_P_H
44
45//
46// W A R N I N G
47// -------------
48//
49// This file is not part of the Qt API. It exists for the convenience
50// of other Qt classes. This header file may change from version to
51// version without notice, or even be removed.
52//
53// We mean it.
54//
55
56#include "private/qabstractitemmodel_p.h"
57
58#ifndef QT_NO_STANDARDITEMMODEL
59
60#include <private/qwidgetitemdata_p.h>
61#include <QtCore/qlist.h>
62#include <QtCore/qpair.h>
63#include <QtCore/qstack.h>
64#include <QtCore/qvariant.h>
65#include <QtCore/qvector.h>
66
67QT_BEGIN_NAMESPACE
68
69class QStandardItemPrivate
70{
71 Q_DECLARE_PUBLIC(QStandardItem)
72public:
73 inline QStandardItemPrivate()
74 : model(0),
75 parent(0),
76 rows(0),
77 columns(0),
78 lastIndexOf(2)
79 { }
80 virtual ~QStandardItemPrivate();
81
82 inline int childIndex(int row, int column) const {
83 if ((row < 0) || (column < 0)
84 || (row >= rowCount()) || (column >= columnCount())) {
85 return -1;
86 }
87 return (row * columnCount()) + column;
88 }
89 inline int childIndex(const QStandardItem *child) {
90 int start = qMax(0, lastIndexOf -2);
91 lastIndexOf = children.indexOf(const_cast<QStandardItem*>(child), start);
92 if (lastIndexOf == -1 && start != 0)
93 lastIndexOf = children.lastIndexOf(const_cast<QStandardItem*>(child), start);
94 return lastIndexOf;
95 }
96 QPair<int, int> position() const;
97 void setChild(int row, int column, QStandardItem *item,
98 bool emitChanged = false);
99 inline int rowCount() const {
100 return rows;
101 }
102 inline int columnCount() const {
103 return columns;
104 }
105 void childDeleted(QStandardItem *child);
106
107 void setModel(QStandardItemModel *mod);
108
109 inline void setParentAndModel(
110 QStandardItem *par,
111 QStandardItemModel *mod) {
112 setModel(mod);
113 parent = par;
114 }
115
116 void changeFlags(bool enable, Qt::ItemFlags f);
117 void setItemData(const QMap<int, QVariant> &roles);
118 const QMap<int, QVariant> itemData() const;
119
120 bool insertRows(int row, int count, const QList<QStandardItem*> &items);
121 bool insertRows(int row, const QList<QStandardItem*> &items);
122 bool insertColumns(int column, int count, const QList<QStandardItem*> &items);
123
124 void sortChildren(int column, Qt::SortOrder order);
125
126 QStandardItemModel *model;
127 QStandardItem *parent;
128 QVector<QWidgetItemData> values;
129 QVector<QStandardItem*> children;
130 int rows;
131 int columns;
132
133 QStandardItem *q_ptr;
134
135 int lastIndexOf;
136};
137
138class QStandardItemModelPrivate : public QAbstractItemModelPrivate
139{
140 Q_DECLARE_PUBLIC(QStandardItemModel)
141
142public:
143 QStandardItemModelPrivate();
144 virtual ~QStandardItemModelPrivate();
145
146 void init();
147
148 inline QStandardItem *createItem() const {
149 return itemPrototype ? itemPrototype->clone() : new QStandardItem;
150 }
151
152 inline QStandardItem *itemFromIndex(const QModelIndex &index) const {
153 Q_Q(const QStandardItemModel);
154 if (!index.isValid())
155 return root;
156 if (index.model() != q)
157 return 0;
158 QStandardItem *parent = static_cast<QStandardItem*>(index.internalPointer());
159 if (parent == 0)
160 return 0;
161 return parent->child(index.row(), index.column());
162 }
163
164 void sort(QStandardItem *parent, int column, Qt::SortOrder order);
165 void itemChanged(QStandardItem *item);
166 void rowsAboutToBeInserted(QStandardItem *parent, int start, int end);
167 void columnsAboutToBeInserted(QStandardItem *parent, int start, int end);
168 void rowsAboutToBeRemoved(QStandardItem *parent, int start, int end);
169 void columnsAboutToBeRemoved(QStandardItem *parent, int start, int end);
170 void rowsInserted(QStandardItem *parent, int row, int count);
171 void columnsInserted(QStandardItem *parent, int column, int count);
172 void rowsRemoved(QStandardItem *parent, int row, int count);
173 void columnsRemoved(QStandardItem *parent, int column, int count);
174
175 void _q_emitItemChanged(const QModelIndex &topLeft,
176 const QModelIndex &bottomRight);
177
178 QVector<QStandardItem*> columnHeaderItems;
179 QVector<QStandardItem*> rowHeaderItems;
180 QStandardItem *root;
181 const QStandardItem *itemPrototype;
182 int sortRole;
183};
184
185QT_END_NAMESPACE
186
187#endif // QT_NO_STANDARDITEMMODEL
188
189#endif // QSTANDARDITEMMODEL_P_H
Note: See TracBrowser for help on using the repository browser.