Opening empty pattern.

--HG--
branch : feature
This commit is contained in:
dismine 2014-03-24 17:02:57 +02:00
parent c2bb84ce38
commit 54cca86be5
17 changed files with 342 additions and 340 deletions

View File

@ -89,13 +89,13 @@ CONFIG(debug, debug|release){
} }
} else { } else {
*-g++{#Don't use additional GCC keys on Windows system. *-g++{#Don't use additional GCC keys on Windows system.
QMAKE_CXXFLAGS += -Og -Wall -Wextra -pedantic QMAKE_CXXFLAGS += -O0 -Wall -Wextra -pedantic
} }
} }
}else{ }else{
# Release # Release
*-g++{ *-g++{
QMAKE_CXXFLAGS += -O1 QMAKE_CXXFLAGS += -O2
} }
DEFINES += QT_NO_DEBUG_OUTPUT DEFINES += QT_NO_DEBUG_OUTPUT

View File

@ -7,6 +7,13 @@
<xs:element name="author" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element> <xs:element name="author" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="description" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element> <xs:element name="description" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="notes" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element> <xs:element name="notes" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="measurements" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="type" type="xs:string" use="required"></xs:attribute>
<xs:attribute name="path" type="xs:string" use="required"></xs:attribute>
<xs:attribute name="unit" type="xs:string" use="required"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="increments" minOccurs="0" maxOccurs="1"> <xs:element name="increments" minOccurs="0" maxOccurs="1">
<xs:complexType> <xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded"> <xs:sequence minOccurs="0" maxOccurs="unbounded">

View File

@ -91,38 +91,18 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
if (qApp->patternType() == Pattern::Individual) if (qApp->patternType() == Pattern::Individual)
{ {
QString filePath = doc->MPath(); QString filePath = doc->MPath();
QFile file(filePath);
if (file.open(QIODevice::ReadOnly))
{
try try
{ {
VDomDocument::ValidatePattern("://schema/individual_measurements.xsd", filePath); VDomDocument::ValidateXML("://schema/individual_measurements.xsd", filePath);
}
catch(VException &e)
{
qWarning()<<"Validation file error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
emit DialogClosed(QDialog::Rejected);
return;
}
m = new VIndividualMeasurements(data); m = new VIndividualMeasurements(data);
try m->setContent(filePath);
{
m->setContent(&file);
} }
catch(VException &e) catch(VException &e)
{ {
qWarning()<<"Parsing measurements file error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO; qWarning()<<"File error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
emit DialogClosed(QDialog::Rejected); emit DialogClosed(QDialog::Rejected);
return; return;
} }
file.close();
}
else
{
qWarning()<<tr("Cannot read file %1:\n%2.").arg(filePath).arg(file.errorString()) << Q_FUNC_INFO;
}
} }
} }

View File

