Fixed issue #299. Error when opening .val file.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-05-11 15:59:53 +03:00
parent e9fcd00111
commit 641e718a04
13 changed files with 208 additions and 16 deletions

View File

@ -79,7 +79,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
ShowUnits(); ShowUnits();
TextDelegate *textDelegate = new TextDelegate(nameRegExp, data, ui->tableWidgetIncrement); TextDelegate *textDelegate = new TextDelegate(NameRegExp(), data, ui->tableWidgetIncrement);
ui->tableWidgetIncrement->setItemDelegateForColumn(0, textDelegate);// name ui->tableWidgetIncrement->setItemDelegateForColumn(0, textDelegate);// name
DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement); DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement);
ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate);// base value ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate);// base value

View File

@ -679,11 +679,9 @@ void DialogTool::NamePointChanged()
if (edit) if (edit)
{ {
QString name = edit->text(); QString name = edit->text();
name.replace(" ", ""); QRegularExpression rx(NameRegExp());
QRegExpValidator v(QRegExp(nameRegExp), this);
int pos = 0;
if (name.isEmpty() || (pointName != name && data->IsUnique(name) == false) || if (name.isEmpty() || (pointName != name && data->IsUnique(name) == false) ||
v.validate(name, pos) == QValidator::Invalid) rx.match(name).hasMatch() == false)
{ {
flagName = false; flagName = false;
ChangeColor(labelEditNamePoint, Qt::red); ChangeColor(labelEditNamePoint, Qt::red);

View File

@ -30,9 +30,6 @@
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
//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 // From documantation: If you use QStringLiteral you should avoid declaring the same literal in multiple places: This
// furthermore blows up the binary sizes. // furthermore blows up the binary sizes.
const QString degreeSymbol = QStringLiteral("°"); const QString degreeSymbol = QStringLiteral("°");

View File

@ -31,6 +31,7 @@
#include "../libs/ifc/ifcdef.h" #include "../libs/ifc/ifcdef.h"
#include "../libs/vgeometry/vgeometrydef.h" #include "../libs/vgeometry/vgeometrydef.h"
#include "../libs/qmuparser/qmudef.h"
#include "../../utils/def.h" #include "../../utils/def.h"
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
@ -49,7 +50,6 @@ class QStringList;
#define SceneSize 50000 #define SceneSize 50000
#define DefPointRadius 1.5//mm #define DefPointRadius 1.5//mm
extern const QString nameRegExp;
extern const QString degreeSymbol; extern const QString degreeSymbol;
extern const QString cursorArrowOpenHand; extern const QString cursorArrowOpenHand;

View File

@ -60,7 +60,7 @@ QWidget *TextDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem
QLineEdit *editor = new QLineEdit(parent); QLineEdit *editor = new QLineEdit(parent);
editor->setLocale(parent->locale()); editor->setLocale(parent->locale());
//Same regex pattern in xsd file //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); connect(editor, &QLineEdit::editingFinished, this, &TextDelegate::commitAndCloseEditor);
return editor; return editor;
} }

View File

@ -431,8 +431,8 @@ void VToolOptionsPropertyBrowser::SetPointName(const QString &name)
return; return;
} }
QRegExp rx(nameRegExp); QRegularExpression rx(NameRegExp());
if (name.isEmpty() || VContainer::IsUnique(name) == false || rx.exactMatch(name) == false) if (name.isEmpty() || VContainer::IsUnique(name) == false || rx.match(name).hasMatch() == false)
{ {
idToProperty[VAbstractTool::AttrName]->setValue(i->name()); idToProperty[VAbstractTool::AttrName]->setValue(i->name());
} }

View File

@ -274,7 +274,7 @@
</xs:element> </xs:element>
<xs:simpleType name="shortName"> <xs:simpleType name="shortName">
<xs:restriction base="xs:string"> <xs:restriction base="xs:string">
<xs:pattern value="^([^0-9-*/^+=\s\(\)%:;!.,`'\&quot;]){1,1}([^-*/^+=\s\(\)%:;!.,`'\&quot;]){0,}$"/> <xs:pattern value="^([^0-9*/^+\-=\s()?%:;!.,`'\&quot;]){1,1}([^*/^+\-=\s()?%:;!.,`'\&quot;]){0,}$"/>
</xs:restriction> </xs:restriction>
</xs:simpleType> </xs:simpleType>
<xs:simpleType name="units"> <xs:simpleType name="units">

View File

@ -0,0 +1,36 @@
/***************************************************************************************************
**
** Copyright (C) 2015 Roman Telezhynskyi <dismine(at)gmail.com>
**
** 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 <QString>
//---------------------------------------------------------------------------------------------------------------------
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

View File

@ -25,4 +25,5 @@ HEADERS += \
$$PWD/qmuparserbase.h \ $$PWD/qmuparserbase.h \
$$PWD/qmuparsertest.h \ $$PWD/qmuparsertest.h \
$$PWD/stable.h \ $$PWD/stable.h \
$$PWD/qmutranslation.h $$PWD/qmutranslation.h \
$$PWD/qmudef.h

View File

@ -38,13 +38,15 @@ SOURCES += \
tst_vposter.cpp \ tst_vposter.cpp \
tst_vabstractdetail.cpp \ tst_vabstractdetail.cpp \
tst_vspline.cpp \ tst_vspline.cpp \
abstracttest.cpp abstracttest.cpp \
tst_nameregexp.cpp
HEADERS += \ HEADERS += \
tst_vposter.h \ tst_vposter.h \
tst_vabstractdetail.h \ tst_vabstractdetail.h \
tst_vspline.h \ tst_vspline.h \
abstracttest.h abstracttest.h \
tst_nameregexp.h
CONFIG(debug, debug|release){ CONFIG(debug, debug|release){
# Debug mode # Debug mode

View File

@ -31,6 +31,7 @@
#include "tst_vposter.h" #include "tst_vposter.h"
#include "tst_vabstractdetail.h" #include "tst_vabstractdetail.h"
#include "tst_vspline.h" #include "tst_vspline.h"
#include "tst_nameregexp.h"
int main(int argc, char** argv) 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_VPoster());
ASSERT_TEST(new TST_VAbstractDetail()); ASSERT_TEST(new TST_VAbstractDetail());
ASSERT_TEST(new TST_VSpline()); ASSERT_TEST(new TST_VSpline());
ASSERT_TEST(new TST_NameRegExp());
return status; return status;
} }

View File

@ -0,0 +1,108 @@
/************************************************************************
**
** @file tst_nameregexp.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "tst_nameregexp.h"
#include "../../libs/qmuparser/qmudef.h"
#include <QtTest>
//---------------------------------------------------------------------------------------------------------------------
TST_NameRegExp::TST_NameRegExp(QObject *parent) :
QObject(parent)
{
}
//---------------------------------------------------------------------------------------------------------------------
void TST_NameRegExp::TestNameRegExp_data()
{
QTest::addColumn<QString>("name");
QTest::addColumn<bool>("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);
}

View File

@ -0,0 +1,48 @@
/************************************************************************
**
** @file tst_nameregexp.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef TST_NAMEREGEXP_H
#define TST_NAMEREGEXP_H
#include <QObject>
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