Skip to content
Snippets Groups Projects
Commit 14be4b4c authored by Mirko Wächter's avatar Mirko Wächter
Browse files

Statechart Editor: now only valid event names are accepted

parent 4e06a6e2
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -36,6 +36,8 @@
#include <ArmarXCore/observers/variant/VariantContainer.h>
#include <ArmarXGui/libraries/ArmarXGuiBase/widgets/RegExpValidatedInputDialog.h>
namespace armarx
{
......@@ -284,12 +286,16 @@ namespace armarx
void StateDialog::eventButtonAdd()
{
bool ok;
QString text = QInputDialog::getText(this, QString("New Event name"), QString("EventName"), QLineEdit::Normal, QString(), &ok);
RegExpValidatedInputDialog d("New Event Name", "Event name",
QRegExp("^([a-zA-Z_]{1})([a-zA-Z_0-9]+)$"), this);
if (ok && !text.isEmpty())
if (d.exec() == QDialog::Accepted)
{
ui->cbOutgoingEvents->addItem(text);
auto eventName = d.getTextValue();
if (!eventName.isEmpty())
{
ui->cbOutgoingEvents->addItem(eventName);
}
// No need to create entry in event description map (automatically done by operator[] on access)
}
}
......@@ -371,7 +377,7 @@ namespace armarx
.unite(ui->tableLocal->getTypes())
.unite(ui->tableOutput->getTypes());
Ice::StringSeq types;
for (auto & var : vars)
for (auto& var : vars)
{
auto type = VariantContainerType::GetInnerType(var.toStdString());
if (!type.empty())
......@@ -380,7 +386,7 @@ namespace armarx
}
}
QStringList libs;
for (std::string & lib : variantInfo->findLibNames(types))
for (std::string& lib : variantInfo->findLibNames(types))
{
libs << QString::fromStdString(lib);
}
......
......@@ -39,6 +39,7 @@ set(LIB_FILES ArmarXWidgetController.cpp
widgets/TipDialog.cpp
widgets/InfixFilterModel.cpp
widgets/InfixCompleter.cpp
widgets/RegExpValidatedInputDialog.cpp
)
set(LIB_HEADERS ArmarXGuiInterface.h
......@@ -58,6 +59,7 @@ set(LIB_HEADERS ArmarXGuiInterface.h
widgets/TipDialog.h
widgets/InfixFilterModel.h
widgets/InfixCompleter.h
widgets/RegExpValidatedInputDialog.h
)
set(GUI_UIS
......@@ -82,6 +84,7 @@ qt4_wrap_cpp(LIB_FILES
widgets/TipDialog.h
widgets/InfixFilterModel.h
widgets/InfixCompleter.h
widgets/RegExpValidatedInputDialog.h
)
qt4_wrap_ui(UI_HEADER ${GUI_UIS})
......
/*
* This file is part of ArmarX.
*
* Copyright (C) 2011-2017, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reservethis->
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package ArmarX
* @author Mirko Waechter( mirko.waechter at kit dot edu)
* @date 2017
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include "RegExpValidatedInputDialog.h"
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QValidator>
namespace armarx
{
RegExpValidatedInputDialog::RegExpValidatedInputDialog(QString const& windowTitle,
QString const& labelName, const QRegExp& regExp, QWidget* parent) : QDialog(parent)
{
this->setWindowTitle(windowTitle);
QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
buttonBox->setOrientation(Qt::Horizontal);
buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
edit = new QLineEdit();
edit->resize(edit->height(), 150);
edit->setValidator(new QRegExpValidator(regExp));
QGridLayout* layout = new QGridLayout(this);
this->setLayout(layout);
layout->addWidget(new QLabel(labelName), 0, 0);
layout->addWidget(edit, 0, 1);
layout->addWidget(buttonBox, 1, 0, 1, 2);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
}
QString RegExpValidatedInputDialog::getTextValue() const
{
return edit->text();
}
} // namespace armarx
/*
* This file is part of ArmarX.
*
* Copyright (C) 2011-2017, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package ArmarX
* @author Mirko Waechter( mirko.waechter at kit dot edu)
* @date 2017
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#ifndef _ARMARX_REGEXPVALIDATEDINPUTDIALOG_H
#define _ARMARX_REGEXPVALIDATEDINPUTDIALOG_H
#include <QDialog>
class QLineEdit;
namespace armarx
{
/**
* @class RegExpValidatedInputDialog
* @brief This class is similar to the QInputDialog, but offers the possibility to specify a regex as input validation.
*/
class RegExpValidatedInputDialog : public QDialog
{
Q_OBJECT
public:
explicit RegExpValidatedInputDialog(const QString& windowTitle, const QString& labelName, const QRegExp& regExp, QWidget* parent = 0);
QString getTextValue() const;
signals:
public slots:
private:
QLineEdit* edit;
};
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment