Nim: Move NimbleTaskStepWidget closer to NimbleTaskStep

Next step towards NimbleTaskStep aspectification.

Change-Id: Ifdb7d942e29ab99da01c6797d1edddd68afc5e30
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2020-08-25 04:19:39 +02:00
parent 367624fbf2
commit 0538e8bfbd
7 changed files with 168 additions and 238 deletions

View File

@@ -13,7 +13,6 @@ add_qtc_plugin(Nim
project/nimbleproject.h project/nimbleproject.cpp
project/nimblerunconfiguration.h project/nimblerunconfiguration.cpp
project/nimbletaskstep.h project/nimbletaskstep.cpp
project/nimbletaskstepwidget.h project/nimbletaskstepwidget.cpp
project/nimblebuildsystem.h project/nimblebuildsystem.cpp
project/nimblebuildconfiguration.h project/nimblebuildconfiguration.cpp
project/nimbuildsystem.cpp project/nimbuildsystem.h

View File

@@ -20,7 +20,6 @@ HEADERS += \
project/nimbleproject.h \
project/nimblerunconfiguration.h \
project/nimbletaskstep.h \
project/nimbletaskstepwidget.h \
tools/nimlexer.h \
tools/sourcecodestream.h \
project/nimbuildsystem.h \
@@ -59,7 +58,6 @@ SOURCES += \
project/nimbletaskstep.cpp \
project/nimbleproject.cpp \
project/nimblerunconfiguration.cpp \
project/nimbletaskstepwidget.cpp \
tools/nimlexer.cpp \
project/nimbuildsystem.cpp \
project/nimblebuildsystem.cpp \

View File

@@ -51,7 +51,6 @@ QtcPlugin {
"nimbleproject.h", "nimbleproject.cpp",
"nimblerunconfiguration.h", "nimblerunconfiguration.cpp",
"nimbletaskstep.h", "nimbletaskstep.cpp",
"nimbletaskstepwidget.h", "nimbletaskstepwidget.cpp",
"nimblebuildsystem.h", "nimblebuildsystem.cpp",
"nimblebuildconfiguration.h", "nimblebuildconfiguration.cpp",
]

View File

@@ -24,7 +24,6 @@
****************************************************************************/
#include "nimblebuildstep.h"
#include "nimbletaskstepwidget.h"
#include "nimconstants.h"
#include "nimbleproject.h"

View File

@@ -24,8 +24,9 @@
****************************************************************************/
#include "nimbletaskstep.h"
#include "nimbletaskstepwidget.h"
#include "nimconstants.h"
#include "nimblebuildsystem.h"
#include "nimbleproject.h"
#include <projectexplorer/buildstep.h>
@@ -33,13 +34,174 @@
#include <projectexplorer/processparameters.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <QFormLayout>
#include <QLineEdit>
#include <QListView>
#include <QStandardItemModel>
#include <QStandardPaths>
using namespace Nim;
using namespace ProjectExplorer;
namespace Nim {
class NimbleTaskStepWidget : public BuildStepConfigWidget
{
Q_DECLARE_TR_FUNCTIONS(Nim::NimbleTaskStep)
public:
explicit NimbleTaskStepWidget(NimbleTaskStep *buildStep);
void selectedTaskChanged(const QString &name)
{
auto taskStep = dynamic_cast<NimbleTaskStep *>(step());
QTC_ASSERT(taskStep, return);
taskStep->setTaskName(name);
}
private:
void updateTaskList();
void selectTask(const QString &name);
void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
void uncheckedAllDifferentFrom(QStandardItem *item);
QStandardItemModel m_tasks;
bool m_selecting = false;
};
NimbleTaskStepWidget::NimbleTaskStepWidget(NimbleTaskStep *bs)
: BuildStepConfigWidget(bs)
{
auto taskArgumentsLineEdit = new QLineEdit(this);
taskArgumentsLineEdit->setText(bs->taskArgs());
auto taskList = new QListView(this);
taskList->setFrameShape(QFrame::StyledPanel);
taskList->setSelectionMode(QAbstractItemView::NoSelection);
taskList->setSelectionBehavior(QAbstractItemView::SelectRows);
taskList->setModel(&m_tasks);
auto formLayout = new QFormLayout(this);
formLayout->setSizeConstraint(QLayout::SetDefaultConstraint);
formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
formLayout->addRow(tr("Task arguments:"), taskArgumentsLineEdit);
formLayout->addRow(tr("Tasks:"), taskList);
auto buildSystem = dynamic_cast<NimbleBuildSystem *>(bs->buildSystem());
QTC_ASSERT(buildSystem, return);
connect(&m_tasks, &QAbstractItemModel::dataChanged, this, &NimbleTaskStepWidget::onDataChanged);
updateTaskList();
connect(buildSystem, &NimbleBuildSystem::tasksChanged, this, &NimbleTaskStepWidget::updateTaskList);
selectTask(bs->taskName());
connect(bs, &NimbleTaskStep::taskNameChanged, this, &NimbleTaskStepWidget::selectTask);
connect(bs, &NimbleTaskStep::taskNameChanged, this, &NimbleTaskStepWidget::recreateSummary);
connect(bs, &NimbleTaskStep::taskArgsChanged, taskArgumentsLineEdit, &QLineEdit::setText);
connect(bs, &NimbleTaskStep::taskArgsChanged, this, &NimbleTaskStepWidget::recreateSummary);
connect(taskArgumentsLineEdit, &QLineEdit::textChanged, bs ,&NimbleTaskStep::setTaskArgs);
setSummaryUpdater([this, bs] {
return QString("<b>%1:</b> nimble %2 %3")
.arg(displayName(), bs->taskName(), bs->taskArgs());
});
}
void NimbleTaskStepWidget::updateTaskList()
{
auto buildSystem = dynamic_cast<NimbleBuildSystem *>(step()->buildSystem());
QTC_ASSERT(buildSystem, return);
const std::vector<NimbleTask> &tasks = buildSystem->tasks();
QSet<QString> newTasks;
for (const NimbleTask &t : tasks)
newTasks.insert(t.name);
QSet<QString> currentTasks;
for (int i = 0; i < m_tasks.rowCount(); ++i)
currentTasks.insert(m_tasks.item(i)->text());
const QSet<QString> added = newTasks - currentTasks;
const QSet<QString> removed = currentTasks - newTasks;
for (const QString &name : added) {
auto item = new QStandardItem();
item->setText(name);
item->setCheckable(true);
item->setCheckState(Qt::Unchecked);
item->setEditable(false);
item->setSelectable(false);
m_tasks.appendRow(item);
}
for (int i = m_tasks.rowCount() - 1; i >= 0; i--)
if (removed.contains(m_tasks.item(i)->text()))
m_tasks.removeRow(i);
m_tasks.sort(0);
}
void NimbleTaskStepWidget::selectTask(const QString &name)
{
if (m_selecting)
return;
m_selecting = true;
QList<QStandardItem *> items = m_tasks.findItems(name);
QStandardItem *item = items.empty() ? nullptr : items.front();
uncheckedAllDifferentFrom(item);
if (item)
item->setCheckState(Qt::Checked);
selectedTaskChanged(name);
m_selecting = false;
}
void NimbleTaskStepWidget::onDataChanged(const QModelIndex &topLeft,
const QModelIndex &bottomRight,
const QVector<int> &roles)
{
QTC_ASSERT(topLeft == bottomRight, return );
if (!roles.contains(Qt::CheckStateRole))
return;
auto item = m_tasks.itemFromIndex(topLeft);
if (!item)
return;
if (m_selecting)
return;
m_selecting = true;
if (item->checkState() == Qt::Checked) {
uncheckedAllDifferentFrom(item);
selectedTaskChanged(item->text());
} else if (item->checkState() == Qt::Unchecked) {
selectedTaskChanged(QString());
}
m_selecting = false;
}
void NimbleTaskStepWidget::uncheckedAllDifferentFrom(QStandardItem *toSkip)
{
for (int i = 0; i < m_tasks.rowCount(); ++i) {
auto item = m_tasks.item(i);
if (!item || item == toSkip)
continue;
item->setCheckState(Qt::Unchecked);
}
}
NimbleTaskStep::NimbleTaskStep(BuildStepList *parentList, Utils::Id id)
: AbstractProcessStep(parentList, id)
{
@@ -118,6 +280,8 @@ bool NimbleTaskStep::validate()
return true;
}
// Factory
NimbleTaskStepFactory::NimbleTaskStepFactory()
{
registerStep<NimbleTaskStep>(Constants::C_NIMBLETASKSTEP_ID);
@@ -128,3 +292,5 @@ NimbleTaskStepFactory::NimbleTaskStepFactory()
setSupportedConfiguration(Constants::C_NIMBLEBUILDCONFIGURATION_ID);
setRepeatable(true);
}
} // Nim

View File

@@ -1,169 +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 "nimbletaskstepwidget.h"
#include "nimbleproject.h"
#include "nimbletaskstep.h"
#include <QFormLayout>
#include <QLineEdit>
#include <QListView>
#include <utils/algorithm.h>
using namespace Nim;
using namespace ProjectExplorer;
NimbleTaskStepWidget::NimbleTaskStepWidget(NimbleTaskStep *bs)
: BuildStepConfigWidget(bs)
{
auto taskArgumentsLineEdit = new QLineEdit(this);
auto taskList = new QListView(this);
taskList->setFrameShape(QFrame::StyledPanel);
taskList->setSelectionMode(QAbstractItemView::NoSelection);
taskList->setSelectionBehavior(QAbstractItemView::SelectRows);
auto formLayout = new QFormLayout(this);
formLayout->setSizeConstraint(QLayout::SetDefaultConstraint);
formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
formLayout->addRow(tr("Task arguments:"), taskArgumentsLineEdit);
formLayout->addRow(tr("Tasks:"), taskList);
auto buildSystem = dynamic_cast<NimbleBuildSystem *>(bs->buildSystem());
QTC_ASSERT(buildSystem, return);
taskList->setModel(&m_tasks);
QObject::connect(&m_tasks, &QAbstractItemModel::dataChanged, this, &NimbleTaskStepWidget::onDataChanged);
updateTaskList();
QObject::connect(buildSystem, &NimbleBuildSystem::tasksChanged, this, &NimbleTaskStepWidget::updateTaskList);
selectTask(bs->taskName());
QObject::connect(bs, &NimbleTaskStep::taskNameChanged, this, &NimbleTaskStepWidget::selectTask);
QObject::connect(bs, &NimbleTaskStep::taskNameChanged, this, &NimbleTaskStepWidget::recreateSummary);
QObject::connect(this, &NimbleTaskStepWidget::selectedTaskChanged, bs, &NimbleTaskStep::setTaskName);
taskArgumentsLineEdit->setText(bs->taskArgs());
QObject::connect(bs, &NimbleTaskStep::taskArgsChanged, taskArgumentsLineEdit, &QLineEdit::setText);
QObject::connect(bs, &NimbleTaskStep::taskArgsChanged, this, &NimbleTaskStepWidget::recreateSummary);
QObject::connect(taskArgumentsLineEdit, &QLineEdit::textChanged, bs ,&NimbleTaskStep::setTaskArgs);
setSummaryUpdater([this, bs] {
return QString("<b>%1:</b> nimble %2 %3")
.arg(displayName())
.arg(bs->taskName())
.arg(bs->taskArgs());
});
}
void NimbleTaskStepWidget::updateTaskList()
{
auto buildSystem = dynamic_cast<NimbleBuildSystem *>(step()->buildSystem());
QTC_ASSERT(buildSystem, return);
const std::vector<NimbleTask> &tasks = buildSystem->tasks();
QSet<QString> newTasks;
for (const NimbleTask &t : tasks)
newTasks.insert(t.name);
QSet<QString> currentTasks;
for (int i = 0; i < m_tasks.rowCount(); ++i)
currentTasks.insert(m_tasks.item(i)->text());
const QSet<QString> added = newTasks - currentTasks;
const QSet<QString> removed = currentTasks - newTasks;
for (const QString &name : added) {
auto item = new QStandardItem();
item->setText(name);
item->setCheckable(true);
item->setCheckState(Qt::Unchecked);
item->setEditable(false);
item->setSelectable(false);
m_tasks.appendRow(item);
}
for (int i = m_tasks.rowCount() - 1; i >= 0; i--)
if (removed.contains(m_tasks.item(i)->text()))
m_tasks.removeRow(i);
m_tasks.sort(0);
}
void NimbleTaskStepWidget::selectTask(const QString &name)
{
if (m_selecting)
return;
m_selecting = true;
QList<QStandardItem*> items = m_tasks.findItems(name);
QStandardItem* item = items.empty() ? nullptr : items.front();
uncheckedAllDifferentFrom(item);
if (item)
item->setCheckState(Qt::Checked);
emit selectedTaskChanged(name);
m_selecting = false;
}
void NimbleTaskStepWidget::onDataChanged(const QModelIndex &topLeft,
const QModelIndex &bottomRight,
const QVector<int> &roles)
{
QTC_ASSERT(topLeft == bottomRight, return );
if (!roles.contains(Qt::CheckStateRole))
return;
auto item = m_tasks.itemFromIndex(topLeft);
if (!item)
return;
if (m_selecting)
return;
m_selecting = true;
if (item->checkState() == Qt::Checked) {
uncheckedAllDifferentFrom(item);
emit selectedTaskChanged(item->text());
} else if (item->checkState() == Qt::Unchecked) {
emit selectedTaskChanged(QString());
}
m_selecting = false;
}
void NimbleTaskStepWidget::uncheckedAllDifferentFrom(QStandardItem *toSkip)
{
for (int i = 0; i < m_tasks.rowCount(); ++i) {
auto item = m_tasks.item(i);
if (!item || item == toSkip)
continue;
item->setCheckState(Qt::Unchecked);
}
}

View File

@@ -1,62 +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>
#include <nim/project/nimbleproject.h>
#include <nim/project/nimblebuildsystem.h>
#include <QStandardItemModel>
namespace Nim {
class NimbleTaskStep;
class NimbleTaskStepWidget : public ProjectExplorer::BuildStepConfigWidget
{
Q_OBJECT
public:
explicit NimbleTaskStepWidget(NimbleTaskStep *buildStep);
signals:
void selectedTaskChanged(const QString &name);
private:
void updateTaskList();
void selectTask(const QString &name);
void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
void uncheckedAllDifferentFrom(QStandardItem *item);
QStandardItemModel m_tasks;
bool m_selecting = false;
};
}