Utils: inline projectintropage.ui

Change-Id: I10f1b76b8bc88c56dfe6d215345d9b92a6832074
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2022-07-22 18:02:04 +02:00
parent 1548eef10b
commit 715e5800a5
5 changed files with 104 additions and 197 deletions

View File

@@ -126,7 +126,7 @@ add_qtc_library(Utils
processreaper.cpp processreaper.h
processutils.cpp processutils.h
progressindicator.cpp progressindicator.h
projectintropage.cpp projectintropage.h projectintropage.ui
projectintropage.cpp projectintropage.h
proxyaction.cpp proxyaction.h
proxycredentialsdialog.cpp proxycredentialsdialog.h proxycredentialsdialog.ui
qrcparser.cpp qrcparser.h

View File

@@ -24,13 +24,23 @@
****************************************************************************/
#include "projectintropage.h"
#include "ui_projectintropage.h"
#include "fancylineedit.h"
#include "filenamevalidatinglineedit.h"
#include "fileutils.h"
#include "infolabel.h"
#include "layoutbuilder.h"
#include "pathchooser.h"
#include "wizard.h"
#include <QApplication>
#include <QCheckBox>
#include <QComboBox>
#include <QDir>
#include <QFormLayout>
#include <QFrame>
#include <QLabel>
#include <QSpacerItem>
/*!
\class Utils::ProjectIntroPage
@@ -59,50 +69,93 @@ namespace Utils {
class ProjectIntroPagePrivate
{
public:
Ui::ProjectIntroPage m_ui;
bool m_complete = false;
QRegularExpressionValidator m_projectNameValidator;
QString m_projectNameValidatorUserMessage;
bool m_forceSubProject = false;
FilePaths m_projectDirectories;
QLabel *m_descriptionLabel;
FancyLineEdit *m_nameLineEdit;
PathChooser *m_pathChooser;
QCheckBox *m_projectsDirectoryCheckBox;
QLabel *m_projectLabel;
QComboBox *m_projectComboBox;
InfoLabel *m_stateLabel;
};
ProjectIntroPage::ProjectIntroPage(QWidget *parent) :
WizardPage(parent),
d(new ProjectIntroPagePrivate)
{
d->m_ui.setupUi(this);
d->m_ui.stateLabel->setFilled(true);
resize(355, 289);
setTitle(tr("Introduction and Project Location"));
d->m_descriptionLabel = new QLabel(this);
d->m_descriptionLabel->setWordWrap(true);
auto frame = new QFrame(this);
frame->setFrameShape(QFrame::StyledPanel);
frame->setFrameShadow(QFrame::Raised);
d->m_nameLineEdit = new Utils::FancyLineEdit(frame);
d->m_pathChooser = new Utils::PathChooser(frame);
d->m_pathChooser->setDisabled(d->m_forceSubProject);
d->m_projectsDirectoryCheckBox = new QCheckBox(tr("Use as default project location"));
d->m_projectsDirectoryCheckBox->setDisabled(d->m_forceSubProject);
d->m_projectComboBox = new QComboBox;
d->m_projectComboBox->setVisible(d->m_forceSubProject);
d->m_stateLabel = new Utils::InfoLabel(this);
d->m_stateLabel->setWordWrap(true);
d->m_stateLabel->setFilled(true);
hideStatusLabel();
d->m_ui.nameLineEdit->setPlaceholderText(tr("Enter project name"));
d->m_ui.nameLineEdit->setFocus();
d->m_ui.nameLineEdit->setValidationFunction([this](FancyLineEdit *edit, QString *errorString) {
d->m_nameLineEdit->setPlaceholderText(tr("Enter project name"));
d->m_nameLineEdit->setFocus();
d->m_nameLineEdit->setValidationFunction([this](FancyLineEdit *edit, QString *errorString) {
return validateProjectName(edit->text(), errorString);
});
d->m_ui.projectLabel->setVisible(d->m_forceSubProject);
d->m_ui.projectComboBox->setVisible(d->m_forceSubProject);
d->m_ui.pathChooser->setDisabled(d->m_forceSubProject);
d->m_ui.projectsDirectoryCheckBox->setDisabled(d->m_forceSubProject);
connect(d->m_ui.pathChooser, &PathChooser::filePathChanged, this, &ProjectIntroPage::slotChanged);
connect(d->m_ui.nameLineEdit, &QLineEdit::textChanged,
d->m_projectLabel = new QLabel("Project:");
d->m_projectLabel->setVisible(d->m_forceSubProject);
using namespace Layouting;
const Break br;
Form {
tr("Name:"), d->m_nameLineEdit, br,
d->m_projectLabel, d->m_projectComboBox, br,
Column { Space(12) }, br,
tr("Create in:"), d->m_pathChooser, br,
Span(2, d->m_projectsDirectoryCheckBox)
}.attachTo(frame);
Column {
d->m_descriptionLabel,
Stretch(),
frame,
d->m_stateLabel
}.attachTo(this);
connect(d->m_pathChooser, &PathChooser::filePathChanged, this, &ProjectIntroPage::slotChanged);
connect(d->m_nameLineEdit, &QLineEdit::textChanged,
this, &ProjectIntroPage::slotChanged);
connect(d->m_ui.pathChooser, &PathChooser::validChanged,
connect(d->m_pathChooser, &PathChooser::validChanged,
this, &ProjectIntroPage::slotChanged);
connect(d->m_ui.pathChooser, &PathChooser::returnPressed,
connect(d->m_pathChooser, &PathChooser::returnPressed,
this, &ProjectIntroPage::slotActivated);
connect(d->m_ui.nameLineEdit, &FancyLineEdit::validReturnPressed,
connect(d->m_nameLineEdit, &FancyLineEdit::validReturnPressed,
this, &ProjectIntroPage::slotActivated);
connect(d->m_ui.projectComboBox, &QComboBox::currentIndexChanged,
connect(d->m_projectComboBox, &QComboBox::currentIndexChanged,
this, &ProjectIntroPage::slotChanged);
setProperty(SHORT_TITLE_PROPERTY, tr("Location"));
registerFieldWithName(QLatin1String("Path"), d->m_ui.pathChooser, "path", SIGNAL(pathChanged(QString)));
registerFieldWithName(QLatin1String("ProjectName"), d->m_ui.nameLineEdit);
}
void ProjectIntroPage::insertControl(int row, QWidget *label, QWidget *control)
{
d->m_ui.formLayout->insertRow(row, label, control);
registerFieldWithName(QLatin1String("Path"), d->m_pathChooser, "path", SIGNAL(pathChanged(QString)));
registerFieldWithName(QLatin1String("ProjectName"), d->m_nameLineEdit);
}
ProjectIntroPage::~ProjectIntroPage()
@@ -112,17 +165,17 @@ ProjectIntroPage::~ProjectIntroPage()
QString ProjectIntroPage::projectName() const
{
return d->m_ui.nameLineEdit->text();
return d->m_nameLineEdit->text();
}
FilePath ProjectIntroPage::filePath() const
{
return d->m_ui.pathChooser->filePath();
return d->m_pathChooser->filePath();
}
void ProjectIntroPage::setFilePath(const FilePath &path)
{
d->m_ui.pathChooser->setFilePath(path);
d->m_pathChooser->setFilePath(path);
}
void ProjectIntroPage::setProjectNameRegularExpression(const QRegularExpression &regEx, const QString &userErrorMessage)
@@ -134,18 +187,18 @@ void ProjectIntroPage::setProjectNameRegularExpression(const QRegularExpression
void ProjectIntroPage::setProjectName(const QString &name)
{
d->m_ui.nameLineEdit->setText(name);
d->m_ui.nameLineEdit->selectAll();
d->m_nameLineEdit->setText(name);
d->m_nameLineEdit->selectAll();
}
QString ProjectIntroPage::description() const
{
return d->m_ui.descriptionLabel->text();
return d->m_descriptionLabel->text();
}
void ProjectIntroPage::setDescription(const QString &description)
{
d->m_ui.descriptionLabel->setText(description);
d->m_descriptionLabel->setText(description);
}
bool ProjectIntroPage::isComplete() const
@@ -156,21 +209,21 @@ bool ProjectIntroPage::isComplete() const
bool ProjectIntroPage::validate()
{
if (d->m_forceSubProject) {
int index = d->m_ui.projectComboBox->currentIndex();
int index = d->m_projectComboBox->currentIndex();
if (index == 0)
return false;
d->m_ui.pathChooser->setFilePath(d->m_projectDirectories.at(index));
d->m_pathChooser->setFilePath(d->m_projectDirectories.at(index));
}
// Validate and display status
if (!d->m_ui.pathChooser->isValid()) {
displayStatusMessage(InfoLabel::Error, d->m_ui.pathChooser->errorMessage());
if (!d->m_pathChooser->isValid()) {
displayStatusMessage(InfoLabel::Error, d->m_pathChooser->errorMessage());
return false;
}
// Name valid?
switch (d->m_ui.nameLineEdit->state()) {
switch (d->m_nameLineEdit->state()) {
case FancyLineEdit::Invalid:
displayStatusMessage(InfoLabel::Error, d->m_ui.nameLineEdit->errorMessage());
displayStatusMessage(InfoLabel::Error, d->m_nameLineEdit->errorMessage());
return false;
case FancyLineEdit::DisplayingPlaceholderText:
displayStatusMessage(InfoLabel::Error, tr("Name is empty."));
@@ -181,7 +234,7 @@ bool ProjectIntroPage::validate()
// Check existence of the directory
const FilePath projectDir =
filePath().pathAppended(QDir::fromNativeSeparators(d->m_ui.nameLineEdit->text()));
filePath().pathAppended(QDir::fromNativeSeparators(d->m_nameLineEdit->text()));
if (!projectDir.exists()) { // All happy
hideStatusLabel();
@@ -225,16 +278,16 @@ bool ProjectIntroPage::forceSubProject() const
void ProjectIntroPage::setForceSubProject(bool force)
{
d->m_forceSubProject = force;
d->m_ui.projectLabel->setVisible(d->m_forceSubProject);
d->m_ui.projectComboBox->setVisible(d->m_forceSubProject);
d->m_ui.pathChooser->setDisabled(d->m_forceSubProject);
d->m_ui.projectsDirectoryCheckBox->setDisabled(d->m_forceSubProject);
d->m_projectLabel->setVisible(d->m_forceSubProject);
d->m_projectComboBox->setVisible(d->m_forceSubProject);
d->m_pathChooser->setDisabled(d->m_forceSubProject);
d->m_projectsDirectoryCheckBox->setDisabled(d->m_forceSubProject);
}
void ProjectIntroPage::setProjectList(const QStringList &projectList)
{
d->m_ui.projectComboBox->clear();
d->m_ui.projectComboBox->addItems(projectList);
d->m_projectComboBox->clear();
d->m_projectComboBox->addItems(projectList);
}
void ProjectIntroPage::setProjectDirectories(const FilePaths &directoryList)
@@ -244,7 +297,7 @@ void ProjectIntroPage::setProjectDirectories(const FilePaths &directoryList)
int ProjectIntroPage::projectIndex() const
{
return d->m_ui.projectComboBox->currentIndex();
return d->m_projectComboBox->currentIndex();
}
bool ProjectIntroPage::validateProjectName(const QString &name, QString *errorMessage)
@@ -293,8 +346,8 @@ bool ProjectIntroPage::validateProjectName(const QString &name, QString *errorMe
void ProjectIntroPage::displayStatusMessage(InfoLabel::InfoType t, const QString &s)
{
d->m_ui.stateLabel->setType(t);
d->m_ui.stateLabel->setText(s);
d->m_stateLabel->setType(t);
d->m_stateLabel->setText(s);
emit statusMessageChanged(t, s);
}
@@ -306,12 +359,12 @@ void ProjectIntroPage::hideStatusLabel()
bool ProjectIntroPage::useAsDefaultPath() const
{
return d->m_ui.projectsDirectoryCheckBox->isChecked();
return d->m_projectsDirectoryCheckBox->isChecked();
}
void ProjectIntroPage::setUseAsDefaultPath(bool u)
{
d->m_ui.projectsDirectoryCheckBox->setChecked(u);
d->m_projectsDirectoryCheckBox->setChecked(u);
}
} // namespace Utils

View File

@@ -33,8 +33,6 @@
namespace Utils {
class ProjectIntroPagePrivate;
class QTCREATOR_UTILS_EXPORT ProjectIntroPage : public WizardPage
{
Q_OBJECT
@@ -53,9 +51,6 @@ public:
QString description() const;
bool useAsDefaultPath() const;
// Insert an additional control into the form layout for the target.
void insertControl(int row, QWidget *label, QWidget *control);
bool isComplete() const override;
bool forceSubProject() const;
@@ -90,7 +85,7 @@ private:
void displayStatusMessage(InfoLabel::InfoType t, const QString &);
void hideStatusLabel();
ProjectIntroPagePrivate *d;
class ProjectIntroPagePrivate *d;
};
} // namespace Utils

View File

@@ -1,140 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Utils::ProjectIntroPage</class>
<widget class="QWizardPage" name="Utils::ProjectIntroPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>355</width>
<height>289</height>
</rect>
</property>
<property name="title">
<string>Introduction and Project Location</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<widget class="QLabel" name="descriptionLabel">
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Utils::FancyLineEdit" name="nameLineEdit"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="pathLabel">
<property name="text">
<string>Create in:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="Utils::PathChooser" name="pathChooser" native="true"/>
</item>
<item row="4" column="0">
<spacer name="directorySeparatorLabel">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>12</height>
</size>
</property>
</spacer>
</item>
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="projectsDirectoryCheckBox">
<property name="text">
<string>Use as default project location</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="projectLabel">
<property name="text">
<string>Project:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="projectComboBox"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="Utils::InfoLabel" name="stateLabel">
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::FancyLineEdit</class>
<extends>QLineEdit</extends>
<header location="global">utils/fancylineedit.h</header>
</customwidget>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>Utils::InfoLabel</class>
<extends>QLabel</extends>
<header location="global">utils/infolabel.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -240,7 +240,6 @@ Project {
"progressindicator.h",
"projectintropage.cpp",
"projectintropage.h",
"projectintropage.ui",
"proxyaction.cpp",
"proxyaction.h",
"proxycredentialsdialog.cpp",