Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:08:16

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QSTANDARDITEMMODEL_H
0005 #define QSTANDARDITEMMODEL_H
0006 
0007 #include <QtGui/qtguiglobal.h>
0008 #include <QtCore/qabstractitemmodel.h>
0009 #include <QtGui/qbrush.h>
0010 #include <QtGui/qfont.h>
0011 #include <QtGui/qicon.h>
0012 #ifndef QT_NO_DATASTREAM
0013 #include <QtCore/qdatastream.h>
0014 #endif
0015 
0016 QT_REQUIRE_CONFIG(standarditemmodel);
0017 
0018 QT_BEGIN_NAMESPACE
0019 
0020 class QStandardItemModel;
0021 
0022 class QStandardItemPrivate;
0023 class Q_GUI_EXPORT QStandardItem
0024 {
0025 public:
0026     QStandardItem();
0027     explicit QStandardItem(const QString &text);
0028     QStandardItem(const QIcon &icon, const QString &text);
0029     explicit QStandardItem(int rows, int columns = 1);
0030     virtual ~QStandardItem();
0031 
0032     virtual QVariant data(int role = Qt::UserRole + 1) const;
0033     virtual void multiData(QModelRoleDataSpan roleDataSpan) const;
0034     virtual void setData(const QVariant &value, int role = Qt::UserRole + 1);
0035     void clearData();
0036 
0037     inline QString text() const {
0038         return qvariant_cast<QString>(data(Qt::DisplayRole));
0039     }
0040     inline void setText(const QString &text);
0041 
0042     inline QIcon icon() const {
0043         return qvariant_cast<QIcon>(data(Qt::DecorationRole));
0044     }
0045     inline void setIcon(const QIcon &icon);
0046 
0047     inline QString toolTip() const {
0048         return qvariant_cast<QString>(data(Qt::ToolTipRole));
0049     }
0050     inline void setToolTip(const QString &toolTip);
0051 
0052 #ifndef QT_NO_STATUSTIP
0053     inline QString statusTip() const {
0054         return qvariant_cast<QString>(data(Qt::StatusTipRole));
0055     }
0056     inline void setStatusTip(const QString &statusTip);
0057 #endif
0058 
0059 #if QT_CONFIG(whatsthis)
0060     inline QString whatsThis() const {
0061         return qvariant_cast<QString>(data(Qt::WhatsThisRole));
0062     }
0063     inline void setWhatsThis(const QString &whatsThis);
0064 #endif
0065 
0066     inline QSize sizeHint() const {
0067         return qvariant_cast<QSize>(data(Qt::SizeHintRole));
0068     }
0069     inline void setSizeHint(const QSize &sizeHint);
0070 
0071     inline QFont font() const {
0072         return qvariant_cast<QFont>(data(Qt::FontRole));
0073     }
0074     inline void setFont(const QFont &font);
0075 
0076     inline Qt::Alignment textAlignment() const {
0077         return qvariant_cast<Qt::Alignment>(data(Qt::TextAlignmentRole));
0078     }
0079     inline void setTextAlignment(Qt::Alignment textAlignment);
0080 
0081     inline QBrush background() const {
0082         return qvariant_cast<QBrush>(data(Qt::BackgroundRole));
0083     }
0084     inline void setBackground(const QBrush &brush);
0085 
0086     inline QBrush foreground() const {
0087         return qvariant_cast<QBrush>(data(Qt::ForegroundRole));
0088     }
0089     inline void setForeground(const QBrush &brush);
0090 
0091     inline Qt::CheckState checkState() const {
0092         return Qt::CheckState(qvariant_cast<int>(data(Qt::CheckStateRole)));
0093     }
0094     inline void setCheckState(Qt::CheckState checkState);
0095 
0096     inline QString accessibleText() const {
0097         return qvariant_cast<QString>(data(Qt::AccessibleTextRole));
0098     }
0099     inline void setAccessibleText(const QString &accessibleText);
0100 
0101     inline QString accessibleDescription() const {
0102         return qvariant_cast<QString>(data(Qt::AccessibleDescriptionRole));
0103     }
0104     inline void setAccessibleDescription(const QString &accessibleDescription);
0105 
0106     Qt::ItemFlags flags() const;
0107     void setFlags(Qt::ItemFlags flags);
0108 
0109     inline bool isEnabled() const {
0110         return bool(flags() & Qt::ItemIsEnabled);
0111     }
0112     void setEnabled(bool enabled);
0113 
0114     inline bool isEditable() const {
0115         return bool(flags() & Qt::ItemIsEditable);
0116     }
0117     void setEditable(bool editable);
0118 
0119     inline bool isSelectable() const {
0120         return bool(flags() & Qt::ItemIsSelectable);
0121     }
0122     void setSelectable(bool selectable);
0123 
0124     inline bool isCheckable() const {
0125         return bool(flags() & Qt::ItemIsUserCheckable);
0126     }
0127     void setCheckable(bool checkable);
0128 
0129     inline bool isAutoTristate() const {
0130         return bool(flags() & Qt::ItemIsAutoTristate);
0131     }
0132     void setAutoTristate(bool tristate);
0133 
0134     inline bool isUserTristate() const {
0135         return bool(flags() & Qt::ItemIsUserTristate);
0136     }
0137     void setUserTristate(bool tristate);
0138 
0139 #if QT_CONFIG(draganddrop)
0140     inline bool isDragEnabled() const {
0141         return bool(flags() & Qt::ItemIsDragEnabled);
0142     }
0143     void setDragEnabled(bool dragEnabled);
0144 
0145     inline bool isDropEnabled() const {
0146         return bool(flags() & Qt::ItemIsDropEnabled);
0147     }
0148     void setDropEnabled(bool dropEnabled);
0149 #endif // QT_CONFIG(draganddrop)
0150 
0151     QStandardItem *parent() const;
0152     int row() const;
0153     int column() const;
0154     QModelIndex index() const;
0155     QStandardItemModel *model() const;
0156 
0157     int rowCount() const;
0158     void setRowCount(int rows);
0159     int columnCount() const;
0160     void setColumnCount(int columns);
0161 
0162     bool hasChildren() const;
0163     QStandardItem *child(int row, int column = 0) const;
0164     void setChild(int row, int column, QStandardItem *item);
0165     inline void setChild(int row, QStandardItem *item);
0166 
0167     void insertRow(int row, const QList<QStandardItem*> &items);
0168     void insertColumn(int column, const QList<QStandardItem*> &items);
0169     void insertRows(int row, const QList<QStandardItem*> &items);
0170     void insertRows(int row, int count);
0171     void insertColumns(int column, int count);
0172 
0173     void removeRow(int row);
0174     void removeColumn(int column);
0175     void removeRows(int row, int count);
0176     void removeColumns(int column, int count);
0177 
0178     inline void appendRow(const QList<QStandardItem*> &items);
0179     inline void appendRows(const QList<QStandardItem*> &items);
0180     inline void appendColumn(const QList<QStandardItem*> &items);
0181     inline void insertRow(int row, QStandardItem *item);
0182     inline void appendRow(QStandardItem *item);
0183 
0184     QStandardItem *takeChild(int row, int column = 0);
0185     QList<QStandardItem*> takeRow(int row);
0186     QList<QStandardItem*> takeColumn(int column);
0187 
0188     void sortChildren(int column, Qt::SortOrder order = Qt::AscendingOrder);
0189 
0190     virtual QStandardItem *clone() const;
0191 
0192     enum ItemType { Type = 0, UserType = 1000 };
0193     virtual int type() const;
0194 
0195 #ifndef QT_NO_DATASTREAM
0196     virtual void read(QDataStream &in);
0197     virtual void write(QDataStream &out) const;
0198 #endif
0199     virtual bool operator<(const QStandardItem &other) const;
0200 
0201 protected:
0202     QStandardItem(const QStandardItem &other);
0203     QStandardItem(QStandardItemPrivate &dd);
0204     QStandardItem &operator=(const QStandardItem &other);
0205     QScopedPointer<QStandardItemPrivate> d_ptr;
0206 
0207     void emitDataChanged();
0208 
0209 private:
0210     Q_DECLARE_PRIVATE(QStandardItem)
0211     friend class QStandardItemModelPrivate;
0212     friend class QStandardItemModel;
0213 };
0214 
0215 inline void QStandardItem::setText(const QString &atext)
0216 { setData(atext, Qt::DisplayRole); }
0217 
0218 inline void QStandardItem::setIcon(const QIcon &aicon)
0219 { setData(aicon, Qt::DecorationRole); }
0220 
0221 inline void QStandardItem::setToolTip(const QString &atoolTip)
0222 { setData(atoolTip, Qt::ToolTipRole); }
0223 
0224 #ifndef QT_NO_STATUSTIP
0225 inline void QStandardItem::setStatusTip(const QString &astatusTip)
0226 { setData(astatusTip, Qt::StatusTipRole); }
0227 #endif
0228 
0229 #if QT_CONFIG(whatsthis)
0230 inline void QStandardItem::setWhatsThis(const QString &awhatsThis)
0231 { setData(awhatsThis, Qt::WhatsThisRole); }
0232 #endif
0233 
0234 inline void QStandardItem::setSizeHint(const QSize &asizeHint)
0235 { setData(asizeHint, Qt::SizeHintRole); }
0236 
0237 inline void QStandardItem::setFont(const QFont &afont)
0238 { setData(afont, Qt::FontRole); }
0239 
0240 inline void QStandardItem::setTextAlignment(Qt::Alignment atextAlignment)
0241 { setData(QVariant::fromValue(atextAlignment), Qt::TextAlignmentRole); }
0242 
0243 inline void QStandardItem::setBackground(const QBrush &abrush)
0244 { setData(abrush, Qt::BackgroundRole); }
0245 
0246 inline void QStandardItem::setForeground(const QBrush &abrush)
0247 { setData(abrush, Qt::ForegroundRole); }
0248 
0249 inline void QStandardItem::setCheckState(Qt::CheckState acheckState)
0250 { setData(acheckState, Qt::CheckStateRole); }
0251 
0252 inline void QStandardItem::setAccessibleText(const QString &aaccessibleText)
0253 { setData(aaccessibleText, Qt::AccessibleTextRole); }
0254 
0255 inline void QStandardItem::setAccessibleDescription(const QString &aaccessibleDescription)
0256 { setData(aaccessibleDescription, Qt::AccessibleDescriptionRole); }
0257 
0258 inline void QStandardItem::setChild(int arow, QStandardItem *aitem)
0259 { setChild(arow, 0, aitem); }
0260 
0261 inline void QStandardItem::appendRow(const QList<QStandardItem*> &aitems)
0262 { insertRow(rowCount(), aitems); }
0263 
0264 inline void QStandardItem::appendRows(const QList<QStandardItem*> &aitems)
0265 { insertRows(rowCount(), aitems); }
0266 
0267 inline void QStandardItem::appendColumn(const QList<QStandardItem*> &aitems)
0268 { insertColumn(columnCount(), aitems); }
0269 
0270 inline void QStandardItem::insertRow(int arow, QStandardItem *aitem)
0271 { insertRow(arow, QList<QStandardItem*>() << aitem); }
0272 
0273 inline void QStandardItem::appendRow(QStandardItem *aitem)
0274 { insertRow(rowCount(), aitem); }
0275 
0276 class QStandardItemModelPrivate;
0277 
0278 class Q_GUI_EXPORT QStandardItemModel : public QAbstractItemModel
0279 {
0280     Q_OBJECT
0281     Q_PROPERTY(int sortRole READ sortRole WRITE setSortRole BINDABLE bindableSortRole)
0282 
0283 public:
0284     explicit QStandardItemModel(QObject *parent = nullptr);
0285     QStandardItemModel(int rows, int columns, QObject *parent = nullptr);
0286     ~QStandardItemModel();
0287 
0288     void setItemRoleNames(const QHash<int,QByteArray> &roleNames);
0289     QHash<int, QByteArray> roleNames() const override;
0290 
0291     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0292     QModelIndex parent(const QModelIndex &child) const override;
0293 
0294     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0295     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0296     bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
0297 
0298     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0299     void multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const override;
0300     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0301     bool clearItemData(const QModelIndex &index) override;
0302 
0303     QVariant headerData(int section, Qt::Orientation orientation,
0304                         int role = Qt::DisplayRole) const override;
0305     bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
0306                        int role = Qt::EditRole) override;
0307 
0308     bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
0309     bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
0310     bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
0311     bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
0312 
0313     Qt::ItemFlags flags(const QModelIndex &index) const override;
0314     Qt::DropActions supportedDropActions() const override;
0315 
0316     QMap<int, QVariant> itemData(const QModelIndex &index) const override;
0317     bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) override;
0318 
0319     void clear();
0320 
0321     using QObject::parent;
0322 
0323     void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
0324 
0325     QStandardItem *itemFromIndex(const QModelIndex &index) const;
0326     QModelIndex indexFromItem(const QStandardItem *item) const;
0327 
0328     QStandardItem *item(int row, int column = 0) const;
0329     void setItem(int row, int column, QStandardItem *item);
0330     inline void setItem(int row, QStandardItem *item);
0331     QStandardItem *invisibleRootItem() const;
0332 
0333     QStandardItem *horizontalHeaderItem(int column) const;
0334     void setHorizontalHeaderItem(int column, QStandardItem *item);
0335     QStandardItem *verticalHeaderItem(int row) const;
0336     void setVerticalHeaderItem(int row, QStandardItem *item);
0337 
0338     void setHorizontalHeaderLabels(const QStringList &labels);
0339     void setVerticalHeaderLabels(const QStringList &labels);
0340 
0341     void setRowCount(int rows);
0342     void setColumnCount(int columns);
0343 
0344     void appendRow(const QList<QStandardItem*> &items);
0345     void appendColumn(const QList<QStandardItem*> &items);
0346     inline void appendRow(QStandardItem *item);
0347 
0348     void insertRow(int row, const QList<QStandardItem*> &items);
0349     void insertColumn(int column, const QList<QStandardItem*> &items);
0350     inline void insertRow(int row, QStandardItem *item);
0351 
0352     inline bool insertRow(int row, const QModelIndex &parent = QModelIndex());
0353     inline bool insertColumn(int column, const QModelIndex &parent = QModelIndex());
0354 
0355     QStandardItem *takeItem(int row, int column = 0);
0356     QList<QStandardItem*> takeRow(int row);
0357     QList<QStandardItem*> takeColumn(int column);
0358 
0359     QStandardItem *takeHorizontalHeaderItem(int column);
0360     QStandardItem *takeVerticalHeaderItem(int row);
0361 
0362     const QStandardItem *itemPrototype() const;
0363     void setItemPrototype(const QStandardItem *item);
0364 
0365     QList<QStandardItem*> findItems(const QString &text,
0366                                     Qt::MatchFlags flags = Qt::MatchExactly,
0367                                     int column = 0) const;
0368 
0369     int sortRole() const;
0370     void setSortRole(int role);
0371     QBindable<int> bindableSortRole();
0372 
0373     QStringList mimeTypes() const override;
0374     QMimeData *mimeData(const QModelIndexList &indexes) const override;
0375     bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
0376 
0377 Q_SIGNALS:
0378     void itemChanged(QStandardItem *item);
0379 
0380 protected:
0381     QStandardItemModel(QStandardItemModelPrivate &dd, QObject *parent = nullptr);
0382 
0383 private:
0384     friend class QStandardItemPrivate;
0385     friend class QStandardItem;
0386     Q_DISABLE_COPY(QStandardItemModel)
0387     Q_DECLARE_PRIVATE(QStandardItemModel)
0388 
0389     Q_PRIVATE_SLOT(d_func(), void _q_emitItemChanged(const QModelIndex &topLeft,
0390                                                      const QModelIndex &bottomRight))
0391 };
0392 
0393 inline void QStandardItemModel::setItem(int arow, QStandardItem *aitem)
0394 { setItem(arow, 0, aitem); }
0395 
0396 inline void QStandardItemModel::appendRow(QStandardItem *aitem)
0397 { appendRow(QList<QStandardItem*>() << aitem); }
0398 
0399 inline void QStandardItemModel::insertRow(int arow, QStandardItem *aitem)
0400 { insertRow(arow, QList<QStandardItem*>() << aitem); }
0401 
0402 inline bool QStandardItemModel::insertRow(int arow, const QModelIndex &aparent)
0403 { return QAbstractItemModel::insertRow(arow, aparent); }
0404 inline bool QStandardItemModel::insertColumn(int acolumn, const QModelIndex &aparent)
0405 { return QAbstractItemModel::insertColumn(acolumn, aparent); }
0406 
0407 #ifndef QT_NO_DATASTREAM
0408 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QStandardItem &item);
0409 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &out, const QStandardItem &item);
0410 #endif
0411 
0412 QT_END_NAMESPACE
0413 
0414 #endif //QSTANDARDITEMMODEL_H