Test unique id.

--HG--
branch : develop
This commit is contained in:
dismine 2013-10-07 12:13:24 +03:00
parent 565c697a44
commit 296a9e5e93
9 changed files with 99 additions and 19 deletions

View File

@ -95,7 +95,8 @@ SOURCES += main.cpp\
exception/vexceptionconversionerror.cpp \ exception/vexceptionconversionerror.cpp \
exception/vexceptionemptyparameter.cpp \ exception/vexceptionemptyparameter.cpp \
exception/vexceptionobjecterror.cpp \ exception/vexceptionobjecterror.cpp \
widgets/vapplication.cpp widgets/vapplication.cpp \
exception/vexceptionuniqueid.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
widgets/vmaingraphicsscene.h \ widgets/vmaingraphicsscene.h \
@ -185,7 +186,8 @@ HEADERS += mainwindow.h \
exception/vexceptionconversionerror.h \ exception/vexceptionconversionerror.h \
exception/vexceptionemptyparameter.h \ exception/vexceptionemptyparameter.h \
exception/vexceptionobjecterror.h \ exception/vexceptionobjecterror.h \
widgets/vapplication.h widgets/vapplication.h \
exception/vexceptionuniqueid.h
FORMS += mainwindow.ui \ FORMS += mainwindow.ui \
dialogs/dialogsinglepoint.ui \ dialogs/dialogsinglepoint.ui \

View File

@ -27,10 +27,8 @@ VExceptionEmptyParameter::VExceptionEmptyParameter(const QString &what, const QS
name(name), tagText(QString()), tagName(QString()), lineNumber(-1){ name(name), tagText(QString()), tagName(QString()), lineNumber(-1){
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "Parameter name is empty"); Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "Parameter name is empty");
if(domElement.isText()){ QTextStream stream(&tagText);
QDomText text = domElement.toText(); domElement.save(stream, 4);
tagText = text.data();
}
tagName = domElement.tagName(); tagName = domElement.tagName();
lineNumber = domElement.lineNumber(); lineNumber = domElement.lineNumber();
} }

View File

@ -25,10 +25,8 @@
VExceptionObjectError::VExceptionObjectError(const QString &what, const QDomElement &domElement): VExceptionObjectError::VExceptionObjectError(const QString &what, const QDomElement &domElement):
VException(what), tagText(QString()), tagName(QString()), lineNumber(-1), moreInfo(QString()){ VException(what), tagText(QString()), tagName(QString()), lineNumber(-1), moreInfo(QString()){
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
if(domElement.isText()){ QTextStream stream(&tagText);
QDomText text = domElement.toText(); domElement.save(stream, 4);
tagText = text.data();
}
tagName = domElement.tagName(); tagName = domElement.tagName();
lineNumber = domElement.lineNumber(); lineNumber = domElement.lineNumber();
} }

View File

@ -0,0 +1,21 @@
#include "vexceptionuniqueid.h"
#include <QTextStream>
VExceptionUniqueId::VExceptionUniqueId(const QString &what, const QDomElement &domElement)
:VException(what), tagText(QString()), tagName(QString()), lineNumber(-1){
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
QTextStream stream(&tagText);
domElement.save(stream, 4);
tagName = domElement.tagName();
lineNumber = domElement.lineNumber();
}
QString VExceptionUniqueId::ErrorMessage() const{
QString error = QString("ExceptionUniqueId: %1").arg(what);
return error;
}
QString VExceptionUniqueId::DetailedInformation() const{
QString detail = QString("tag: %1 in line %2\nFull tag:\n%3").arg(tagName).arg(lineNumber).arg(tagText);
return detail;
}

View File

@ -0,0 +1,24 @@
#ifndef VEXCEPTIONUNIQUEID_H
#define VEXCEPTIONUNIQUEID_H
#include "vexception.h"
#include <QDomElement>
class VExceptionUniqueId : public VException{
public:
VExceptionUniqueId(const QString &what, const QDomElement &domElement);
VExceptionUniqueId(const VExceptionUniqueId &e):VException(e), tagText(e.TagText()),
tagName(e.TagName()), lineNumber(e.LineNumber()){}
virtual ~VExceptionUniqueId() noexcept(true){}
virtual QString ErrorMessage() const;
virtual QString DetailedInformation() const;
QString TagText() const {return tagText;}
QString TagName() const {return tagName;}
qint32 LineNumber() const {return lineNumber;}
protected:
QString tagText;
QString tagName;
qint32 lineNumber;
};
#endif // VEXCEPTIONUNIQUEID_H

View File

@ -25,10 +25,8 @@
VExceptionWrongParameterId::VExceptionWrongParameterId(const QString &what, const QDomElement &domElement): VExceptionWrongParameterId::VExceptionWrongParameterId(const QString &what, const QDomElement &domElement):
VException(what), tagText(QString()), tagName(QString()), lineNumber(-1){ VException(what), tagText(QString()), tagName(QString()), lineNumber(-1){
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
if(domElement.isText()){ QTextStream stream(&tagText);
QDomText text = domElement.toText(); domElement.save(stream, 4);
tagText = text.data();
}
tagName = domElement.tagName(); tagName = domElement.tagName();
lineNumber = domElement.lineNumber(); lineNumber = domElement.lineNumber();
} }

