Nim: Inline nimcompilerbuildstepconfigwidget.*

Step towards aspectification. The new position of the method
implementation are intentional to keep the follow-up patch small.

Change-Id: I89c6982c8380c2a6b0e2bc50fb10f48d5413fc51
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2020-08-26 10:48:29 +02:00
parent 53c763029b
commit b3652da3ac
7 changed files with 152 additions and 313 deletions

View File

@@ -18,7 +18,6 @@ add_qtc_plugin(Nim
project/nimbuildsystem.cpp project/nimbuildsystem.h
project/nimbuildconfiguration.cpp project/nimbuildconfiguration.h
project/nimcompilerbuildstep.cpp project/nimcompilerbuildstep.h
project/nimcompilerbuildstepconfigwidget.cpp project/nimcompilerbuildstepconfigwidget.h project/nimcompilerbuildstepconfigwidget.ui
project/nimcompilercleanstep.cpp project/nimcompilercleanstep.h
project/nimproject.cpp project/nimproject.h
project/nimprojectnode.cpp project/nimprojectnode.h

View File

@@ -28,7 +28,6 @@ HEADERS += \
project/nimprojectnode.h \
project/nimbuildconfiguration.h \
project/nimcompilerbuildstep.h \
project/nimcompilerbuildstepconfigwidget.h \
project/nimcompilercleanstep.h \
project/nimrunconfiguration.h \
editor/nimeditorfactory.h \
@@ -65,7 +64,6 @@ SOURCES += \
project/nimprojectnode.cpp \
project/nimbuildconfiguration.cpp \
project/nimcompilerbuildstep.cpp \
project/nimcompilerbuildstepconfigwidget.cpp \
project/nimcompilercleanstep.cpp \
project/nimrunconfiguration.cpp \
editor/nimeditorfactory.cpp \
@@ -83,6 +81,5 @@ SOURCES += \
suggest/server.cpp
FORMS += \
project/nimcompilerbuildstepconfigwidget.ui \
settings/nimcodestylepreferenceswidget.ui \
settings/nimtoolssettingswidget.ui

View File

@@ -40,7 +40,6 @@ QtcPlugin {
"nimbuildsystem.cpp", "nimbuildsystem.h",
"nimbuildconfiguration.h", "nimbuildconfiguration.cpp",
"nimcompilerbuildstep.h", "nimcompilerbuildstep.cpp",
"nimcompilerbuildstepconfigwidget.h", "nimcompilerbuildstepconfigwidget.cpp", "nimcompilerbuildstepconfigwidget.ui",
"nimcompilercleanstep.h", "nimcompilercleanstep.cpp",
"nimproject.h", "nimproject.cpp",
"nimprojectnode.h", "nimprojectnode.cpp",

View File

@@ -24,27 +24,62 @@
****************************************************************************/
#include "nimcompilerbuildstep.h"
#include "nimbuildconfiguration.h"
#include "nimbuildsystem.h"
#include "nimcompilerbuildstepconfigwidget.h"
#include "nimconstants.h"
#include "nimtoolchain.h"
#include <projectexplorer/processparameters.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/ioutputparser.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/processparameters.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/qtcassert.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <QApplication>
#include <QComboBox>
#include <QDir>
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
#include <QRegularExpression>
#include <QTextEdit>
using namespace ProjectExplorer;
using namespace Utils;
namespace Nim {
class NimCompilerBuildStepConfigWidget : public ProjectExplorer::BuildStepConfigWidget
{
Q_DECLARE_TR_FUNCTIONS(Nim::NimCompilerBuildStep)
public:
explicit NimCompilerBuildStepConfigWidget(NimCompilerBuildStep *buildStep);
private:
void updateUi();
void updateCommandLineText();
void updateTargetComboBox();
void updateAdditionalArgumentsLineEdit();
void updateDefaultArgumentsComboBox();
void onAdditionalArgumentsTextEdited(const QString &text);
void onTargetChanged(int index);
void onDefaultArgumentsComboBoxIndexChanged(int index);
NimCompilerBuildStep *m_buildStep;
QTextEdit *m_commandTextEdit;
QComboBox *m_defaultArgumentsComboBox;
QComboBox *m_targetComboBox;
QLineEdit *m_additionalArgumentsLineEdit;
};
// NimParser
class NimParser : public ProjectExplorer::OutputTaskParser
{
Result handleLine(const QString &lne, Utils::OutputFormat) override
@@ -108,6 +143,53 @@ void NimCompilerBuildStep::setupOutputFormatter(OutputFormatter *formatter)
AbstractProcessStep::setupOutputFormatter(formatter);
}
NimCompilerBuildStepConfigWidget::NimCompilerBuildStepConfigWidget(NimCompilerBuildStep *buildStep)
: BuildStepConfigWidget(buildStep)
, m_buildStep(buildStep)
{
setDisplayName(tr(Constants::C_NIMCOMPILERBUILDSTEPWIDGET_DISPLAY));
setSummaryText(tr(Constants::C_NIMCOMPILERBUILDSTEPWIDGET_SUMMARY));
m_targetComboBox = new QComboBox(this);
m_additionalArgumentsLineEdit = new QLineEdit(this);
m_commandTextEdit = new QTextEdit(this);
m_commandTextEdit->setEnabled(false);
m_commandTextEdit->setMinimumSize(QSize(0, 0));
m_defaultArgumentsComboBox = new QComboBox(this);
m_defaultArgumentsComboBox->addItem(tr("None"));
m_defaultArgumentsComboBox->addItem(tr("Debug"));
m_defaultArgumentsComboBox->addItem(tr("Release"));
auto formLayout = new QFormLayout(this);
formLayout->addRow(tr("Target:"), m_targetComboBox);
formLayout->addRow(tr("Default arguments:"), m_defaultArgumentsComboBox);
formLayout->addRow(tr("Extra arguments:"), m_additionalArgumentsLineEdit);
formLayout->addRow(tr("Command:"), m_commandTextEdit);
// Connect the project signals
connect(m_buildStep->project(),
&Project::fileListChanged,
this,
&NimCompilerBuildStepConfigWidget::updateUi);
// Connect build step signals
connect(m_buildStep, &NimCompilerBuildStep::processParametersChanged,
this, &NimCompilerBuildStepConfigWidget::updateUi);
// Connect UI signals
connect(m_targetComboBox, QOverload<int>::of(&QComboBox::activated),
this, &NimCompilerBuildStepConfigWidget::onTargetChanged);
connect(m_additionalArgumentsLineEdit, &QLineEdit::textEdited,
this, &NimCompilerBuildStepConfigWidget::onAdditionalArgumentsTextEdited);
connect(m_defaultArgumentsComboBox, QOverload<int>::of(&QComboBox::activated),
this, &NimCompilerBuildStepConfigWidget::onDefaultArgumentsComboBoxIndexChanged);
updateUi();
}
BuildStepConfigWidget *NimCompilerBuildStep::createConfigWidget()
{
return new NimCompilerBuildStepConfigWidget(this);
@@ -255,6 +337,73 @@ void NimCompilerBuildStep::updateTargetNimFile()
setTargetNimFile(nimFiles.at(0));
}
void NimCompilerBuildStepConfigWidget::onTargetChanged(int index)
{
Q_UNUSED(index)
auto data = m_targetComboBox->currentData();
FilePath path = FilePath::fromString(data.toString());
m_buildStep->setTargetNimFile(path);
}
void NimCompilerBuildStepConfigWidget::onDefaultArgumentsComboBoxIndexChanged(int index)
{
auto options = static_cast<NimCompilerBuildStep::DefaultBuildOptions>(index);
m_buildStep->setDefaultCompilerOptions(options);
}
void NimCompilerBuildStepConfigWidget::updateUi()
{
updateCommandLineText();
updateTargetComboBox();
updateAdditionalArgumentsLineEdit();
updateDefaultArgumentsComboBox();
}
void NimCompilerBuildStepConfigWidget::onAdditionalArgumentsTextEdited(const QString &text)
{
m_buildStep->setUserCompilerOptions(text.split(QChar::Space));
}
void NimCompilerBuildStepConfigWidget::updateCommandLineText()
{
ProcessParameters *parameters = m_buildStep->processParameters();
const CommandLine cmd = parameters->command();
const QStringList parts = QtcProcess::splitArgs(cmd.toUserOutput());
m_commandTextEdit->setText(parts.join(QChar::LineFeed));
}
void NimCompilerBuildStepConfigWidget::updateTargetComboBox()
{
QTC_ASSERT(m_buildStep, return );
// Re enter the files
m_targetComboBox->clear();
const FilePaths nimFiles = m_buildStep->project()->files([](const Node *n) {
return Project::AllFiles(n) && n->path().endsWith(".nim");
});
for (const FilePath &file : nimFiles)
m_targetComboBox->addItem(file.fileName(), file.toString());
const int index = m_targetComboBox->findData(m_buildStep->targetNimFile().toString());
m_targetComboBox->setCurrentIndex(index);
}
void NimCompilerBuildStepConfigWidget::updateAdditionalArgumentsLineEdit()
{
const QString text = m_buildStep->userCompilerOptions().join(QChar::Space);
m_additionalArgumentsLineEdit->setText(text);
}
void NimCompilerBuildStepConfigWidget::updateDefaultArgumentsComboBox()
{
const int index = m_buildStep->defaultCompilerOptions();
m_defaultArgumentsComboBox->setCurrentIndex(index);
}
// NimCompilerBuildStepFactory
NimCompilerBuildStepFactory::NimCompilerBuildStepFactory()

View File

@@ -1,146 +0,0 @@
/****************************************************************************
**
** Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
** Contact: http://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 "nimcompilerbuildstepconfigwidget.h"
#include "nimbuildconfiguration.h"
#include "nimbuildsystem.h"
#include "nimcompilerbuildstep.h"
#include "ui_nimcompilerbuildstepconfigwidget.h"
#include "../nimconstants.h"
#include <projectexplorer/processparameters.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
using namespace ProjectExplorer;
using namespace Utils;
namespace Nim {
NimCompilerBuildStepConfigWidget::NimCompilerBuildStepConfigWidget(NimCompilerBuildStep *buildStep)
: BuildStepConfigWidget(buildStep)
, m_buildStep(buildStep)
, m_ui(new Ui::NimCompilerBuildStepConfigWidget())
{
m_ui->setupUi(this);
setDisplayName(tr(Constants::C_NIMCOMPILERBUILDSTEPWIDGET_DISPLAY));
setSummaryText(tr(Constants::C_NIMCOMPILERBUILDSTEPWIDGET_SUMMARY));
// Connect the project signals
connect(m_buildStep->project(),
&Project::fileListChanged,
this,
&NimCompilerBuildStepConfigWidget::updateUi);
// Connect build step signals
connect(m_buildStep, &NimCompilerBuildStep::processParametersChanged,
this, &NimCompilerBuildStepConfigWidget::updateUi);
// Connect UI signals
connect(m_ui->targetComboBox, QOverload<int>::of(&QComboBox::activated),
this, &NimCompilerBuildStepConfigWidget::onTargetChanged);
connect(m_ui->additionalArgumentsLineEdit, &QLineEdit::textEdited,
this, &NimCompilerBuildStepConfigWidget::onAdditionalArgumentsTextEdited);
connect(m_ui->defaultArgumentsComboBox, QOverload<int>::of(&QComboBox::activated),
this, &NimCompilerBuildStepConfigWidget::onDefaultArgumentsComboBoxIndexChanged);
updateUi();
}
NimCompilerBuildStepConfigWidget::~NimCompilerBuildStepConfigWidget() = default;
void NimCompilerBuildStepConfigWidget::onTargetChanged(int index)
{
Q_UNUSED(index)
auto data = m_ui->targetComboBox->currentData();
FilePath path = FilePath::fromString(data.toString());
m_buildStep->setTargetNimFile(path);
}
void NimCompilerBuildStepConfigWidget::onDefaultArgumentsComboBoxIndexChanged(int index)
{
auto options = static_cast<NimCompilerBuildStep::DefaultBuildOptions>(index);
m_buildStep->setDefaultCompilerOptions(options);
}
void NimCompilerBuildStepConfigWidget::updateUi()
{
updateCommandLineText();
updateTargetComboBox();
updateAdditionalArgumentsLineEdit();
updateDefaultArgumentsComboBox();
}
void NimCompilerBuildStepConfigWidget::onAdditionalArgumentsTextEdited(const QString &text)
{
m_buildStep->setUserCompilerOptions(text.split(QChar::Space));
}
void NimCompilerBuildStepConfigWidget::updateCommandLineText()
{
ProcessParameters *parameters = m_buildStep->processParameters();
const CommandLine cmd = parameters->command();
const QStringList parts = QtcProcess::splitArgs(cmd.toUserOutput());
m_ui->commandTextEdit->setText(parts.join(QChar::LineFeed));
}
void NimCompilerBuildStepConfigWidget::updateTargetComboBox()
{
QTC_ASSERT(m_buildStep, return );
// Re enter the files
m_ui->targetComboBox->clear();
const FilePaths nimFiles = m_buildStep->project()->files([](const Node *n) {
return Project::AllFiles(n) && n->path().endsWith(".nim");
});
for (const FilePath &file : nimFiles)
m_ui->targetComboBox->addItem(file.fileName(), file.toString());
const int index = m_ui->targetComboBox->findData(m_buildStep->targetNimFile().toString());
m_ui->targetComboBox->setCurrentIndex(index);
}
void NimCompilerBuildStepConfigWidget::updateAdditionalArgumentsLineEdit()
{
const QString text = m_buildStep->userCompilerOptions().join(QChar::Space);
m_ui->additionalArgumentsLineEdit->setText(text);
}
void NimCompilerBuildStepConfigWidget::updateDefaultArgumentsComboBox()
{
const int index = m_buildStep->defaultCompilerOptions();
m_ui->defaultArgumentsComboBox->setCurrentIndex(index);
}
}

View File

@@ -1,59 +0,0 @@
/****************************************************************************
**
** Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
** Contact: http://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.
**
****************************************************************************/
#pragma once
#include <projectexplorer/buildstep.h>
namespace Nim {
class NimCompilerBuildStep;
namespace Ui { class NimCompilerBuildStepConfigWidget; }
class NimCompilerBuildStepConfigWidget : public ProjectExplorer::BuildStepConfigWidget
{
Q_OBJECT
public:
NimCompilerBuildStepConfigWidget(NimCompilerBuildStep *buildStep);
~NimCompilerBuildStepConfigWidget();
private:
void updateUi();
void updateCommandLineText();
void updateTargetComboBox();
void updateAdditionalArgumentsLineEdit();
void updateDefaultArgumentsComboBox();
void onAdditionalArgumentsTextEdited(const QString &text);
void onTargetChanged(int index);
void onDefaultArgumentsComboBoxIndexChanged(int index);
NimCompilerBuildStep *m_buildStep;
QScopedPointer<Ui::NimCompilerBuildStepConfigWidget> m_ui;
};
}

View File

@@ -1,100 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Nim::NimCompilerBuildStepConfigWidget</class>
<widget class="QWidget" name="Nim::NimCompilerBuildStepConfigWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>497</width>
<height>283</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="targetLabel">
<property name="text">
<string>Target:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="targetComboBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="additionalArgumentsLabel">
<property name="text">
<string>Extra arguments:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="additionalArgumentsLineEdit"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="commandLabel">
<property name="text">
<string>Command:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QTextEdit" name="commandTextEdit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="defaultArgumentsLabel">
<property name="text">
<string>Default arguments:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="defaultArgumentsComboBox">
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Debug</string>
</property>
</item>
<item>
<property name="text">
<string>Release</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<tabstops>
<tabstop>targetComboBox</tabstop>
<tabstop>defaultArgumentsComboBox</tabstop>
<tabstop>additionalArgumentsLineEdit</tabstop>
<tabstop>commandTextEdit</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>