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 "ui_dialogstandardmeasurements.h"
#include <QDir>
#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."<<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
#include <QDialog>
#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();

View File

@ -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<void (QComboBox::*)(int)>(&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<void (QComboBox::*)(int)>(&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<void (QComboBox::*)(int)>(&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<void (QComboBox::*)(int)>(&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

View File

@ -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;
}
}

View File

@ -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.