diff options
Diffstat (limited to 'src/gui/itemmodels')
-rw-r--r-- | src/gui/itemmodels/qstandarditemmodel.cpp | 83 | ||||
-rw-r--r-- | src/gui/itemmodels/qstandarditemmodel.h | 22 | ||||
-rw-r--r-- | src/gui/itemmodels/qstandarditemmodel_p.h | 2 |
3 files changed, 87 insertions, 20 deletions
diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp index 8d848b662f..25b82b94b5 100644 --- a/src/gui/itemmodels/qstandarditemmodel.cpp +++ b/src/gui/itemmodels/qstandarditemmodel.cpp @@ -1224,7 +1224,7 @@ void QStandardItem::setSelectable(bool selectable) The item delegate will render a checkable item with a check box next to the item's text. - \sa isCheckable(), setCheckState(), setTristate() + \sa isCheckable(), setCheckState(), setUserTristate(), setAutoTristate() */ void QStandardItem::setCheckable(bool checkable) { @@ -1244,34 +1244,88 @@ void QStandardItem::setCheckable(bool checkable) The default value is false. - \sa setCheckable(), checkState(), isTristate() + \sa setCheckable(), checkState(), isUserTristate(), isAutoTristate() */ /*! - Sets whether the item is tristate. If \a tristate is true, the - item is checkable with three separate states; otherwise, the item - is checkable with two states. (Note that this also requires that - the item is checkable; see isCheckable().) + \fn void QStandardItem::setTristate(bool tristate) + \obsolete - \sa isTristate(), setCheckable(), setCheckState() + Use QStandardItem::setAutoTristate(bool tristate) instead. + For a tristate checkbox that the user can change between all three + states, use QStandardItem::setUserTristate(bool tristate) instead. */ -void QStandardItem::setTristate(bool tristate) + +/*! + \fn void QStandardItem::isTristate() const + \obsolete + + Use QStandardItem::isAutoTristate() instead. + For a tristate checkbox that the user can change between all three + states, use QStandardItem::isUserTristate() instead. +*/ + +/*! + Determines that the item is tristate and controlled by QTreeWidget if \a tristate + is \c true. + This enables automatic management of the state of parent items in QTreeWidget + (checked if all children are checked, unchecked if all children are unchecked, + or partially checked if only some children are checked). + + \since 5.6 + \sa isAutoTristate(), setCheckable(), setCheckState() +*/ +void QStandardItem::setAutoTristate(bool tristate) { Q_D(QStandardItem); - d->changeFlags(tristate, Qt::ItemIsTristate); + d->changeFlags(tristate, Qt::ItemIsAutoTristate); } /*! - \fn bool QStandardItem::isTristate() const + \fn bool QStandardItem::isAutoTristate() const + + Returns whether the item is tristate and is controlled by QTreeWidget. + + The default value is false. + + \since 5.6 + \sa setAutoTristate(), isCheckable(), checkState() +*/ + +/*! + Sets whether the item is tristate and controlled by the user. + If \a tristate is true, the user can cycle through three separate states; + otherwise, the item is checkable with two states. + (Note that this also requires that the item is checkable; see isCheckable().) + + \since 5.6 + \sa isUserTristate(), setCheckable(), setCheckState() +*/ +void QStandardItem::setUserTristate(bool tristate) +{ + Q_D(QStandardItem); + d->changeFlags(tristate, Qt::ItemIsUserTristate); +} + +/*! + \fn bool QStandardItem::isUserTristate() const + \since 5.6 Returns whether the item is tristate; that is, if it's checkable with three - separate states. + separate states and the user can cycle through all three states. The default value is false. - \sa setTristate(), isCheckable(), checkState() + \sa setUserTristate(), isCheckable(), checkState() */ +#if QT_DEPRECATED_SINCE(5, 6) +void QStandardItem::setTristate(bool tristate) +{ + setAutoTristate(tristate); +} +#endif + #ifndef QT_NO_DRAGANDDROP /*! @@ -1750,6 +1804,7 @@ QList<QStandardItem*> QStandardItem::takeRow(int row) int index = d->childIndex(row, 0); // Will return -1 if there are no columns if (index != -1) { int col_count = d->columnCount(); + items.reserve(col_count); for (int column = 0; column < col_count; ++column) { QStandardItem *ch = d->children.at(index + column); if (ch) @@ -2467,7 +2522,9 @@ QList<QStandardItem*> QStandardItemModel::findItems(const QString &text, QModelIndexList indexes = match(index(0, column, QModelIndex()), Qt::DisplayRole, text, -1, flags); QList<QStandardItem*> items; - for (int i = 0; i < indexes.size(); ++i) + const int numIndexes = indexes.size(); + items.reserve(numIndexes); + for (int i = 0; i < numIndexes; ++i) items.append(itemFromIndex(indexes.at(i))); return items; } diff --git a/src/gui/itemmodels/qstandarditemmodel.h b/src/gui/itemmodels/qstandarditemmodel.h index 3dd613f907..8740f7940b 100644 --- a/src/gui/itemmodels/qstandarditemmodel.h +++ b/src/gui/itemmodels/qstandarditemmodel.h @@ -158,10 +158,20 @@ public: } void setCheckable(bool checkable); - inline bool isTristate() const { - return (flags() & Qt::ItemIsTristate) != 0; + inline bool isAutoTristate() const { + return (flags() & Qt::ItemIsAutoTristate) != 0; } - void setTristate(bool tristate); + void setAutoTristate(bool tristate); + + inline bool isUserTristate() const { + return (flags() & Qt::ItemIsUserTristate) != 0; + } + void setUserTristate(bool tristate); + +#if QT_DEPRECATED_SINCE(5, 6) + QT_DEPRECATED bool isTristate() const { return isAutoTristate(); } + QT_DEPRECATED void setTristate(bool tristate); +#endif #ifndef QT_NO_DRAGANDDROP inline bool isDragEnabled() const { @@ -310,8 +320,8 @@ class Q_GUI_EXPORT QStandardItemModel : public QAbstractItemModel Q_PROPERTY(int sortRole READ sortRole WRITE setSortRole) public: - explicit QStandardItemModel(QObject *parent = 0); - QStandardItemModel(int rows, int columns, QObject *parent = 0); + explicit QStandardItemModel(QObject *parent = Q_NULLPTR); + QStandardItemModel(int rows, int columns, QObject *parent = Q_NULLPTR); ~QStandardItemModel(); void setItemRoleNames(const QHash<int,QByteArray> &roleNames); @@ -405,7 +415,7 @@ Q_SIGNALS: void itemChanged(QStandardItem *item); protected: - QStandardItemModel(QStandardItemModelPrivate &dd, QObject *parent = 0); + QStandardItemModel(QStandardItemModelPrivate &dd, QObject *parent = Q_NULLPTR); private: friend class QStandardItemPrivate; diff --git a/src/gui/itemmodels/qstandarditemmodel_p.h b/src/gui/itemmodels/qstandarditemmodel_p.h index 491a49f9c2..b49045d283 100644 --- a/src/gui/itemmodels/qstandarditemmodel_p.h +++ b/src/gui/itemmodels/qstandarditemmodel_p.h @@ -61,7 +61,7 @@ class QStandardItemData { public: inline QStandardItemData() : role(-1) {} - inline QStandardItemData(int r, QVariant v) : role(r), value(v) {} + inline QStandardItemData(int r, const QVariant &v) : role(r), value(v) {} int role; QVariant value; inline bool operator==(const QStandardItemData &other) const { return role == other.role && value == other.value; } |