Creation list with all tables with standard measurements.

--HG--
branch : feature
This commit is contained in:
dismine 2014-03-14 19:54:20 +02:00
parent 4d210ddd48
commit de85cad839
5 changed files with 150 additions and 119 deletions

View File

@ -29,9 +29,10 @@
#include "dialogstandardmeasurements.h" #include "dialogstandardmeasurements.h"
#include "ui_dialogstandardmeasurements.h" #include "ui_dialogstandardmeasurements.h"
#include <QDir> #include <QDir>
#include "../../xml/vstandardmeasurements.h"
DialogStandardMeasurements::DialogStandardMeasurements(QWidget *parent) : DialogStandardMeasurements::DialogStandardMeasurements(VContainer *data, QWidget *parent) :
QDialog(parent), ui(new Ui::DialogStandardMeasurements), _name(QString()), _tablePath(QString()) QDialog(parent), ui(new Ui::DialogStandardMeasurements), data(data), _name(QString()), _tablePath(QString())
{ {
ui->setupUi(this); ui->setupUi(this);
@ -70,7 +71,8 @@ QString DialogStandardMeasurements::tablePath() const
void DialogStandardMeasurements::DialogAccepted() void DialogStandardMeasurements::DialogAccepted()
{ {
_name = ui->lineEditName->text(); _name = ui->lineEditName->text();
_tablePath = "path"; const qint32 index = ui->comboBoxTables->currentIndex();
_tablePath = ui->comboBoxTables->itemData(index).toString();
accept(); accept();
} }
@ -107,20 +109,19 @@ void DialogStandardMeasurements::CheckState()
void DialogStandardMeasurements::LoadStandardTables() void DialogStandardMeasurements::LoadStandardTables()
{ {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
const QString pathToTables = QString("/standard_tables"); const QString pathToTables = QString("/tables/standard");
#else #else
#ifdef QT_DEBUG #ifdef QT_DEBUG
const QString pathToTables = QString("/standard_tables"); const QString pathToTables = QString("/tables/standard");
#else #else
const QString pathToTables = QString("/usr/share/valentina/standard_tables"); const QString pathToTables = QString("/usr/share/valentina/tables/standard");
#endif #endif
#endif #endif
QDir tablesDir(pathToTables);
{
QStringList filters; QStringList filters;
filters << "*.cpp"; filters << "*.vst";
QDir tablesDir(pathToTables);
tablesDir.setNameFilters(filters); tablesDir.setNameFilters(filters);
}
const QStringList allFiles = tablesDir.entryList(QDir::NoDotAndDotDot | QDir::Files); const QStringList allFiles = tablesDir.entryList(QDir::NoDotAndDotDot | QDir::Files);
if (allFiles.isEmpty() == true) if (allFiles.isEmpty() == true)
{ {
@ -131,6 +132,36 @@ void DialogStandardMeasurements::LoadStandardTables()
for (int i = 0; i < allFiles.size(); ++i) 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."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
continue;
}
VStandardMeasurements m(data);
try
{
m.setContent(&file);
ui->comboBoxTables->addItem(m.Description(), QVariant(allFiles.at(i)));
}
catch(VException &e)
{
qWarning()<<"Parsing pattern file error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
continue;
}
file.close();
}
else
{
qWarning()<<tr("Cannot read file %1:\n%2.").arg(allFiles.at(i)).arg(file.errorString()) << Q_FUNC_INFO;
}
} }
} }

View File

