diff --git a/src/geometry/vdetail.cpp b/src/geometry/vdetail.cpp index ab7379dd4..d92786a5c 100644 --- a/src/geometry/vdetail.cpp +++ b/src/geometry/vdetail.cpp @@ -174,13 +174,13 @@ ptrdiff_t VDetail::Edge(const quint32 &p1, const quint32 &p2) const void VDetail::NodeOnEdge(const quint32 &index, VNodeDetail &p1, VNodeDetail &p2) const { QVector list = listNodePoint(); - if (index < 0 || index > list.size()) + if (index > static_cast(list.size())) { qWarning()<<"Wrong edge index index ="< list.size() - 1) + if (index + 1 > static_cast(list.size()) - 1) { p2 = list.at(0); } @@ -196,9 +196,9 @@ VDetail VDetail::RemoveEdge(const quint32 &index) const det.ClearNodes(); QVector list = this->listNodePoint(); - qint32 edge = list.size(); - ptrdiff_t k = 0; - for (ptrdiff_t i=0; i(list.size()); + quint32 k = 0; + for (quint32 i=0; i #include #include -#include -#include #include -#include -//This class need for validation pattern file using XSD shema -class MessageHandler : public QAbstractMessageHandler -{ -public: - MessageHandler() : QAbstractMessageHandler(0), m_messageType(QtMsgType()), m_description(QString()), - m_sourceLocation(QSourceLocation()){} - inline QString statusMessage() const {return m_description;} - inline qint64 line() const {return m_sourceLocation.line();} - inline qint64 column() const {return m_sourceLocation.column();} -protected: - virtual void handleMessage(QtMsgType type, const QString &description, - const QUrl &identifier, const QSourceLocation &sourceLocation) - { - Q_UNUSED(type); - Q_UNUSED(identifier); - - m_messageType = type; - m_description = description; - m_sourceLocation = sourceLocation; - } -private: - QtMsgType m_messageType; - QString m_description; - QSourceLocation m_sourceLocation; -}; MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainWindow), pattern(0), doc(0), tool(Tool::ArrowTool), currentScene(0), @@ -1146,56 +1118,6 @@ void MainWindow::MinimumScrollBar() verScrollBar->setValue(verScrollBar->minimum()); } -bool MainWindow::ValidatePattern(const QString &schema, const QString &fileName, QString &errorMsg, qint64 &errorLine, - qint64 &errorColumn) const -{ - errorLine = -1; - errorColumn = -1; - QFile pattern(fileName); - if (pattern.open(QIODevice::ReadOnly) == false) - { - errorMsg = QString(tr("Can't open pattern file %1:\n%2.").arg(fileName).arg(pattern.errorString())); - return false; - } - QFile fileSchema(schema); - if (fileSchema.open(QIODevice::ReadOnly) == false) - { - errorMsg = QString(tr("Can't open schema file %1:\n%2.").arg(schema).arg(fileSchema.errorString())); - return false; - } - - MessageHandler messageHandler; - QXmlSchema sch; - sch.setMessageHandler(&messageHandler); - sch.load(&fileSchema, QUrl::fromLocalFile(fileSchema.fileName())); - - bool errorOccurred = false; - if (sch.isValid() == false) - { - errorOccurred = true; - } - else - { - QXmlSchemaValidator validator(sch); - if (validator.validate(&pattern, QUrl::fromLocalFile(pattern.fileName())) == false) - { - errorOccurred = true; - } - } - - if (errorOccurred) - { - errorMsg = messageHandler.statusMessage(); - errorLine = messageHandler.line(); - errorColumn = messageHandler.column(); - return false; - } - else - { - return true; - } -} - bool MainWindow::SavePattern(const QString &fileName) { try @@ -1455,7 +1377,7 @@ void MainWindow::LoadPattern(const QString &fileName) qint64 errorColumn = 0; if (file.open(QIODevice::ReadOnly)) { - if (ValidatePattern("://schema/pattern.xsd", fileName, errorMsg, errorLine, errorColumn)) + if (VDomDocument::ValidatePattern("://schema/pattern.xsd", fileName, errorMsg, errorLine, errorColumn)) { qint32 errorLine = 0; qint32 errorColumn = 0; diff --git a/src/mainwindow.h b/src/mainwindow.h index 04c6625b4..0421cf7df 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -516,17 +516,6 @@ private: * @brief MinimumScrollBar set scroll bar to minimum. */ void MinimumScrollBar(); - /** - * @brief ValidatePattern validate pattern file by xsd schema. - * @param schema path to schema file. - * @param fileName name of pattern file. - * @param errorMsg error message. - * @param errorLine number error line. - * @param errorColumn number error column. - * @return true if validation successful. - */ - bool ValidatePattern(const QString &schema, const QString &curFile, QString &errorMsg, qint64 &errorLine, - qint64 &errorColumn) const; template /** * @brief ClosedDialog handle close dialog diff --git a/src/tools/drawTools/vtoolalongline.cpp b/src/tools/drawTools/vtoolalongline.cpp index c7c2da657..bf6abdba3 100644 --- a/src/tools/drawTools/vtoolalongline.cpp +++ b/src/tools/drawTools/vtoolalongline.cpp @@ -56,8 +56,8 @@ void VToolAlongLine::FullUpdateFromFile() { typeLine = domElement.attribute(AttrTypeLine, ""); formula = domElement.attribute(AttrLength, ""); - basePointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); - secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + basePointId = domElement.attribute(AttrFirstPoint, "").toUInt(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } RefreshGeometry(); } diff --git a/src/tools/drawTools/vtoolbisector.cpp b/src/tools/drawTools/vtoolbisector.cpp index 087ef7b2a..7208a4610 100644 --- a/src/tools/drawTools/vtoolbisector.cpp +++ b/src/tools/drawTools/vtoolbisector.cpp @@ -155,9 +155,9 @@ void VToolBisector::FullUpdateFromFile() { typeLine = domElement.attribute(AttrTypeLine, ""); formula = domElement.attribute(AttrLength, ""); - firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); - basePointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); - thirdPointId = domElement.attribute(AttrThirdPoint, "").toLongLong(); + firstPointId = domElement.attribute(AttrFirstPoint, "").toUInt(); + basePointId = domElement.attribute(AttrSecondPoint, "").toUInt(); + thirdPointId = domElement.attribute(AttrThirdPoint, "").toUInt(); } RefreshGeometry(); } diff --git a/src/tools/drawTools/vtoolcutarc.cpp b/src/tools/drawTools/vtoolcutarc.cpp index c181191b3..e34f08fef 100644 --- a/src/tools/drawTools/vtoolcutarc.cpp +++ b/src/tools/drawTools/vtoolcutarc.cpp @@ -165,7 +165,7 @@ void VToolCutArc::FullUpdateFromFile() if (domElement.isElement()) { formula = domElement.attribute(AttrLength, ""); - arcId = domElement.attribute(AttrArc, "").toLongLong(); + arcId = domElement.attribute(AttrArc, "").toUInt(); } RefreshGeometry(); } diff --git a/src/tools/drawTools/vtoolcutspline.cpp b/src/tools/drawTools/vtoolcutspline.cpp index 0debf801d..162080406 100644 --- a/src/tools/drawTools/vtoolcutspline.cpp +++ b/src/tools/drawTools/vtoolcutspline.cpp @@ -166,7 +166,7 @@ void VToolCutSpline::FullUpdateFromFile() if (domElement.isElement()) { formula = domElement.attribute(AttrLength, ""); - splineId = domElement.attribute(AttrSpline, "").toLongLong(); + splineId = domElement.attribute(AttrSpline, "").toUInt(); } RefreshGeometry(); } diff --git a/src/tools/drawTools/vtoolcutsplinepath.cpp b/src/tools/drawTools/vtoolcutsplinepath.cpp index e8ff9a8e9..92a43ddd0 100644 --- a/src/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/tools/drawTools/vtoolcutsplinepath.cpp @@ -247,7 +247,7 @@ void VToolCutSplinePath::FullUpdateFromFile() if (domElement.isElement()) { formula = domElement.attribute(AttrLength, ""); - splinePathId = domElement.attribute(AttrSplinePath, "").toLongLong(); + splinePathId = domElement.attribute(AttrSplinePath, "").toUInt(); } RefreshGeometry(); } diff --git a/src/tools/drawTools/vtoolendline.cpp b/src/tools/drawTools/vtoolendline.cpp index 2fb50a4ff..68504a32d 100644 --- a/src/tools/drawTools/vtoolendline.cpp +++ b/src/tools/drawTools/vtoolendline.cpp @@ -127,7 +127,7 @@ void VToolEndLine::FullUpdateFromFile() { typeLine = domElement.attribute(AttrTypeLine, ""); formula = domElement.attribute(AttrLength, ""); - basePointId = domElement.attribute(AttrBasePoint, "").toLongLong(); + basePointId = domElement.attribute(AttrBasePoint, "").toUInt(); angle = domElement.attribute(AttrAngle, "").toInt(); } RefreshGeometry(); diff --git a/src/tools/drawTools/vtoolheight.cpp b/src/tools/drawTools/vtoolheight.cpp index bddc198b7..9f3525cba 100644 --- a/src/tools/drawTools/vtoolheight.cpp +++ b/src/tools/drawTools/vtoolheight.cpp @@ -131,9 +131,9 @@ void VToolHeight::FullUpdateFromFile() if (domElement.isElement()) { typeLine = domElement.attribute(AttrTypeLine, ""); - basePointId = domElement.attribute(AttrBasePoint, "").toLongLong(); - p1LineId = domElement.attribute(AttrP1Line, "").toLongLong(); - p2LineId = domElement.attribute(AttrP2Line, "").toLongLong(); + basePointId = domElement.attribute(AttrBasePoint, "").toUInt(); + p1LineId = domElement.attribute(AttrP1Line, "").toUInt(); + p2LineId = domElement.attribute(AttrP2Line, "").toUInt(); } RefreshGeometry(); diff --git a/src/tools/drawTools/vtoollineintersect.cpp b/src/tools/drawTools/vtoollineintersect.cpp index 8f1aef09a..d6ec5cc8f 100644 --- a/src/tools/drawTools/vtoollineintersect.cpp +++ b/src/tools/drawTools/vtoollineintersect.cpp @@ -136,10 +136,10 @@ void VToolLineIntersect::FullUpdateFromFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - p1Line1 = domElement.attribute(AttrP1Line1, "").toLongLong(); - p2Line1 = domElement.attribute(AttrP2Line1, "").toLongLong(); - p1Line2 = domElement.attribute(AttrP1Line2, "").toLongLong(); - p2Line2 = domElement.attribute(AttrP2Line2, "").toLongLong(); + p1Line1 = domElement.attribute(AttrP1Line1, "").toUInt(); + p2Line1 = domElement.attribute(AttrP2Line1, "").toUInt(); + p1Line2 = domElement.attribute(AttrP1Line2, "").toUInt(); + p2Line2 = domElement.attribute(AttrP2Line2, "").toUInt(); } RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); } diff --git a/src/tools/drawTools/vtoolnormal.cpp b/src/tools/drawTools/vtoolnormal.cpp index 88ea3ae81..bcc9f0eb0 100644 --- a/src/tools/drawTools/vtoolnormal.cpp +++ b/src/tools/drawTools/vtoolnormal.cpp @@ -140,8 +140,8 @@ void VToolNormal::FullUpdateFromFile() { typeLine = domElement.attribute(AttrTypeLine, ""); formula = domElement.attribute(AttrLength, ""); - basePointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); - secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + basePointId = domElement.attribute(AttrFirstPoint, "").toUInt(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); angle = domElement.attribute(AttrAngle, "").toDouble(); } RefreshGeometry(); diff --git a/src/tools/drawTools/vtoolpointofcontact.cpp b/src/tools/drawTools/vtoolpointofcontact.cpp index 21b944bd3..0791d4dfd 100644 --- a/src/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/tools/drawTools/vtoolpointofcontact.cpp @@ -160,9 +160,9 @@ void VToolPointOfContact::FullUpdateFromFile() if (domElement.isElement()) { arcRadius = domElement.attribute(AttrRadius, ""); - center = domElement.attribute(AttrCenter, "").toLongLong(); - firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); - secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + center = domElement.attribute(AttrCenter, "").toUInt(); + firstPointId = domElement.attribute(AttrFirstPoint, "").toUInt(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); } diff --git a/src/tools/drawTools/vtoolpointofintersection.cpp b/src/tools/drawTools/vtoolpointofintersection.cpp index 1b1fbaac9..6744f1d6f 100644 --- a/src/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/tools/drawTools/vtoolpointofintersection.cpp @@ -111,8 +111,8 @@ void VToolPointOfIntersection::FullUpdateFromFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); - secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + firstPointId = domElement.attribute(AttrFirstPoint, "").toUInt(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); } diff --git a/src/tools/drawTools/vtoolshoulderpoint.cpp b/src/tools/drawTools/vtoolshoulderpoint.cpp index 962298b69..95ca09e19 100644 --- a/src/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/tools/drawTools/vtoolshoulderpoint.cpp @@ -162,9 +162,9 @@ void VToolShoulderPoint::FullUpdateFromFile() { typeLine = domElement.attribute(AttrTypeLine, ""); formula = domElement.attribute(AttrLength, ""); - basePointId = domElement.attribute(AttrP1Line, "").toLongLong(); - p2Line = domElement.attribute(AttrP2Line, "").toLongLong(); - pShoulder = domElement.attribute(AttrPShoulder, "").toLongLong(); + basePointId = domElement.attribute(AttrP1Line, "").toUInt(); + p2Line = domElement.attribute(AttrP2Line, "").toUInt(); + pShoulder = domElement.attribute(AttrPShoulder, "").toUInt(); } RefreshGeometry(); } diff --git a/src/tools/drawTools/vtooltriangle.cpp b/src/tools/drawTools/vtooltriangle.cpp index 8fd15aa2f..1e86786ee 100644 --- a/src/tools/drawTools/vtooltriangle.cpp +++ b/src/tools/drawTools/vtooltriangle.cpp @@ -163,10 +163,10 @@ void VToolTriangle::FullUpdateFromFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - axisP1Id = domElement.attribute(AttrAxisP1, "").toLongLong(); - axisP2Id = domElement.attribute(AttrAxisP2, "").toLongLong(); - firstPointId = domElement.attribute(AttrFirstPoint, "").toLongLong(); - secondPointId = domElement.attribute(AttrSecondPoint, "").toLongLong(); + axisP1Id = domElement.attribute(AttrAxisP1, "").toUInt(); + axisP2Id = domElement.attribute(AttrAxisP2, "").toUInt(); + firstPointId = domElement.attribute(AttrFirstPoint, "").toUInt(); + secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); } diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index 041330daf..734ebae19 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -31,6 +31,37 @@ #include "../exception/vexceptionemptyparameter.h" #include "../exception/vexceptionbadid.h" +#include +#include +#include +#include + +//This class need for validation pattern file using XSD shema +class MessageHandler : public QAbstractMessageHandler +{ +public: + MessageHandler() : QAbstractMessageHandler(0), m_messageType(QtMsgType()), m_description(QString()), + m_sourceLocation(QSourceLocation()){} + inline QString statusMessage() const {return m_description;} + inline qint64 line() const {return m_sourceLocation.line();} + inline qint64 column() const {return m_sourceLocation.column();} +protected: + virtual void handleMessage(QtMsgType type, const QString &description, + const QUrl &identifier, const QSourceLocation &sourceLocation) + { + Q_UNUSED(type); + Q_UNUSED(identifier); + + m_messageType = type; + m_description = description; + m_sourceLocation = sourceLocation; + } +private: + QtMsgType m_messageType; + QString m_description; + QSourceLocation m_sourceLocation; +}; + VDomDocument::VDomDocument(VContainer *data) : QDomDocument(), data(data), map(QHash()) { @@ -162,3 +193,53 @@ QString VDomDocument::UniqueTagText(const QString &tagName, const QString &defVa } return defVal; } + +bool VDomDocument::ValidatePattern(const QString &schema, const QString &fileName, QString &errorMsg, qint64 &errorLine, + qint64 &errorColumn) +{ + errorLine = -1; + errorColumn = -1; + QFile pattern(fileName); + if (pattern.open(QIODevice::ReadOnly) == false) + { + errorMsg = QString(tr("Can't open file %1:\n%2.").arg(fileName).arg(pattern.errorString())); + return false; + } + QFile fileSchema(schema); + if (fileSchema.open(QIODevice::ReadOnly) == false) + { + errorMsg = QString(tr("Can't open schema file %1:\n%2.").arg(schema).arg(fileSchema.errorString())); + return false; + } + + MessageHandler messageHandler; + QXmlSchema sch; + sch.setMessageHandler(&messageHandler); + sch.load(&fileSchema, QUrl::fromLocalFile(fileSchema.fileName())); + + bool errorOccurred = false; + if (sch.isValid() == false) + { + errorOccurred = true; + } + else + { + QXmlSchemaValidator validator(sch); + if (validator.validate(&pattern, QUrl::fromLocalFile(pattern.fileName())) == false) + { + errorOccurred = true; + } + } + + if (errorOccurred) + { + errorMsg = messageHandler.statusMessage(); + errorLine = messageHandler.line(); + errorColumn = messageHandler.column(); + return false; + } + else + { + return true; + } +} diff --git a/src/xml/vdomdocument.h b/src/xml/vdomdocument.h index 2b510dd66..e1a944956 100644 --- a/src/xml/vdomdocument.h +++ b/src/xml/vdomdocument.h @@ -101,6 +101,17 @@ public: */ qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const; QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const; + /** + * @brief ValidatePattern validate pattern file by xsd schema. + * @param schema path to schema file. + * @param fileName name of pattern file. + * @param errorMsg error message. + * @param errorLine number error line. + * @param errorColumn number error column. + * @return true if validation successful. + */ + static bool ValidatePattern(const QString &schema, const QString &fileName, QString &errorMsg, qint64 &errorLine, + qint64 &errorColumn); protected: /** * @brief data container with data.