Qt 4.8
qstandarditemmodel_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 
68 
70 {
72 public:
74  : model(0),
75  parent(0),
76  rows(0),
77  columns(0),
78  q_ptr(0),
79  lastIndexOf(2)
80  { }
81  virtual ~QStandardItemPrivate();
82 
83  inline int childIndex(int row, int column) const {
84  if ((row < 0) || (column < 0)
85  || (row >= rowCount()) || (column >= columnCount())) {
86  return -1;
87  }
88  return (row * columnCount()) + column;
89  }
90  inline int childIndex(const QStandardItem *child) {
91  int start = qMax(0, lastIndexOf -2);
92  lastIndexOf = children.indexOf(const_cast<QStandardItem*>(child), start);
93  if (lastIndexOf == -1 && start != 0)
94  lastIndexOf = children.lastIndexOf(const_cast<QStandardItem*>(child), start);
95  return lastIndexOf;
96  }
97  QPair<int, int> position() const;
98  void setChild(int row, int column, QStandardItem *item,
99  bool emitChanged = false);
100  inline int rowCount() const {
101  return rows;
102  }
103  inline int columnCount() const {
104  return columns;
105  }
106  void childDeleted(QStandardItem *child);
107 
108  void setModel(QStandardItemModel *mod);
109 
110  inline void setParentAndModel(
111  QStandardItem *par,
112  QStandardItemModel *mod) {
113  setModel(mod);
114  parent = par;
115  }
116 
117  void changeFlags(bool enable, Qt::ItemFlags f);
118  void setItemData(const QMap<int, QVariant> &roles);
119  const QMap<int, QVariant> itemData() const;
120 
121  bool insertRows(int row, int count, const QList<QStandardItem*> &items);
122  bool insertRows(int row, const QList<QStandardItem*> &items);
123  bool insertColumns(int column, int count, const QList<QStandardItem*> &items);
124 
125  void sortChildren(int column, Qt::SortOrder order);
126 
131  int rows;
132  int columns;
133 
135 
137 };
138 
140 {
142 
143 public:
145  virtual ~QStandardItemModelPrivate();
146 
147  void init();
148 
149  inline QStandardItem *createItem() const {
150  return itemPrototype ? itemPrototype->clone() : new QStandardItem;
151  }
152 
154  Q_Q(const QStandardItemModel);
155  if (!index.isValid())
156  return root.data();
157  if (index.model() != q)
158  return 0;
159  QStandardItem *parent = static_cast<QStandardItem*>(index.internalPointer());
160  if (parent == 0)
161  return 0;
162  return parent->child(index.row(), index.column());
163  }
164 
165  void sort(QStandardItem *parent, int column, Qt::SortOrder order);
166  void itemChanged(QStandardItem *item);
167  void rowsAboutToBeInserted(QStandardItem *parent, int start, int end);
168  void columnsAboutToBeInserted(QStandardItem *parent, int start, int end);
169  void rowsAboutToBeRemoved(QStandardItem *parent, int start, int end);
170  void columnsAboutToBeRemoved(QStandardItem *parent, int start, int end);
171  void rowsInserted(QStandardItem *parent, int row, int count);
172  void columnsInserted(QStandardItem *parent, int column, int count);
173  void rowsRemoved(QStandardItem *parent, int row, int count);
174  void columnsRemoved(QStandardItem *parent, int column, int count);
175 
176  void _q_emitItemChanged(const QModelIndex &topLeft,
177  const QModelIndex &bottomRight);
178 
179  void decodeDataRecursive(QDataStream &stream, QStandardItem *item);
180 
185  int sortRole;
186 };
187 
189 
190 #endif // QT_NO_STANDARDITEMMODEL
191 
192 #endif // QSTANDARDITEMMODEL_P_H
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
QScopedPointer< QStandardItem > root
const QMap< int, QVariant > itemData() const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setModel(QStandardItemModel *mod)
const QStandardItem * itemPrototype
The QStandardItemModel class provides a generic model for storing custom data.
QVector< QStandardItem * > children
int childIndex(int row, int column) const
QStandardItem * createItem() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
#define Q_Q(Class)
Definition: qglobal.h:2483
void setParentAndModel(QStandardItem *par, QStandardItemModel *mod)
virtual QStandardItem * clone() const
Returns a copy of this item.
SortOrder
Definition: qnamespace.h:189
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QPair< int, int > position() const
QVector< QStandardItem * > columnHeaderItems
static FILE * stream
static void sort(T *array, int count, LessThan lessThan)
static bool init
void childDeleted(QStandardItem *child)
bool insertColumns(int column, int count, const QList< QStandardItem *> &items)
int row() const
Returns the row this model index refers to.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool insertRows(int row, int count, const QList< QStandardItem *> &items)
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the vector, searching forward from ind...
Definition: qvector.h:698
int childIndex(const QStandardItem *child)
QStandardItemModel * model
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QVector< QStandardItem * > rowHeaderItems
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
The QModelIndex class is used to locate data in a data model.
void setChild(int row, int column, QStandardItem *item, bool emitChanged=false)
void sortChildren(int column, Qt::SortOrder order)
void changeFlags(bool enable, Qt::ItemFlags f)
void setItemData(const QMap< int, QVariant > &roles)
quint16 index
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
The QStandardItem class provides an item for use with the QStandardItemModel class.
static const KeyPair *const end
int lastIndexOf(const T &t, int from=-1) const
Returns the index position of the last occurrence of the value value in the vector, searching backward from index position from.
Definition: qvector.h:713
QVector< QWidgetItemData > values
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
QStandardItem * itemFromIndex(const QModelIndex &index) const
int column() const
Returns the column this model index refers to.
QStandardItem * child(int row, int column=0) const
Returns the child item at (row, column) if one has been set; otherwise returns 0. ...
The QList class is a template class that provides lists.
Definition: qdatastream.h:62