@ -30,6 +30,7 @@
#define DIALOGSTANDARDMEASUREMENTS_H #define DIALOGSTANDARDMEASUREMENTS_H
#include <QDialog> #include <QDialog>
#include "../../container/vcontainer.h"
namespace Ui namespace Ui
{ {
@ -40,13 +41,14 @@ class DialogStandardMeasurements : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DialogStandardMeasurements(QWidget *parent = nullptr); explicit DialogStandardMeasurements(VContainer *data, QWidget *parent = nullptr);
~DialogStandardMeasurements(); ~DialogStandardMeasurements();
QString name() const; QString name() const;
QString tablePath() const; QString tablePath() const;
private: private:
Q_DISABLE_COPY(DialogStandardMeasurements) Q_DISABLE_COPY(DialogStandardMeasurements)
Ui::DialogStandardMeasurements *ui; Ui::DialogStandardMeasurements *ui;
VContainer *data;
QString _name; QString _name;
QString _tablePath; QString _tablePath;
void DialogAccepted(); void DialogAccepted();

View File

@ -120,7 +120,7 @@ void MainWindow::ActionNewDraw()
measurements.exec(); measurements.exec();
if (measurements.type() == Measurements::Standard) if (measurements.type() == Measurements::Standard)
{ {
DialogStandardMeasurements stMeasurements(this); DialogStandardMeasurements stMeasurements(pattern, this);
if (stMeasurements.exec() == QDialog::Accepted) if (stMeasurements.exec() == QDialog::Accepted)
{ {
nameDraw = stMeasurements.name(); nameDraw = stMeasurements.name();
@ -1381,17 +1381,32 @@ MainWindow::~MainWindow()
void MainWindow::LoadPattern(const QString &fileName) void MainWindow::LoadPattern(const QString &fileName)
{ {
QFile file(fileName); QFile file(fileName);
QString errorMsg;
qint64 errorLine = 0;
qint64 errorColumn = 0;
if (file.open(QIODevice::ReadOnly)) if (file.open(QIODevice::ReadOnly))
{ {
if (VDomDocument::ValidatePattern("://schema/pattern.xsd", fileName, errorMsg, errorLine, errorColumn)) try
{ {
qint32 errorLine = 0; VDomDocument::ValidatePattern("://schema/pattern.xsd", fileName);
qint32 errorColumn = 0; }
if (doc->setContent(&file, &errorMsg, &errorLine, &errorColumn)) catch(VException &e)
{ {
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<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &MainWindow::currentDrawChanged); this, &MainWindow::currentDrawChanged);
try try
@ -1450,38 +1465,7 @@ void MainWindow::LoadPattern(const QString &fileName)
SetEnableTool(false); SetEnableTool(false);
} }
SetEnableWidgets(true); 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;
}
}
else
{
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();
file.close();
Clear();
return;
}
file.close(); file.close();
} }
else else

View File

@ -244,22 +244,27 @@ QString VDomDocument::UniqueTagText(const QString &tagName, const QString &defVa
return defVal; return defVal;
} }
bool VDomDocument::ValidatePattern(const QString &schema, const QString &fileName, QString &errorMsg, qint64 &errorLine, void VDomDocument::ValidatePattern(const QString &schema, const QString &fileName)
qint64 &errorColumn)
{ {
errorLine = -1; QString errorMsg;
errorColumn = -1; qint64 errorLine = -1;
qint64 errorColumn = -1;
QFile pattern(fileName); QFile pattern(fileName);
if (pattern.open(QIODevice::ReadOnly) == false) if (pattern.open(QIODevice::ReadOnly) == false)
{ {
errorMsg = QString(tr("Can't open file %1:\n%2.").arg(fileName).arg(pattern.errorString())); 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); QFile fileSchema(schema);
if (fileSchema.open(QIODevice::ReadOnly) == false) if (fileSchema.open(QIODevice::ReadOnly) == false)
{ {
errorMsg = QString(tr("Can't open schema file %1:\n%2.").arg(schema).arg(fileSchema.errorString())); 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; MessageHandler messageHandler;
@ -283,14 +288,23 @@ bool VDomDocument::ValidatePattern(const QString &schema, const QString &fileNam
if (errorOccurred) if (errorOccurred)
{ {
errorMsg = messageHandler.statusMessage(); VException e(messageHandler.statusMessage());
errorLine = messageHandler.line(); e.AddMoreInformation(tr("Error in line %1 column %2").arg(messageHandler.line()).arg(messageHandler.column()));
errorColumn = messageHandler.column(); throw e;
return false;
} }
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;
} }
} }

View File

@ -114,8 +114,8 @@ public:
* @param errorColumn number error column. * @param errorColumn number error column.
* @return true if validation successful. * @return true if validation successful.
*/ */
static bool ValidatePattern(const QString &schema, const QString &fileName, QString &errorMsg, qint64 &errorLine, static void ValidatePattern(const QString &schema, const QString &fileName);
qint64 &errorColumn); void setContent(QIODevice * dev);
protected: protected:
/** /**
* @brief data container with data. * @brief data container with data.