diff --git a/interfaces/iproblem.h b/interfaces/iproblem.h --- a/interfaces/iproblem.h +++ b/interfaces/iproblem.h @@ -52,11 +52,12 @@ /// Severity of the problem. That is, how serious is the found problem. enum Severity { - Error, - Warning, - Hint + NoSeverity = 0, + Error = 1, + Warning = 2, + Hint = 4 }; - + Q_DECLARE_FLAGS(Severities, Severity) IProblem(){} virtual ~IProblem(){} @@ -113,6 +114,8 @@ virtual QExplicitlySharedDataPointer solutionAssistant() const = 0; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(IProblem::Severities) + } Q_DECLARE_METATYPE(KDevelop::IProblem::Ptr); diff --git a/plugins/problemreporter/problemtreeview.h b/plugins/problemreporter/problemtreeview.h --- a/plugins/problemreporter/problemtreeview.h +++ b/plugins/problemreporter/problemtreeview.h @@ -53,7 +53,7 @@ public slots: void openDocumentForCurrentProblem(); - + signals: // Emitted when the model's rows change (added/removed/reset) void changed(); @@ -63,13 +63,17 @@ private slots: void itemActivated(const QModelIndex& index); - + void handleSeverityActionToggled(); + void setScope(int scope); private: void resizeColumns(); ProblemReporterPlugin* m_plugin; QSortFilterProxyModel* m_proxy; + QAction* errorSeverityAction; + QAction* warningSeverityAction; + QAction* hintSeverityAction; }; #endif diff --git a/plugins/problemreporter/problemtreeview.cpp b/plugins/problemreporter/problemtreeview.cpp --- a/plugins/problemreporter/problemtreeview.cpp +++ b/plugins/problemreporter/problemtreeview.cpp @@ -81,8 +81,10 @@ ProblemTreeView::ProblemTreeView(QWidget* parent, QAbstractItemModel* itemModel) : QTreeView(parent) , m_proxy(new QSortFilterProxyModel(this)) + , errorSeverityAction(nullptr) + , warningSeverityAction(nullptr) + , hintSeverityAction(nullptr) { - setObjectName("Problem Reporter Tree"); setWhatsThis(i18n("Problems")); setItemDelegate(new ProblemTreeViewItemDelegate(this)); @@ -199,15 +201,16 @@ if (problemModel->features().testFlag(ProblemModel::SeverityFilter)) { QActionGroup* severityActions = new QActionGroup(this); - auto errorSeverityAction = new QAction(this); + + errorSeverityAction = new QAction(this); errorSeverityAction->setToolTip(i18nc("@info:tooltip", "Display only errors")); errorSeverityAction->setIcon(QIcon::fromTheme("dialog-error")); - auto warningSeverityAction = new QAction(this); + warningSeverityAction = new QAction(this); warningSeverityAction->setToolTip(i18nc("@info:tooltip", "Display errors and warnings")); warningSeverityAction->setIcon(QIcon::fromTheme("dialog-warning")); - auto hintSeverityAction = new QAction(this); + hintSeverityAction = new QAction(this); hintSeverityAction->setToolTip(i18nc("@info:tooltip", "Display errors, warnings and hints")); hintSeverityAction->setIcon(QIcon::fromTheme("dialog-information")); @@ -217,21 +220,16 @@ severityActions->addAction(severityActionArray[i]); addAction(severityActionArray[i]); } + severityActions->setExclusive(false); hintSeverityAction->setChecked(true); - model()->setSeverity(IProblem::Hint); - QSignalMapper* severityMapper = new QSignalMapper(this); - severityMapper->setMapping(errorSeverityAction, IProblem::Error); - severityMapper->setMapping(warningSeverityAction, IProblem::Warning); - severityMapper->setMapping(hintSeverityAction, IProblem::Hint); - connect(errorSeverityAction, &QAction::triggered, severityMapper, - static_cast(&QSignalMapper::map)); - connect(warningSeverityAction, &QAction::triggered, severityMapper, - static_cast(&QSignalMapper::map)); - connect(hintSeverityAction, &QAction::triggered, severityMapper, - static_cast(&QSignalMapper::map)); - connect(severityMapper, static_cast(&QSignalMapper::mapped), model(), - &ProblemModel::setSeverity); + warningSeverityAction->setChecked(true); + errorSeverityAction->setChecked(true); + + model()->setSeverities(IProblem::Error | IProblem::Warning | IProblem::Hint); + connect(errorSeverityAction, &QAction::toggled, this, &ProblemTreeView::handleSeverityActionToggled); + connect(warningSeverityAction, &QAction::toggled, this, &ProblemTreeView::handleSeverityActionToggled); + connect(hintSeverityAction, &QAction::toggled, this, &ProblemTreeView::handleSeverityActionToggled); } if (problemModel->features().testFlag(ProblemModel::Grouping)) { @@ -308,6 +306,14 @@ ICore::self()->documentController()->openDocument(url, start); } +void ProblemTreeView::handleSeverityActionToggled() +{ + model()->setSeverities( (errorSeverityAction->isChecked() ? IProblem::Error : IProblem::NoSeverity) | + (warningSeverityAction->isChecked() ? IProblem::Warning : IProblem::NoSeverity) | + (hintSeverityAction->isChecked() ? IProblem::Hint : IProblem::NoSeverity) ); + qDebug() << errorSeverityAction->isChecked() << warningSeverityAction->isChecked() << hintSeverityAction->isChecked(); +} + void ProblemTreeView::setScope(int scope) { foreach (auto action, actions()) { diff --git a/shell/filteredproblemstore.cpp b/shell/filteredproblemstore.cpp --- a/shell/filteredproblemstore.cpp +++ b/shell/filteredproblemstore.cpp @@ -309,7 +309,7 @@ bool FilteredProblemStorePrivate::match(const IProblem::Ptr &problem) const { /// If the problem is less severe than our filter criterion then it's discarded - if(problem->severity() > q->severity()) + if(!q->severities().testFlag(problem->severity())) return false; /// If we have bypass on, don't check the scope diff --git a/shell/problemmodel.h b/shell/problemmodel.h --- a/shell/problemmodel.h +++ b/shell/problemmodel.h @@ -143,7 +143,22 @@ virtual void setScope(int scope); /// Sets the severity filter. Uses int to be able to use QSignalMapper - virtual void setSeverity(int severity); + virtual void setSeverity(int severity) + { + switch (severity) + { + case KDevelop::IProblem::Error: + setSeverities(KDevelop::IProblem::Error); + break; + case KDevelop::IProblem::Warning: + setSeverities(KDevelop::IProblem::Error | KDevelop::IProblem::Warning); + break; + case KDevelop::IProblem::Hint: + setSeverities(KDevelop::IProblem::Error | KDevelop::IProblem::Warning | KDevelop::IProblem::Hint); + break; + } + }//TODO: remove this + virtual void setSeverities(KDevelop::IProblem::Severities severities); void setGrouping(int grouping); diff --git a/shell/problemmodel.cpp b/shell/problemmodel.cpp --- a/shell/problemmodel.cpp +++ b/shell/problemmodel.cpp @@ -301,12 +301,12 @@ d->m_problems->setScope(scope); } -void ProblemModel::setSeverity(int severity) +void ProblemModel::setSeverities(KDevelop::IProblem::Severities severities) { Q_ASSERT(thread() == QThread::currentThread()); - + qDebug() << int(severities); /// Will trigger signals beginRebuild(), endRebuild() if problems change and are rebuilt - d->m_problems->setSeverity(severity); + d->m_problems->setSeverities(severities); } void ProblemModel::setGrouping(int grouping) diff --git a/shell/problemstore.h b/shell/problemstore.h --- a/shell/problemstore.h +++ b/shell/problemstore.h @@ -95,10 +95,28 @@ virtual void rebuild(); /// Specifies the severity filter - virtual void setSeverity(int severity); + virtual void setSeverity(int severity) + { + switch (severity) + { + case KDevelop::IProblem::Error: + setSeverities(KDevelop::IProblem::Error); + break; + case KDevelop::IProblem::Warning: + setSeverities(KDevelop::IProblem::Error | KDevelop::IProblem::Warning); + break; + case KDevelop::IProblem::Hint: + setSeverities(KDevelop::IProblem::Error | KDevelop::IProblem::Warning | KDevelop::IProblem::Hint); + break; + } + }//TODO: remove + virtual void setSeverities(KDevelop::IProblem::Severities severities); /// Retrives the severity filter settings - int severity() const; + int severity() const;//TODO: remove + KDevelop::IProblem::Severities severities() const; + + /// Retrieves the currently watched document set WatchedDocumentSet* documents() const; diff --git a/shell/problemstore.cpp b/shell/problemstore.cpp --- a/shell/problemstore.cpp +++ b/shell/problemstore.cpp @@ -27,16 +27,16 @@ { ProblemStorePrivate() : m_documents(nullptr) - , m_severity(KDevelop::IProblem::Hint) + , m_severities(KDevelop::IProblem::Error | KDevelop::IProblem::Warning | KDevelop::IProblem::Hint) , m_rootNode(new KDevelop::ProblemStoreNode()) { } /// Watched document set. Only problems that are in files in this set are stored. KDevelop::WatchedDocumentSet *m_documents; /// The severity filter setting - int m_severity; + KDevelop::IProblem::Severities m_severities; /// The problems list KDevelop::ProblemStoreNode *m_rootNode; @@ -100,19 +100,30 @@ { } -void ProblemStore::setSeverity(int severity) +void ProblemStore::setSeverities(KDevelop::IProblem::Severities severities) { - if(severity != d->m_severity) + if(severities != d->m_severities) { - d->m_severity = severity; + d->m_severities = severities; rebuild(); emit changed(); } } int ProblemStore::severity() const { - return d->m_severity; + if (d->m_severities.testFlag(KDevelop::IProblem::Hint)) + return KDevelop::IProblem::Hint; + if (d->m_severities.testFlag(KDevelop::IProblem::Warning)) + return KDevelop::IProblem::Warning; + if (d->m_severities.testFlag(KDevelop::IProblem::Error)) + return KDevelop::IProblem::Error; + return 0; +}//TODO: remove + +KDevelop::IProblem::Severities ProblemStore::severities() const +{ + return d->m_severities; } WatchedDocumentSet* ProblemStore::documents() const diff --git a/shell/tests/test_filteredproblemstore.cpp b/shell/tests/test_filteredproblemstore.cpp --- a/shell/tests/test_filteredproblemstore.cpp +++ b/shell/tests/test_filteredproblemstore.cpp @@ -32,8 +32,9 @@ namespace { const int ErrorCount = 1; -const int WarningCount = 1; -const int HintCount = 1; +const int WarningCount = 2; +const int HintCount = 3; +const int ProblemsCount = ErrorCount + WarningCount + HintCount; const int ErrorFilterProblemCount = ErrorCount; const int WarningFilterProblemCount = ErrorCount + WarningCount; @@ -51,6 +52,7 @@ void testBypass(); void testSeverity(); + void testSeverities(); void testGrouping(); void testNoGrouping(); @@ -130,6 +132,25 @@ m_store->setSeverity(IProblem::Hint); } +void TestFilteredProblemStore::testSeverities() +{ + QVERIFY(m_store->severities() == (IProblem::Error | IProblem::Warning | IProblem::Hint)); + + QSignalSpy changedSpy(m_store.data(), &FilteredProblemStore::changed); + QSignalSpy beginRebuildSpy(m_store.data(), &FilteredProblemStore::beginRebuild); + QSignalSpy endRebuildSpy(m_store.data(), &FilteredProblemStore::endRebuild); + + m_store->setSeverities(IProblem::Error | IProblem::Hint); + + QVERIFY(m_store->severities() == (IProblem::Error | IProblem::Hint)); + + QCOMPARE(changedSpy.count(), 1); + QCOMPARE(beginRebuildSpy.count(), 1); + QCOMPARE(endRebuildSpy.count(), 1); + + m_store->setSeverities(IProblem::Error | IProblem::Warning | IProblem::Hint); +} + void TestFilteredProblemStore::testGrouping() { QVERIFY(m_store->grouping() == NoGrouping); @@ -202,15 +223,15 @@ QCOMPARE(node->problem()->description(), m_problems[i]->description()); } - // Check severity filtering + // Check old style severity filtering + //TODO: remove // Error filter m_store->setSeverity(IProblem::Error); QCOMPARE(m_store->count(), ErrorFilterProblemCount); - - { + for (int i = 0; i < ErrorFilterProblemCount; i++) { const ProblemNode *node = dynamic_cast(m_store->findNode(0)); QVERIFY(node != nullptr); - QCOMPARE(node->problem()->description(), m_problems[0]->description()); + QCOMPARE(node->problem()->description(), m_problems[i]->description()); } // Warning filter @@ -232,7 +253,54 @@ QCOMPARE(node->problem()->description(), m_problems[i]->description()); } + + // Check new severity filtering + // Error filter + m_store->setSeverities(IProblem::Error); + QCOMPARE(m_store->count(), ErrorCount); + for (int i = 0; i < ErrorCount; i++) { + const ProblemNode *node = dynamic_cast(m_store->findNode(i)); + QVERIFY(node != nullptr); + QCOMPARE(node->problem()->description(), m_problems[i]->description()); + } + + // Warning filter + m_store->setSeverities(IProblem::Warning); + QCOMPARE(m_store->count(), WarningCount); + for (int i = 0; i < WarningCount; i++) { + const ProblemNode *node = dynamic_cast(m_store->findNode(i)); + QVERIFY(node != nullptr); + + QCOMPARE(node->problem()->description(), m_problems[i+ErrorCount]->description()); + } + + // Hint filter + m_store->setSeverities(IProblem::Hint); + QCOMPARE(m_store->count(), HintCount); + for (int i = 0; i < HintCount; i++) { + const ProblemNode *node = dynamic_cast(m_store->findNode(i)); + QVERIFY(node != nullptr); + + QCOMPARE(node->problem()->description(), m_problems[i+ErrorCount+WarningCount]->description()); + } + + //Error + Hint filter + m_store->setSeverities(IProblem::Error | IProblem::Hint); + QCOMPARE(m_store->count(), HintCount + ErrorCount); + for (int i = 0; i < ErrorCount; i++) { + const ProblemNode *node = dynamic_cast(m_store->findNode(i)); + QVERIFY(node != nullptr); + + QCOMPARE(node->problem()->description(), m_problems[i]->description()); + } + for (int i = ErrorCount; i < ErrorCount+HintCount; i++) { + const ProblemNode *node = dynamic_cast(m_store->findNode(i)); + QVERIFY(node != nullptr); + QCOMPARE(node->problem()->description(), m_problems[i+WarningCount]->description()); + } + + m_store->setSeverities(IProblem::Error | IProblem::Warning | IProblem::Hint); m_store->clear(); // Check if diagnostics are added properly @@ -274,7 +342,7 @@ m_store->addProblem(p); } - QCOMPARE(m_store->count(), 3); + QCOMPARE(m_store->count(), ProblemsCount); for (int i = 0; i < 3; i++) { const ProblemStoreNode *node = m_store->findNode(i); @@ -291,7 +359,7 @@ p->setFinalLocation(m_problems[2]->finalLocation()); m_store->addProblem(p); - QCOMPARE(m_store->count(), 3); + QCOMPARE(m_store->count(), ProblemsCount); // Check the first 2 top-nodes for (int i = 0; i < 2; i++) { @@ -315,13 +383,14 @@ m_store->setProblems(m_problems); // Check filters + //TODO: remove this // Error filter m_store->setSeverity(IProblem::Error); QCOMPARE(m_store->count(), ErrorFilterProblemCount); { const ProblemStoreNode *node = m_store->findNode(0); checkNodeLabel(node, m_problems[0]->finalLocation().document.str()); - QCOMPARE(node->count(), ErrorCount); + QCOMPARE(node->count(), 1); checkNodeDescription(node->child(0), m_problems[0]->description()); } @@ -331,7 +400,7 @@ for (int i = 0; i < WarningFilterProblemCount; i++) { const ProblemStoreNode *node = m_store->findNode(i); checkNodeLabel(node, m_problems[i]->finalLocation().document.str()); - QCOMPARE(node->count(), WarningCount); + QCOMPARE(node->count(), 1); checkNodeDescription(node->child(0), m_problems[i]->description()); } @@ -341,9 +410,55 @@ for (int i = 0; i < HintFilterProblemCount; i++) { const ProblemStoreNode *node = m_store->findNode(i); checkNodeLabel(node, m_problems[i]->finalLocation().document.str()); - QCOMPARE(node->count(), HintCount); + QCOMPARE(node->count(), 1); + checkNodeDescription(node->child(0), m_problems[i]->description()); + } + + // Check new severity filtering + // Error filter + m_store->setSeverities(IProblem::Error); + for (int i = 0; i < ErrorCount; i++) { + const ProblemStoreNode *node = m_store->findNode(i); + checkNodeLabel(node, m_problems[i]->finalLocation().document.str()); + QCOMPARE(node->count(), 1); + checkNodeDescription(node->child(0), m_problems[i]->description()); + } + + // Warning filter + m_store->setSeverities(IProblem::Warning); + for (int i = 0; i < WarningCount; i++) { + const ProblemStoreNode *node = m_store->findNode(i); + checkNodeLabel(node, m_problems[i+ErrorCount]->finalLocation().document.str()); + QCOMPARE(node->count(), 1); + checkNodeDescription(node->child(0), m_problems[i+ErrorCount]->description()); + } + + // Hint filter + m_store->setSeverities(IProblem::Hint); + for (int i = 0; i < HintCount; i++) { + const ProblemStoreNode *node = m_store->findNode(i); + checkNodeLabel(node, m_problems[i+ErrorCount+WarningCount]->finalLocation().document.str()); + QCOMPARE(node->count(), 1); + checkNodeDescription(node->child(0), m_problems[i+ErrorCount+WarningCount]->description()); + } + + //Error + Hint filter + m_store->setSeverities(IProblem::Error | IProblem::Hint); + QCOMPARE(m_store->count(), HintCount + ErrorCount); + for (int i = 0; i < ErrorCount; i++) { + const ProblemStoreNode *node = m_store->findNode(i); + checkNodeLabel(node, m_problems[i]->finalLocation().document.str()); + QCOMPARE(node->count(), 1); checkNodeDescription(node->child(0), m_problems[i]->description()); } + for (int i = ErrorCount; i < ErrorCount+HintCount; i++) { + const ProblemStoreNode *node = m_store->findNode(i); + checkNodeLabel(node, m_problems[i+WarningCount]->finalLocation().document.str()); + QCOMPARE(node->count(), 1); + checkNodeDescription(node->child(0), m_problems[i+WarningCount]->description()); + } + + m_store->setSeverities(IProblem::Error | IProblem::Warning | IProblem::Hint); m_store->clear(); // Check if the diagnostics are added properly @@ -366,17 +481,28 @@ // Add problems int c = 0; - foreach (const IProblem::Ptr &p, m_problems) { + foreach (const IProblem::Ptr &p, m_problems) {//TODO: fix this dirty hack m_store->addProblem(p); - - QCOMPARE(m_store->findNode(c)->count(), 1); + int pp; + if (c==0) + pp=0; + else if (c<=2) + pp=1; + else + pp=2; + if (c==0 or c==1 or c==3) + QCOMPARE(m_store->findNode(pp)->count(), 1); + else if (c==2 or c==4) + QCOMPARE(m_store->findNode(pp)->count(), 2); + else + QCOMPARE(m_store->findNode(pp)->count(), 3); c++; } QVERIFY(checkNodeLabels()); QVERIFY(checkCounts(ErrorCount, WarningCount, HintCount)); checkNodeDescription(errorNode->child(0), m_problems[0]->description()); checkNodeDescription(warningNode->child(0), m_problems[1]->description()); - checkNodeDescription(hintNode->child(0), m_problems[2]->description()); + checkNodeDescription(hintNode->child(0), m_problems[3]->description()); // Clear m_store->clear(); @@ -390,9 +516,10 @@ QVERIFY(checkCounts(ErrorCount, WarningCount, HintCount)); checkNodeDescription(errorNode->child(0), m_problems[0]->description()); checkNodeDescription(warningNode->child(0), m_problems[1]->description()); - checkNodeDescription(hintNode->child(0), m_problems[2]->description()); + checkNodeDescription(hintNode->child(0), m_problems[3]->description()); // Check severity filter + //TODO: remove // Error filter m_store->setSeverity(IProblem::Error); QCOMPARE(m_store->count(), 3); @@ -415,8 +542,40 @@ QVERIFY(checkCounts(ErrorCount, WarningCount, HintCount)); checkNodeDescription(errorNode->child(0), m_problems[0]->description()); checkNodeDescription(warningNode->child(0), m_problems[1]->description()); - checkNodeDescription(hintNode->child(0), m_problems[2]->description()); + checkNodeDescription(hintNode->child(0), m_problems[3]->description()); + + // Check severity filter + // Error filter + m_store->setSeverities(IProblem::Error); + QCOMPARE(m_store->count(), 3); + QVERIFY(checkNodeLabels()); + QVERIFY(checkCounts(ErrorCount, 0, 0)); + checkNodeDescription(errorNode->child(0), m_problems[0]->description()); + + // Warning filter + m_store->setSeverities(IProblem::Warning); + QCOMPARE(m_store->count(), 3); + QVERIFY(checkNodeLabels()); + QVERIFY(checkCounts(0, WarningCount, 0)); + checkNodeDescription(warningNode->child(0), m_problems[1]->description()); + // Hint filter + m_store->setSeverities(IProblem::Hint); + QCOMPARE(m_store->count(), 3); + QVERIFY(checkNodeLabels()); + QVERIFY(checkCounts(0, 0, HintCount)); + checkNodeDescription(hintNode->child(0), m_problems[3]->description()); + + // Error + Hint filter + m_store->setSeverities(IProblem::Error | IProblem::Hint); + QCOMPARE(m_store->count(), 3); + QVERIFY(checkNodeLabels()); + QVERIFY(checkCounts(ErrorCount, 0, HintCount)); + checkNodeDescription(errorNode->child(0), m_problems[0]->description()); + checkNodeDescription(hintNode->child(0), m_problems[3]->description()); + + m_store->setSeverities(IProblem::Error | IProblem::Warning | IProblem::Hint); + m_store->clear(); // Check if diagnostics are added properly m_store->addProblem(m_diagnosticTestProblem); @@ -462,6 +621,9 @@ IProblem::Ptr p1(new DetectedProblem()); IProblem::Ptr p2(new DetectedProblem()); IProblem::Ptr p3(new DetectedProblem()); + IProblem::Ptr p4(new DetectedProblem()); + IProblem::Ptr p5(new DetectedProblem()); + IProblem::Ptr p6(new DetectedProblem()); DocumentRange r1; r1.document = IndexedString("/just/a/random/path"); @@ -476,17 +638,42 @@ p2->setDescription(QStringLiteral("PROBLEM2")); p2->setSeverity(IProblem::Warning); p2->setFinalLocation(r2); - + DocumentRange r3; - r3.document = IndexedString("/yet/another/test/path"); + r3.document = IndexedString("/just/another/pathy/patha"); - p2->setDescription(QStringLiteral("PROBLEM3")); - p3->setSeverity(IProblem::Hint); + p3->setDescription(QStringLiteral("PROBLEM3")); + p3->setSeverity(IProblem::Warning); p3->setFinalLocation(r3); + DocumentRange r4; + r4.document = IndexedString("/yet/another/test/path"); + + p4->setDescription(QStringLiteral("PROBLEM4")); + p4->setSeverity(IProblem::Hint); + p4->setFinalLocation(r4); + + DocumentRange r5; + r5.document = IndexedString("/yet/another/pathy/test/path"); + + p5->setDescription(QStringLiteral("PROBLEM5")); + p5->setSeverity(IProblem::Hint); + p5->setFinalLocation(r5); + + DocumentRange r6; + r6.document = IndexedString("/yet/another/test/pathy/path"); + + p6->setDescription(QStringLiteral("PROBLEM6")); + p6->setSeverity(IProblem::Hint); + p6->setFinalLocation(r6); + + m_problems.push_back(p1); m_problems.push_back(p2); m_problems.push_back(p3); + m_problems.push_back(p4); + m_problems.push_back(p5); + m_problems.push_back(p6); // Problem for diagnostic testing IProblem::Ptr p(new DetectedProblem()); diff --git a/shell/tests/test_problemmodel.cpp b/shell/tests/test_problemmodel.cpp --- a/shell/tests/test_problemmodel.cpp +++ b/shell/tests/test_problemmodel.cpp @@ -117,6 +117,7 @@ // Check if filtering works + //TODO: remove // Error filter m_model->setSeverity(IProblem::Error); QCOMPARE(m_model->rowCount(), 1); @@ -134,7 +135,32 @@ QVERIFY(checkIsSame(0, QModelIndex(), m_problems[0])); QVERIFY(checkIsSame(1, QModelIndex(), m_problems[1])); QVERIFY(checkIsSame(2, QModelIndex(), m_problems[2])); + + // Check if filtering works + // new style + // Error filter + m_model->setSeverities(IProblem::Error); + QCOMPARE(m_model->rowCount(), 1); + QVERIFY(checkIsSame(0, QModelIndex(), m_problems[0])); + + // Warning filter + m_model->setSeverities(IProblem::Warning); + QCOMPARE(m_model->rowCount(), 1); + QVERIFY(checkIsSame(0, QModelIndex(), m_problems[1])); + // Hint filter + m_model->setSeverities(IProblem::Hint); + QCOMPARE(m_model->rowCount(), 1); + QVERIFY(checkIsSame(0, QModelIndex(), m_problems[2])); + + // Error + Hint filter + m_model->setSeverities(IProblem::Error | IProblem::Hint); + QCOMPARE(m_model->rowCount(), 2); + QVERIFY(checkIsSame(0, QModelIndex(), m_problems[0])); + QVERIFY(checkIsSame(1, QModelIndex(), m_problems[2])); + + m_model->setSeverities(IProblem::Error | IProblem::Warning | IProblem::Hint); + // Check if diagnostics are added properly m_model->clearProblems(); m_model->addProblem(m_diagnosticTestProblem); @@ -190,6 +216,7 @@ } // Check if filtering works + //TODO: remove // Error filtering m_model->setSeverity(IProblem::Error); QCOMPARE(m_model->rowCount(), 1); @@ -208,6 +235,31 @@ QVERIFY(checkPathGroup(1, m_problems[1])); QVERIFY(checkPathGroup(2, m_problems[2])); + // Check if filtering works + // new style + // Error filtering + m_model->setSeverities(IProblem::Error); + QCOMPARE(m_model->rowCount(), 1); + QVERIFY(checkPathGroup(0, m_problems[0])); + + // Warning filtering + m_model->setSeverities(IProblem::Warning); + QCOMPARE(m_model->rowCount(), 1); + QVERIFY(checkPathGroup(0, m_problems[1])); + + // Hint filtering + m_model->setSeverities(IProblem::Hint); + QCOMPARE(m_model->rowCount(), 1);; + QVERIFY(checkPathGroup(0, m_problems[2])); + + // Error + Hint filtering + m_model->setSeverities(IProblem::Error | IProblem::Hint); + QCOMPARE(m_model->rowCount(), 2); + QVERIFY(checkPathGroup(0, m_problems[0])); + QVERIFY(checkPathGroup(1, m_problems[2])); + + m_model->setSeverities(IProblem::Error | IProblem::Warning | IProblem::Hint); + // Check if diagnostics get to the right place m_model->clearProblems(); m_model->addProblem(m_diagnosticTestProblem); @@ -254,6 +306,7 @@ } // Check if filtering works + //TODO: remove // Error filtering m_model->setSeverity(IProblem::Error); QCOMPARE(m_model->rowCount(), 3); @@ -271,7 +324,31 @@ checkSeverityGroup(0, m_problems[0]); checkSeverityGroup(1, m_problems[1]); checkSeverityGroup(2, m_problems[2]); + + // Check if filtering works + // Error filtering + m_model->setSeverities(IProblem::Error); + QCOMPARE(m_model->rowCount(), 3); + checkSeverityGroup(0, m_problems[0]); + + // Warning filtering + m_model->setSeverities(IProblem::Warning); + QCOMPARE(m_model->rowCount(), 3); + checkSeverityGroup(1, m_problems[1]); + + // Hint filtering + m_model->setSeverities(IProblem::Hint); + QCOMPARE(m_model->rowCount(), 3); + checkSeverityGroup(2, m_problems[2]); + + // Error + Hint filtering + m_model->setSeverities(IProblem::Error | IProblem::Hint); + QCOMPARE(m_model->rowCount(), 3); + checkSeverityGroup(0, m_problems[0]); + checkSeverityGroup(2, m_problems[2]); + m_model->setSeverities(IProblem::Error | IProblem::Warning | IProblem::Hint); + // Check if diagnostics get to the right place m_model->clearProblems(); m_model->addProblem(m_diagnosticTestProblem); diff --git a/shell/tests/test_problemstore.cpp b/shell/tests/test_problemstore.cpp --- a/shell/tests/test_problemstore.cpp +++ b/shell/tests/test_problemstore.cpp @@ -42,6 +42,7 @@ void testSetProblems(); void testFindNode(); void testSeverity(); + void testSeverities(); void testScope(); private: @@ -119,6 +120,19 @@ QCOMPARE(spy.count(), 1); } +void TestProblemStore::testSeverities() +{ + IProblem::Severities severities = IProblem::Error | IProblem::Hint; + + QVERIFY(severities != m_store->severities()); + + QSignalSpy spy(m_store.data(), &ProblemStore::changed); + m_store->setSeverities(severities); + + QVERIFY(m_store->severities() == severities); + QCOMPARE(spy.count(), 1); +} + void TestProblemStore::testScope() { QSignalSpy spy(m_store.data(), &ProblemStore::changed);