From cf52c268b036d808901313acc554587465bdd746 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Mon, 30 Jan 2012 11:04:07 +1000 Subject: 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 --- .../qstandarditemmodel/tst_qstandarditemmodel.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/auto/widgets/itemviews') 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 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 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 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" -- cgit v1.2.3