ui: replace invalid characters in project name during project creation (issue #671)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include "QtProjectWizzardContentProjectData.h"
|
#include "QtProjectWizzardContentProjectData.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
|
|
||||||
#include "ProjectSettings.h"
|
#include "ProjectSettings.h"
|
||||||
@@ -32,6 +33,7 @@ void QtProjectWizzardContentProjectData::populate(QGridLayout* layout, int& row)
|
|||||||
m_projectName->setObjectName("name");
|
m_projectName->setObjectName("name");
|
||||||
m_projectName->setAttribute(Qt::WA_MacShowFocusRect, 0);
|
m_projectName->setAttribute(Qt::WA_MacShowFocusRect, 0);
|
||||||
m_projectName->setEnabled(!m_disableNameEditing);
|
m_projectName->setEnabled(!m_disableNameEditing);
|
||||||
|
connect(m_projectName, &QLineEdit::textEdited, this, &QtProjectWizzardContentProjectData::onProjectNameEdited);
|
||||||
|
|
||||||
layout->addWidget(nameLabel, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight);
|
layout->addWidget(nameLabel, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight);
|
||||||
layout->addWidget(m_projectName, row, QtProjectWizzardWindow::BACK_COL);
|
layout->addWidget(m_projectName, row, QtProjectWizzardWindow::BACK_COL);
|
||||||
@@ -125,3 +127,14 @@ bool QtProjectWizzardContentProjectData::check()
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QtProjectWizzardContentProjectData::onProjectNameEdited(QString text)
|
||||||
|
{
|
||||||
|
const int cursorPosition = m_projectName->cursorPosition();
|
||||||
|
|
||||||
|
QRegularExpression regex("[^A-Za-z0-9_.-]");
|
||||||
|
text.replace(regex, "_");
|
||||||
|
|
||||||
|
m_projectName->setText(text);
|
||||||
|
m_projectName->setCursorPosition(cursorPosition);
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ public:
|
|||||||
virtual void save() override;
|
virtual void save() override;
|
||||||
virtual bool check() override;
|
virtual bool check() override;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onProjectNameEdited(QString text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<ProjectSettings> m_projectSettings;
|
std::shared_ptr<ProjectSettings> m_projectSettings;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user