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

- File List
- File Members

# qstandarditemmodel.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 QSTANDARDITEMMODEL_H
    00043 #define QSTANDARDITEMMODEL_H
    00044
    00045 #include <QtCore/qabstractitemmodel.h>
    00046 #include <QtGui/qbrush.h>
    00047 #include <QtGui/qfont.h>
    00048 #include <QtGui/qicon.h>
    00049 #ifndef QT_NO_DATASTREAM
    00050 #include <QtCore/qdatastream.h>
    00051 #endif
    00052
    00053 QT_BEGIN_HEADER
    00054
    00055 QT_BEGIN_NAMESPACE
    00056
    00057 QT_MODULE(Gui)
    00058
    00059 #ifndef QT_NO_STANDARDITEMMODEL
    00060
    00061 template <class T> class QList;
    00062
    00063 class QStandardItemModel;
    00064
    00065 class QStandardItemPrivate;
    00066 class Q_GUI_EXPORT QStandardItem
    00067 {
    00068 public:
    00069     QStandardItem();
    00070     QStandardItem(const QString &text);
    00071     QStandardItem(const QIcon &icon, const QString &text);
    00072     explicit QStandardItem(int rows, int columns = 1);
    00073     virtual ~QStandardItem();
    00074
    00075     virtual QVariant data(int role = Qt::UserRole + 1) const;
    00076     virtual void setData(const QVariant &value, int role = Qt::UserRole + 1);
    00077
    00078     inline QString text() const {
    00079         return qvariant_cast<QString>(data(Qt::DisplayRole));
    00080     }
    00081     inline void setText(const QString &text);
    00082
    00083     inline QIcon icon() const {
    00084         return qvariant_cast<QIcon>(data(Qt::DecorationRole));
    00085     }
    00086     inline void setIcon(const QIcon &icon);
    00087
    00088 #ifndef QT_NO_TOOLTIP
    00089     inline QString toolTip() const {
    00090         return qvariant_cast<QString>(data(Qt::ToolTipRole));
    00091     }
    00092     inline void setToolTip(const QString &toolTip);
    00093 #endif
    00094
    00095 #ifndef QT_NO_STATUSTIP
    00096     inline QString statusTip() const {
    00097         return qvariant_cast<QString>(data(Qt::StatusTipRole));
    00098     }
    00099     inline void setStatusTip(const QString &statusTip);
    00100 #endif
    00101
    00102 #ifndef QT_NO_WHATSTHIS
    00103     inline QString whatsThis() const {
    00104         return qvariant_cast<QString>(data(Qt::WhatsThisRole));
    00105     }
    00106     inline void setWhatsThis(const QString &whatsThis);
    00107 #endif
    00108
    00109     inline QSize sizeHint() const {
    00110         return qvariant_cast<QSize>(data(Qt::SizeHintRole));
    00111     }
    00112     inline void setSizeHint(const QSize &sizeHint);
    00113
    00114     inline QFont font() const {
    00115         return qvariant_cast<QFont>(data(Qt::FontRole));
    00116     }
    00117     inline void setFont(const QFont &font);
    00118
    00119     inline Qt::Alignment textAlignment() const {
    00120         return Qt::Alignment(qvariant_cast<int>(data(Qt::TextAlignmentRole)));
    00121     }
    00122     inline void setTextAlignment(Qt::Alignment textAlignment);
    00123
    00124     inline QBrush background() const {
    00125         return qvariant_cast<QBrush>(data(Qt::BackgroundRole));
    00126     }
    00127     inline void setBackground(const QBrush &brush);
    00128
    00129     inline QBrush foreground() const {
    00130         return qvariant_cast<QBrush>(data(Qt::ForegroundRole));
    00131     }
    00132     inline void setForeground(const QBrush &brush);
    00133
    00134     inline Qt::CheckState checkState() const {
    00135         return Qt::CheckState(qvariant_cast<int>(data(Qt::CheckStateRole)));
    00136     }
    00137     inline void setCheckState(Qt::CheckState checkState);
    00138
    00139     inline QString accessibleText() const {
    00140         return qvariant_cast<QString>(data(Qt::AccessibleTextRole));
    00141     }
    00142     inline void setAccessibleText(const QString &accessibleText);
    00143
    00144     inline QString accessibleDescription() const {
    00145         return qvariant_cast<QString>(data(Qt::AccessibleDescriptionRole));
    00146     }
    00147     inline void setAccessibleDescription(const QString &accessibleDescription);
    00148
    00149     Qt::ItemFlags flags() const;
    00150     void setFlags(Qt::ItemFlags flags);
    00151
    00152     inline bool isEnabled() const {
    00153         return (flags() & Qt::ItemIsEnabled) != 0;
    00154     }
    00155     void setEnabled(bool enabled);
    00156
    00157     inline bool isEditable() const {
    00158         return (flags() & Qt::ItemIsEditable) != 0;
    00159     }
    00160     void setEditable(bool editable);
    00161
    00162     inline bool isSelectable() const {
    00163         return (flags() & Qt::ItemIsSelectable) != 0;
    00164     }
    00165     void setSelectable(bool selectable);
    00166
    00167     inline bool isCheckable() const {
    00168         return (flags() & Qt::ItemIsUserCheckable) != 0;
    00169     }
    00170     void setCheckable(bool checkable);
    00171
    00172     inline bool isTristate() const {
    00173         return (flags() & Qt::ItemIsTristate) != 0;
    00174     }
    00175     void setTristate(bool tristate);
    00176
    00177 #ifndef QT_NO_DRAGANDDROP
    00178     inline bool isDragEnabled() const {
    00179         return (flags() & Qt::ItemIsDragEnabled) != 0;
    00180     }
    00181     void setDragEnabled(bool dragEnabled);
    00182
    00183     inline bool isDropEnabled() const {
    00184         return (flags() & Qt::ItemIsDropEnabled) != 0;
    00185     }
    00186     void setDropEnabled(bool dropEnabled);
    00187 #endif // QT_NO_DRAGANDDROP
    00188
    00189     QStandardItem *parent() const;
    00190     int row() const;
    00191     int column() const;
    00192     QModelIndex index() const;
    00193     QStandardItemModel *model() const;
    00194
    00195     int rowCount() const;
    00196     void setRowCount(int rows);
    00197     int columnCount() const;
    00198     void setColumnCount(int columns);
    00199
    00200     bool hasChildren() const;
    00201     QStandardItem *child(int row, int column = 0) const;
    00202     void setChild(int row, int column, QStandardItem *item);
    00203     inline void setChild(int row, QStandardItem *item);
    00204
    00205     void insertRow(int row, const QList<QStandardItem*> &items);
    00206     void insertColumn(int column, const QList<QStandardItem*> &items);
    00207     void insertRows(int row, const QList<QStandardItem*> &items);
    00208     void insertRows(int row, int count);
    00209     void insertColumns(int column, int count);
    00210
    00211     void removeRow(int row);
    00212     void removeColumn(int column);
    00213     void removeRows(int row, int count);
    00214     void removeColumns(int column, int count);
    00215
    00216     inline void appendRow(const QList<QStandardItem*> &items);
    00217     inline void appendRows(const QList<QStandardItem*> &items);
    00218     inline void appendColumn(const QList<QStandardItem*> &items);
    00219     inline void insertRow(int row, QStandardItem *item);
    00220     inline void appendRow(QStandardItem *item);
    00221
    00222     QStandardItem *takeChild(int row, int column = 0);
    00223     QList<QStandardItem*> takeRow(int row);
    00224     QList<QStandardItem*> takeColumn(int column);
    00225
    00226     void sortChildren(int column, Qt::SortOrder order = Qt::AscendingOrder);
    00227
    00228     virtual QStandardItem *clone() const;
    00229
    00230     enum ItemType { Type = 0, UserType = 1000 };
    00231     virtual int type() const;
    00232
    00233 #ifndef QT_NO_DATASTREAM
    00234     virtual void read(QDataStream &in);
    00235     virtual void write(QDataStream &out) const;
    00236 #endif
    00237     virtual bool operator<(const QStandardItem &other) const;
    00238
    00239 protected:
    00240     QStandardItem(const QStandardItem &other);
    00241     QStandardItem(QStandardItemPrivate &dd);
    00242     QStandardItem &operator=(const QStandardItem &other);
    00243     QScopedPointer<QStandardItemPrivate> d_ptr;
    00244
    00245     void emitDataChanged();
    00246
    00247 private:
    00248     Q_DECLARE_PRIVATE(QStandardItem)
    00249     friend class QStandardItemModelPrivate;
    00250     friend class QStandardItemModel;
    00251 };
    00252
    00253 inline void QStandardItem::setText(const QString &atext)
    00254 { setData(atext, Qt::DisplayRole); }
    00255
    00256 inline void QStandardItem::setIcon(const QIcon &aicon)
    00257 { setData(aicon, Qt::DecorationRole); }
    00258
    00259 #ifndef QT_NO_TOOLTIP
    00260 inline void QStandardItem::setToolTip(const QString &atoolTip)
    00261 { setData(atoolTip, Qt::ToolTipRole); }
    00262 #endif
    00263
    00264 #ifndef QT_NO_STATUSTIP
    00265 inline void QStandardItem::setStatusTip(const QString &astatusTip)
    00266 { setData(astatusTip, Qt::StatusTipRole); }
    00267 #endif
    00268
    00269 #ifndef QT_NO_WHATSTHIS
    00270 inline void QStandardItem::setWhatsThis(const QString &awhatsThis)
    00271 { setData(awhatsThis, Qt::WhatsThisRole); }
    00272 #endif
    00273
    00274 inline void QStandardItem::setSizeHint(const QSize &asizeHint)
    00275 { setData(asizeHint, Qt::SizeHintRole); }
    00276
    00277 inline void QStandardItem::setFont(const QFont &afont)
    00278 { setData(afont, Qt::FontRole); }
    00279
    00280 inline void QStandardItem::setTextAlignment(Qt::Alignment atextAlignment)
    00281 { setData(int(atextAlignment), Qt::TextAlignmentRole); }
    00282
    00283 inline void QStandardItem::setBackground(const QBrush &abrush)
    00284 { setData(abrush, Qt::BackgroundRole); }
    00285
    00286 inline void QStandardItem::setForeground(const QBrush &abrush)
    00287 { setData(abrush, Qt::ForegroundRole); }
    00288
    00289 inline void QStandardItem::setCheckState(Qt::CheckState acheckState)
    00290 { setData(acheckState, Qt::CheckStateRole); }
    00291
    00292 inline void QStandardItem::setAccessibleText(const QString &aaccessibleText)
    00293 { setData(aaccessibleText, Qt::AccessibleTextRole); }
    00294
    00295 inline void QStandardItem::setAccessibleDescription(const QString &aaccessibleDescription)
    00296 { setData(aaccessibleDescription, Qt::AccessibleDescriptionRole); }
    00297
    00298 inline void QStandardItem::setChild(int arow, QStandardItem *aitem)
    00299 { setChild(arow, 0, aitem); }
    00300
    00301 inline void QStandardItem::appendRow(const QList<QStandardItem*> &aitems)
    00302 { insertRow(rowCount(), aitems); }
    00303
    00304 inline void QStandardItem::appendRows(const QList<QStandardItem*> &aitems)
    00305 { insertRows(rowCount(), aitems); }
    00306
    00307 inline void QStandardItem::appendColumn(const QList<QStandardItem*> &aitems)
    00308 { insertColumn(columnCount(), aitems); }
    00309
    00310 inline void QStandardItem::insertRow(int arow, QStandardItem *aitem)
    00311 { insertRow(arow, QList<QStandardItem*>() << aitem); }
    00312
    00313 inline void QStandardItem::appendRow(QStandardItem *aitem)
    00314 { insertRow(rowCount(), aitem); }
    00315
    00316 class QStandardItemModelPrivate;
    00317
    00318 class Q_GUI_EXPORT QStandardItemModel : public QAbstractItemModel
    00319 {
    00320     Q_OBJECT
    00321     Q_PROPERTY(int sortRole READ sortRole WRITE setSortRole)
    00322
    00323 public:
    00324     explicit QStandardItemModel(QObject *parent = 0);
    00325     QStandardItemModel(int rows, int columns, QObject *parent = 0);
    00326     ~QStandardItemModel();
    00327
    00328     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
    00329     QModelIndex parent(const QModelIndex &child) const;
    00330
    00331     int rowCount(const QModelIndex &parent = QModelIndex()) const;
    00332     int columnCount(const QModelIndex &parent = QModelIndex()) const;
    00333     bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
    00334
    00335     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    00336     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
    00337
    00338     QVariant headerData(int section, Qt::Orientation orientation,
    00339                         int role = Qt::DisplayRole) const;
    00340     bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
    00341                        int role = Qt::EditRole);
    00342
    00343     bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
    00344     bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex());
    00345     bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
    00346     bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
    00347
    00348     Qt::ItemFlags flags(const QModelIndex &index) const;
    00349     Qt::DropActions supportedDropActions() const;
    00350
    00351     QMap<int, QVariant> itemData(const QModelIndex &index) const;
    00352     bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles);
    00353
    00354     void clear();
    00355
    00356 #ifdef Q_NO_USING_KEYWORD
    00357     inline QObject *parent() const { return QObject::parent(); }
    00358 #else
    00359     using QObject::parent;
    00360 #endif
    00361
    00362     void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
    00363
    00364     QStandardItem *itemFromIndex(const QModelIndex &index) const;
    00365     QModelIndex indexFromItem(const QStandardItem *item) const;
    00366
    00367     QStandardItem *item(int row, int column = 0) const;
    00368     void setItem(int row, int column, QStandardItem *item);
    00369     inline void setItem(int row, QStandardItem *item);
    00370     QStandardItem *invisibleRootItem() const;
    00371
    00372     QStandardItem *horizontalHeaderItem(int column) const;
    00373     void setHorizontalHeaderItem(int column, QStandardItem *item);
    00374     QStandardItem *verticalHeaderItem(int row) const;
    00375     void setVerticalHeaderItem(int row, QStandardItem *item);
    00376
    00377     void setHorizontalHeaderLabels(const QStringList &labels);
    00378     void setVerticalHeaderLabels(const QStringList &labels);
    00379
    00380     void setRowCount(int rows);
    00381     void setColumnCount(int columns);
    00382
    00383     void appendRow(const QList<QStandardItem*> &items);
    00384     void appendColumn(const QList<QStandardItem*> &items);
    00385     inline void appendRow(QStandardItem *item);
    00386
    00387     void insertRow(int row, const QList<QStandardItem*> &items);
    00388     void insertColumn(int column, const QList<QStandardItem*> &items);
    00389     inline void insertRow(int row, QStandardItem *item);
    00390
    00391     inline bool insertRow(int row, const QModelIndex &parent = QModelIndex());
    00392     inline bool insertColumn(int column, const QModelIndex &parent = QModelIndex());
    00393
    00394     QStandardItem *takeItem(int row, int column = 0);
    00395     QList<QStandardItem*> takeRow(int row);
    00396     QList<QStandardItem*> takeColumn(int column);
    00397
    00398     QStandardItem *takeHorizontalHeaderItem(int column);
    00399     QStandardItem *takeVerticalHeaderItem(int row);
    00400
    00401     const QStandardItem *itemPrototype() const;
    00402     void setItemPrototype(const QStandardItem *item);
    00403
    00404     QList<QStandardItem*> findItems(const QString &text,
    00405                                     Qt::MatchFlags flags = Qt::MatchExactly,
    00406                                     int column = 0) const;
    00407
    00408     int sortRole() const;
    00409     void setSortRole(int role);
    00410
    00411     QStringList mimeTypes() const;
    00412     QMimeData *mimeData(const QModelIndexList &indexes) const;
    00413     bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
    00414
    00415 Q_SIGNALS:
    00416     void itemChanged(QStandardItem *item);
    00417
    00418 protected:
    00419     QStandardItemModel(QStandardItemModelPrivate &dd, QObject *parent = 0);
    00420
    00421 private:
    00422     friend class QStandardItemPrivate;
    00423     friend class QStandardItem;
    00424     Q_DISABLE_COPY(QStandardItemModel)
    00425     Q_DECLARE_PRIVATE(QStandardItemModel)
    00426
    00427     Q_PRIVATE_SLOT(d_func(), void _q_emitItemChanged(const QModelIndex &topLeft,
    00428                                                      const QModelIndex &bottomRight))
    00429 };
    00430
    00431 inline void QStandardItemModel::setItem(int arow, QStandardItem *aitem)
    00432 { setItem(arow, 0, aitem); }
    00433
    00434 inline void QStandardItemModel::appendRow(QStandardItem *aitem)
    00435 { appendRow(QList<QStandardItem*>() << aitem); }
    00436
    00437 inline void QStandardItemModel::insertRow(int arow, QStandardItem *aitem)
    00438 { insertRow(arow, QList<QStandardItem*>() << aitem); }
    00439
    00440 inline bool QStandardItemModel::insertRow(int arow, const QModelIndex &aparent)
    00441 { return QAbstractItemModel::insertRow(arow, aparent); }
    00442 inline bool QStandardItemModel::insertColumn(int acolumn, const QModelIndex &aparent)
    00443 { return QAbstractItemModel::insertColumn(acolumn, aparent); }
    00444
    00445 #ifndef QT_NO_DATASTREAM
    00446 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QStandardItem &item);
    00447 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &out, const QStandardItem &item);
    00448 #endif
    00449
    00450 #endif // QT_NO_STANDARDITEMMODEL
    00451
    00452 QT_END_NAMESPACE
    00453
    00454 QT_END_HEADER
    00455
    00456 #endif //QSTANDARDITEMMODEL_H