@ -95,43 +95,19 @@ void DialogIndividualMeasurements::DialogAccepted()
return; return;
} }
} }
QFile file(_tablePath);
if (file.open(QIODevice::ReadOnly))
{
try try
{ {
VDomDocument::ValidatePattern("://schema/individual_measurements.xsd", _tablePath); VDomDocument::ValidateXML("://schema/individual_measurements.xsd", _tablePath);
}
catch(VException &e)
{
e.CriticalMessageBox(tr("Validation file error."), this);
qWarning()<<"Validation file error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
return;
}
VIndividualMeasurements m(data); VIndividualMeasurements m(data);
try m.setContent(_tablePath);
{
m.setContent(&file);
qApp->setPatternUnit( m.Unit()); qApp->setPatternUnit( m.Unit());
} }
catch(VException &e) catch(VException &e)
{ {
e.CriticalMessageBox(tr("Parsing pattern file error."), this); e.CriticalMessageBox(tr("File error."), this);
qWarning()<<"Parsing pattern file error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO; qWarning()<<"File error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
return; return;
} }
file.close();
}
else
{
QString message = tr("Cannot read file %1:\n%2.").arg(_tablePath).arg(file.errorString());
QMessageBox::warning(this, tr("Cannot read file"), message);
qWarning()<<tr("Cannot read file %1:\n%2.").arg(_tablePath).arg(file.errorString()) << Q_FUNC_INFO;
return;
}
accept(); accept();
} }
@ -214,38 +190,19 @@ void DialogIndividualMeasurements::LoadIndividualTables()
for (int i = 0; i < allFiles.size(); ++i) for (int i = 0; i < allFiles.size(); ++i)
{ {
QFileInfo fi(allFiles.at(i)); QFileInfo fi(allFiles.at(i));
QFile file(allFiles.at(i));
if (file.open(QIODevice::ReadOnly))
{
try try
{ {
VDomDocument::ValidatePattern("://schema/individual_measurements.xsd", fi.absoluteFilePath()); VDomDocument::ValidateXML("://schema/individual_measurements.xsd", fi.absoluteFilePath());
}
catch(VException &e)
{
qWarning()<<"Validation file error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
continue;
}
VIndividualMeasurements m(data); VIndividualMeasurements m(data);
try m.setContent(fi.absoluteFilePath());
{
m.setContent(&file);
const QString lang = QLocale(m.Language()).nativeLanguageName(); const QString lang = QLocale(m.Language()).nativeLanguageName();
ui->comboBoxLang->addItem(lang, QVariant(fi.absoluteFilePath())); ui->comboBoxLang->addItem(lang, QVariant(fi.absoluteFilePath()));
} }
catch(VException &e) catch(VException &e)
{ {
qWarning()<<"Parsing pattern file error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO; qWarning()<<"File error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
continue; continue;
} }
file.close();
}
else
{
qWarning()<<tr("Cannot read file %1:\n%2.").arg(fi.absoluteFilePath()).arg(file.errorString())<<Q_FUNC_INFO;
}
} }
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName()); QApplication::applicationName());
@ -267,24 +224,13 @@ void DialogIndividualMeasurements::OpenTable()
{ {
const QString filter(tr("Individual measurements (*.vit)")); const QString filter(tr("Individual measurements (*.vit)"));
QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter); QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter);
QFile file(fileName);
if (file.open(QIODevice::ReadOnly))
{
try try
{ {
VDomDocument::ValidatePattern("://schema/individual_measurements.xsd", fileName); VDomDocument::ValidateXML("://schema/individual_measurements.xsd", fileName);
} }
catch(VException &e) catch(VException &e)
{ {
e.CriticalMessageBox(tr("Validation file error."), this); e.CriticalMessageBox(tr("File error."), this);
fileName.clear();
}
file.close();
}
else
{
QMessageBox::warning(this, tr("Valentina"), tr("Cannot read file %1:\n%2.").arg(fileName)
.arg(file.errorString()));
fileName.clear(); fileName.clear();
} }
ui->lineEditPathExistM->setText(fileName); ui->lineEditPathExistM->setText(fileName);

View File

@ -77,40 +77,18 @@ void DialogStandardMeasurements::DialogAccepted()
_name = ui->lineEditName->text(); _name = ui->lineEditName->text();
const qint32 index = ui->comboBoxTables->currentIndex(); const qint32 index = ui->comboBoxTables->currentIndex();
_tablePath = ui->comboBoxTables->itemData(index).toString(); _tablePath = ui->comboBoxTables->itemData(index).toString();
QFile file(_tablePath);
if (file.open(QIODevice::ReadOnly))
{
try
{
VDomDocument::ValidatePattern("://schema/standard_measurements.xsd", _tablePath);
}
catch(VException &e)
{
e.CriticalMessageBox(tr("Validation file error."), this);
qWarning()<<"Validation file error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
return;
}
VStandardMeasurements m(data);
try try
{ {
m.setContent(&file); VDomDocument::ValidateXML("://schema/standard_measurements.xsd", _tablePath);
VStandardMeasurements m(data);
m.setContent(_tablePath);
qApp->setPatternUnit(m.Unit()); qApp->setPatternUnit(m.Unit());
} }
catch(VException &e) catch(VException &e)
{ {
e.CriticalMessageBox(tr("Parsing pattern file error."), this); e.CriticalMessageBox(tr("File error."), this);
qWarning()<<"Parsing pattern file error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO; qWarning()<<"File error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
return;
}
file.close();
}
else
{
QString message = tr("Cannot read file %1:\n%2.").arg(_tablePath).arg(file.errorString());
QMessageBox::warning(this, tr("Cannot read file"), message);
qWarning()<<tr("Cannot read file %1:\n%2.").arg(_tablePath).arg(file.errorString()) << Q_FUNC_INFO;
return; return;
} }
@ -166,36 +144,17 @@ void DialogStandardMeasurements::LoadStandardTables()
for (int i = 0; i < allFiles.size(); ++i) for (int i = 0; i < allFiles.size(); ++i)
{ {
QFileInfo fi(allFiles.at(i)); QFileInfo fi(allFiles.at(i));
QFile file(allFiles.at(i));
if (file.open(QIODevice::ReadOnly))
{
try try
{ {
VDomDocument::ValidatePattern("://schema/standard_measurements.xsd", fi.absoluteFilePath()); VDomDocument::ValidateXML("://schema/standard_measurements.xsd", fi.absoluteFilePath());
}
catch(VException &e)
{
qWarning()<<"Validation file error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
continue;
}
VStandardMeasurements m(data); VStandardMeasurements m(data);
try m.setContent(fi.absoluteFilePath());
{
m.setContent(&file);
ui->comboBoxTables->addItem(m.Description(), QVariant(fi.absoluteFilePath())); ui->comboBoxTables->addItem(m.Description(), QVariant(fi.absoluteFilePath()));
} }
catch(VException &e) catch(VException &e)
{ {
qWarning()<<"Parsing pattern file error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO; qWarning()<<"File error."<<e.ErrorMessage()<<e.DetailedInformation()<<Q_FUNC_INFO;
continue; continue;
} }
file.close();
}
else
{
qWarning()<<tr("Cannot read file %1:\n%2.").arg(fi.absoluteFilePath()).arg(file.errorString()) << Q_FUNC_INFO;
}
} }
} }

