Commit 198a279f authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

testview: port foreach -> range-based for

parent 2fe1ffa9
......@@ -121,8 +121,8 @@ TestView::TestView(TestViewPlugin* plugin, QWidget* parent)
connect (tc, &ITestController::testRunStarted,
this, &TestView::notifyTestCaseStarted);
foreach (ITestSuite* suite, tc->testSuites())
{
const auto suites = tc->testSuites();
for (ITestSuite* suite : suites) {
addTestSuite(suite);
}
}
......@@ -222,15 +222,12 @@ QIcon TestView::iconForTestResult(TestResult::TestCaseResult result)
QStandardItem* TestView::itemForSuite(ITestSuite* suite)
{
foreach (QStandardItem* item, m_model->findItems(suite->name(), Qt::MatchRecursive))
{
if (item->parent() && item->parent()->text() == suite->project()->name()
&& !item->parent()->parent())
{
return item;
}
}
return nullptr;
const auto items = m_model->findItems(suite->name(), Qt::MatchRecursive);
auto it = std::find_if(items.begin(), items.end(), [&](QStandardItem* item) {
return (item->parent() && item->parent()->text() == suite->project()->name()
&& !item->parent()->parent());
});
return (it != items.end()) ? *it : nullptr;
}
QStandardItem* TestView::itemForProject(IProject* project)
......@@ -268,8 +265,7 @@ void TestView::runSelectedTests()
* This is the somewhat-intuitive approach. Maybe a configuration should be offered.
*/
foreach (const QModelIndex& idx, indexes)
{
for (const QModelIndex& idx : qAsConst(indexes)) {
QModelIndex index = m_filter->mapToSource(idx);
if (index.parent().isValid() && indexes.contains(index.parent()))
{
......@@ -280,8 +276,8 @@ void TestView::runSelectedTests()
{
// A project was selected
IProject* project = ICore::self()->projectController()->findProjectByName(item->data(ProjectRole).toString());
foreach (ITestSuite* suite, tc->testSuitesForProject(project))
{
const auto suites = tc->testSuitesForProject(project);
for (ITestSuite* suite : suites) {
jobs << suite->launchAllCases(ITestSuite::Silent);
}
}
......@@ -366,8 +362,8 @@ void TestView::addTestSuite(ITestSuite* suite)
QStandardItem* suiteItem = new QStandardItem(QIcon::fromTheme(QStringLiteral("view-list-tree")), suite->name());
suiteItem->setData(suite->name(), SuiteRole);
foreach (const QString& caseName, suite->cases())
{
const auto caseNames = suite->cases();
for (const QString& caseName : caseNames) {
QStandardItem* caseItem = new QStandardItem(iconForTestResult(TestResult::NotRun), caseName);
caseItem->setData(caseName, CaseRole);
suiteItem->appendRow(caseItem);
......
......@@ -101,11 +101,11 @@ void TestViewPlugin::unload()
void TestViewPlugin::runAllTests()
{
ITestController* tc = core()->testController();
foreach (IProject* project, core()->projectController()->projects())
{
const auto projects = core()->projectController()->projects();
for (IProject* project : projects) {
QList<KJob*> jobs;
foreach (ITestSuite* suite, tc->testSuitesForProject(project))
{
const auto suites = tc->testSuitesForProject(project);
for (ITestSuite* suite : suites) {
if (KJob* job = suite->launchAllCases(ITestSuite::Silent))
{
jobs << job;
......@@ -124,8 +124,8 @@ void TestViewPlugin::runAllTests()
void TestViewPlugin::stopRunningTests()
{
foreach (KJob* job, core()->runController()->currentJobs())
{
const auto jobs = core()->runController()->currentJobs();
for (KJob* job : jobs) {
if (job->property("test_job").toBool())
{
job->kill();
......@@ -135,15 +135,11 @@ void TestViewPlugin::stopRunningTests()
void TestViewPlugin::jobStateChanged()
{
bool found = false;
foreach (KJob* job, core()->runController()->currentJobs())
{
if (job->property("test_job").toBool())
{
found = true;
break;
}
}
const auto jobs = core()->runController()->currentJobs();
const bool found = std::any_of(jobs.begin(), jobs.end(), [](KJob* job) {
return (job->property("test_job").toBool());
});
actionCollection()->action(QStringLiteral("run_all_tests"))->setEnabled(!found);
actionCollection()->action(QStringLiteral("stop_running_tests"))->setEnabled(found);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment