- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qtablewidget.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtGui module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QTABLEWIDGET_H
    00043 #define QTABLEWIDGET_H
    00044
    00045 #include <QtGui/qtableview.h>
    00046 #include <QtCore/qvariant.h>
    00047 #include <QtCore/qvector.h>
    00048 //#include <QtGui/qitemselectionmodel.h>
    00049
    00050 QT_BEGIN_HEADER
    00051
    00052 QT_BEGIN_NAMESPACE
    00053
    00054 QT_MODULE(Gui)
    00055
    00056 #ifndef QT_NO_TABLEWIDGET
    00057
    00058 class Q_GUI_EXPORT QTableWidgetSelectionRange
    00059 {
    00060 public:
    00061     QTableWidgetSelectionRange();
    00062     QTableWidgetSelectionRange(int top, int left, int bottom, int right);
    00063     QTableWidgetSelectionRange(const QTableWidgetSelectionRange &other);
    00064     ~QTableWidgetSelectionRange();
    00065
    00066     inline int topRow() const { return top; }
    00067     inline int bottomRow() const { return bottom; }
    00068     inline int leftColumn() const { return left; }
    00069     inline int rightColumn() const { return right; }
    00070     inline int rowCount() const { return bottom - top + 1; }
    00071     inline int columnCount() const { return right - left + 1; }
    00072
    00073 private:
    00074     int top, left, bottom, right;
    00075 };
    00076
    00077 class QTableWidget;
    00078 class QTableModel;
    00079 class QWidgetItemData;
    00080 class QTableWidgetItemPrivate;
    00081
    00082 class Q_GUI_EXPORT QTableWidgetItem
    00083 {
    00084     friend class QTableWidget;
    00085     friend class QTableModel;
    00086 public:
    00087     enum ItemType { Type = 0, UserType = 1000 };
    00088     QTableWidgetItem(int type = Type);
    00089     explicit QTableWidgetItem(const QString &text, int type = Type);
    00090     explicit QTableWidgetItem(const QIcon &icon, const QString &text, int type = Type);
    00091     QTableWidgetItem(const QTableWidgetItem &other);
    00092     virtual ~QTableWidgetItem();
    00093
    00094     virtual QTableWidgetItem *clone() const;
    00095
    00096     inline QTableWidget *tableWidget() const { return view; }
    00097
    00098     inline int row() const;
    00099     inline int column() const;
    00100
    00101     inline void setSelected(bool select);
    00102     inline bool isSelected() const;
    00103
    00104     inline Qt::ItemFlags flags() const { return itemFlags; }
    00105     void setFlags(Qt::ItemFlags flags);
    00106
    00107     inline QString text() const
    00108         { return data(Qt::DisplayRole).toString(); }
    00109     inline void setText(const QString &text);
    00110
    00111     inline QIcon icon() const
    00112         { return qvariant_cast<QIcon>(data(Qt::DecorationRole)); }
    00113     inline void setIcon(const QIcon &icon);
    00114
    00115     inline QString statusTip() const
    00116         { return data(Qt::StatusTipRole).toString(); }
    00117     inline void setStatusTip(const QString &statusTip);
    00118
    00119 #ifndef QT_NO_TOOLTIP
    00120     inline QString toolTip() const
    00121         { return data(Qt::ToolTipRole).toString(); }
    00122     inline void setToolTip(const QString &toolTip);
    00123 #endif
    00124
    00125 #ifndef QT_NO_WHATSTHIS
    00126     inline QString whatsThis() const
    00127         { return data(Qt::WhatsThisRole).toString(); }
    00128     inline void setWhatsThis(const QString &whatsThis);
    00129 #endif
    00130
    00131     inline QFont font() const
    00132         { return qvariant_cast<QFont>(data(Qt::FontRole)); }
    00133     inline void setFont(const QFont &font);
    00134
    00135     inline int textAlignment() const
    00136         { return data(Qt::TextAlignmentRole).toInt(); }
    00137     inline void setTextAlignment(int alignment)
    00138         { setData(Qt::TextAlignmentRole, alignment); }
    00139
    00140     inline QColor backgroundColor() const
    00141         { return qvariant_cast<QColor>(data(Qt::BackgroundColorRole)); }
    00142     inline void setBackgroundColor(const QColor &color)
    00143         { setData(Qt::BackgroundColorRole, color); }
    00144
    00145     inline QBrush background() const
    00146         { return qvariant_cast<QBrush>(data(Qt::BackgroundRole)); }
    00147     inline void setBackground(const QBrush &brush)
    00148         { setData(Qt::BackgroundRole, brush); }
    00149
    00150     inline QColor textColor() const
    00151         { return qvariant_cast<QColor>(data(Qt::TextColorRole)); }
    00152     inline void setTextColor(const QColor &color)
    00153         { setData(Qt::TextColorRole, color); }
    00154
    00155     inline QBrush foreground() const
    00156         { return qvariant_cast<QBrush>(data(Qt::ForegroundRole)); }
    00157     inline void setForeground(const QBrush &brush)
    00158         { setData(Qt::ForegroundRole, brush); }
    00159
    00160     inline Qt::CheckState checkState() const
    00161         { return static_cast<Qt::CheckState>(data(Qt::CheckStateRole).toInt()); }
    00162     inline void setCheckState(Qt::CheckState state)
    00163         { setData(Qt::CheckStateRole, state); }
    00164
    00165     inline QSize sizeHint() const
    00166         { return qvariant_cast<QSize>(data(Qt::SizeHintRole)); }
    00167     inline void setSizeHint(const QSize &size)
    00168         { setData(Qt::SizeHintRole, size); }
    00169
    00170     virtual QVariant data(int role) const;
    00171     virtual void setData(int role, const QVariant &value);
    00172
    00173     virtual bool operator<(const QTableWidgetItem &other) const;
    00174
    00175 #ifndef QT_NO_DATASTREAM
    00176     virtual void read(QDataStream &in);
    00177     virtual void write(QDataStream &out) const;
    00178 #endif
    00179     QTableWidgetItem &operator=(const QTableWidgetItem &other);
    00180
    00181     inline int type() const { return rtti; }
    00182
    00183 private:
    00184     int rtti;
    00185     QVector<QWidgetItemData> values;
    00186     QTableWidget *view;
    00187     QTableWidgetItemPrivate *d;
    00188     Qt::ItemFlags itemFlags;
    00189 };
    00190
    00191 inline void QTableWidgetItem::setText(const QString &atext)
    00192 { setData(Qt::DisplayRole, atext); }
    00193
    00194 inline void QTableWidgetItem::setIcon(const QIcon &aicon)
    00195 { setData(Qt::DecorationRole, aicon); }
    00196
    00197 inline void QTableWidgetItem::setStatusTip(const QString &astatusTip)
    00198 { setData(Qt::StatusTipRole, astatusTip); }
    00199
    00200 #ifndef QT_NO_TOOLTIP
    00201 inline void QTableWidgetItem::setToolTip(const QString &atoolTip)
    00202 { setData(Qt::ToolTipRole, atoolTip); }
    00203 #endif
    00204
    00205 #ifndef QT_NO_WHATSTHIS
    00206 inline void QTableWidgetItem::setWhatsThis(const QString &awhatsThis)
    00207 { setData(Qt::WhatsThisRole, awhatsThis); }
    00208 #endif
    00209
    00210 inline void QTableWidgetItem::setFont(const QFont &afont)
    00211 { setData(Qt::FontRole, afont); }
    00212
    00213 #ifndef QT_NO_DATASTREAM
    00214 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QTableWidgetItem &item);
    00215 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &out, const QTableWidgetItem &item);
    00216 #endif
    00217
    00218 class QTableWidgetPrivate;
    00219
    00220 class Q_GUI_EXPORT QTableWidget : public QTableView
    00221 {
    00222     Q_OBJECT
    00223     Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount)
    00224     Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount)
    00225
    00226     friend class QTableModel;
    00227 public:
    00228     explicit QTableWidget(QWidget *parent = 0);
    00229     QTableWidget(int rows, int columns, QWidget *parent = 0);
    00230     ~QTableWidget();
    00231
    00232     void setRowCount(int rows);
    00233     int rowCount() const;
    00234
    00235     void setColumnCount(int columns);
    00236     int columnCount() const;
    00237
    00238     int row(const QTableWidgetItem *item) const;
    00239     int column(const QTableWidgetItem *item) const;
    00240
    00241     QTableWidgetItem *item(int row, int column) const;
    00242     void setItem(int row, int column, QTableWidgetItem *item);
    00243     QTableWidgetItem *takeItem(int row, int column);
    00244
    00245     QTableWidgetItem *verticalHeaderItem(int row) const;
    00246     void setVerticalHeaderItem(int row, QTableWidgetItem *item);
    00247     QTableWidgetItem *takeVerticalHeaderItem(int row);
    00248
    00249     QTableWidgetItem *horizontalHeaderItem(int column) const;
    00250     void setHorizontalHeaderItem(int column, QTableWidgetItem *item);
    00251     QTableWidgetItem *takeHorizontalHeaderItem(int column);
    00252     void setVerticalHeaderLabels(const QStringList &labels);
    00253     void setHorizontalHeaderLabels(const QStringList &labels);
    00254
    00255     int currentRow() const;
    00256     int currentColumn() const;
    00257     QTableWidgetItem *currentItem() const;
    00258     void setCurrentItem(QTableWidgetItem *item);
    00259     void setCurrentItem(QTableWidgetItem *item, QItemSelectionModel::SelectionFlags command);
    00260     void setCurrentCell(int row, int column);
    00261     void setCurrentCell(int row, int column, QItemSelectionModel::SelectionFlags command);
    00262
    00263     void sortItems(int column, Qt::SortOrder order = Qt::AscendingOrder);
    00264     void setSortingEnabled(bool enable);
    00265     bool isSortingEnabled() const;
    00266
    00267     void editItem(QTableWidgetItem *item);
    00268     void openPersistentEditor(QTableWidgetItem *item);
    00269     void closePersistentEditor(QTableWidgetItem *item);
    00270
    00271     QWidget *cellWidget(int row, int column) const;
    00272     void setCellWidget(int row, int column, QWidget *widget);
    00273     inline void removeCellWidget(int row, int column);
    00274
    00275     bool isItemSelected(const QTableWidgetItem *item) const;
    00276     void setItemSelected(const QTableWidgetItem *item, bool select);
    00277     void setRangeSelected(const QTableWidgetSelectionRange &range, bool select);
    00278
    00279     QList<QTableWidgetSelectionRange> selectedRanges() const;
    00280     QList<QTableWidgetItem*> selectedItems();
    00281     QList<QTableWidgetItem*> findItems(const QString &text, Qt::MatchFlags flags) const;
    00282
    00283     int visualRow(int logicalRow) const;
    00284     int visualColumn(int logicalColumn) const;
    00285
    00286     QTableWidgetItem *itemAt(const QPoint &p) const;
    00287     inline QTableWidgetItem *itemAt(int x, int y) const;
    00288     QRect visualItemRect(const QTableWidgetItem *item) const;
    00289
    00290     const QTableWidgetItem *itemPrototype() const;
    00291     void setItemPrototype(const QTableWidgetItem *item);
    00292
    00293 public Q_SLOTS:
    00294     void scrollToItem(const QTableWidgetItem *item, QAbstractItemView::ScrollHint hint = EnsureVisible);
    00295     void insertRow(int row);
    00296     void insertColumn(int column);
    00297     void removeRow(int row);
    00298     void removeColumn(int column);
    00299     void clear();
    00300     void clearContents();
    00301
    00302 Q_SIGNALS:
    00303     void itemPressed(QTableWidgetItem *item);
    00304     void itemClicked(QTableWidgetItem *item);
    00305     void itemDoubleClicked(QTableWidgetItem *item);
    00306
    00307     void itemActivated(QTableWidgetItem *item);
    00308     void itemEntered(QTableWidgetItem *item);
    00309     void itemChanged(QTableWidgetItem *item);
    00310
    00311     void currentItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous);
    00312     void itemSelectionChanged();
    00313
    00314     void cellPressed(int row, int column);
    00315     void cellClicked(int row, int column);
    00316     void cellDoubleClicked(int row, int column);
    00317
    00318     void cellActivated(int row, int column);
    00319     void cellEntered(int row, int column);
    00320     void cellChanged(int row, int column);
    00321
    00322     void currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn);
    00323
    00324 protected:
    00325     bool event(QEvent *e);
    00326     virtual QStringList mimeTypes() const;
    00327     virtual QMimeData *mimeData(const QList<QTableWidgetItem*> items) const;
    00328     virtual bool dropMimeData(int row, int column, const QMimeData *data, Qt::DropAction action);
    00329     virtual Qt::DropActions supportedDropActions() const;
    00330     QList<QTableWidgetItem*> items(const QMimeData *data) const;
    00331
    00332     QModelIndex indexFromItem(QTableWidgetItem *item) const;
    00333     QTableWidgetItem *itemFromIndex(const QModelIndex &index) const;
    00334     void dropEvent(QDropEvent *event);
    00335
    00336 private:
    00337     void setModel(QAbstractItemModel *model);
    00338
    00339     Q_DECLARE_PRIVATE(QTableWidget)
    00340     Q_DISABLE_COPY(QTableWidget)
    00341
    00342     Q_PRIVATE_SLOT(d_func(), void _q_emitItemPressed(const QModelIndex &index))
    00343     Q_PRIVATE_SLOT(d_func(), void _q_emitItemClicked(const QModelIndex &index))
    00344     Q_PRIVATE_SLOT(d_func(), void _q_emitItemDoubleClicked(const QModelIndex &index))
    00345     Q_PRIVATE_SLOT(d_func(), void _q_emitItemActivated(const QModelIndex &index))
    00346     Q_PRIVATE_SLOT(d_func(), void _q_emitItemEntered(const QModelIndex &index))
    00347     Q_PRIVATE_SLOT(d_func(), void _q_emitItemChanged(const QModelIndex &index))
    00348     Q_PRIVATE_SLOT(d_func(), void _q_emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex &current))
    00349     Q_PRIVATE_SLOT(d_func(), void _q_sort())
    00350     Q_PRIVATE_SLOT(d_func(), void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight))
    00351 };
    00352
    00353 inline void QTableWidget::removeCellWidget(int arow, int acolumn)
    00354 { setCellWidget(arow, acolumn, 0); }
    00355
    00356 inline QTableWidgetItem *QTableWidget::itemAt(int ax, int ay) const
    00357 { return itemAt(QPoint(ax, ay)); }
    00358
    00359 inline int QTableWidgetItem::row() const
    00360 { return (view ? view->row(this) : -1); }
    00361
    00362 inline int QTableWidgetItem::column() const
    00363 { return (view ? view->column(this) : -1); }
    00364
    00365 inline void QTableWidgetItem::setSelected(bool aselect)
    00366 { if (view) view->setItemSelected(this, aselect); }
    00367
    00368 inline bool QTableWidgetItem::isSelected() const
    00369 { return (view ? view->isItemSelected(this) : false); }
    00370
    00371 #endif // QT_NO_TABLEWIDGET
    00372
    00373 QT_END_NAMESPACE
    00374
    00375 QT_END_HEADER
    00376
    00377 #endif // QTABLEWIDGET_H