View File

@ -50,12 +50,12 @@ QString VException::ErrorMessage() const
void VException::CriticalMessageBox(const QString &situation, QWidget * parent) const void VException::CriticalMessageBox(const QString &situation, QWidget * parent) const
{ {
QMessageBox msgBox(parent); QMessageBox msgBox(parent);
msgBox.setWindowTitle("Critical error!"); msgBox.setWindowTitle(tr("Critical error!"));
msgBox.setText(situation); msgBox.setText(situation);
msgBox.setInformativeText(ErrorMessage()); msgBox.setInformativeText(ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok);
if (DetailedInformation().isEmpty() == false) if (moreInfo.isEmpty() == false)
{ {
msgBox.setDetailedText(DetailedInformation()); msgBox.setDetailedText(DetailedInformation());
} }

View File

@ -39,6 +39,7 @@
*/ */
class VException : public QException class VException : public QException
{ {
Q_DECLARE_TR_FUNCTIONS(VException)
public: public:
/** /**
* @brief VException constructor exception * @brief VException constructor exception

View File

@ -35,6 +35,7 @@
#include "exception/vexceptionemptyparameter.h" #include "exception/vexceptionemptyparameter.h"
#include "exception/vexceptionwrongid.h" #include "exception/vexceptionwrongid.h"
#include "version.h" #include "version.h"
#include "xml/vstandardmeasurements.h"
#include <QInputDialog> #include <QInputDialog>
#include <QtCore> #include <QtCore>
@ -55,7 +56,6 @@ MainWindow::MainWindow(QWidget *parent)
{ {
CreateActions(); CreateActions();
CreateMenus(); CreateMenus();
ToolBarOption();
ToolBarDraws(); ToolBarDraws();
sceneDraw = new VMainGraphicsScene(); sceneDraw = new VMainGraphicsScene();
@ -542,39 +542,36 @@ void MainWindow::closeEvent(QCloseEvent *event)
void MainWindow::ToolBarOption() void MainWindow::ToolBarOption()
{ {
QLabel * labelGrowth = new QLabel; if (qApp->patternType() == Pattern::Standard)
labelGrowth->setText(tr("Height: ")); {
ui->toolBarOption->addWidget(labelGrowth); ui->toolBarOption->addWidget(new QLabel(tr("Height: ")));
QStringList list; QStringList list;
list <<"92"<<"98"<<"104"<<"110"<<"116"<<"122"<<"128"<<"134"<<"140"<<"146"<<"152"<<"158"<<"164"<<"170"<<"176" list <<"92"<<"98"<<"104"<<"110"<<"116"<<"122"<<"128"<<"134"<<"140"<<"146"<<"152"<<"158"<<"164"<<"170"<<"176"
<<"182"<<"188"; <<"182"<<"188";
QComboBox *comboBoxGrow = new QComboBox; QComboBox *comboBoxHeight = new QComboBox;
comboBoxGrow->clear(); comboBoxHeight->addItems(list);
comboBoxGrow->addItems(list); comboBoxHeight->setCurrentIndex(14);//176
comboBoxGrow->setCurrentIndex(14); ui->toolBarOption->addWidget(comboBoxHeight);
ui->toolBarOption->addWidget(comboBoxGrow); connect(comboBoxHeight, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
connect(comboBoxGrow, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedHeight); this, &MainWindow::ChangedHeight);
QLabel * labelSize = new QLabel; ui->toolBarOption->addWidget(new QLabel(tr(" Size: ")));
labelSize->setText(tr(" Size: "));
ui->toolBarOption->addWidget(labelSize);
list.clear(); list.clear();
list <<"22"<<"24"<<"26"<<"28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50"<<"52"<<"54"<<"56"; list <<"22"<<"24"<<"26"<<"28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50"<<"52"<<"54"
<<"56";
QComboBox *comboBoxSize = new QComboBox; QComboBox *comboBoxSize = new QComboBox;
comboBoxSize->clear();
comboBoxSize->addItems(list); comboBoxSize->addItems(list);
comboBoxSize->setCurrentIndex(14); comboBoxSize->setCurrentIndex(14);//50
ui->toolBarOption->addWidget(comboBoxSize); ui->toolBarOption->addWidget(comboBoxSize);
connect(comboBoxSize, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged), connect(comboBoxSize, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedSize); this, &MainWindow::ChangedSize);
ui->toolBarOption->addSeparator(); ui->toolBarOption->addSeparator();
}
mouseCoordinate = new QLabel; mouseCoordinate = new QLabel("0, 0");
mouseCoordinate ->setText("0, 0");
ui->toolBarOption->addWidget(mouseCoordinate); ui->toolBarOption->addWidget(mouseCoordinate);
} }
@ -626,10 +623,12 @@ void MainWindow::currentDrawChanged( int index )
void MainWindow::mouseMove(const QPointF &scenePos) void MainWindow::mouseMove(const QPointF &scenePos)
{ {
QString string = QString("%1, %2") QString string = QString("%1, %2").arg(static_cast<qint32>(qApp->fromPixel(scenePos.x())))
.arg(static_cast<qint32>(qApp->fromPixel(scenePos.x())))
.arg(static_cast<qint32>(qApp->fromPixel(scenePos.y()))); .arg(static_cast<qint32>(qApp->fromPixel(scenePos.y())));
if (mouseCoordinate != nullptr)
{
mouseCoordinate->setText(string); mouseCoordinate->setText(string);
}
} }
void MainWindow::CancelTool() void MainWindow::CancelTool()
@ -953,6 +952,9 @@ void MainWindow::Clear()
ui->actionSave->setEnabled(false); ui->actionSave->setEnabled(false);
ui->actionPattern_properties->setEnabled(false); ui->actionPattern_properties->setEnabled(false);
SetEnableTool(false); SetEnableTool(false);
qApp->setPatternUnit(Valentina::Cm);
qApp->setPatternType(Pattern::Individual);
ui->toolBarOption->clear();
#ifndef QT_NO_CURSOR #ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
#endif #endif
@ -1386,29 +1388,55 @@ MainWindow::~MainWindow()
void MainWindow::LoadPattern(const QString &fileName) void MainWindow::LoadPattern(const QString &fileName)
{ {
QFile file(fileName);
if (file.open(QIODevice::ReadOnly))
{
try try
{ {
VDomDocument::ValidatePattern("://schema/pattern.xsd", fileName); VDomDocument::ValidateXML("://schema/pattern.xsd", fileName);
} doc->setContent(fileName);
catch(VException &e)
qApp->setPatternUnit(doc->MUnit());
qApp->setPatternType(doc->MType());
QString path = doc->MPath();
path = CheckPathToMeasurements(path, qApp->patternType());
if(path.isEmpty())
{ {
e.CriticalMessageBox(tr("Validation file error."), this);
file.close();
Clear(); Clear();
return; return;
} }
try QString text = tr("Measurements use different units than pattern. This pattern required measurements in %1")
.arg(doc->UnitsToStr(qApp->patternUnit()));
if (qApp->patternType() == Pattern::Standard)
{ {
doc->setContent(&file); VStandardMeasurements m(pattern);
m.setContent(path);
Valentina::Units mUnit = m.Unit();
if (qApp->patternUnit() != mUnit)
{
QMessageBox::critical(this, tr("Wrong units."), text);
Clear();
return;
}
m.SetSize();
m.SetHeight();
ToolBarOption();
}
else
{
VIndividualMeasurements m(pattern);
m.setContent(path);
Valentina::Units mUnit = m.Unit();
if (qApp->patternUnit() != mUnit)
{
QMessageBox::critical(this, tr("Wrong units."), text);
Clear();
return;
}
}
} }
catch(VException &e) catch(VException &e)
{ {
e.CriticalMessageBox(tr("Parsing pattern file error."), this); e.CriticalMessageBox(tr("File error."), this);
file.close();
Clear(); Clear();
return; return;
} }
@ -1420,7 +1448,9 @@ void MainWindow::LoadPattern(const QString &fileName)
#ifndef QT_NO_CURSOR #ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
#endif #endif
doc->Parse(Document::FullParse, sceneDraw, sceneDetails); doc->Parse(Document::FullParse, sceneDraw, sceneDetails);
#ifndef QT_NO_CURSOR #ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
#endif #endif
@ -1429,28 +1459,24 @@ void MainWindow::LoadPattern(const QString &fileName)
catch (const VExceptionObjectError &e) catch (const VExceptionObjectError &e)
{ {
e.CriticalMessageBox(tr("Error parsing file."), this); e.CriticalMessageBox(tr("Error parsing file."), this);
file.close();
Clear(); Clear();
return; return;
} }
catch (const VExceptionConversionError &e) catch (const VExceptionConversionError &e)
{ {
e.CriticalMessageBox(tr("Error can't convert value."), this); e.CriticalMessageBox(tr("Error can't convert value."), this);
file.close();
Clear(); Clear();
return; return;
} }
catch (const VExceptionEmptyParameter &e) catch (const VExceptionEmptyParameter &e)
{ {
e.CriticalMessageBox(tr("Error empty parameter."), this); e.CriticalMessageBox(tr("Error empty parameter."), this);
file.close();
Clear(); Clear();
return; return;
} }
catch (const VExceptionWrongId &e) catch (const VExceptionWrongId &e)
{ {
e.CriticalMessageBox(tr("Error wrong id."), this); e.CriticalMessageBox(tr("Error wrong id."), this);
file.close();
Clear(); Clear();
return; return;
} }
@ -1472,14 +1498,55 @@ void MainWindow::LoadPattern(const QString &fileName)
} }
SetEnableWidgets(true); SetEnableWidgets(true);
file.close();
}
else
{
QMessageBox::warning(this, tr("Valentina"), tr("Cannot read file %1:\n%2.")
.arg(fileName)
.arg(file.errorString()));
}
setCurrentFile(fileName); setCurrentFile(fileName);
helpLabel->setText(tr("File loaded")); helpLabel->setText(tr("File loaded"));
} }
QString MainWindow::CheckPathToMeasurements(const QString &path, const Pattern::Measurements &patternType)
{
QFile table(path);
if (table.exists() == false)
{
QString text = tr("The measurements file <br/><br/> <b>%1</b> <br/><br/> %3").arg(path)
.arg(tr("could not be found. Do you want to update the file location"));
QMessageBox::StandardButton res = QMessageBox::question(this, "Loading measurements file", text,
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes);
if(res == QMessageBox::No)
{
return QString();
}
else
{
QString filter;
if (patternType == Pattern::Standard)
{
filter = tr("Standard measurements (*.vst)");
}
else
{
filter = tr("Individual measurements (*.vit)");
}
QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter);
if(mPath.isEmpty())
{
return mPath;
}
else
{
if (patternType == Pattern::Standard)
{
VDomDocument::ValidateXML("://schema/standard_measurements.xsd", mPath);
}
else
{
VDomDocument::ValidateXML("://schema/individual_measurements.xsd", mPath);
}
doc->SetPath(mPath);
return mPath;
}
}
}
return path;
}

View File

@ -562,6 +562,7 @@ private:
void CreateActions(); void CreateActions();
void InitAutoSave(); void InitAutoSave();
QString PatternPieceName(const QString &text); QString PatternPieceName(const QString &text);
QString CheckPathToMeasurements(const QString &path, const Pattern::Measurements &patternType);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -92,7 +92,7 @@ namespace Valentina
/** /**
* @brief The Unit enum * @brief The Unit enum
*/ */
enum Unit { Mm, Cm, In }; enum Unit { Mm, Cm, Inch };
Q_DECLARE_FLAGS(Units, Unit) Q_DECLARE_FLAGS(Units, Unit)
} }
Q_DECLARE_OPERATORS_FOR_FLAGS( Valentina::Scenes ) Q_DECLARE_OPERATORS_FOR_FLAGS( Valentina::Scenes )

View File

@ -99,7 +99,7 @@ double VApplication::toPixel(double unit) const
case Valentina::Cm: case Valentina::Cm:
result = ((unit * 10.0) / 25.4) * PrintDPI; result = ((unit * 10.0) / 25.4) * PrintDPI;
break; break;
case Valentina::In: case Valentina::Inch:
result = unit * PrintDPI; result = unit * PrintDPI;
break; break;
default: default:
@ -119,7 +119,7 @@ double VApplication::fromPixel(double pix) const
case Valentina::Cm: case Valentina::Cm:
result = ((pix / PrintDPI) * 25.4) / 10.0; result = ((pix / PrintDPI) * 25.4) / 10.0;
break; break;
case Valentina::In: case Valentina::Inch:
result = pix / PrintDPI; result = pix / PrintDPI;
break; break;
default: default:

View File

@ -81,7 +81,7 @@ const QString VDomDocument::AttrId = QStringLiteral("id");
const QString VDomDocument::AttrUnit = QStringLiteral("unit"); const QString VDomDocument::AttrUnit = QStringLiteral("unit");
const QString VDomDocument::UnitMM = QStringLiteral("mm"); const QString VDomDocument::UnitMM = QStringLiteral("mm");
const QString VDomDocument::UnitCM = QStringLiteral("cm"); const QString VDomDocument::UnitCM = QStringLiteral("cm");
const QString VDomDocument::UnitIN = QStringLiteral("in"); const QString VDomDocument::UnitINCH = QStringLiteral("inch");
VDomDocument::VDomDocument(VContainer *data) VDomDocument::VDomDocument(VContainer *data)
: QDomDocument(), data(data), map(QHash<QString, QDomElement>()) : QDomDocument(), data(data), map(QHash<QString, QDomElement>())
@ -250,27 +250,21 @@ QString VDomDocument::UniqueTagText(const QString &tagName, const QString &defVa
return defVal; return defVal;
} }
void VDomDocument::ValidatePattern(const QString &schema, const QString &fileName) void VDomDocument::ValidateXML(const QString &schema, const QString &fileName)
{ {
QString errorMsg;
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())); const QString errorMsg(tr("Can't open file %1:\n%2.").arg(fileName).arg(pattern.errorString()));
VException e(errorMsg); throw VException(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())); pattern.close();
VException e(errorMsg); const QString errorMsg(tr("Can't open schema file %1:\n%2.").arg(schema).arg(fileSchema.errorString()));
e.AddMoreInformation(tr("Error in line %1 column %2").arg(errorLine).arg(errorColumn)); throw VException(errorMsg);
throw e;
} }
MessageHandler messageHandler; MessageHandler messageHandler;
@ -294,30 +288,41 @@ void VDomDocument::ValidatePattern(const QString &schema, const QString &fileNam
if (errorOccurred) if (errorOccurred)
{ {
pattern.close();
fileSchema.close();
VException e(messageHandler.statusMessage()); VException e(messageHandler.statusMessage());
e.AddMoreInformation(tr("Error in line %1 column %2").arg(messageHandler.line()).arg(messageHandler.column())); e.AddMoreInformation(tr("Validation error in line %1 column %2").arg(messageHandler.line()).arg(messageHandler.column()));
throw e; throw e;
} }
pattern.close();
fileSchema.close();
} }
void VDomDocument::setContent(QIODevice *dev) void VDomDocument::setContent(const QString &fileName)
{ {
QString errorMsg; QFile file(fileName);
int errorLine = 0; if (file.open(QIODevice::ReadOnly) == false)
int errorColumn = 0;
if (QDomDocument::setContent(dev, &errorMsg, &errorLine, &errorColumn) == false)
{ {
const QString errorMsg(tr("Can't open file %1:\n%2.").arg(fileName).arg(file.errorString()));
throw VException(errorMsg);
}
QString errorMsg;
int errorLine = -1;
int errorColumn = -1;
if (QDomDocument::setContent(&file, &errorMsg, &errorLine, &errorColumn) == false)
{
file.close();
VException e(errorMsg); VException e(errorMsg);
e.AddMoreInformation(tr("Error in line %1 column %2").arg(errorLine).arg(errorColumn)); e.AddMoreInformation(tr("Parcing error in line %1 column %2").arg(errorLine).arg(errorColumn));
throw e; throw e;
} }
} }
Valentina::Units VDomDocument::Units(const QString &unit) Valentina::Units VDomDocument::StrToUnits(const QString &unit)
{ {
QStringList units; QStringList units;
units << UnitMM << UnitCM << UnitIN; units << UnitMM << UnitCM << UnitINCH;
Valentina::Units result = Valentina::Cm; Valentina::Units result = Valentina::Cm;
switch (units.indexOf(unit)) switch (units.indexOf(unit))
{ {
@ -327,8 +332,8 @@ Valentina::Units VDomDocument::Units(const QString &unit)
case 1:// cm case 1:// cm
result = Valentina::Cm; result = Valentina::Cm;
break; break;
case 2:// in case 2:// inch
result = Valentina::In; result = Valentina::Inch;
break; break;
default: default:
result = Valentina::Cm; result = Valentina::Cm;
@ -336,3 +341,24 @@ Valentina::Units VDomDocument::Units(const QString &unit)
} }
return result; return result;
} }
QString VDomDocument::UnitsToStr(const Valentina::Units &unit)
{
QString result;
switch(unit)
{
case Valentina::Mm:
result = "mm";
break;
case Valentina::Cm:
result = "cm";
break;
case Valentina::Inch:
result = "inch";
break;
default:
result = "cm";
break;
}
return result;
}

