bool WarningsModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { Q_UNUSED(sourceParent); QAbstractItemModel *sourceItemModel = sourceModel(); Models::ArtItemsModel *artItemsModel = dynamic_cast<Models::ArtItemsModel *>(sourceItemModel); Q_ASSERT(artItemsModel != NULL); Models::ArtworkMetadata *metadata = artItemsModel->getArtwork(sourceRow); bool rowIsOk = false; if (metadata != NULL) { Common::WarningFlags warningsFlags = metadata->getWarningsFlags(); bool anyWarnings = warningsFlags != Common::WarningFlags::None; rowIsOk = anyWarnings; if (m_ShowOnlySelected) { rowIsOk = metadata->isSelected() && anyWarnings; } } return rowIsOk; }
int SpellingProducesWarningsTest::doTest() { Models::ArtItemsModel *artItemsModel = m_CommandManager->getArtItemsModel(); QList<QUrl> files; files << getImagePathForTest("images-for-tests/vector/026.jpg"); int addedCount = artItemsModel->addLocalArtworks(files); VERIFY(addedCount == files.length(), "Failed to add file"); MetadataIO::MetadataIOCoordinator *ioCoordinator = m_CommandManager->getMetadataIOCoordinator(); SignalWaiter waiter; QObject::connect(ioCoordinator, SIGNAL(metadataReadingFinished()), &waiter, SIGNAL(finished())); ioCoordinator->continueReading(true); if (!waiter.wait(20)) { VERIFY(false, "Timeout exceeded for reading metadata."); } VERIFY(!ioCoordinator->getHasErrors(), "Errors in IO Coordinator while reading"); Models::ArtworkMetadata *metadata = artItemsModel->getArtwork(0); sleepWait(3, [metadata]() { return !Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInTitle) && !Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInDescription) && !Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInKeywords); }); VERIFY(!Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInTitle), "Error for reading title"); VERIFY(!Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInDescription), "Error for reading description"); VERIFY(!Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInKeywords), "Error for reading keywords"); QString wrongWord = "abbreviatioe"; metadata->setDescription(metadata->getDescription() + ' ' + wrongWord); metadata->setTitle(metadata->getTitle() + ' ' + wrongWord); metadata->appendKeyword("correct part " + wrongWord); metadata->setIsSelected(true); Models::FilteredArtItemsProxyModel *filteredModel = m_CommandManager->getFilteredArtItemsModel(); SpellCheck::SpellCheckerService *spellCheckService = m_CommandManager->getSpellCheckerService(); SignalWaiter spellingWaiter; QObject::connect(spellCheckService, SIGNAL(spellCheckQueueIsEmpty()), &spellingWaiter, SIGNAL(finished())); filteredModel->spellCheckSelected(); if (!spellingWaiter.wait(5)) { VERIFY(false, "Timeout for waiting for first spellcheck results"); } LOG_INFO << "Spellchecking finished. Waiting for warnings..."; sleepWait(5, [=]() { return Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInTitle) && Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInDescription) && Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInKeywords); }); auto *keywordsModel = metadata->getBasicModel(); VERIFY(keywordsModel->hasDescriptionSpellError(), "Description spell error not detected"); VERIFY(keywordsModel->hasTitleSpellError(), "Title spell error not detected"); VERIFY(keywordsModel->hasKeywordsSpellError(), "Keywords spell error not detected"); VERIFY(Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInTitle), "Warning was not produced for title spelling error"); VERIFY(Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInDescription), "Warning was not produced for description spelling error"); VERIFY(Common::HasFlag(metadata->getWarningsFlags(), Common::WarningFlags::SpellErrorsInKeywords), "Warning was not produced for keywords spelling error"); return 0; }