Qt 4.8
qtablewidget_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 QTABLEWIDGET_P_H
43 #define QTABLEWIDGET_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. This header file may change
50 // from version to version without notice, or even be removed.
51 //
52 // We mean it.
53 //
54 
55 #include <qheaderview.h>
56 #include <qtablewidget.h>
57 #include <qabstractitemmodel.h>
58 #include <private/qabstractitemmodel_p.h>
59 #include <private/qtableview_p.h>
60 #include <private/qwidgetitemdata_p.h>
61 
62 #ifndef QT_NO_TABLEWIDGET
63 
65 
66 // workaround for VC++ 6.0 linker bug
68 
70 {
71  Q_OBJECT
72 public:
74 };
75 
77 {
78 public:
79  inline bool operator()(QTableWidgetItem *i1, QTableWidgetItem *i2) const
80  { return (*i1 < *i2); }
81 };
82 
84 {
85 public:
86  inline bool operator()(QTableWidgetItem *i1, QTableWidgetItem *i2) const
87  { return (*i2 < *i1); }
88 };
89 
91 {
92  Q_OBJECT
93 public:
95  ItemIsHeaderItem = 128
96  }; // we need this to separate header items from other items
97 
98  QTableModel(int rows, int columns, QTableWidget *parent);
99  ~QTableModel();
100 
101  bool insertRows(int row, int count = 1, const QModelIndex &parent = QModelIndex());
102  bool insertColumns(int column, int count = 1, const QModelIndex &parent = QModelIndex());
103 
104  bool removeRows(int row, int count = 1, const QModelIndex &parent = QModelIndex());
105  bool removeColumns(int column, int count = 1, const QModelIndex &parent = QModelIndex());
106 
107  void setItem(int row, int column, QTableWidgetItem *item);
108  QTableWidgetItem *takeItem(int row, int column);
109  QTableWidgetItem *item(int row, int column) const;
110  QTableWidgetItem *item(const QModelIndex &index) const;
111  void removeItem(QTableWidgetItem *item);
112 
113  void setHorizontalHeaderItem(int section, QTableWidgetItem *item);
114  void setVerticalHeaderItem(int section, QTableWidgetItem *item);
115  QTableWidgetItem *takeHorizontalHeaderItem(int section);
116  QTableWidgetItem *takeVerticalHeaderItem(int section);
117  QTableWidgetItem *horizontalHeaderItem(int section);
118  QTableWidgetItem *verticalHeaderItem(int section);
119 
120  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const
121  { return QAbstractTableModel::index(row, column, parent); }
122 
123  QModelIndex index(const QTableWidgetItem *item) const;
124 
125  void setRowCount(int rows);
126  void setColumnCount(int columns);
127 
128  int rowCount(const QModelIndex &parent = QModelIndex()) const;
129  int columnCount(const QModelIndex &parent = QModelIndex()) const;
130 
131  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
132  bool setData(const QModelIndex &index, const QVariant &value, int role);
133  bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles);
134 
135  QMap<int, QVariant> itemData(const QModelIndex &index) const;
136 
137  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
138  bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role);
139 
140  Qt::ItemFlags flags(const QModelIndex &index) const;
141 
142  void sort(int column, Qt::SortOrder order);
143  static bool itemLessThan(const QPair<QTableWidgetItem*,int> &left,
145  static bool itemGreaterThan(const QPair<QTableWidgetItem*,int> &left,
146  const QPair<QTableWidgetItem*,int> &right);
147 
148  void ensureSorted(int column, Qt::SortOrder order, int start, int end);
149  QVector<QTableWidgetItem*> columnItems(int column) const;
150  void updateRowIndexes(QModelIndexList &indexes, int movedFromRow, int movedToRow);
151  static QVector<QTableWidgetItem*>::iterator sortedInsertionIterator(
154  Qt::SortOrder order, QTableWidgetItem *item);
155 
156  bool isValid(const QModelIndex &index) const;
157  inline long tableIndex(int row, int column) const
158  { return (row * horizontalHeaderItems.count()) + column; }
159 
160  void clear();
161  void clearContents();
162  void itemChanged(QTableWidgetItem *item);
163 
164  QTableWidgetItem *createItem() const;
165  const QTableWidgetItem *itemPrototype() const;
166  void setItemPrototype(const QTableWidgetItem *item);
167 
168  // dnd
169  QStringList mimeTypes() const;
170  QMimeData *mimeData(const QModelIndexList &indexes) const;
171  bool dropMimeData(const QMimeData *data, Qt::DropAction action,
172  int row, int column, const QModelIndex &parent);
173  Qt::DropActions supportedDropActions() const;
174 
175  QMimeData *internalMimeData() const;
176 
177 private:
182 
183  // A cache must be mutable if get-functions should have const modifiers
185 };
186 
188 {
190 public:
192  inline QTableModel *tableModel() const { return qobject_cast<QTableModel*>(model); }
193  void setup();
194 
195  // view signals
196  void _q_emitItemPressed(const QModelIndex &index);
197  void _q_emitItemClicked(const QModelIndex &index);
198  void _q_emitItemDoubleClicked(const QModelIndex &index);
199  void _q_emitItemActivated(const QModelIndex &index);
200  void _q_emitItemEntered(const QModelIndex &index);
201  // model signals
202  void _q_emitItemChanged(const QModelIndex &index);
203  // selection signals
204  void _q_emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex &current);
205  // sorting
206  void _q_sort();
207  void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
208 };
209 
211 {
212 public:
213  QTableWidgetItemPrivate(QTableWidgetItem *item) : q(item), id(-1) {}
215  int id;
216 };
217 
219 
220 #endif // QT_NO_TABLEWIDGET
221 
222 #endif // QTABLEWIDGET_P_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool operator()(QTableWidgetItem *i1, QTableWidgetItem *i2) const
void setData(const QString &mimetype, const QByteArray &data)
Sets the data associated with the MIME type given by mimeType to the specified data.
Definition: qmimedata.cpp:547
void clear()
Removes all the MIME type and data entries in the object.
Definition: qmimedata.cpp:613
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QVector< QTableWidgetItem * > verticalHeaderItems
The QTableWidget class provides an item-based table view with a default model.
Definition: qtablewidget.h:220
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the index of the data in row and column with parent.
long tableIndex(int row, int column) const
bool(* LessThan)(const QPair< QTableWidgetItem *, int > &, const QPair< QTableWidgetItem *, int > &)
QByteArray data(const QString &mimetype) const
Returns the data stored in the object in the format described by the MIME type specified by mimeType...
Definition: qmimedata.cpp:524
T * qobject_cast(QObject *object)
Definition: qobject.h:375
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the index of the data in row and column with parent.
SortOrder
Definition: qnamespace.h:189
const QTableWidgetItem * prototype
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QTableModel * tableModel() const
static void sort(T *array, int count, LessThan lessThan)
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QTableWidgetItemPrivate(QTableWidgetItem *item)
DropAction
Definition: qnamespace.h:1597
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
QVector< QTableWidgetItem * > horizontalHeaderItems
#define Q_OBJECT
Definition: qobjectdefs.h:157
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QTableWidgetItem * q
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QModelIndexList cachedIndexes
bool operator()(QTableWidgetItem *i1, QTableWidgetItem *i2) const
The QModelIndex class is used to locate data in a data model.
quint16 index
QList< QTableWidgetItem * > items
static const KeyPair *const end
Orientation
Definition: qnamespace.h:174
QVector< QTableWidgetItem * > tableItems
The QTableWidgetItem class provides an item for use with the QTableWidget class.
Definition: qtablewidget.h:82
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
The QAbstractTableModel class provides an abstract model that can be subclassed to create table model...
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
static void setup()
Definition: qtextcodec.cpp:718
The QList class is a template class that provides lists.
Definition: qdatastream.h:62