aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/autotest/projectsettingswidget.cpp
diff options
context:
space:
mode:
authorChristian Stenger <christian.stenger@qt.io>2019-08-05 15:47:10 +0200
committerDavid Schulz <david.schulz@qt.io>2019-09-02 05:49:52 +0000
commit43e27f76b3ac96ae4d13e5410be28831ffdbb059 (patch)
tree99b0cbe1686894f704c089a278d331d9c2c5f17b /src/plugins/autotest/projectsettingswidget.cpp
parentedcd955aadf28358c9e006624a868de927e9f066 (diff)
AutoTest: Add project based {en|dis}abling of test frameworks
Provide integration into the 'Project' view which allows to set some settings on a per project base. For now only enabling or disabling of test frameworks. Task-number: QTCREATORBUG-16704 Change-Id: Iedd9a300164931e07a21cbb4e5a222be3266c81e Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/autotest/projectsettingswidget.cpp')
-rw-r--r--src/plugins/autotest/projectsettingswidget.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/plugins/autotest/projectsettingswidget.cpp b/src/plugins/autotest/projectsettingswidget.cpp
new file mode 100644
index 00000000000..f8263938240
--- /dev/null
+++ b/src/plugins/autotest/projectsettingswidget.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "autotestplugin.h"
+#include "projectsettingswidget.h"
+#include "testframeworkmanager.h"
+#include "testprojectsettings.h"
+
+#include <QBoxLayout>
+#include <QComboBox>
+#include <QLabel>
+#include <QTreeWidget>
+
+namespace Autotest {
+namespace Internal {
+
+enum ItemDataRole { FrameworkIdRole = Qt::UserRole + 1 };
+
+static QSpacerItem *createSpacer(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
+{
+ return new QSpacerItem(20, 10, horizontal, vertical);
+}
+
+ProjectTestSettingsWidget::ProjectTestSettingsWidget(ProjectExplorer::Project *project,
+ QWidget *parent)
+ : QWidget(parent)
+ , m_projectSettings(AutotestPlugin::projectSettings(project))
+{
+ auto verticalLayout = new QVBoxLayout(this);
+ m_useGlobalSettings = new QComboBox;
+ m_useGlobalSettings->addItem(tr("Global"));
+ m_useGlobalSettings->addItem(tr("Custom"));
+
+ auto generalWidget = new QWidget;
+ auto groupBoxLayout = new QVBoxLayout;
+ m_activeFrameworks = new QTreeWidget;
+ m_activeFrameworks->setHeaderHidden(true);
+ m_activeFrameworks->setRootIsDecorated(false);
+ groupBoxLayout->addWidget(new QLabel(tr("Active frameworks:")));
+ groupBoxLayout->addWidget(m_activeFrameworks);
+ generalWidget->setLayout(groupBoxLayout);
+
+ auto horizontalLayout = new QHBoxLayout;
+ horizontalLayout->addWidget(m_useGlobalSettings);
+ horizontalLayout->addItem(createSpacer(QSizePolicy::Expanding, QSizePolicy::Minimum));
+ verticalLayout->addLayout(horizontalLayout);
+ horizontalLayout = new QHBoxLayout;
+ verticalLayout->addItem(createSpacer(QSizePolicy::Minimum, QSizePolicy::Fixed));
+ horizontalLayout->addWidget(generalWidget);
+ horizontalLayout->addItem(createSpacer(QSizePolicy::Expanding, QSizePolicy::Minimum));
+ verticalLayout->addLayout(horizontalLayout);
+ verticalLayout->addItem(createSpacer(QSizePolicy::Minimum, QSizePolicy::Expanding));
+
+ m_useGlobalSettings->setCurrentIndex(m_projectSettings->useGlobalSettings() ? 0 : 1);
+ generalWidget->setDisabled(m_projectSettings->useGlobalSettings());
+
+ populateFrameworks(m_projectSettings->activeFrameworks());
+
+ connect(m_useGlobalSettings, QOverload<int>::of(&QComboBox::currentIndexChanged),
+ this, [this, generalWidget](int index) {
+ generalWidget->setEnabled(index != 0);
+ m_projectSettings->setUseGlobalSettings(index == 0);
+ });
+ connect(m_activeFrameworks, &QTreeWidget::itemChanged,
+ this, &ProjectTestSettingsWidget::onActiveFrameworkChanged);
+}
+
+void ProjectTestSettingsWidget::populateFrameworks(const QMap<Core::Id, bool> &frameworks)
+{
+ TestFrameworkManager *frameworkManager = TestFrameworkManager::instance();
+ auto end = frameworks.cend();
+ for (auto it = frameworks.cbegin(); it != end; ++it) {
+ auto *item = new QTreeWidgetItem(m_activeFrameworks,
+ QStringList(frameworkManager->frameworkNameForId(it.key())));
+ item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
+ item->setCheckState(0, it.value() ? Qt::Checked : Qt::Unchecked);
+ item->setData(0, FrameworkIdRole, it.key().toSetting());
+ }
+}
+
+void ProjectTestSettingsWidget::onActiveFrameworkChanged(QTreeWidgetItem *item, int column)
+{
+ auto id = Core::Id::fromSetting(item->data(column, FrameworkIdRole));
+ m_projectSettings->activateFramework(id, item->data(0, Qt::CheckStateRole) == Qt::Checked);
+}
+
+} // namespace Internal
+} // namespace Autotest