View File

@ -35,6 +35,7 @@
#include "exception/vexceptionconversionerror.h" #include "exception/vexceptionconversionerror.h"
#include "exception/vexceptionemptyparameter.h" #include "exception/vexceptionemptyparameter.h"
#include "exception/vexceptionwrongparameterid.h" #include "exception/vexceptionwrongparameterid.h"
#include "exception/vexceptionuniqueid.h"
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow), tool(Tool::ArrowTool), currentScene(0), sceneDraw(0), QMainWindow(parent), ui(new Ui::MainWindow), tool(Tool::ArrowTool), currentScene(0), sceneDraw(0),
@ -1011,7 +1012,7 @@ void MainWindow::OpenPattern(const QString &fileName){
if(file.open(QIODevice::ReadOnly)){ if(file.open(QIODevice::ReadOnly)){
if(doc->setContent(&file, &errorMsg, &errorLine, &errorColumn)){ if(doc->setContent(&file, &errorMsg, &errorLine, &errorColumn)){
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged); this, &MainWindow::currentDrawChanged);
try{ try{
doc->Parse(Document::FullParse, sceneDraw, sceneDetails); doc->Parse(Document::FullParse, sceneDraw, sceneDetails);
} }
@ -1070,6 +1071,20 @@ void MainWindow::OpenPattern(const QString &fileName){
Clear(); Clear();
return; return;
} }
catch(const VExceptionUniqueId &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error don't unique id."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setDetailedText(e.DetailedInformation());
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
file.close();
Clear();
return;
}
connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), connect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged); this, &MainWindow::currentDrawChanged);
QString nameDraw = doc->GetNameActivDraw(); QString nameDraw = doc->GetNameActivDraw();

View File

@ -33,7 +33,7 @@
#include "exception/vexceptionemptyparameter.h" #include "exception/vexceptionemptyparameter.h"
#include "exception/vexceptionbadid.h" #include "exception/vexceptionbadid.h"
#include "exception/vexceptionobjecterror.h" #include "exception/vexceptionobjecterror.h"
#include "exception/vexceptionuniqueid.h"
VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode) : QDomDocument(), VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode) : QDomDocument(),
map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data),
@ -255,6 +255,7 @@ void VDomDocument::Parse(Document::Documents parse, VMainGraphicsScene *sceneDra
Q_CHECK_PTR(sceneDraw); Q_CHECK_PTR(sceneDraw);
Q_CHECK_PTR(sceneDetail); Q_CHECK_PTR(sceneDetail);
if(parse == Document::FullParse){ if(parse == Document::FullParse){
TestUniqueId();
data->Clear(); data->Clear();
nameActivDraw.clear(); nameActivDraw.clear();
sceneDraw->clear(); sceneDraw->clear();
@ -370,6 +371,28 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri
return param; return param;
} }
void VDomDocument::TestUniqueId() const{
QVector<qint64> vector;
CollectId(this->documentElement(), vector);
}
void VDomDocument::CollectId(QDomElement node, QVector<qint64> &vector) const{
if (node.hasAttribute("id")) {
qint64 id = GetParametrId(node);
if(vector.contains(id)){
throw VExceptionUniqueId(tr("This id is not unique."), node);
}
vector.append(id);
}
for (qint32 i=0; i<node.childNodes().length(); ++i) {
QDomNode n = node.childNodes().at(i);
if (n.isElement()) {
CollectId(n.toElement(), vector);
}
}
}
void VDomDocument::ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, void VDomDocument::ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
const QDomNode& node, const Document::Documents &parse){ const QDomNode& node, const Document::Documents &parse){
QDomNode domNode = node.firstChild(); QDomNode domNode = node.firstChild();

View File

@ -37,8 +37,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Document::Documents)
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++" #pragma GCC diagnostic ignored "-Weffc++"
class VDomDocument : public QObject, public QDomDocument class VDomDocument : public QObject, public QDomDocument{
{
Q_OBJECT Q_OBJECT
public: public:
VDomDocument(VContainer *data,QComboBox *comboBoxDraws, Draw::Draws *mode); VDomDocument(VContainer *data,QComboBox *comboBoxDraws, Draw::Draws *mode);
@ -112,7 +111,9 @@ private:
qint64 GetParametrId(const QDomElement& domElement) const; qint64 GetParametrId(const QDomElement& domElement) const;
qint64 GetParametrLongLong(const QDomElement& domElement, const QString &name) const; qint64 GetParametrLongLong(const QDomElement& domElement, const QString &name) const;
QString GetParametrString(const QDomElement& domElement, const QString &name) const; QString GetParametrString(const QDomElement& domElement, const QString &name) const;
qreal GetParametrDouble(const QDomElement& domElement, const QString &name) const; qreal GetParametrDouble(const QDomElement& domElement, const QString &name) const;
void TestUniqueId() const;
void CollectId(QDomElement node, QVector<qint64> &vector)const;
}; };
#pragma GCC diagnostic pop #pragma GCC diagnostic pop