diff options
author | Marius Bugge Monsen <mmonsen@trolltech.com> | 2009-09-30 12:08:51 +0200 |
---|---|---|
committer | Marius Bugge Monsen <mmonsen@trolltech.com> | 2009-09-30 12:08:51 +0200 |
commit | 053a9a4a293eed32ed625e961a5ec8570f154d4a (patch) | |
tree | 0bc67302fe554450bdb405bd12a4a2239ff52b67 | |
parent | 35f07e0ad9ddcf9660f36d4b30d5627170951f71 (diff) |
Compile after converting from int role to QByteArray role names.
-rw-r--r-- | examples/chat/chatmodel.cpp | 18 | ||||
-rw-r--r-- | examples/chat/chatmodel.h | 2 | ||||
-rw-r--r-- | examples/chat/chatview.cpp | 8 | ||||
-rw-r--r-- | src/qgraphicslistview.h | 21 | ||||
-rw-r--r-- | src/qgraphicstreeview.h | 18 | ||||
-rw-r--r-- | tests/qlistfromtreeadaptor/tst_qlistfromtreeadaptor.cpp | 17 | ||||
-rw-r--r-- | tests/qlistmodeladaptor/tst_qlistmodeladaptor.cpp | 33 | ||||
-rw-r--r-- | tests/qtreedefaultmodel/tst_qtreedefaultmodel.cpp | 18 |
8 files changed, 59 insertions, 76 deletions
diff --git a/examples/chat/chatmodel.cpp b/examples/chat/chatmodel.cpp index 5d259f6..1f587dd 100644 --- a/examples/chat/chatmodel.cpp +++ b/examples/chat/chatmodel.cpp @@ -213,17 +213,17 @@ int ChatModel::count() const return messages.count(); } -QHash<int,QVariant> ChatModel::data(int index, const QList<int> &roles) const +QHash<QByteArray,QVariant> ChatModel::data(int index, const QList<QByteArray> &roles) const { - QHash<int,QVariant> hash; + QHash<QByteArray,QVariant> hash; if (index >= 0 && index < messages.count()) { for (int i = 0; i < roles.count(); ++i) { - if (roles.at(i) == Qt::DisplayRole) - hash.insert(Qt::DisplayRole, messages.at(index)); - if (roles.at(i) == Qt::BackgroundRole) - hash.insert(Qt::BackgroundRole, userIds.at(index)); - if (roles.at(i) == Qt::ToolTipRole) - hash.insert(Qt::ToolTipRole, nicks[userIds.at(index)]); + if (roles.at(i) == "DisplayRole") + hash.insert("DisplayRole", messages.at(index)); + if (roles.at(i) == "BackgroundRole") + hash.insert("BackgroundRole", userIds.at(index)); + if (roles.at(i) == "ToolTipRole") + hash.insert("ToolTipRole", nicks[userIds.at(index)]); } } return hash; @@ -233,7 +233,7 @@ void ChatModel::appendMessage(const QString &message, int userId) { if (!userIds.isEmpty() && userIds.last() == userId) { messages[messages.count() - 1] += ("\n" + message); - emit itemsChanged(messages.count() - 1, 1, QList<int>() << Qt::DisplayRole); + emit itemsChanged(messages.count() - 1, 1, QList<QByteArray>() << "DisplayRole"); } else { messages.append(message); userIds.append(userId); diff --git a/examples/chat/chatmodel.h b/examples/chat/chatmodel.h index afbbb06..a01f6c5 100644 --- a/examples/chat/chatmodel.h +++ b/examples/chat/chatmodel.h @@ -34,7 +34,7 @@ public: ~ChatModel(); int count() const; - QHash<int,QVariant> data(int index, const QList<int> &roles) const; + QHash<QByteArray,QVariant> data(int index, const QList<QByteArray> &roles) const; protected: void appendMessage(const QString &message, int userId); diff --git a/examples/chat/chatview.cpp b/examples/chat/chatview.cpp index 2a43f7d..1963382 100644 --- a/examples/chat/chatview.cpp +++ b/examples/chat/chatview.cpp @@ -51,10 +51,10 @@ void ChatViewItem::startAnimation(const QVariant &start, const QVariant &end) void ChatViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(widget); - const QHash<int, QVariant> hash = view()->model()->data(index(), QList<int>() << Qt::BackgroundRole << Qt::ToolTipRole << Qt::DisplayRole); - const int userId = hash.value(Qt::BackgroundRole).toInt(); - const QString nick = hash.value(Qt::ToolTipRole).toString(); - const QString text = hash.value(Qt::DisplayRole).toString(); + const QHash<QByteArray, QVariant> hash = view()->model()->data(index(), QList<QByteArray>() << "BackgroundRole" << "ToolTipRole" << "DisplayRole"); + const int userId = hash.value("BackgroundRole").toInt(); + const QString nick = hash.value("ToolTipRole").toString(); + const QString text = hash.value("DisplayRole").toString(); const ChatView *chatView = qobject_cast<ChatView*>(view()); const qreal line = QFontMetrics(chatView->font()).height(); diff --git a/src/qgraphicslistview.h b/src/qgraphicslistview.h index 1fa2602..b2e244b 100644 --- a/src/qgraphicslistview.h +++ b/src/qgraphicslistview.h @@ -88,21 +88,10 @@ template <class T> class QtGraphicsListViewItemCreator : public QtGraphicsListViewItemCreatorBase { public: - inline QGraphicsObject *create(int index, QtGraphicsListView *view) - { - return new T(index, view); - } - inline QGraphicsObject *reassign(int index, QGraphicsObject *item, QtGraphicsListView *view) - { - Q_UNUSED(view); - static_cast<T*>(item)->setIndex(index); - return item; - } - inline void update(int index, QGraphicsObject *item, const QList<QByteArray> &roles) - { - Q_UNUSED(index); - static_cast<T*>(item)->itemChanged(roles); - } + inline ~QtGraphicsListViewItemCreator(); + inline QGraphicsObject *create(int index, QtGraphicsListView *view); + inline QGraphicsObject *reassign(int index, QGraphicsObject *item, QtGraphicsListView *view); + inline void update(int index, QGraphicsObject *item, const QList<QByteArray> &roles); }; template <class T> @@ -122,7 +111,7 @@ inline QGraphicsObject *QtGraphicsListViewItemCreator<T>::reassign(int index, QG } template <class T> -inline void QtGraphicsListViewItemCreator<T>::update(int index, QGraphicsObject *item, const QList<int> &roles) +inline void QtGraphicsListViewItemCreator<T>::update(int index, QGraphicsObject *item, const QList<QByteArray> &roles) { Q_UNUSED(index); static_cast<T*>(item)->itemChanged(roles); diff --git a/src/qgraphicstreeview.h b/src/qgraphicstreeview.h index c97a28e..e37123b 100644 --- a/src/qgraphicstreeview.h +++ b/src/qgraphicstreeview.h @@ -98,18 +98,10 @@ template <class T> class QtGraphicsTreeViewItemCreator : public QtGraphicsTreeViewItemCreatorBase { public: - inline QGraphicsObject *create(const QtTreeModelIterator &it, QtGraphicsTreeView *view) { return new T(it, view); } - inline QGraphicsObject *reassign(const QtTreeModelIterator &it, QGraphicsObject *item, QtGraphicsTreeView *view) - { - Q_UNUSED(view); - static_cast<QtGraphicsTreeViewItem*>(item)->setIterator(it); - return item; - } - inline void update(const QtTreeModelIterator &it, QGraphicsObject *item, const QList<QByteArray> &roles) - { - Q_UNUSED(it); - static_cast<QtGraphicsTreeViewItem*>(item)->itemChanged(roles); - } + inline ~QtGraphicsTreeViewItemCreator(); + inline QGraphicsObject *create(const QtTreeModelIterator &it, QtGraphicsTreeView *view); + inline QGraphicsObject *reassign(const QtTreeModelIterator &it, QGraphicsObject *item, QtGraphicsTreeView *view); + inline void update(const QtTreeModelIterator &it, QGraphicsObject *item, const QList<QByteArray> &roles); }; template <class T> @@ -129,7 +121,7 @@ inline QGraphicsObject *QtGraphicsTreeViewItemCreator<T>::reassign(const QtTreeM } template <class T> -inline void QtGraphicsTreeViewItemCreator<T>::update(const QtTreeModelIterator &it, QGraphicsObject *item, const QList<int> &roles) +inline void QtGraphicsTreeViewItemCreator<T>::update(const QtTreeModelIterator &it, QGraphicsObject *item, const QList<QByteArray> &roles) { Q_UNUSED(it); static_cast<QtGraphicsTreeViewItem*>(item)->itemChanged(roles); diff --git a/tests/qlistfromtreeadaptor/tst_qlistfromtreeadaptor.cpp b/tests/qlistfromtreeadaptor/tst_qlistfromtreeadaptor.cpp index f2882fe..e0f131e 100644 --- a/tests/qlistfromtreeadaptor/tst_qlistfromtreeadaptor.cpp +++ b/tests/qlistfromtreeadaptor/tst_qlistfromtreeadaptor.cpp @@ -24,6 +24,7 @@ #include <qlistfromtreeadaptor.h> #include <qtreedefaultmodel.h> +#include <qdataroles_p.h> class tst_QtListFromTreeAdaptor : public QObject { @@ -170,21 +171,19 @@ void tst_QtListFromTreeAdaptor::dataCheck() QFETCH(int, signalCount); int x; - QSignalSpy sourceItemsChanged(source, - SIGNAL(itemsChanged(const QtTreeModelBase::iterator_base&,int,QList<int>))); - QSignalSpy adaptorItemsChanged(adaptor, - SIGNAL(itemsChanged(int,int,QList<int>))); + QSignalSpy sourceItemsChanged(source, SIGNAL(itemsChanged(const QtTreeModelBase::iterator_base&, int, QList<QByteArray>))); + QSignalSpy adaptorItemsChanged(adaptor, SIGNAL(itemsChanged(int, int, QList<QByteArray>))); for (x = 0; x < itemCount; x++) { new QtTreeDefaultItem(QString::number(x), source->rootItem()); - QCOMPARE(source->rootItem()->children().at(x)->data(0, QList<int>() << Qt::DisplayRole), - adaptor->data(x, QList<int>() << Qt::DisplayRole)); + QCOMPARE(source->rootItem()->children().at(x)->data(0, QList<QByteArray>() << "DisplayRole"), + adaptor->data(x, QList<QByteArray>() << "DisplayRole")); - source->rootItem()->children().at(x)->setData(QString("changed text"), 0, Qt::DisplayRole); + source->rootItem()->children().at(x)->setData(QString("changed text"), 0, "DisplayRole"); - QCOMPARE(source->rootItem()->children().at(x)->data(0, QList<int>() << Qt::DisplayRole), - adaptor->data(x, QList<int>() << Qt::DisplayRole)); + QCOMPARE(source->rootItem()->children().at(x)->data(0, QList<QByteArray>() << "DisplayRole"), + adaptor->data(x, QList<QByteArray>() << "DisplayRole")); } QCOMPARE(sourceItemsChanged.count(), signalCount); diff --git a/tests/qlistmodeladaptor/tst_qlistmodeladaptor.cpp b/tests/qlistmodeladaptor/tst_qlistmodeladaptor.cpp index d148d5a..e8680f2 100644 --- a/tests/qlistmodeladaptor/tst_qlistmodeladaptor.cpp +++ b/tests/qlistmodeladaptor/tst_qlistmodeladaptor.cpp @@ -24,6 +24,7 @@ #include <QtGui/qstandarditemmodel.h> #include <qlistmodeladaptor.h> +#include <qdataroles_p.h> class tst_QtListModelAdaptor : public QObject { @@ -109,19 +110,19 @@ void tst_QtListModelAdaptor::count() void tst_QtListModelAdaptor::getData_data() { QTest::addColumn<QStringList>("items"); - QTest::addColumn<int>("role"); + QTest::addColumn<QByteArray>("role"); QTest::addColumn<QStringList>("data"); QTest::addColumn<int>("signalCount"); QTest::newRow("no items") << QStringList() - << int(Qt::DisplayRole) + << "DisplayRole" << QStringList() << 0; QTest::newRow("three items") << (QStringList() << "one" << "two" << "three") - << int(Qt::DisplayRole) + << "DisplayRole" << (QStringList() << "four" << "five" << "six") << 3; } @@ -129,24 +130,24 @@ void tst_QtListModelAdaptor::getData_data() void tst_QtListModelAdaptor::getData() { QFETCH(QStringList, items); - QFETCH(int, role); + QFETCH(QByteArray, role); QFETCH(QStringList, data); QFETCH(int, signalCount); - QSignalSpy itemsChanged(adaptor, SIGNAL(itemsChanged(int,int,const QList<int>&))); + QSignalSpy itemsChanged(adaptor, SIGNAL(itemsChanged(int,int,const QList<QByteArray>&))); for (int i = 0; i < items.count(); ++i) source->appendRow(new QStandardItem(items.at(i))); QCOMPARE(adaptor->count(), items.count()); for (int j = 0; j < items.count(); ++j) - QCOMPARE(adaptor->data(j, QList<int>() << role).value(role).toString(), items.at(j)); + QCOMPARE(adaptor->data(j, QList<QByteArray>() << role).value(role).toString(), items.at(j)); for (int k = 0; k < data.count(); ++k) - source->setData(source->index(k, 0), data.at(k), role); + source->setData(source->index(k, 0), data.at(k), QtDataRoles::value(role)); for (int l = 0; l < data.count(); ++l) - QCOMPARE(adaptor->data(l, QList<int>() << role).value(role).toString(), data.at(l)); + QCOMPARE(adaptor->data(l, QList<QByteArray>() << role).value(role).toString(), data.at(l)); QCOMPARE(itemsChanged.count(), signalCount); } @@ -154,19 +155,19 @@ void tst_QtListModelAdaptor::getData() void tst_QtListModelAdaptor::setData_data() { QTest::addColumn<QStringList>("items"); - QTest::addColumn<int>("role"); + QTest::addColumn<QByteArray>("role"); QTest::addColumn<QStringList>("data"); QTest::addColumn<int>("signalCount"); QTest::newRow("no items") << QStringList() - << int(Qt::DisplayRole) + << "DisplayRole" << QStringList() << 0; QTest::newRow("three items") << (QStringList() << "one" << "two" << "three") - << int(Qt::DisplayRole) + << "DisplayRole" << (QStringList() << "four" << "five" << "six") << 3; } @@ -174,27 +175,27 @@ void tst_QtListModelAdaptor::setData_data() void tst_QtListModelAdaptor::setData() { QFETCH(QStringList, items); - QFETCH(int, role); + QFETCH(QByteArray, role); QFETCH(QStringList, data); QFETCH(int, signalCount); - QSignalSpy itemsChanged(adaptor, SIGNAL(itemsChanged(int,int,const QList<int>&))); + QSignalSpy itemsChanged(adaptor, SIGNAL(itemsChanged(int,int,const QList<QByteArray>&))); for (int i = 0; i < items.count(); ++i) source->appendRow(new QStandardItem(items.at(i))); QCOMPARE(adaptor->count(), items.count()); for (int j = 0; j < items.count(); ++j) - QCOMPARE(adaptor->data(j, QList<int>() << role).value(role).toString(), items.at(j)); + QCOMPARE(adaptor->data(j, QList<QByteArray>() << role).value(role).toString(), items.at(j)); for (int k = 0; k < data.count(); ++k) { - QHash<int, QVariant> hash; + QHash<QByteArray, QVariant> hash; hash.insert(role, data.at(k)); adaptor->setData(k, hash); } for (int l = 0; l < data.count(); ++l) - QCOMPARE(source->data(source->index(l, 0), role).toString(), data.at(l)); + QCOMPARE(source->data(source->index(l, 0), QtDataRoles::value(role)).toString(), data.at(l)); QCOMPARE(itemsChanged.count(), signalCount); } diff --git a/tests/qtreedefaultmodel/tst_qtreedefaultmodel.cpp b/tests/qtreedefaultmodel/tst_qtreedefaultmodel.cpp index a1bd857..0124e7b 100644 --- a/tests/qtreedefaultmodel/tst_qtreedefaultmodel.cpp +++ b/tests/qtreedefaultmodel/tst_qtreedefaultmodel.cpp @@ -24,6 +24,7 @@ #include <QtTest/QtTest> #include <qtreemodelinterface.h> #include <qtreedefaultmodel.h> +#include <qdataroles_p.h> class tst_QtTreeDefaultModel : public QObject { @@ -58,6 +59,7 @@ protected: Q_DECLARE_METATYPE(QList<int>) Q_DECLARE_METATYPE(QList<bool>) +Q_DECLARE_METATYPE(QList<QByteArray>) Q_DECLARE_METATYPE(QtTreeModelBase::iterator_base) tst_QtTreeDefaultModel::tst_QtTreeDefaultModel() @@ -566,49 +568,49 @@ void tst_QtTreeDefaultModel::setData_data() { QTest::addColumn<QStringList>("initialChildren"); QTest::addColumn<QList<int> >("columns"); - QTest::addColumn<QList<int> >("roles"); + QTest::addColumn<QList<QByteArray> >("roles"); QTest::addColumn<QList<QVariant> >("data"); QTest::addColumn<int>("signalCount"); QTest::newRow("no children") << QStringList() << QList<int>() - << QList<int>() + << QList<QByteArray>() << QList<QVariant>() << 0; QTest::newRow("one child, no data") << (QStringList() << "one") << QList<int>() - << QList<int>() + << QList<QByteArray>() << QList<QVariant>() << 0; QTest::newRow("one child, one column, one text") << (QStringList() << "one") << (QList<int>() << 0) - << (QList<int>() << int(Qt::DisplayRole)) + << (QList<QByteArray>() << "DisplayRole") << (QList<QVariant>() << QVariant("text")) << 1; QTest::newRow("one child, two columns, one role") << (QStringList() << "one") << (QList<int>() << 0 << 1) - << (QList<int>() << int(Qt::DisplayRole)) + << (QList<QByteArray>() << "DisplayRole") << (QList<QVariant>() << QVariant("text") << QVariant("text")) << 2; QTest::newRow("one child, one column, two roles") << (QStringList() << "one") << (QList<int>() << 0) - << (QList<int>() << int(Qt::DisplayRole) << int(Qt::EditRole)) + << (QList<QByteArray>() << "DisplayRole" << "EditRole") << (QList<QVariant>() << QVariant("text") << QVariant("edit")) << 2; QTest::newRow("one child, two columns, two roles") << (QStringList() << "one") << (QList<int>() << 0 << 1) - << (QList<int>() << int(Qt::DisplayRole) << int(Qt::EditRole)) + << (QList<QByteArray>() << "DisplayRole" << "EditRole") << (QList<QVariant>() // for each column and for each role << QVariant("text") << QVariant("edit") << QVariant("text") << QVariant("edit")) @@ -619,7 +621,7 @@ void tst_QtTreeDefaultModel::setData() { QFETCH(QStringList, initialChildren); QFETCH(QList<int>, columns); - QFETCH(QList<int>, roles); + QFETCH(QList<QByteArray>, roles); QFETCH(QList<QVariant>, data); QFETCH(int, signalCount); |