diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index c9b9c4653..0e77a9b69 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -79,7 +79,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par ShowUnits(); - TextDelegate *textDelegate = new TextDelegate(nameRegExp, data, ui->tableWidgetIncrement); + TextDelegate *textDelegate = new TextDelegate(NameRegExp(), data, ui->tableWidgetIncrement); ui->tableWidgetIncrement->setItemDelegateForColumn(0, textDelegate);// name DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement); ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate);// base value diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 0e1e87243..893e6e868 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -679,11 +679,9 @@ void DialogTool::NamePointChanged() if (edit) { QString name = edit->text(); - name.replace(" ", ""); - QRegExpValidator v(QRegExp(nameRegExp), this); - int pos = 0; + QRegularExpression rx(NameRegExp()); if (name.isEmpty() || (pointName != name && data->IsUnique(name) == false) || - v.validate(name, pos) == QValidator::Invalid) + rx.match(name).hasMatch() == false) { flagName = false; ChangeColor(labelEditNamePoint, Qt::red); diff --git a/src/app/options.cpp b/src/app/options.cpp index 85b9221ed..c8944ec88 100644 --- a/src/app/options.cpp +++ b/src/app/options.cpp @@ -30,9 +30,6 @@ #include #include -//Same regexp in pattern.xsd shema file. Don't forget synchronize. -const QString nameRegExp = QStringLiteral("^([^0-9-*/^+=\\s\\(\\)%:;!.,`'\"]){1,1}([^-*/^+=\\s\\(\\)%:;!.,`'\"]){0,}$"); - // From documantation: If you use QStringLiteral you should avoid declaring the same literal in multiple places: This // furthermore blows up the binary sizes. const QString degreeSymbol = QStringLiteral("°"); diff --git a/src/app/options.h b/src/app/options.h index e7ff07983..3838862b3 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -31,6 +31,7 @@ #include "../libs/ifc/ifcdef.h" #include "../libs/vgeometry/vgeometrydef.h" +#include "../libs/qmuparser/qmudef.h" #include "../../utils/def.h" #ifdef Q_OS_WIN32 @@ -49,7 +50,6 @@ class QStringList; #define SceneSize 50000 #define DefPointRadius 1.5//mm -extern const QString nameRegExp; extern const QString degreeSymbol; extern const QString cursorArrowOpenHand; diff --git a/src/app/widgets/textdelegate.cpp b/src/app/widgets/textdelegate.cpp index 860175bb6..e9589e0d9 100644 --- a/src/app/widgets/textdelegate.cpp +++ b/src/app/widgets/textdelegate.cpp @@ -60,7 +60,7 @@ QWidget *TextDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem QLineEdit *editor = new QLineEdit(parent); editor->setLocale(parent->locale()); //Same regex pattern in xsd file - editor->setValidator( new QRegExpValidator(QRegExp(regex)) ); + editor->setValidator( new QRegularExpressionValidator(QRegularExpression(regex)) ); connect(editor, &QLineEdit::editingFinished, this, &TextDelegate::commitAndCloseEditor); return editor; } diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 77e069795..5b71762aa 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -431,8 +431,8 @@ void VToolOptionsPropertyBrowser::SetPointName(const QString &name) return; } - QRegExp rx(nameRegExp); - if (name.isEmpty() || VContainer::IsUnique(name) == false || rx.exactMatch(name) == false) + QRegularExpression rx(NameRegExp()); + if (name.isEmpty() || VContainer::IsUnique(name) == false || rx.match(name).hasMatch() == false) { idToProperty[VAbstractTool::AttrName]->setValue(i->name()); } diff --git a/src/libs/ifc/schema/pattern/v0.1.3.xsd b/src/libs/ifc/schema/pattern/v0.1.3.xsd index 093973f62..94319dc32 100644 --- a/src/libs/ifc/schema/pattern/v0.1.3.xsd +++ b/src/libs/ifc/schema/pattern/v0.1.3.xsd @@ -274,7 +274,7 @@ - + diff --git a/src/libs/qmuparser/qmudef.h b/src/libs/qmuparser/qmudef.h new file mode 100644 index 000000000..fb120cdbd --- /dev/null +++ b/src/libs/qmuparser/qmudef.h @@ -0,0 +1,36 @@ +/*************************************************************************************************** + ** + ** Copyright (C) 2015 Roman Telezhynskyi + ** + ** Permission is hereby granted, free of charge, to any person obtaining a copy of this + ** software and associated documentation files (the "Software"), to deal in the Software + ** without restriction, including without limitation the rights to use, copy, modify, + ** merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + ** permit persons to whom the Software is furnished to do so, subject to the following conditions: + ** + ** The above copyright notice and this permission notice shall be included in all copies or + ** substantial portions of the Software. + ** + ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT + ** NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + ** + ******************************************************************************************************/ + +#ifndef QMUDEF_H +#define QMUDEF_H + +#include "qmuparser_global.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +QMUPARSERSHARED_EXPORT inline QString NameRegExp() +{ + //Same regexp in pattern.xsd shema file. Don't forget synchronize. + return QStringLiteral("^([^0-9*/^+\\-=\\s()?%:;!.,`'\"]){1,1}([^*/^+\\-=\\s()?%:;!.,`'\"]){0,}$"); +} + +#endif // QMUDEF_H diff --git a/src/libs/qmuparser/qmuparser.pri b/src/libs/qmuparser/qmuparser.pri index 13a555b84..fd12ad376 100644 --- a/src/libs/qmuparser/qmuparser.pri +++ b/src/libs/qmuparser/qmuparser.pri @@ -25,4 +25,5 @@ HEADERS += \ $$PWD/qmuparserbase.h \ $$PWD/qmuparsertest.h \ $$PWD/stable.h \ - $$PWD/qmutranslation.h + $$PWD/qmutranslation.h \ + $$PWD/qmudef.h diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index be0b18382..f7ee09a1e 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -38,13 +38,15 @@ SOURCES += \ tst_vposter.cpp \ tst_vabstractdetail.cpp \ tst_vspline.cpp \ - abstracttest.cpp + abstracttest.cpp \ + tst_nameregexp.cpp HEADERS += \ tst_vposter.h \ tst_vabstractdetail.h \ tst_vspline.h \ - abstracttest.h + abstracttest.h \ + tst_nameregexp.h CONFIG(debug, debug|release){ # Debug mode diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index 8af765e4c..152ded166 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -31,6 +31,7 @@ #include "tst_vposter.h" #include "tst_vabstractdetail.h" #include "tst_vspline.h" +#include "tst_nameregexp.h" int main(int argc, char** argv) { @@ -46,6 +47,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_VPoster()); ASSERT_TEST(new TST_VAbstractDetail()); ASSERT_TEST(new TST_VSpline()); + ASSERT_TEST(new TST_NameRegExp()); return status; } diff --git a/src/test/ValentinaTest/tst_nameregexp.cpp b/src/test/ValentinaTest/tst_nameregexp.cpp new file mode 100644 index 000000000..d1ad988f6 --- /dev/null +++ b/src/test/ValentinaTest/tst_nameregexp.cpp @@ -0,0 +1,108 @@ +/************************************************************************ + ** + ** @file tst_nameregexp.cpp + ** @author Roman Telezhynskyi + ** @date 11 5, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina 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 Valentina. If not, see . + ** + *************************************************************************/ + +#include "tst_nameregexp.h" +#include "../../libs/qmuparser/qmudef.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_NameRegExp::TST_NameRegExp(QObject *parent) : + QObject(parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_NameRegExp::TestNameRegExp_data() +{ + QTest::addColumn("name"); + QTest::addColumn("result"); + + QTest::newRow("First character can't be 0") << "0a" << false; + QTest::newRow("First character can't be 1") << "1a" << false; + QTest::newRow("First character can't be 2") << "2a" << false; + QTest::newRow("First character can't be 3") << "3a" << false; + QTest::newRow("First character can't be 4") << "4a" << false; + QTest::newRow("First character can't be 5") << "5a" << false; + QTest::newRow("First character can't be 6") << "6a" << false; + QTest::newRow("First character can't be 7") << "7a" << false; + QTest::newRow("First character can't be 8") << "8a" << false; + QTest::newRow("First character can't be 9") << "9a" << false; + QTest::newRow("First character can't be \"*\"") << "*a" << false; + QTest::newRow("First character can't be \"/\"") << "/a" << false; + QTest::newRow("First character can't be \"^\"") << "^a" << false; + QTest::newRow("First character can't be \"+\"") << "+a" << false; + QTest::newRow("First character can't be \"=\"") << "=a" << false; + QTest::newRow("First character can't be \"-\"") << "-a" << false; + QTest::newRow("First character can't be whitespace") << " a" << false; + QTest::newRow("First character can't be \"(\"") << "(a" << false; + QTest::newRow("First character can't be \")\"") << ")a" << false; + QTest::newRow("First character can't be \"?\"") << "?a" << false; + QTest::newRow("First character can't be \"%\"") << "%a" << false; + QTest::newRow("First character can't be \":\"") << ":a" << false; + QTest::newRow("First character can't be \";\"") << ";a" << false; + QTest::newRow("First character can't be \"!\"") << "!a" << false; + QTest::newRow("First character can't be \".\"") << ".a" << false; + QTest::newRow("First character can't be \",\"") << ",a" << false; + QTest::newRow("First character can't be \"`\"") << "`a" << false; + QTest::newRow("First character can't be \"\"\"") << "\"a" << false; + + QTest::newRow("Any next character can't be \"-\"") << "a-" << false; + QTest::newRow("Any next character can't be \"*\"") << "a*" << false; + QTest::newRow("Any next character can't be \"/\"") << "a/" << false; + QTest::newRow("Any next character can't be \"^\"") << "a^" << false; + QTest::newRow("Any next character can't be \"+\"") << "a+" << false; + QTest::newRow("Any next character can't be \"=\"") << "a=" << false; + QTest::newRow("Any next character can't be whitespace") << "L bust" << false; + QTest::newRow("Any next character can't be \"(\"") << "a(" << false; + QTest::newRow("Any next character can't be \")\"") << "a)" << false; + QTest::newRow("Any next character can't be \"?\"") << "a?" << false; + QTest::newRow("Any next character can't be \"%\"") << "a%" << false; + QTest::newRow("Any next character can't be \":\"") << "a:" << false; + QTest::newRow("Any next character can't be \";\"") << "a:" << false; + QTest::newRow("Any next character can't be \"!\"") << "a!" << false; + QTest::newRow("Any next character can't be \".\"") << "a." << false; + QTest::newRow("Any next character can't be \",\"") << "a," << false; + QTest::newRow("Any next character can't be \"`\"") << "a`" << false; + QTest::newRow("Any next character can't be \"\"\"") << "a\"" << false; + + QTest::newRow("Good name \"p12\"") << "p12" << true; + QTest::newRow("Good name \"height\"") << "height" << true; + QTest::newRow("Good name \"A_1\"") << "A_1" << true; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_NameRegExp::TestNameRegExp() +{ + const QRegularExpression re(NameRegExp()); + + QFETCH(QString, name); + QFETCH(bool, result); + + QCOMPARE(re.match(name).hasMatch(), result); +} diff --git a/src/test/ValentinaTest/tst_nameregexp.h b/src/test/ValentinaTest/tst_nameregexp.h new file mode 100644 index 000000000..fc20cc349 --- /dev/null +++ b/src/test/ValentinaTest/tst_nameregexp.h @@ -0,0 +1,48 @@ +/************************************************************************ + ** + ** @file tst_nameregexp.h + ** @author Roman Telezhynskyi + ** @date 11 5, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina 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 Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef TST_NAMEREGEXP_H +#define TST_NAMEREGEXP_H + +#include + +class TST_NameRegExp : public QObject +{ + Q_OBJECT +public: + explicit TST_NameRegExp(QObject *parent = 0); + +signals: + +private slots: + void TestNameRegExp_data(); + void TestNameRegExp(); + +}; + +#endif // TST_NAMEREGEXP_H