diff options
author | Chris Adams <christopher.adams@nokia.com> | 2012-01-30 11:04:07 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-31 12:00:31 +0100 |
commit | cf52c268b036d808901313acc554587465bdd746 (patch) | |
tree | e0efea11753f61faed7fbb3f15ea86a4adb702e9 /tests/auto/widgets/itemviews/qstandarditemmodel | |
parent | cf20c06756a461730f35acf7631cbf5e762fcfe1 (diff) |
Add public role names setter to QStandardItemModel
This allows QStandardItemModel to be usable in QML without requiring
clients to subclass it.
Task-number: QTBUG-15067
Change-Id: I867fcd8137132affdf21f37a9fa293e855a09a13
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'tests/auto/widgets/itemviews/qstandarditemmodel')
-rw-r--r-- | tests/auto/widgets/itemviews/qstandarditemmodel/tst_qstandarditemmodel.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qstandarditemmodel/tst_qstandarditemmodel.cpp b/tests/auto/widgets/itemviews/qstandarditemmodel/tst_qstandarditemmodel.cpp index bcabedf89c..1c661f9060 100644 --- a/tests/auto/widgets/itemviews/qstandarditemmodel/tst_qstandarditemmodel.cpp +++ b/tests/auto/widgets/itemviews/qstandarditemmodel/tst_qstandarditemmodel.cpp @@ -134,6 +134,8 @@ private slots: void treeDragAndDrop(); void removeRowsAndColumns(); + void itemRoleNames(); + private: QAbstractItemModel *m_model; QPersistentModelIndex persistent; @@ -1658,6 +1660,24 @@ void tst_QStandardItemModel::removeRowsAndColumns() VERIFY_MODEL } +void tst_QStandardItemModel::itemRoleNames() +{ + QVector<QString> row_list = QString("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20").split(',').toVector(); + QVector<QString> col_list = row_list; + QStandardItemModel model; + for (int c = 0; c < col_list.count(); c++) + for (int r = 0; r < row_list.count(); r++) + model.setItem(r, c, new QStandardItem(row_list[r] + "x" + col_list[c])); + VERIFY_MODEL + + QHash<int, QByteArray> newRoleNames; + newRoleNames.insert(Qt::DisplayRole, "Name"); + newRoleNames.insert(Qt::DecorationRole, "Avatar"); + model.setItemRoleNames(newRoleNames); + QCOMPARE(model.roleNames(), newRoleNames); + VERIFY_MODEL +} + QTEST_MAIN(tst_QStandardItemModel) #include "tst_qstandarditemmodel.moc" |