0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#ifndef QTABLEWIDGET_H
|
|
43 |
#define QTABLEWIDGET_H
|
|
44 |
|
|
45 |
#include <QtGui/qtableview.h>
|
|
46 |
#include <QtCore/qvariant.h>
|
|
47 |
#include <QtCore/qvector.h>
|
|
48 |
//#include <QtGui/qitemselectionmodel.h>
|
|
49 |
|
|
50 |
QT_BEGIN_HEADER
|
|
51 |
|
|
52 |
QT_BEGIN_NAMESPACE
|
|
53 |
|
|
54 |
QT_MODULE(Gui)
|
|
55 |
|
|
56 |
#ifndef QT_NO_TABLEWIDGET
|
|
57 |
|
|
58 |
class Q_GUI_EXPORT QTableWidgetSelectionRange
|
|
59 |
{
|
|
60 |
public:
|
|
61 |
QTableWidgetSelectionRange();
|
|
62 |
QTableWidgetSelectionRange(int top, int left, int bottom, int right);
|
|
63 |
QTableWidgetSelectionRange(const QTableWidgetSelectionRange &other);
|
|
64 |
~QTableWidgetSelectionRange();
|
|
65 |
|
|
66 |
inline int topRow() const { return top; }
|
|
67 |
inline int bottomRow() const { return bottom; }
|
|
68 |
inline int leftColumn() const { return left; }
|
|
69 |
inline int rightColumn() const { return right; }
|
|
70 |
inline int rowCount() const { return bottom - top + 1; }
|
|
71 |
inline int columnCount() const { return right - left + 1; }
|
|
72 |
|
|
73 |
private:
|
|
74 |
int top, left, bottom, right;
|
|
75 |
};
|
|
76 |
|
|
77 |
class QTableWidget;
|
|
78 |
class QTableModel;
|
|
79 |
class QWidgetItemData;
|
|
80 |
class QTableWidgetItemPrivate;
|
|
81 |
|
|
82 |
class Q_GUI_EXPORT QTableWidgetItem
|
|
83 |
{
|
|
84 |
friend class QTableWidget;
|
|
85 |
friend class QTableModel;
|
|
86 |
public:
|
|
87 |
enum ItemType { Type = 0, UserType = 1000 };
|
|
88 |
QTableWidgetItem(int type = Type);
|
|
89 |
explicit QTableWidgetItem(const QString &text, int type = Type);
|
|
90 |
explicit QTableWidgetItem(const QIcon &icon, const QString &text, int type = Type);
|
|
91 |
QTableWidgetItem(const QTableWidgetItem &other);
|
|
92 |
virtual ~QTableWidgetItem();
|
|
93 |
|
|
94 |
virtual QTableWidgetItem *clone() const;
|
|
95 |
|
|
96 |
inline QTableWidget *tableWidget() const { return view; }
|
|
97 |
|
|
98 |
inline int row() const;
|
|
99 |
inline int column() const;
|
|
100 |
|
|
101 |
inline void setSelected(bool select);
|
|
102 |
inline bool isSelected() const;
|
|
103 |
|
|
104 |
inline Qt::ItemFlags flags() const { return itemFlags; }
|
|
105 |
void setFlags(Qt::ItemFlags flags);
|
|
106 |
|
|
107 |
inline QString text() const
|
|
108 |
{ return data(Qt::DisplayRole).toString(); }
|
|
109 |
inline void setText(const QString &text);
|
|
110 |
|
|
111 |
inline QIcon icon() const
|
|
112 |
{ return qvariant_cast<QIcon>(data(Qt::DecorationRole)); }
|
|
113 |
inline void setIcon(const QIcon &icon);
|
|
114 |
|
|
115 |
inline QString statusTip() const
|
|
116 |
{ return data(Qt::StatusTipRole).toString(); }
|
|
117 |
inline void setStatusTip(const QString &statusTip);
|
|
118 |
|
|
119 |
#ifndef QT_NO_TOOLTIP
|
|
120 |
inline QString toolTip() const
|
|
121 |
{ return data(Qt::ToolTipRole).toString(); }
|
|
122 |
inline void setToolTip(const QString &toolTip);
|
|
123 |
#endif
|
|
124 |
|
|
125 |
#ifndef QT_NO_WHATSTHIS
|
|
126 |
inline QString whatsThis() const
|
|
127 |
{ return data(Qt::WhatsThisRole).toString(); }
|
|
128 |
inline void setWhatsThis(const QString &whatsThis);
|
|
129 |
#endif
|
|
130 |
|
|
131 |
inline QFont font() const
|
|
132 |
{ return qvariant_cast<QFont>(data(Qt::FontRole)); }
|
|
133 |
inline void setFont(const QFont &font);
|
|
134 |
|
|
135 |
inline int textAlignment() const
|
|
136 |
{ return data(Qt::TextAlignmentRole).toInt(); }
|
|
137 |
inline void setTextAlignment(int alignment)
|
|
138 |
{ setData(Qt::TextAlignmentRole, alignment); }
|
|
139 |
|
|
140 |
inline QColor backgroundColor() const
|
|
141 |
{ return qvariant_cast<QColor>(data(Qt::BackgroundColorRole)); }
|
|
142 |
inline void setBackgroundColor(const QColor &color)
|
|
143 |
{ setData(Qt::BackgroundColorRole, color); }
|
|
144 |
|
|
145 |
inline QBrush background() const
|
|
146 |
{ return qvariant_cast<QBrush>(data(Qt::BackgroundRole)); }
|
|
147 |
inline void setBackground(const QBrush &brush)
|
|
148 |
{ setData(Qt::BackgroundRole, brush); }
|
|
149 |
|
|
150 |
inline QColor textColor() const
|
|
151 |
{ return qvariant_cast<QColor>(data(Qt::TextColorRole)); }
|
|
152 |
inline void setTextColor(const QColor &color)
|
|
153 |
{ setData(Qt::TextColorRole, color); }
|
|
154 |
|
|
155 |
inline QBrush foreground() const
|
|
156 |
{ return qvariant_cast<QBrush>(data(Qt::ForegroundRole)); }
|
|
157 |
inline void setForeground(const QBrush &brush)
|
|
158 |
{ setData(Qt::ForegroundRole, brush); }
|
|
159 |
|
|
160 |
inline Qt::CheckState checkState() const
|
|
161 |
{ return static_cast<Qt::CheckState>(data(Qt::CheckStateRole).toInt()); }
|
|
162 |
inline void setCheckState(Qt::CheckState state)
|
|
163 |
{ setData(Qt::CheckStateRole, state); }
|
|
164 |
|
|
165 |
inline QSize sizeHint() const
|
|
166 |
{ return qvariant_cast<QSize>(data(Qt::SizeHintRole)); }
|
|
167 |
inline void setSizeHint(const QSize &size)
|
|
168 |
{ setData(Qt::SizeHintRole, size); }
|
|
169 |
|
|
170 |
virtual QVariant data(int role) const;
|
|
171 |
virtual void setData(int role, const QVariant &value);
|
|
172 |
|
|
173 |
virtual bool operator<(const QTableWidgetItem &other) const;
|
|
174 |
|
|
175 |
#ifndef QT_NO_DATASTREAM
|
|
176 |
virtual void read(QDataStream &in);
|
|
177 |
virtual void write(QDataStream &out) const;
|
|
178 |
#endif
|
|
179 |
QTableWidgetItem &operator=(const QTableWidgetItem &other);
|
|
180 |
|
|
181 |
inline int type() const { return rtti; }
|
|
182 |
|
|
183 |
private:
|
|
184 |
int rtti;
|
|
185 |
QVector<QWidgetItemData> values;
|
|
186 |
QTableWidget *view;
|
|
187 |
QTableWidgetItemPrivate *d;
|
|
188 |
Qt::ItemFlags itemFlags;
|
|
189 |
};
|
|
190 |
|
|
191 |
inline void QTableWidgetItem::setText(const QString &atext)
|
|
192 |
{ setData(Qt::DisplayRole, atext); }
|
|
193 |
|
|
194 |
inline void QTableWidgetItem::setIcon(const QIcon &aicon)
|
|
195 |
{ setData(Qt::DecorationRole, aicon); }
|
|
196 |
|
|
197 |
inline void QTableWidgetItem::setStatusTip(const QString &astatusTip)
|
|
198 |
{ setData(Qt::StatusTipRole, astatusTip); }
|
|
199 |
|
|
200 |
#ifndef QT_NO_TOOLTIP
|
|
201 |
inline void QTableWidgetItem::setToolTip(const QString &atoolTip)
|
|
202 |
{ setData(Qt::ToolTipRole, atoolTip); }
|
|
203 |
#endif
|
|
204 |
|
|
205 |
#ifndef QT_NO_WHATSTHIS
|
|
206 |
inline void QTableWidgetItem::setWhatsThis(const QString &awhatsThis)
|
|
207 |
{ setData(Qt::WhatsThisRole, awhatsThis); }
|
|
208 |
#endif
|
|
209 |
|
|
210 |
inline void QTableWidgetItem::setFont(const QFont &afont)
|
|
211 |
{ setData(Qt::FontRole, afont); }
|
|
212 |
|
|
213 |
#ifndef QT_NO_DATASTREAM
|
|
214 |
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QTableWidgetItem &item);
|
|
215 |
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &out, const QTableWidgetItem &item);
|
|
216 |
#endif
|
|
217 |
|
|
218 |
class QTableWidgetPrivate;
|
|
219 |
|
|
220 |
class Q_GUI_EXPORT QTableWidget : public QTableView
|
|
221 |
{
|
|
222 |
Q_OBJECT
|
|
223 |
Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount)
|
|
224 |
Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount)
|
|
225 |
|
|
226 |
friend class QTableModel;
|
|
227 |
public:
|
|
228 |
explicit QTableWidget(QWidget *parent = 0);
|
|
229 |
QTableWidget(int rows, int columns, QWidget *parent = 0);
|
|
230 |
~QTableWidget();
|
|
231 |
|
|
232 |
void setRowCount(int rows);
|
|
233 |
int rowCount() const;
|
|
234 |
|
|
235 |
void setColumnCount(int columns);
|
|
236 |
int columnCount() const;
|
|
237 |
|
|
238 |
int row(const QTableWidgetItem *item) const;
|
|
239 |
int column(const QTableWidgetItem *item) const;
|
|
240 |
|
|
241 |
QTableWidgetItem *item(int row, int column) const;
|
|
242 |
void setItem(int row, int column, QTableWidgetItem *item);
|
|
243 |
QTableWidgetItem *takeItem(int row, int column);
|
|
244 |
|
|
245 |
QTableWidgetItem *verticalHeaderItem(int row) const;
|
|
246 |
void setVerticalHeaderItem(int row, QTableWidgetItem *item);
|
|
247 |
QTableWidgetItem *takeVerticalHeaderItem(int row);
|
|
248 |
|
|
249 |
QTableWidgetItem *horizontalHeaderItem(int column) const;
|
|
250 |
void setHorizontalHeaderItem(int column, QTableWidgetItem *item);
|
|
251 |
QTableWidgetItem *takeHorizontalHeaderItem(int column);
|
|
252 |
void setVerticalHeaderLabels(const QStringList &labels);
|
|
253 |
void setHorizontalHeaderLabels(const QStringList &labels);
|
|
254 |
|
|
255 |
int currentRow() const;
|
|
256 |
int currentColumn() const;
|
|
257 |
QTableWidgetItem *currentItem() const;
|
|
258 |
void setCurrentItem(QTableWidgetItem *item);
|
|
259 |
void setCurrentItem(QTableWidgetItem *item, QItemSelectionModel::SelectionFlags command);
|
|
260 |
void setCurrentCell(int row, int column);
|
|
261 |
void setCurrentCell(int row, int column, QItemSelectionModel::SelectionFlags command);
|
|
262 |
|
|
263 |
void sortItems(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
|
264 |
void setSortingEnabled(bool enable);
|
|
265 |
bool isSortingEnabled() const;
|
|
266 |
|
|
267 |
void editItem(QTableWidgetItem *item);
|
|
268 |
void openPersistentEditor(QTableWidgetItem *item);
|
|
269 |
void closePersistentEditor(QTableWidgetItem *item);
|
|
270 |
|
|
271 |
QWidget *cellWidget(int row, int column) const;
|
|
272 |
void setCellWidget(int row, int column, QWidget *widget);
|
|
273 |
inline void removeCellWidget(int row, int column);
|
|
274 |
|
|
275 |
bool isItemSelected(const QTableWidgetItem *item) const;
|
|
276 |
void setItemSelected(const QTableWidgetItem *item, bool select);
|
|
277 |
void setRangeSelected(const QTableWidgetSelectionRange &range, bool select);
|
|
278 |
|
|
279 |
QList<QTableWidgetSelectionRange> selectedRanges() const;
|
|
280 |
QList<QTableWidgetItem*> selectedItems();
|
|
281 |
QList<QTableWidgetItem*> findItems(const QString &text, Qt::MatchFlags flags) const;
|
|
282 |
|
|
283 |
int visualRow(int logicalRow) const;
|
|
284 |
int visualColumn(int logicalColumn) const;
|
|
285 |
|
|
286 |
QTableWidgetItem *itemAt(const QPoint &p) const;
|
|
287 |
inline QTableWidgetItem *itemAt(int x, int y) const;
|
|
288 |
QRect visualItemRect(const QTableWidgetItem *item) const;
|
|
289 |
|
|
290 |
const QTableWidgetItem *itemPrototype() const;
|
|
291 |
void setItemPrototype(const QTableWidgetItem *item);
|
|
292 |
|
|
293 |
public Q_SLOTS:
|
|
294 |
void scrollToItem(const QTableWidgetItem *item, QAbstractItemView::ScrollHint hint = EnsureVisible);
|
|
295 |
void insertRow(int row);
|
|
296 |
void insertColumn(int column);
|
|
297 |
void removeRow(int row);
|
|
298 |
void removeColumn(int column);
|
|
299 |
void clear();
|
|
300 |
void clearContents();
|
|
301 |
|
|
302 |
Q_SIGNALS:
|
|
303 |
void itemPressed(QTableWidgetItem *item);
|
|
304 |
void itemClicked(QTableWidgetItem *item);
|
|
305 |
void itemDoubleClicked(QTableWidgetItem *item);
|
|
306 |
|
|
307 |
void itemActivated(QTableWidgetItem *item);
|
|
308 |
void itemEntered(QTableWidgetItem *item);
|
|
309 |
void itemChanged(QTableWidgetItem *item);
|
|
310 |
|
|
311 |
void currentItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous);
|
|
312 |
void itemSelectionChanged();
|
|
313 |
|
|
314 |
void cellPressed(int row, int column);
|
|
315 |
void cellClicked(int row, int column);
|
|
316 |
void cellDoubleClicked(int row, int column);
|
|
317 |
|
|
318 |
void cellActivated(int row, int column);
|
|
319 |
void cellEntered(int row, int column);
|
|
320 |
void cellChanged(int row, int column);
|
|
321 |
|
|
322 |
void currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn);
|
|
323 |
|
|
324 |
protected:
|
|
325 |
bool event(QEvent *e);
|
|
326 |
virtual QStringList mimeTypes() const;
|
|
327 |
virtual QMimeData *mimeData(const QList<QTableWidgetItem*> items) const;
|
|
328 |
virtual bool dropMimeData(int row, int column, const QMimeData *data, Qt::DropAction action);
|
|
329 |
virtual Qt::DropActions supportedDropActions() const;
|
|
330 |
QList<QTableWidgetItem*> items(const QMimeData *data) const;
|
|
331 |
|
|
332 |
QModelIndex indexFromItem(QTableWidgetItem *item) const;
|
|
333 |
QTableWidgetItem *itemFromIndex(const QModelIndex &index) const;
|
|
334 |
void dropEvent(QDropEvent *event);
|
|
335 |
|
|
336 |
private:
|
|
337 |
void setModel(QAbstractItemModel *model);
|
|
338 |
|
|
339 |
Q_DECLARE_PRIVATE(QTableWidget)
|
|
340 |
Q_DISABLE_COPY(QTableWidget)
|
|
341 |
|
|
342 |
Q_PRIVATE_SLOT(d_func(), void _q_emitItemPressed(const QModelIndex &index))
|
|
343 |
Q_PRIVATE_SLOT(d_func(), void _q_emitItemClicked(const QModelIndex &index))
|
|
344 |
Q_PRIVATE_SLOT(d_func(), void _q_emitItemDoubleClicked(const QModelIndex &index))
|
|
345 |
Q_PRIVATE_SLOT(d_func(), void _q_emitItemActivated(const QModelIndex &index))
|
|
346 |
Q_PRIVATE_SLOT(d_func(), void _q_emitItemEntered(const QModelIndex &index))
|
|
347 |
Q_PRIVATE_SLOT(d_func(), void _q_emitItemChanged(const QModelIndex &index))
|
|
348 |
Q_PRIVATE_SLOT(d_func(), void _q_emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex ¤t))
|
|
349 |
Q_PRIVATE_SLOT(d_func(), void _q_sort())
|
|
350 |
Q_PRIVATE_SLOT(d_func(), void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight))
|
|
351 |
};
|
|
352 |
|
|
353 |
inline void QTableWidget::removeCellWidget(int arow, int acolumn)
|
|
354 |
{ setCellWidget(arow, acolumn, 0); }
|
|
355 |
|
|
356 |
inline QTableWidgetItem *QTableWidget::itemAt(int ax, int ay) const
|
|
357 |
{ return itemAt(QPoint(ax, ay)); }
|
|
358 |
|
|
359 |
inline int QTableWidgetItem::row() const
|
|
360 |
{ return (view ? view->row(this) : -1); }
|
|
361 |
|
|
362 |
inline int QTableWidgetItem::column() const
|
|
363 |
{ return (view ? view->column(this) : -1); }
|
|
364 |
|
|
365 |
inline void QTableWidgetItem::setSelected(bool aselect)
|
|
366 |
{ if (view) view->setItemSelected(this, aselect); }
|
|
367 |
|
|
368 |
inline bool QTableWidgetItem::isSelected() const
|
|
369 |
{ return (view ? view->isItemSelected(this) : false); }
|
|
370 |
|
|
371 |
#endif // QT_NO_TABLEWIDGET
|
|
372 |
|
|
373 |
QT_END_NAMESPACE
|
|
374 |
|
|
375 |
QT_END_HEADER
|
|
376 |
|
|
377 |
#endif // QTABLEWIDGET_H
|