From 03354a6a0542773b89cbf757f158f0a629a565f6 Mon Sep 17 00:00:00 2001 From: Robert Loehning Date: Tue, 12 May 2015 13:15:04 +0200 Subject: Add basic 'Close Test Suite' functionality Change-Id: I1e0a6d51d170ff186ac0ad50a62a35de83964160 Reviewed-by: Robert Loehning --- plugins/autotest/testnavigationwidget.cpp | 15 +++++++++++++++ plugins/autotest/testsquishfilehandler.cpp | 21 +++++++++++++++++++++ plugins/autotest/testsquishfilehandler.h | 3 +++ plugins/autotest/testtreemodel.cpp | 2 ++ 4 files changed, 41 insertions(+) (limited to 'plugins/autotest') diff --git a/plugins/autotest/testnavigationwidget.cpp b/plugins/autotest/testnavigationwidget.cpp index 2a15c36013..c0c65eb22a 100644 --- a/plugins/autotest/testnavigationwidget.cpp +++ b/plugins/autotest/testnavigationwidget.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -107,6 +108,7 @@ bool TestNavigationWidget::handleSquishContextMenuEvent(QContextMenuEvent *event deleteTestCase->setEnabled(enabled); menu.addSeparator(); } else if (type == TestTreeItem::SQUISH_SUITE) { + const QString suiteName = list.first().data().toString(); isSquishMenu = true; QAction *runThisTestSuite = new QAction(tr("Run This Test Suite"), &menu); menu.addAction(runThisTestSuite); @@ -122,6 +124,11 @@ bool TestNavigationWidget::handleSquishContextMenuEvent(QContextMenuEvent *event menu.addAction(deleteTestSuite); deleteTestSuite->setEnabled(enabled); menu.addSeparator(); + + connect(closeTestSuite, &QAction::triggered, + [suiteName] () { + TestSquishFileHandler::instance()->closeTestSuite(suiteName); + }); } } } @@ -148,6 +155,14 @@ bool TestNavigationWidget::handleSquishContextMenuEvent(QContextMenuEvent *event QAction *closeAllSuites = new QAction(tr("Close All Test Suites"), &menu); menu.addAction(closeAllSuites); closeAllSuites->setEnabled(enabled); + + connect(closeAllSuites, &QAction::triggered, [this] () { + if (QMessageBox::question(this, tr("Close All Test Suites"), + tr("Are you sure you want to close all test suites?" + /*"\nThis will close all related files as well."*/)) + == QMessageBox::Yes) + TestSquishFileHandler::instance()->closeAllTestSuites(); + }); } menu.exec(mapToGlobal(event->pos())); diff --git a/plugins/autotest/testsquishfilehandler.cpp b/plugins/autotest/testsquishfilehandler.cpp index 3e8ac46104..26a2f718b0 100644 --- a/plugins/autotest/testsquishfilehandler.cpp +++ b/plugins/autotest/testsquishfilehandler.cpp @@ -89,5 +89,26 @@ void TestSquishFileHandler::openTestSuites() } } +void TestSquishFileHandler::closeTestSuite(const QString &suite) +{ + const QString suiteConf = m_suites.value(suite); + if (suiteConf.isEmpty()) + return; + + // TODO close respective editors if there are any + // TODO remove file watcher + emit testTreeItemsRemoved(suiteConf, TestTreeModel::SquishTest); + m_suites.remove(suite); +} + +void TestSquishFileHandler::closeAllTestSuites() +{ + // TODO close respective editors if there are any + // TODO remove file watcher + foreach (const QString &suiteConf, m_suites.values()) + emit testTreeItemsRemoved(suiteConf, TestTreeModel::SquishTest); + m_suites.clear(); +} + } // namespace Internal } // namespace Autotest diff --git a/plugins/autotest/testsquishfilehandler.h b/plugins/autotest/testsquishfilehandler.h index 66c6ccecdd..a63d435929 100644 --- a/plugins/autotest/testsquishfilehandler.h +++ b/plugins/autotest/testsquishfilehandler.h @@ -38,10 +38,13 @@ public: static TestSquishFileHandler *instance(); void openTestSuites(); + void closeTestSuite(const QString &suite); + void closeAllTestSuites(); signals: void testTreeItemCreated(const TestTreeItem &item, TestTreeModel::Type type); void testTreeItemModified(const TestTreeItem &item, TestTreeModel::Type type, const QString &file); + void testTreeItemsRemoved(const QString &filePath, TestTreeModel::Type type); private: QMap m_suites; diff --git a/plugins/autotest/testtreemodel.cpp b/plugins/autotest/testtreemodel.cpp index 82bdf23a84..5e9aaa4aea 100644 --- a/plugins/autotest/testtreemodel.cpp +++ b/plugins/autotest/testtreemodel.cpp @@ -81,6 +81,8 @@ TestTreeModel::TestTreeModel(QObject *parent) : this, &TestTreeModel::addTestTreeItem, Qt::QueuedConnection); connect(m_squishFileHandler, &TestSquishFileHandler::testTreeItemModified, this, &TestTreeModel::modifyTestTreeItem, Qt::QueuedConnection); + connect(m_squishFileHandler, &TestSquishFileHandler::testTreeItemsRemoved, + this, &TestTreeModel::removeTestTreeItems, Qt::QueuedConnection); // CppTools::CppModelManagerInterface *cppMM = CppTools::CppModelManagerInterface::instance(); // if (cppMM) { -- cgit v1.2.1