View File

@ -51,7 +51,7 @@ public:
static const QString AttrUnit; static const QString AttrUnit;
static const QString UnitMM; static const QString UnitMM;
static const QString UnitCM; static const QString UnitCM;
static const QString UnitIN; static const QString UnitINCH;
/** /**
* @brief VDomDocument constructor. * @brief VDomDocument constructor.
* @param data container with variables. * @param data container with variables.
@ -111,22 +111,24 @@ public:
qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const; qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const;
QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const; QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const;
/** /**
* @brief ValidatePattern validate pattern file by xsd schema. * @brief ValidateXML validate xml file by xsd schema.
* @param schema path to schema file. * @param schema path to schema file.
* @param fileName name of pattern file. * @param fileName name of xml file.
* @param errorMsg error message. * @param errorMsg error message.
* @param errorLine number error line. * @param errorLine number error line.
* @param errorColumn number error column. * @param errorColumn number error column.
* @return true if validation successful. * @return true if validation successful.
*/ */
static void ValidatePattern(const QString &schema, const QString &fileName); static void ValidateXML(const QString &schema, const QString &fileName);
void setContent(QIODevice * dev); void setContent(const QString &fileName);
static Valentina::Units StrToUnits(const QString &unit);
static QString UnitsToStr(const Valentina::Units &unit);
protected: protected:
/** /**
* @brief data container with data. * @brief data container with data.
*/ */
VContainer *data; VContainer *data;
Valentina::Units Units(const QString &unit);
private: private:
Q_DISABLE_COPY(VDomDocument) Q_DISABLE_COPY(VDomDocument)
/** /**
@ -163,27 +165,6 @@ inline void VDomDocument::SetAttribute<Pattern::Measurements>(QDomElement &domEl
} }
} }
template <>
inline void VDomDocument::SetAttribute<Valentina::Units>(QDomElement &domElement, const QString &name,
const Valentina::Units &value)
{
switch(value)
{
case Valentina::Mm:
domElement.setAttribute(name, "mm");
break;
case Valentina::Cm:
domElement.setAttribute(name, "cm");
break;
case Valentina::In:
domElement.setAttribute(name, "in");
break;
default:
domElement.setAttribute(name, "cm");
break;
}
}
#ifdef Q_CC_GNU #ifdef Q_CC_GNU
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif

View File

@ -47,7 +47,7 @@ VIndividualMeasurements::VIndividualMeasurements(VContainer *data):VDomDocument(
Valentina::Units VIndividualMeasurements::Unit() Valentina::Units VIndividualMeasurements::Unit()
{ {
const QString unit = UniqueTagText(AttrUnit, UnitCM); const QString unit = UniqueTagText(AttrUnit, UnitCM);
return VDomDocument::Units(unit); return VDomDocument::StrToUnits(unit);
} }
void VIndividualMeasurements::Measurements() void VIndividualMeasurements::Measurements()

View File

@ -35,6 +35,8 @@
#include "../exception/vexceptionobjecterror.h" #include "../exception/vexceptionobjecterror.h"
#include "../exception/vexceptionwrongid.h" #include "../exception/vexceptionwrongid.h"
#include "../exception/vexceptionconversionerror.h" #include "../exception/vexceptionconversionerror.h"
#include "vstandardmeasurements.h"
#include "vindividualmeasurements.h"
#include <QMessageBox> #include <QMessageBox>
@ -85,7 +87,7 @@ void VPattern::CreateEmptyFile(const QString &tablePath)
patternElement.appendChild(createElement(TagNotes)); patternElement.appendChild(createElement(TagNotes));
QDomElement measurements = createElement(TagMeasurements); QDomElement measurements = createElement(TagMeasurements);
SetAttribute(measurements, AttrUnit, qApp->patternUnit()); SetAttribute(measurements, AttrUnit, UnitsToStr(qApp->patternUnit()));
SetAttribute(measurements, AttrType, qApp->patternType()); SetAttribute(measurements, AttrType, qApp->patternType());
SetAttribute(measurements, AttrPath, tablePath); SetAttribute(measurements, AttrPath, tablePath);
patternElement.appendChild(measurements); patternElement.appendChild(measurements);
@ -417,7 +419,7 @@ bool VPattern::GetActivNodeElement(const QString &name, QDomElement &element)
QString VPattern::MPath() const QString VPattern::MPath() const
{ {
QDomNodeList list = elementsByTagName(VPattern::TagMeasurements); QDomNodeList list = elementsByTagName(TagMeasurements);
QDomElement element = list.at(0).toElement(); QDomElement element = list.at(0).toElement();
if (element.isElement()) if (element.isElement())
{ {
@ -429,6 +431,20 @@ QString VPattern::MPath() const
} }
} }
void VPattern::SetPath(const QString &path)
{
QDomNodeList list = elementsByTagName(TagMeasurements);
QDomElement element = list.at(0).toElement();
if (element.isElement())
{
SetAttribute(element, AttrPath, path);
}
else
{
qWarning()<<"Can't save path to measurements"<<Q_FUNC_INFO;
}
}
Valentina::Units VPattern::MUnit() const Valentina::Units VPattern::MUnit() const
{ {
QDomNodeList list = elementsByTagName(VPattern::TagMeasurements); QDomNodeList list = elementsByTagName(VPattern::TagMeasurements);
@ -436,7 +452,7 @@ Valentina::Units VPattern::MUnit() const
if (element.isElement()) if (element.isElement())
{ {
QStringList units; QStringList units;
units << "mm" << "cm" << "in"; units << "mm" << "cm" << "inch";
QString unit = GetParametrString(element, AttrUnit); QString unit = GetParametrString(element, AttrUnit);
switch(units.indexOf(unit)) switch(units.indexOf(unit))
{ {
@ -447,7 +463,7 @@ Valentina::Units VPattern::MUnit() const
return Valentina::Cm; return Valentina::Cm;
break; break;
case 2:// in case 2:// in
return Valentina::In; return Valentina::Inch;
break; break;
default: default:
return Valentina::Cm; return Valentina::Cm;
@ -1385,7 +1401,7 @@ void VPattern::PrepareForParse(const Document::Documents &parse, VMainGraphicsSc
{ {
TestUniqueId(); TestUniqueId();
data->Clear(); data->Clear();
emit UpdateMeasurements(); UpdateMeasurements();
nameActivDraw.clear(); nameActivDraw.clear();
sceneDraw->clear(); sceneDraw->clear();
sceneDetail->clear(); sceneDetail->clear();
@ -1400,3 +1416,20 @@ void VPattern::PrepareForParse(const Document::Documents &parse, VMainGraphicsSc
data->ClearDetails(); data->ClearDetails();
history.clear(); history.clear();
} }
void VPattern::UpdateMeasurements()
{
const QString path = MPath();
if (MType() == Pattern::Standard)
{
VStandardMeasurements m(data);
m.setContent(path);
m.Measurements();
}
else
{
VIndividualMeasurements m(data);
m.setContent(path);
m.Measurements();
}
}

View File

@ -166,6 +166,7 @@ public:
*/ */
bool GetActivNodeElement(const QString& name, QDomElement& element); bool GetActivNodeElement(const QString& name, QDomElement& element);
QString MPath() const; QString MPath() const;
void SetPath(const QString &path);
Valentina::Units MUnit() const; Valentina::Units MUnit() const;
Pattern::Measurements MType() const; Pattern::Measurements MType() const;
static const QString TagPattern; static const QString TagPattern;
@ -224,7 +225,6 @@ signals:
* @param id tool id. * @param id tool id.
*/ */
void ChangedCursor(quint32 id); void ChangedCursor(quint32 id);
void UpdateMeasurements();
public slots: public slots:
/** /**
* @brief FullUpdateTree lite parse file. * @brief FullUpdateTree lite parse file.
@ -382,6 +382,7 @@ private:
void CollectId(const QDomElement &node, QVector<quint32> &vector)const; void CollectId(const QDomElement &node, QVector<quint32> &vector)const;
void PrepareForParse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw, void PrepareForParse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw,
VMainGraphicsScene *sceneDetail); VMainGraphicsScene *sceneDetail);
void UpdateMeasurements();
}; };
inline QString VPattern::GetNameActivDraw() const inline QString VPattern::GetNameActivDraw() const

View File

@ -47,7 +47,7 @@ VStandardMeasurements::VStandardMeasurements(VContainer *data):VDomDocument(data
Valentina::Units VStandardMeasurements::Unit() Valentina::Units VStandardMeasurements::Unit()
{ {
const QString unit = UniqueTagText(AttrUnit, UnitCM); const QString unit = UniqueTagText(AttrUnit, UnitCM);
return VDomDocument::Units(unit); return VDomDocument::StrToUnits(unit);
} }
QString VStandardMeasurements::Description() QString VStandardMeasurements::Description()