diff --git a/src/dialogs/app/dialogstandardmeasurements.cpp b/src/dialogs/app/dialogstandardmeasurements.cpp index 9d84b4d1c..4d9daee79 100644 --- a/src/dialogs/app/dialogstandardmeasurements.cpp +++ b/src/dialogs/app/dialogstandardmeasurements.cpp @@ -29,9 +29,10 @@ #include "dialogstandardmeasurements.h" #include "ui_dialogstandardmeasurements.h" #include +#include "../../xml/vstandardmeasurements.h" -DialogStandardMeasurements::DialogStandardMeasurements(QWidget *parent) : - QDialog(parent), ui(new Ui::DialogStandardMeasurements), _name(QString()), _tablePath(QString()) +DialogStandardMeasurements::DialogStandardMeasurements(VContainer *data, QWidget *parent) : + QDialog(parent), ui(new Ui::DialogStandardMeasurements), data(data), _name(QString()), _tablePath(QString()) { ui->setupUi(this); @@ -70,7 +71,8 @@ QString DialogStandardMeasurements::tablePath() const void DialogStandardMeasurements::DialogAccepted() { _name = ui->lineEditName->text(); - _tablePath = "path"; + const qint32 index = ui->comboBoxTables->currentIndex(); + _tablePath = ui->comboBoxTables->itemData(index).toString(); accept(); } @@ -107,20 +109,19 @@ void DialogStandardMeasurements::CheckState() void DialogStandardMeasurements::LoadStandardTables() { #ifdef Q_OS_WIN - const QString pathToTables = QString("/standard_tables"); + const QString pathToTables = QString("/tables/standard"); #else #ifdef QT_DEBUG - const QString pathToTables = QString("/standard_tables"); + const QString pathToTables = QString("/tables/standard"); #else - const QString pathToTables = QString("/usr/share/valentina/standard_tables"); + const QString pathToTables = QString("/usr/share/valentina/tables/standard"); #endif #endif + QStringList filters; + filters << "*.vst"; QDir tablesDir(pathToTables); - { - QStringList filters; - filters << "*.cpp"; - tablesDir.setNameFilters(filters); - } + tablesDir.setNameFilters(filters); + const QStringList allFiles = tablesDir.entryList(QDir::NoDotAndDotDot | QDir::Files); if (allFiles.isEmpty() == true) { @@ -131,6 +132,36 @@ void DialogStandardMeasurements::LoadStandardTables() for (int i = 0; i < allFiles.size(); ++i) { + QFile file(allFiles.at(i)); + if (file.open(QIODevice::ReadOnly)) + { + try + { + VDomDocument::ValidatePattern("://schema/standard_measurements.xsd", allFiles.at(i)); + } + catch(VException &e) + { + qWarning()<<"Validation file error."<comboBoxTables->addItem(m.Description(), QVariant(allFiles.at(i))); + } + catch(VException &e) + { + qWarning()<<"Parsing pattern file error."< +#include "../../container/vcontainer.h" namespace Ui { @@ -40,13 +41,14 @@ class DialogStandardMeasurements : public QDialog { Q_OBJECT public: - explicit DialogStandardMeasurements(QWidget *parent = nullptr); + explicit DialogStandardMeasurements(VContainer *data, QWidget *parent = nullptr); ~DialogStandardMeasurements(); QString name() const; QString tablePath() const; private: Q_DISABLE_COPY(DialogStandardMeasurements) Ui::DialogStandardMeasurements *ui; + VContainer *data; QString _name; QString _tablePath; void DialogAccepted(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 543875485..7aaf7cb80 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -120,7 +120,7 @@ void MainWindow::ActionNewDraw() measurements.exec(); if (measurements.type() == Measurements::Standard) { - DialogStandardMeasurements stMeasurements(this); + DialogStandardMeasurements stMeasurements(pattern, this); if (stMeasurements.exec() == QDialog::Accepted) { nameDraw = stMeasurements.name(); @@ -1381,107 +1381,91 @@ MainWindow::~MainWindow() void MainWindow::LoadPattern(const QString &fileName) { QFile file(fileName); - QString errorMsg; - qint64 errorLine = 0; - qint64 errorColumn = 0; if (file.open(QIODevice::ReadOnly)) { - if (VDomDocument::ValidatePattern("://schema/pattern.xsd", fileName, errorMsg, errorLine, errorColumn)) + try { - qint32 errorLine = 0; - qint32 errorColumn = 0; - if (doc->setContent(&file, &errorMsg, &errorLine, &errorColumn)) - { - disconnect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentDrawChanged); - try - { - #ifndef QT_NO_CURSOR - QApplication::setOverrideCursor(Qt::WaitCursor); - #endif - doc->Parse(Document::FullParse, sceneDraw, sceneDetails); - #ifndef QT_NO_CURSOR - QApplication::restoreOverrideCursor(); - #endif - ui->actionPattern_properties->setEnabled(true); - } - catch (const VExceptionObjectError &e) - { - e.CriticalMessageBox(tr("Error parsing file."), this); - file.close(); - Clear(); - return; - } - catch (const VExceptionConversionError &e) - { - e.CriticalMessageBox(tr("Error can't convert value."), this); - file.close(); - Clear(); - return; - } - catch (const VExceptionEmptyParameter &e) - { - e.CriticalMessageBox(tr("Error empty parameter."), this); - file.close(); - Clear(); - return; - } - catch (const VExceptionWrongId &e) - { - e.CriticalMessageBox(tr("Error wrong id."), this); - file.close(); - Clear(); - return; - } - connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentDrawChanged); - QString nameDraw = doc->GetNameActivDraw(); - qint32 index = comboBoxDraws->findText(nameDraw); - if ( index != -1 ) - { // -1 for not found - comboBoxDraws->setCurrentIndex(index); - } - if (comboBoxDraws->count() > 0) - { - SetEnableTool(true); - } - else - { - SetEnableTool(false); - } - SetEnableWidgets(true); - } - else - { - QMessageBox msgBox(this); - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Parsing pattern file error.")); - msgBox.setInformativeText(errorMsg); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - QString error = QString(tr("Error in line %1 column %2")).arg(errorLine).arg(errorColumn); - msgBox.setDetailedText(error); - msgBox.exec(); - file.close(); - Clear(); - return; - } + VDomDocument::ValidatePattern("://schema/pattern.xsd", fileName); } - else + catch(VException &e) { - QMessageBox msgBox(this); - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Validation file error.")); - msgBox.setInformativeText(errorMsg); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - QString error = QString(tr("Error in line %1 column %2")).arg(errorLine).arg(errorColumn); - msgBox.setDetailedText(error); - msgBox.exec(); + e.CriticalMessageBox(tr("Validation file error."), this); file.close(); Clear(); return; } + + try + { + doc->setContent(&file); + } + catch(VException &e) + { + e.CriticalMessageBox(tr("Parsing pattern file error."), this); + file.close(); + Clear(); + return; + } + + disconnect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::currentDrawChanged); + try + { + #ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); + #endif + doc->Parse(Document::FullParse, sceneDraw, sceneDetails); + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif + ui->actionPattern_properties->setEnabled(true); + } + catch (const VExceptionObjectError &e) + { + e.CriticalMessageBox(tr("Error parsing file."), this); + file.close(); + Clear(); + return; + } + catch (const VExceptionConversionError &e) + { + e.CriticalMessageBox(tr("Error can't convert value."), this); + file.close(); + Clear(); + return; + } + catch (const VExceptionEmptyParameter &e) + { + e.CriticalMessageBox(tr("Error empty parameter."), this); + file.close(); + Clear(); + return; + } + catch (const VExceptionWrongId &e) + { + e.CriticalMessageBox(tr("Error wrong id."), this); + file.close(); + Clear(); + return; + } + connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::currentDrawChanged); + QString nameDraw = doc->GetNameActivDraw(); + qint32 index = comboBoxDraws->findText(nameDraw); + if ( index != -1 ) + { // -1 for not found + comboBoxDraws->setCurrentIndex(index); + } + if (comboBoxDraws->count() > 0) + { + SetEnableTool(true); + } + else + { + SetEnableTool(false); + } + SetEnableWidgets(true); + file.close(); } else diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index ea9f94dee..bff6d5c19 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -244,22 +244,27 @@ 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) +void VDomDocument::ValidatePattern(const QString &schema, const QString &fileName) { - errorLine = -1; - errorColumn = -1; + QString errorMsg; + qint64 errorLine = -1; + qint64 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; + VException e(errorMsg); + e.AddMoreInformation(tr("Error in line %1 column %2").arg(errorLine).arg(errorColumn)); + throw e; } 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; + VException e(errorMsg); + e.AddMoreInformation(tr("Error in line %1 column %2").arg(errorLine).arg(errorColumn)); + throw e; } MessageHandler messageHandler; @@ -283,14 +288,23 @@ bool VDomDocument::ValidatePattern(const QString &schema, const QString &fileNam if (errorOccurred) { - errorMsg = messageHandler.statusMessage(); - errorLine = messageHandler.line(); - errorColumn = messageHandler.column(); - return false; + VException e(messageHandler.statusMessage()); + e.AddMoreInformation(tr("Error in line %1 column %2").arg(messageHandler.line()).arg(messageHandler.column())); + throw e; } - else + +} + +void VDomDocument::setContent(QIODevice *dev) +{ + QString errorMsg; + int errorLine = 0; + int errorColumn = 0; + if (QDomDocument::setContent(dev, &errorMsg, &errorLine, &errorColumn) == false) { - return true; + VException e(errorMsg); + e.AddMoreInformation(tr("Error in line %1 column %2").arg(errorLine).arg(errorColumn)); + throw e; } } diff --git a/src/xml/vdomdocument.h b/src/xml/vdomdocument.h index 3de21dc03..e4d645dee 100644 --- a/src/xml/vdomdocument.h +++ b/src/xml/vdomdocument.h @@ -114,8 +114,8 @@ public: * @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); + static void ValidatePattern(const QString &schema, const QString &fileName); + void setContent(QIODevice * dev); protected: /** * @brief data container with data.