source: trunk/src/gui/itemviews/qtablewidget_p.h@ 104

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

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

File size: 8.1 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 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
64QT_BEGIN_NAMESPACE
65
66// workaround for VC++ 6.0 linker bug
67typedef bool(*LessThan)(const QPair<QTableWidgetItem*,int>&,const QPair<QTableWidgetItem*,int>&);
68
69class QTableWidgetMimeData : public QMimeData
70{
71 Q_OBJECT
72public:
73 QList<QTableWidgetItem*> items;
74};
75
76class QTableModelLessThan
77{
78public:
79 inline bool operator()(QTableWidgetItem *i1, QTableWidgetItem *i2) const
80 { return (*i1 < *i2); }
81};
82
83class QTableModelGreaterThan
84{
85public:
86 inline bool operator()(QTableWidgetItem *i1, QTableWidgetItem *i2) const
87 { return (*i2 < *i1); }
88};
89
90class QTableModel : public QAbstractTableModel
91{
92 Q_OBJECT
93public:
94 enum ItemFlagsExtension {
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,
144 const QPair<QTableWidgetItem*,int> &right);
145 static bool itemGreaterThan(const QPair<QTableWidgetItem*,int> &left,
146 const QPair<QTableWidgetItem*,int> &right);
147 static bool canConvertToDouble(const QVariant &value);
148
149 void ensureSorted(int column, Qt::SortOrder order, int start, int end);
150 QVector<QTableWidgetItem*> columnItems(int column) const;
151 void updateRowIndexes(QModelIndexList &indexes, int movedFromRow, int movedToRow);
152 static QVector<QTableWidgetItem*>::iterator sortedInsertionIterator(
153 const QVector<QTableWidgetItem*>::iterator &begin,
154 const QVector<QTableWidgetItem*>::iterator &end,
155 Qt::SortOrder order, QTableWidgetItem *item);
156
157 bool isValid(const QModelIndex &index) const;
158 inline long tableIndex(int row, int column) const
159 { return (row * horizontalHeaderItems.count()) + column; }
160
161 void clear();
162 void clearContents();
163 void itemChanged(QTableWidgetItem *item);
164
165 QTableWidgetItem *createItem() const;
166 const QTableWidgetItem *itemPrototype() const;
167 void setItemPrototype(const QTableWidgetItem *item);
168
169 // dnd
170 QStringList mimeTypes() const;
171 QMimeData *mimeData(const QModelIndexList &indexes) const;
172 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
173 int row, int column, const QModelIndex &parent);
174 Qt::DropActions supportedDropActions() const;
175
176 QMimeData *internalMimeData() const;
177
178private:
179 const QTableWidgetItem *prototype;
180 QVector<QTableWidgetItem*> tableItems;
181 QVector<QTableWidgetItem*> verticalHeaderItems;
182 QVector<QTableWidgetItem*> horizontalHeaderItems;
183
184 // A cache must be mutable if get-functions should have const modifiers
185 mutable QModelIndexList cachedIndexes;
186};
187
188class QTableWidgetPrivate : public QTableViewPrivate
189{
190 Q_DECLARE_PUBLIC(QTableWidget)
191public:
192 QTableWidgetPrivate() : QTableViewPrivate() {}
193 inline QTableModel *model() const { return qobject_cast<QTableModel*>(q_func()->model()); }
194 void setup();
195
196 // view signals
197 void _q_emitItemPressed(const QModelIndex &index);
198 void _q_emitItemClicked(const QModelIndex &index);
199 void _q_emitItemDoubleClicked(const QModelIndex &index);
200 void _q_emitItemActivated(const QModelIndex &index);
201 void _q_emitItemEntered(const QModelIndex &index);
202 // model signals
203 void _q_emitItemChanged(const QModelIndex &index);
204 // selection signals
205 void _q_emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex &current);
206 // sorting
207 void _q_sort();
208 void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
209};
210
211class QTableWidgetItemPrivate
212{
213public:
214 QTableWidgetItemPrivate(QTableWidgetItem *item) : q(item), id(-1) {}
215 QTableWidgetItem *q;
216 int id;
217};
218
219QT_END_NAMESPACE
220
221#endif // QT_NO_TABLEWIDGET
222
223#endif // QTABLEWIDGET_P_H
Note: See TracBrowser for help on using the repository browser.