Port QStandardItemModel to the new property system
Task-number: QTBUG-85520 Task-number: QTBUG-85521 Change-Id: I2f9bbe8bc06838fcbadd446e111fb697120f550c Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>bb10
parent
709a0942aa
commit
ba62256c5a
|
|
@ -420,9 +420,7 @@ void QStandardItemPrivate::setModel(QStandardItemModel *mod)
|
|||
\internal
|
||||
*/
|
||||
QStandardItemModelPrivate::QStandardItemModelPrivate()
|
||||
: root(new QStandardItem),
|
||||
itemPrototype(nullptr),
|
||||
sortRole(Qt::DisplayRole)
|
||||
: root(new QStandardItem), itemPrototype(nullptr)
|
||||
{
|
||||
root->setFlags(Qt::ItemIsDropEnabled);
|
||||
}
|
||||
|
|
@ -2821,6 +2819,12 @@ void QStandardItemModel::setSortRole(int role)
|
|||
d->sortRole = role;
|
||||
}
|
||||
|
||||
QBindable<int> QStandardItemModel::bindableSortRole()
|
||||
{
|
||||
Q_D(QStandardItemModel);
|
||||
return &d->sortRole;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ class QStandardItemModelPrivate;
|
|||
class Q_GUI_EXPORT QStandardItemModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int sortRole READ sortRole WRITE setSortRole)
|
||||
Q_PROPERTY(int sortRole READ sortRole WRITE setSortRole BINDABLE bindableSortRole)
|
||||
|
||||
public:
|
||||
explicit QStandardItemModel(QObject *parent = nullptr);
|
||||
|
|
@ -404,6 +404,7 @@ public:
|
|||
|
||||
int sortRole() const;
|
||||
void setSortRole(int role);
|
||||
QBindable<int> bindableSortRole();
|
||||
|
||||
QStringList mimeTypes() const override;
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ public:
|
|||
QHash<int, QByteArray> roleNames;
|
||||
QScopedPointer<QStandardItem> root;
|
||||
const QStandardItem *itemPrototype;
|
||||
int sortRole;
|
||||
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QStandardItemModelPrivate, int, sortRole, Qt::DisplayRole)
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ private slots:
|
|||
void sort();
|
||||
void sortRole_data();
|
||||
void sortRole();
|
||||
void sortRoleBindings();
|
||||
void findItems();
|
||||
void getSetHeaderItem();
|
||||
void indexFromItem();
|
||||
|
|
@ -905,6 +906,22 @@ void tst_QStandardItemModel::sortRole()
|
|||
}
|
||||
}
|
||||
|
||||
void tst_QStandardItemModel::sortRoleBindings()
|
||||
{
|
||||
QStandardItemModel model;
|
||||
QCOMPARE(model.sortRole(), Qt::DisplayRole);
|
||||
|
||||
QProperty<int> sortRole;
|
||||
model.bindableSortRole().setBinding(Qt::makePropertyBinding(sortRole));
|
||||
sortRole = Qt::UserRole;
|
||||
QCOMPARE(model.sortRole(), Qt::UserRole);
|
||||
|
||||
QProperty<int> sortRoleObserver;
|
||||
sortRoleObserver.setBinding([&] { return model.sortRole(); });
|
||||
model.setSortRole(Qt::EditRole);
|
||||
QCOMPARE(sortRoleObserver, Qt::EditRole);
|
||||
}
|
||||
|
||||
void tst_QStandardItemModel::findItems()
|
||||
{
|
||||
QStandardItemModel model;
|
||||
|
|
|
|||
Loading…
Reference in New Issue