diff --git a/autotests/libs/entitytreemodeltest.cpp b/autotests/libs/entitytreemodeltest.cpp --- a/autotests/libs/entitytreemodeltest.cpp +++ b/autotests/libs/entitytreemodeltest.cpp @@ -99,20 +99,19 @@ private: QPair populateModel(const QString &serverContent, const QString &mimeType = QString()) { - FakeMonitor *fakeMonitor = new FakeMonitor(this); + const auto fakeMonitor = new FakeMonitor(this); fakeMonitor->setSession(m_fakeSession); fakeMonitor->setCollectionMonitored(Collection::root()); if (!mimeType.isEmpty()) { fakeMonitor->setMimeTypeMonitored(mimeType); } - EntityTreeModel *model = new EntityTreeModel(fakeMonitor, this); + const auto model = new EntityTreeModel(fakeMonitor, this); m_modelSpy = new ModelSpy{model, this}; - FakeServerData *serverData = new FakeServerData(model, m_fakeSession, fakeMonitor); - QList initialFetchResponse = FakeJobResponse::interpret(serverData, serverContent); - serverData->setCommands(initialFetchResponse); + const auto serverData = new FakeServerData(model, m_fakeSession, fakeMonitor); + serverData->setCommands(FakeJobResponse::interpret(serverData, serverContent)); // Give the model a chance to populate QTest::qWait(100); @@ -126,6 +125,16 @@ }; +QModelIndex firstMatchedIndex(const QAbstractItemModel &model, const QString pattern) +{ + if (pattern.isEmpty()) { + return {}; + } + const auto list = model.match(model.index(0, 0), Qt::DisplayRole, pattern, 1, Qt::MatchRecursive); + Q_ASSERT(!list.isEmpty()); + return list.first(); +} + void EntityTreeModelTest::initTestCase() { m_sessionName = "EntityTreeModelTest fake session"; @@ -137,17 +146,16 @@ void EntityTreeModelTest::testInitialFetch() { - FakeMonitor *fakeMonitor = new FakeMonitor(this); + const auto fakeMonitor = new FakeMonitor(this); fakeMonitor->setSession(m_fakeSession); fakeMonitor->setCollectionMonitored(Collection::root()); - EntityTreeModel *model = new EntityTreeModel(fakeMonitor, this); + const auto model = new EntityTreeModel(fakeMonitor, this); - FakeServerData *serverData = new FakeServerData(model, m_fakeSession, fakeMonitor); - QList initialFetchResponse = FakeJobResponse::interpret(serverData, serverContent1); - serverData->setCommands(initialFetchResponse); + const auto serverData = new FakeServerData(model, m_fakeSession, fakeMonitor); + serverData->setCommands(FakeJobResponse::interpret(serverData, serverContent1)); - m_modelSpy = new ModelSpy{model, this}; + m_modelSpy = new ModelSpy(model, this); m_modelSpy->startSpying(); const QList expectedSignals { @@ -227,20 +235,19 @@ QFETCH(QString, movedCollection); QFETCH(QString, targetCollection); - QPair testDrivers = populateModel(serverContent); - FakeServerData *serverData = testDrivers.first; - Akonadi::EntityTreeModel *model = testDrivers.second; + const auto testDrivers = populateModel(serverContent); + const auto serverData = testDrivers.first; + const auto model = testDrivers.second; - QModelIndexList list = model->match(model->index(0, 0), Qt::DisplayRole, movedCollection, 1, Qt::MatchRecursive); - Q_ASSERT(!list.isEmpty()); - QModelIndex movedIndex = list.first(); - QString sourceCollection = movedIndex.parent().data().toString(); - int sourceRow = movedIndex.row(); + const auto movedIndex = firstMatchedIndex(*model, movedCollection); + Q_ASSERT(movedIndex.isValid()); + const auto sourceCollection = movedIndex.parent().data().toString(); + const auto sourceRow = movedIndex.row(); - FakeCollectionMovedCommand *moveCommand = new FakeCollectionMovedCommand(movedCollection, sourceCollection, targetCollection, serverData); + const auto moveCommand = new FakeCollectionMovedCommand(movedCollection, sourceCollection, targetCollection, serverData); m_modelSpy->startSpying(); - serverData->setCommands(QList() << moveCommand); + serverData->setCommands({moveCommand}); const QList expectedSignals { {RowsAboutToBeMoved, sourceRow, sourceRow, sourceCollection, 0, targetCollection, {movedCollection}}, @@ -276,13 +283,13 @@ QFETCH(QString, addedCollection); QFETCH(QString, parentCollection); - QPair testDrivers = populateModel(serverContent); - FakeServerData *serverData = testDrivers.first; + const auto testDrivers = populateModel(serverContent); + const auto serverData = testDrivers.first; - FakeCollectionAddedCommand *addCommand = new FakeCollectionAddedCommand(addedCollection, parentCollection, serverData); + const auto addCommand = new FakeCollectionAddedCommand(addedCollection, parentCollection, serverData); m_modelSpy->startSpying(); - serverData->setCommands(QList() << addCommand); + serverData->setCommands({addCommand}); const QList expectedSignals { {RowsAboutToBeInserted, 0, 0, parentCollection, QVariantList{addedCollection}}, @@ -320,20 +327,18 @@ QFETCH(QString, serverContent); QFETCH(QString, removedCollection); - QPair testDrivers = populateModel(serverContent); - FakeServerData *serverData = testDrivers.first; - Akonadi::EntityTreeModel *model = testDrivers.second; + const auto testDrivers = populateModel(serverContent); + const auto serverData = testDrivers.first; + const auto model = testDrivers.second; - QModelIndexList list = model->match(model->index(0, 0), Qt::DisplayRole, removedCollection, 1, Qt::MatchRecursive); - Q_ASSERT(!list.isEmpty()); - QModelIndex removedIndex = list.first(); - QString parentCollection = removedIndex.parent().data().toString(); - int sourceRow = removedIndex.row(); + const auto removedIndex = firstMatchedIndex(*model, removedCollection); + const auto parentCollection = removedIndex.parent().data().toString(); + const auto sourceRow = removedIndex.row(); - FakeCollectionRemovedCommand *removeCommand = new FakeCollectionRemovedCommand(removedCollection, parentCollection, serverData); + const auto removeCommand = new FakeCollectionRemovedCommand(removedCollection, parentCollection, serverData); m_modelSpy->startSpying(); - serverData->setCommands(QList() << removeCommand); + serverData->setCommands({removeCommand}); const QList expectedSignals { {RowsAboutToBeRemoved, sourceRow, sourceRow, parentCollection, QVariantList{removedCollection}}, @@ -372,21 +377,19 @@ QFETCH(QString, collectionName); QFETCH(QString, monitoredMimeType); - QPair testDrivers = populateModel(serverContent, monitoredMimeType); - FakeServerData *serverData = testDrivers.first; - Akonadi::EntityTreeModel *model = testDrivers.second; + const auto testDrivers = populateModel(serverContent); + const auto serverData = testDrivers.first; + const auto model = testDrivers.second; - QModelIndexList list = model->match(model->index(0, 0), Qt::DisplayRole, collectionName, 1, Qt::MatchRecursive); - Q_ASSERT(!list.isEmpty()); - QModelIndex changedIndex = list.first(); - QString parentCollection = changedIndex.parent().data().toString(); + const auto changedIndex = firstMatchedIndex(*model, collectionName); + const auto parentCollection = changedIndex.parent().data().toString(); qDebug() << parentCollection; - int changedRow = changedIndex.row(); + const auto changedRow = changedIndex.row(); - FakeCollectionChangedCommand *changeCommand = new FakeCollectionChangedCommand(collectionName, parentCollection, serverData); + const auto changeCommand = new FakeCollectionChangedCommand(collectionName, parentCollection, serverData); m_modelSpy->startSpying(); - serverData->setCommands(QList() << changeCommand); + serverData->setCommands({changeCommand}); const QList expectedSignals { {DataChanged, changedRow, changedRow, parentCollection, QVariantList{collectionName}} @@ -421,25 +424,21 @@ QFETCH(QString, movedItem); QFETCH(QString, targetCollection); - QPair testDrivers = populateModel(serverContent); - FakeServerData *serverData = testDrivers.first; - Akonadi::EntityTreeModel *model = testDrivers.second; + const auto testDrivers = populateModel(serverContent); + const auto serverData = testDrivers.first; + const auto model = testDrivers.second; - QModelIndexList list = model->match(model->index(0, 0), Qt::DisplayRole, movedItem, 1, Qt::MatchRecursive); - Q_ASSERT(!list.isEmpty()); - QModelIndex movedIndex = list.first(); - QString sourceCollection = movedIndex.parent().data().toString(); - int sourceRow = movedIndex.row(); + const auto movedIndex = firstMatchedIndex(*model, movedItem); + const auto sourceCollection = movedIndex.parent().data().toString(); + const auto sourceRow = movedIndex.row(); - QModelIndexList targetList = model->match(model->index(0, 0), Qt::DisplayRole, targetCollection, 1, Qt::MatchRecursive); - Q_ASSERT(!targetList.isEmpty()); - QModelIndex targetIndex = targetList.first(); - int targetRow = model->rowCount(targetIndex); + const auto targetIndex = firstMatchedIndex(*model, targetCollection); + const auto targetRow = model->rowCount(targetIndex); - FakeItemMovedCommand *moveCommand = new FakeItemMovedCommand(movedItem, sourceCollection, targetCollection, serverData); + const auto moveCommand = new FakeItemMovedCommand(movedItem, sourceCollection, targetCollection, serverData); m_modelSpy->startSpying(); - serverData->setCommands(QList() << moveCommand); + serverData->setCommands({moveCommand}); const QList expectedSignals { //Currently moves are implemented as remove + insert in the ETM. @@ -481,20 +480,18 @@ QFETCH(QString, addedItem); QFETCH(QString, parentCollection); - QPair testDrivers = populateModel(serverContent); - FakeServerData *serverData = testDrivers.first; - Akonadi::EntityTreeModel *model = testDrivers.second; + const auto testDrivers = populateModel(serverContent); + const auto serverData = testDrivers.first; + const auto model = testDrivers.second; - QModelIndexList list = model->match(model->index(0, 0), Qt::DisplayRole, parentCollection, 1, Qt::MatchRecursive); - Q_ASSERT(!list.isEmpty()); - QModelIndex parentIndex = list.first(); - int targetRow = model->rowCount(parentIndex); + const auto parentIndex = firstMatchedIndex(*model, parentCollection); + const auto targetRow = model->rowCount(parentIndex); - FakeItemAddedCommand *addedCommand = new FakeItemAddedCommand(addedItem, parentCollection, serverData); + const auto addedCommand = new FakeItemAddedCommand(addedItem, parentCollection, serverData); m_modelSpy->startSpying(); - serverData->setCommands(QList() << addedCommand); + serverData->setCommands({addedCommand}); const QList expectedSignals { {RowsAboutToBeInserted, targetRow, targetRow, parentCollection, QVariantList{addedItem}}, @@ -536,20 +533,18 @@ QFETCH(QString, serverContent); QFETCH(QString, removedItem); - QPair testDrivers = populateModel(serverContent); - FakeServerData *serverData = testDrivers.first; - Akonadi::EntityTreeModel *model = testDrivers.second; + const auto testDrivers = populateModel(serverContent); + const auto serverData = testDrivers.first; + const auto model = testDrivers.second; - const QModelIndexList list = model->match(model->index(0, 0), Qt::DisplayRole, removedItem, 1, Qt::MatchRecursive); - Q_ASSERT(!list.isEmpty()); - QModelIndex removedIndex = list.first(); - const QString sourceCollection = removedIndex.parent().data().toString(); - int sourceRow = removedIndex.row(); + const auto removedIndex = firstMatchedIndex(*model, removedItem); + const auto sourceCollection = removedIndex.parent().data().toString(); + const auto sourceRow = removedIndex.row(); - FakeItemRemovedCommand *removeCommand = new FakeItemRemovedCommand(removedItem, sourceCollection, serverData); + const auto removeCommand = new FakeItemRemovedCommand(removedItem, sourceCollection, serverData); m_modelSpy->startSpying(); - serverData->setCommands(QList() << removeCommand); + serverData->setCommands({removeCommand}); const QList expectedSignals { {RowsAboutToBeRemoved, sourceRow, sourceRow, sourceCollection, QVariantList{removedItem}}, @@ -592,20 +587,18 @@ QFETCH(QString, serverContent); QFETCH(QString, changedItem); - QPair testDrivers = populateModel(serverContent); - FakeServerData *serverData = testDrivers.first; - Akonadi::EntityTreeModel *model = testDrivers.second; + const auto testDrivers = populateModel(serverContent); + const auto serverData = testDrivers.first; + const auto model = testDrivers.second; - QModelIndexList list = model->match(model->index(0, 0), Qt::DisplayRole, changedItem, 1, Qt::MatchRecursive); - Q_ASSERT(!list.isEmpty()); - QModelIndex changedIndex = list.first(); - QString parentCollection = changedIndex.parent().data().toString(); - int sourceRow = changedIndex.row(); + const auto changedIndex = firstMatchedIndex(*model, changedItem); + const auto parentCollection = changedIndex.parent().data().toString(); + const auto sourceRow = changedIndex.row(); - FakeItemChangedCommand *changeCommand = new FakeItemChangedCommand(changedItem, parentCollection, serverData); + const auto changeCommand = new FakeItemChangedCommand(changedItem, parentCollection, serverData); m_modelSpy->startSpying(); - serverData->setCommands(QList() << changeCommand); + serverData->setCommands({changeCommand}); const QList expectedSignals { {DataChanged, sourceRow, sourceRow, QVariantList{changedItem}} @@ -622,28 +615,27 @@ void EntityTreeModelTest::testRemoveCollectionOnChanged() { - const QString serverContent = QStringLiteral( - "- C (inode/directory, text/directory) 'Col 1' 2" - "- - C (text/directory) 'Col 2' 1" - "- - - I text/directory 'Item 1'"); - const QString collectionName = QStringLiteral("Col 2"); - const QString monitoredMimeType = QStringLiteral("text/directory"); - - QPair testDrivers = populateModel(serverContent, monitoredMimeType); - FakeServerData *serverData = testDrivers.first; - Akonadi::EntityTreeModel *model = testDrivers.second; - - QModelIndexList list = model->match(model->index(0, 0), Qt::DisplayRole, collectionName, 1, Qt::MatchRecursive); - Q_ASSERT(!list.isEmpty()); - QModelIndex changedIndex = list.first(); - Akonadi::Collection changedCol = changedIndex.data(Akonadi::EntityTreeModel::CollectionRole).value(); - changedCol.setContentMimeTypes(QStringList() << QStringLiteral("foobar")); - QString parentCollection = changedIndex.parent().data().toString(); + const auto serverContent = QStringLiteral( + "- C (inode/directory, text/directory) 'Col 1' 2" + "- - C (text/directory) 'Col 2' 1" + "- - - I text/directory 'Item 1'" + ); + const auto collectionName = QStringLiteral("Col 2"); + const auto monitoredMimeType = QStringLiteral("text/directory"); + + const auto testDrivers = populateModel(serverContent, monitoredMimeType); + const auto serverData = testDrivers.first; + const auto model = testDrivers.second; + + const auto changedIndex = firstMatchedIndex(*model, collectionName); + auto changedCol = changedIndex.data(Akonadi::EntityTreeModel::CollectionRole).value(); + changedCol.setContentMimeTypes({QStringLiteral("foobar")}); + const auto parentCollection = changedIndex.parent().data().toString(); - FakeCollectionChangedCommand *changeCommand = new FakeCollectionChangedCommand(changedCol, serverData); + const auto changeCommand = new FakeCollectionChangedCommand(changedCol, serverData); m_modelSpy->startSpying(); - serverData->setCommands(QList() << changeCommand); + serverData->setCommands({changeCommand}); const QList expectedSignals { {RowsAboutToBeRemoved, changedIndex.row(), changedIndex.row(), parentCollection, QVariantList{collectionName}}, diff --git a/autotests/libs/modelspy.cpp b/autotests/libs/modelspy.cpp --- a/autotests/libs/modelspy.cpp +++ b/autotests/libs/modelspy.cpp @@ -160,61 +160,61 @@ if (!m_expectedSignals.isEmpty()) { verifySignal(RowsAboutToBeInserted, parent, start, end); } else { - append(QVariantList() << RowsAboutToBeInserted << QVariant::fromValue(parent) << start << end); + append(QVariantList{RowsAboutToBeInserted, QVariant::fromValue(parent), start, end}); } } void ModelSpy::rowsInserted(const QModelIndex &parent, int start, int end) { if (!m_expectedSignals.isEmpty()) { verifySignal(RowsInserted, parent, start, end); } else { - append(QVariantList() << RowsInserted << QVariant::fromValue(parent) << start << end); + append(QVariantList{RowsInserted, QVariant::fromValue(parent), start, end}); } } void ModelSpy::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) { if (!m_expectedSignals.isEmpty()) { verifySignal(RowsAboutToBeRemoved, parent, start, end); } else { - append(QVariantList() << RowsAboutToBeRemoved << QVariant::fromValue(parent) << start << end); + append(QVariantList{RowsAboutToBeRemoved, QVariant::fromValue(parent), start, end}); } } void ModelSpy::rowsRemoved(const QModelIndex &parent, int start, int end) { if (!m_expectedSignals.isEmpty()) { verifySignal(RowsRemoved, parent, start, end); } else { - append(QVariantList() << RowsRemoved << QVariant::fromValue(parent) << start << end); + append(QVariantList{RowsRemoved, QVariant::fromValue(parent), start, end}); } } void ModelSpy::rowsAboutToBeMoved(const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destStart) { if (!m_expectedSignals.isEmpty()) { verifySignal(RowsAboutToBeMoved, srcParent, start, end, destParent, destStart); } else { - append(QVariantList() << RowsAboutToBeMoved << QVariant::fromValue(srcParent) << start << end << QVariant::fromValue(destParent) << destStart); + append(QVariantList{RowsAboutToBeMoved, QVariant::fromValue(srcParent), start, end, QVariant::fromValue(destParent), destStart}); } } void ModelSpy::rowsMoved(const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destStart) { if (!m_expectedSignals.isEmpty()) { verifySignal(RowsMoved, srcParent, start, end, destParent, destStart); } else { - append(QVariantList() << RowsMoved << QVariant::fromValue(srcParent) << start << end << QVariant::fromValue(destParent) << destStart); + append(QVariantList{RowsMoved, QVariant::fromValue(srcParent), start, end, QVariant::fromValue(destParent), destStart}); } } void ModelSpy::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { if (!m_expectedSignals.isEmpty()) { verifySignal(DataChanged, topLeft, bottomRight); } else { - append(QVariantList() << DataChanged << QVariant::fromValue(topLeft) << QVariant::fromValue(bottomRight)); + append(QVariantList{DataChanged, QVariant::fromValue(topLeft), QVariant::fromValue(bottomRight)}); } } diff --git a/autotests/libs/tagmodeltest.cpp b/autotests/libs/tagmodeltest.cpp --- a/autotests/libs/tagmodeltest.cpp +++ b/autotests/libs/tagmodeltest.cpp @@ -61,19 +61,18 @@ private: QPair populateModel(const QString &serverContent) { - FakeMonitor *fakeMonitor = new FakeMonitor(this); + const auto fakeMonitor = new FakeMonitor(this); fakeMonitor->setSession(m_fakeSession); fakeMonitor->setCollectionMonitored(Collection::root()); fakeMonitor->setTypeMonitored(Akonadi::Monitor::Tags); - TagModel *model = new TagModel(fakeMonitor, this); + const auto model = new TagModel(fakeMonitor, this); m_modelSpy = new ModelSpy{model, this}; - FakeServerData *serverData = new FakeServerData(model, m_fakeSession, fakeMonitor); - QList initialFetchResponse = FakeJobResponse::interpret(serverData, serverContent); - serverData->setCommands(initialFetchResponse); + const auto serverData = new FakeServerData(model, m_fakeSession, fakeMonitor); + serverData->setCommands(FakeJobResponse::interpret(serverData, serverContent)); // Give the model a chance to populate QTest::qWait(100); @@ -86,6 +85,16 @@ QByteArray m_sessionName; }; +QModelIndex firstMatchedIndex(const QAbstractItemModel &model, const QString pattern) +{ + if (pattern.isEmpty()) { + return {}; + } + const auto list = model.match(model.index(0, 0), Qt::DisplayRole, pattern, 1, Qt::MatchRecursive); + Q_ASSERT(!list.isEmpty()); + return list.first(); +} + void TagModelTest::initTestCase() { m_sessionName = "TagModelTest fake session"; @@ -97,14 +106,14 @@ void TagModelTest::testInitialFetch() { - FakeMonitor *fakeMonitor = new FakeMonitor(this); + const auto fakeMonitor = new FakeMonitor(this); fakeMonitor->setSession(m_fakeSession); fakeMonitor->setCollectionMonitored(Collection::root()); - TagModel *model = new TagModel(fakeMonitor, this); + const auto model = new TagModel(fakeMonitor, this); - FakeServerData *serverData = new FakeServerData(model, m_fakeSession, fakeMonitor); - QList initialFetchResponse = FakeJobResponse::interpret(serverData, serverContent1); + const auto serverData = new FakeServerData(model, m_fakeSession, fakeMonitor); + const auto initialFetchResponse = FakeJobResponse::interpret(serverData, serverContent1); serverData->setCommands(initialFetchResponse); m_modelSpy = new ModelSpy{model, this}; @@ -155,20 +164,17 @@ QFETCH(QString, addedTag); QFETCH(QString, parentTag); - QPair testDrivers = populateModel(serverContent); - FakeServerData *serverData = testDrivers.first; - Akonadi::TagModel *model = testDrivers.second; - - const QModelIndexList list = model->match(model->index(0, 0), Qt::DisplayRole, parentTag, 1, Qt::MatchRecursive); - QVERIFY(!list.isEmpty()); - const QModelIndex parentIndex = list.first(); - const int newRow = model->rowCount(parentIndex); + const auto testDrivers = populateModel(serverContent); + const auto serverData = testDrivers.first; + const auto model = testDrivers.second; + const auto parentIndex = firstMatchedIndex(*model, parentTag); + const auto newRow = model->rowCount(parentIndex); - FakeTagAddedCommand *addCommand = new FakeTagAddedCommand(addedTag, parentTag, serverData); + const auto addCommand = new FakeTagAddedCommand(addedTag, parentTag, serverData); m_modelSpy->startSpying(); - serverData->setCommands(QList() << addCommand); + serverData->setCommands({addCommand}); const QList expectedSignals { @@ -201,17 +207,15 @@ QFETCH(QString, serverContent); QFETCH(QString, tagName); - const QPair testDrivers = populateModel(serverContent); - FakeServerData *serverData = testDrivers.first; - Akonadi::TagModel *model = testDrivers.second; + const auto testDrivers = populateModel(serverContent); + const auto serverData = testDrivers.first; + const auto model = testDrivers.second; - const QModelIndexList list = model->match(model->index(0, 0), Qt::DisplayRole, tagName, 1, Qt::MatchRecursive); - QVERIFY(!list.isEmpty()); - const QModelIndex changedIndex = list.first(); - const QString parentTag = changedIndex.parent().data().toString(); - const int changedRow = changedIndex.row(); + const auto changedIndex = firstMatchedIndex(*model, tagName); + const auto parentTag = changedIndex.parent().data().toString(); + const auto changedRow = changedIndex.row(); - FakeTagChangedCommand *changeCommand = new FakeTagChangedCommand(tagName, parentTag, serverData); + const auto changeCommand = new FakeTagChangedCommand(tagName, parentTag, serverData); m_modelSpy->startSpying(); serverData->setCommands(QList() << changeCommand); @@ -246,21 +250,18 @@ QFETCH(QString, serverContent); QFETCH(QString, removedTag); - const QPair testDrivers = populateModel(serverContent); - FakeServerData *serverData = testDrivers.first; - Akonadi::TagModel *model = testDrivers.second; + const auto testDrivers = populateModel(serverContent); + const auto serverData = testDrivers.first; + const auto model = testDrivers.second; - const QModelIndexList list = model->match(model->index(0, 0), Qt::DisplayRole, removedTag, 1, Qt::MatchRecursive); - QVERIFY(!list.isEmpty()); - const QModelIndex removedIndex = list.first(); - const QString parentTag = removedIndex.parent().data().toString(); - const int sourceRow = removedIndex.row(); + const auto removedIndex = firstMatchedIndex(*model, removedTag); + const auto parentTag = removedIndex.parent().data().toString(); + const auto sourceRow = removedIndex.row(); - - FakeTagRemovedCommand *removeCommand = new FakeTagRemovedCommand(removedTag, parentTag, serverData); + const auto removeCommand = new FakeTagRemovedCommand(removedTag, parentTag, serverData); m_modelSpy->startSpying(); - serverData->setCommands(QList() << removeCommand); + serverData->setCommands({removeCommand}); const auto removedTagList = QVariantList{removedTag}; const auto parentTagVariant = parentTag.isEmpty() ? QVariant{} : parentTag; @@ -299,28 +300,21 @@ QFETCH(QString, changedTag); QFETCH(QString, newParent); - const QPair testDrivers = populateModel(serverContent); - FakeServerData *serverData = testDrivers.first; - Akonadi::TagModel *model = testDrivers.second; - - QModelIndexList list = model->match(model->index(0, 0), Qt::DisplayRole, changedTag, 1, Qt::MatchRecursive); - QVERIFY(!list.isEmpty()); - const QModelIndex changedIndex = list.first(); - const QString parentTag = changedIndex.parent().data().toString(); - const int sourceRow = changedIndex.row(); - - QModelIndex newParentIndex; - if (!newParent.isEmpty()) { - list = model->match(model->index(0, 0), Qt::DisplayRole, newParent, 1, Qt::MatchRecursive); - QVERIFY(!list.isEmpty()); - newParentIndex = list.first(); - } - const int destRow = model->rowCount(newParentIndex); + const auto testDrivers = populateModel(serverContent); + const auto serverData = testDrivers.first; + const auto model = testDrivers.second; + + const auto changedIndex = firstMatchedIndex(*model, changedTag); + const auto parentTag = changedIndex.parent().data().toString(); + const auto sourceRow = changedIndex.row(); - FakeTagMovedCommand *moveCommand = new FakeTagMovedCommand(changedTag, parentTag, newParent, serverData); + QModelIndex newParentIndex = firstMatchedIndex(*model, newParent); + const auto destRow = model->rowCount(newParentIndex); + + const auto moveCommand = new FakeTagMovedCommand(changedTag, parentTag, newParent, serverData); m_modelSpy->startSpying(); - serverData->setCommands(QList() << moveCommand); + serverData->setCommands({moveCommand}); const auto parentTagVariant = parentTag.isEmpty() ? QVariant{} : parentTag; const auto newParentVariant = newParent.isEmpty() ? QVariant{} : newParent; @@ -338,7 +332,6 @@ QVERIFY(m_modelSpy->isEmpty()); } - #include "tagmodeltest.moc" QTEST_MAIN(TagModelTest)