QtBase  v6.3.1
qabstractitemmodel_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtCore 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 The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QABSTRACTITEMMODEL_P_H
41 #define QABSTRACTITEMMODEL_P_H
42 
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists for the convenience
48 // of QAbstractItemModel*. This header file may change from version
49 // to version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 //
54 
55 #include "QtCore/qabstractitemmodel.h"
56 #include "QtCore/private/qobject_p.h"
57 #include "QtCore/qstack.h"
58 #include "QtCore/qset.h"
59 #include "QtCore/qhash.h"
60 
62 
63 QT_REQUIRE_CONFIG(itemmodel);
64 
66 {
67 public:
74 };
75 
76 class Q_CORE_EXPORT QAbstractItemModelPrivate : public QObjectPrivate
77 {
78  Q_DECLARE_PUBLIC(QAbstractItemModel)
79 
80 public:
83 
84  void removePersistentIndexData(QPersistentModelIndexData *data);
85  void movePersistentIndexes(const QList<QPersistentModelIndexData *> &indexes, int change, const QModelIndex &parent,
86  Qt::Orientation orientation);
87  void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last);
88  void rowsInserted(const QModelIndex &parent, int first, int last);
89  void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last);
90  void rowsRemoved(const QModelIndex &parent, int first, int last);
91  void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last);
92  void columnsInserted(const QModelIndex &parent, int first, int last);
93  void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last);
94  void columnsRemoved(const QModelIndex &parent, int first, int last);
95  static QAbstractItemModel *staticEmptyModel();
96  static bool variantLessThan(const QVariant &v1, const QVariant &v2);
97 
98  void itemsAboutToBeMoved(const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation);
99  void itemsMoved(const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation);
100  bool allowMove(const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation);
101 
102  // ugly hack for QTreeModel, see QTBUG-94546
103  virtual void executePendingOperations() const;
104 
105  inline QModelIndex createIndex(int row, int column, void *data = nullptr) const {
106  return q_func()->createIndex(row, column, data);
107  }
108 
109  inline QModelIndex createIndex(int row, int column, int id) const {
110  return q_func()->createIndex(row, column, id);
111  }
112 
113  inline bool indexValid(const QModelIndex &index) const {
114  return (index.row() >= 0) && (index.column() >= 0) && (index.model() == q_func());
115  }
116 
117  void invalidatePersistentIndexes();
118  void invalidatePersistentIndex(const QModelIndex &index);
119 
120  struct Change {
121  constexpr Change() : parent(), first(-1), last(-1), needsAdjust(false) {}
122  constexpr Change(const QModelIndex &p, int f, int l) : parent(p), first(f), last(l), needsAdjust(false) {}
123 
125  int first, last;
126 
127 
128  // In cases such as this:
129  // - A
130  // - B
131  // - C
132  // - - D
133  // - - E
134  // - - F
135  //
136  // If B is moved to above E, C is the source parent in the signal and its row is 2. When the move is
137  // completed however, C is at row 1 and there is no row 2 at the same level in the model at all.
138  // The QModelIndex is adjusted to correct that in those cases before reporting it though the
139  // rowsMoved signal.
141 
142  constexpr bool isValid() const { return first >= 0 && last >= 0; }
143  };
145 
146  struct Persistent {
151  void insertMultiAtEnd(const QModelIndex& key, QPersistentModelIndexData *data);
152  } persistent;
153 
154  static const QHash<int,QByteArray> &defaultRoleNames();
155  static bool isVariantLessThan(const QVariant &left, const QVariant &right,
156  Qt::CaseSensitivity cs = Qt::CaseSensitive, bool isLocaleAware = false);
157 };
159 
160 namespace QtPrivate {
161 
180 template <typename T>
182 {
183  static_assert(std::is_enum_v<T>);
184  if (data.userType() == qMetaTypeId<T>())
185  return data.value<T>();
186  else if (data.userType() == qMetaTypeId<int>())
187  return T(data.toInt());
188 
189  return T();
190 }
191 
192 template <typename T>
194 {
195  if (data.userType() == qMetaTypeId<T>())
196  return data.value<T>();
197  else if (data.userType() == qMetaTypeId<int>())
198  return T::fromInt(data.toInt());
199 
200  return T();
201 }
202 
203 } // namespace QtPrivate
204 
205 
207 
208 #endif // QABSTRACTITEMMODEL_P_H
FT_UInt idx
Definition: cffcmap.c:135
The QAbstractItemModel class provides the abstract interface for item model classes.
QModelIndex createIndex(int row, int column, int id) const
QModelIndex createIndex(int row, int column, void *data=nullptr) const
bool indexValid(const QModelIndex &index) const
The QAtomicInt class provides platform-independent atomic operations on int.
Definition: qatomic.h:158
Definition: qlist.h:108
The QModelIndex class is used to locate data in a data model.
static void destroy(QPersistentModelIndexData *data)
static QPersistentModelIndexData * create(const QModelIndex &index)
QPersistentModelIndexData(const QModelIndex &idx)
The QStack class is a template class that provides a stack.
Definition: qstack.h:49
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
#define T(x)
Definition: main.cpp:42
Orientation
Definition: qnamespace.h:123
CaseSensitivity
Definition: qnamespace.h:1282
@ CaseSensitive
Definition: qnamespace.h:1284
T legacyEnumValueFromModelData(const QVariant &data)
T legacyFlagValueFromModelData(const QVariant &data)
QT_BEGIN_NAMESPACE QT_REQUIRE_CONFIG(itemmodel)
Q_DECLARE_TYPEINFO(QAbstractItemModelPrivate::Change, Q_RELOCATABLE_TYPE)
GLint GLfloat GLfloat GLfloat v2
GLuint64 key
GLuint index
[2]
GLdouble GLdouble right
GLfloat GLfloat f
GLint left
GLint GLfloat GLfloat v1
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint first
GLenum GLenum GLsizei void GLsizei void * column
Definition: qopenglext.h:2747
GLenum GLenum GLsizei void * row
Definition: qopenglext.h:2747
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
@ Q_RELOCATABLE_TYPE
Definition: qtypeinfo.h:156
constexpr Change(const QModelIndex &p, int f, int l)
QMultiHash< QModelIndex, QPersistentModelIndexData * > indexes
QStack< QList< QPersistentModelIndexData * > > moved
QStack< QList< QPersistentModelIndexData * > > invalidated
Definition: main.cpp:38
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent