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 {
*-g++{#Don't use additional GCC keys on Windows system.
QMAKE_CXXFLAGS += -Og -Wall -Wextra -pedantic
QMAKE_CXXFLAGS += -O0 -Wall -Wextra -pedantic
}
}
}else{
# Release
*-g++{
QMAKE_CXXFLAGS += -O1
QMAKE_CXXFLAGS += -O2
}
DEFINES += QT_NO_DEBUG_OUTPUT

View File

@ -4,9 +4,16 @@
<xs:element name="pattern">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<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="notes" 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="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:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -35,6 +35,7 @@
#include "exception/vexceptionemptyparameter.h"
#include "exception/vexceptionwrongid.h"
#include "version.h"
#include "xml/vstandardmeasurements.h"
#include <QInputDialog>
#include <QtCore>
@ -55,7 +56,6 @@ MainWindow::MainWindow(QWidget *parent)
{
CreateActions();
CreateMenus();
ToolBarOption();
ToolBarDraws();
sceneDraw = new VMainGraphicsScene();
@ -542,39 +542,36 @@ void MainWindow::closeEvent(QCloseEvent *event)
void MainWindow::ToolBarOption()
{
QLabel * labelGrowth = new QLabel;
labelGrowth->setText(tr("Height: "));
ui->toolBarOption->addWidget(labelGrowth);
if (qApp->patternType() == Pattern::Standard)
{
ui->toolBarOption->addWidget(new QLabel(tr("Height: ")));
QStringList list;
list <<"92"<<"98"<<"104"<<"110"<<"116"<<"122"<<"128"<<"134"<<"140"<<"146"<<"152"<<"158"<<"164"<<"170"<<"176"
<<"182"<<"188";
QComboBox *comboBoxGrow = new QComboBox;
comboBoxGrow->clear();
comboBoxGrow->addItems(list);
comboBoxGrow->setCurrentIndex(14);
ui->toolBarOption->addWidget(comboBoxGrow);
connect(comboBoxGrow, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedHeight);
QStringList list;
list <<"92"<<"98"<<"104"<<"110"<<"116"<<"122"<<"128"<<"134"<<"140"<<"146"<<"152"<<"158"<<"164"<<"170"<<"176"
<<"182"<<"188";
QComboBox *comboBoxHeight = new QComboBox;
comboBoxHeight->addItems(list);
comboBoxHeight->setCurrentIndex(14);//176
ui->toolBarOption->addWidget(comboBoxHeight);
connect(comboBoxHeight, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedHeight);
QLabel * labelSize = new QLabel;
labelSize->setText(tr(" Size: "));
ui->toolBarOption->addWidget(labelSize);
ui->toolBarOption->addWidget(new QLabel(tr(" Size: ")));
list.clear();
list <<"22"<<"24"<<"26"<<"28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50"<<"52"<<"54"<<"56";
QComboBox *comboBoxSize = new QComboBox;
comboBoxSize->clear();
comboBoxSize->addItems(list);
comboBoxSize->setCurrentIndex(14);
ui->toolBarOption->addWidget(comboBoxSize);
connect(comboBoxSize, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedSize);
list.clear();
list <<"22"<<"24"<<"26"<<"28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50"<<"52"<<"54"
<<"56";
QComboBox *comboBoxSize = new QComboBox;
comboBoxSize->addItems(list);
comboBoxSize->setCurrentIndex(14);//50
ui->toolBarOption->addWidget(comboBoxSize);
connect(comboBoxSize, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedSize);
ui->toolBarOption->addSeparator();
ui->toolBarOption->addSeparator();
}
mouseCoordinate = new QLabel;
mouseCoordinate ->setText("0, 0");
mouseCoordinate = new QLabel("0, 0");
ui->toolBarOption->addWidget(mouseCoordinate);
}
@ -626,10 +623,12 @@ void MainWindow::currentDrawChanged( int index )
void MainWindow::mouseMove(const QPointF &scenePos)
{
QString string = QString("%1, %2")
.arg(static_cast<qint32>(qApp->fromPixel(scenePos.x())))
.arg(static_cast<qint32>(qApp->fromPixel(scenePos.y())));
mouseCoordinate->setText(string);
QString string = QString("%1, %2").arg(static_cast<qint32>(qApp->fromPixel(scenePos.x())))
.arg(static_cast<qint32>(qApp->fromPixel(scenePos.y())));
if (mouseCoordinate != nullptr)
{
mouseCoordinate->setText(string);
}
}
void MainWindow::CancelTool()
@ -953,6 +952,9 @@ void MainWindow::Clear()
ui->actionSave->setEnabled(false);
ui->actionPattern_properties->setEnabled(false);
SetEnableTool(false);
qApp->setPatternUnit(Valentina::Cm);
qApp->setPatternType(Pattern::Individual);
ui->toolBarOption->clear();
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
@ -1386,100 +1388,165 @@ MainWindow::~MainWindow()
void MainWindow::LoadPattern(const QString &fileName)
{
QFile file(fileName);
if (file.open(QIODevice::ReadOnly))
try
{
try
VDomDocument::ValidateXML("://schema/pattern.xsd", fileName);
doc->setContent(fileName);
qApp->setPatternUnit(doc->MUnit());
qApp->setPatternType(doc->MType());
QString path = doc->MPath();
path = CheckPathToMeasurements(path, qApp->patternType());
if(path.isEmpty())
{
VDomDocument::ValidatePattern("://schema/pattern.xsd", fileName);
}
catch(VException &e)
{
e.CriticalMessageBox(tr("Validation file error."), this);
file.close();
Clear();
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);
}
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);
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
{
SetEnableTool(false);
VIndividualMeasurements m(pattern);
m.setContent(path);
Valentina::Units mUnit = m.Unit();
if (qApp->patternUnit() != mUnit)
{
QMessageBox::critical(this, tr("Wrong units."), text);
Clear();
return;
}
}
SetEnableWidgets(true);
}
catch(VException &e)
{
e.CriticalMessageBox(tr("File error."), this);
Clear();
return;
}
file.close();
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);
Clear();
return;
}
catch (const VExceptionConversionError &e)
{
e.CriticalMessageBox(tr("Error can't convert value."), this);
Clear();
return;
}
catch (const VExceptionEmptyParameter &e)
{
e.CriticalMessageBox(tr("Error empty parameter."), this);
Clear();
return;
}
catch (const VExceptionWrongId &e)
{
e.CriticalMessageBox(tr("Error wrong id."), this);
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
{
QMessageBox::warning(this, tr("Valentina"), tr("Cannot read file %1:\n%2.")
.arg(fileName)
.arg(file.errorString()));
SetEnableTool(false);
}
SetEnableWidgets(true);
setCurrentFile(fileName);
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 InitAutoSave();
QString PatternPieceName(const QString &text);
QString CheckPathToMeasurements(const QString &path, const Pattern::Measurements &patternType);
};
#endif // MAINWINDOW_H

View File

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

View File

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

View File

@ -81,7 +81,7 @@ const QString VDomDocument::AttrId = QStringLiteral("id");
const QString VDomDocument::AttrUnit = QStringLiteral("unit");
const QString VDomDocument::UnitMM = QStringLiteral("mm");
const QString VDomDocument::UnitCM = QStringLiteral("cm");
const QString VDomDocument::UnitIN = QStringLiteral("in");
const QString VDomDocument::UnitINCH = QStringLiteral("inch");
VDomDocument::VDomDocument(VContainer *data)
: QDomDocument(), data(data), map(QHash<QString, QDomElement>())
@ -250,27 +250,21 @@ QString VDomDocument::UniqueTagText(const QString &tagName, const QString &defVa
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);
if (pattern.open(QIODevice::ReadOnly) == false)
{
errorMsg = QString(tr("Can't open file %1:\n%2.").arg(fileName).arg(pattern.errorString()));
VException e(errorMsg);
e.AddMoreInformation(tr("Error in line %1 column %2").arg(errorLine).arg(errorColumn));
throw e;
const QString errorMsg(tr("Can't open file %1:\n%2.").arg(fileName).arg(pattern.errorString()));
throw VException(errorMsg);
}
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()));
VException e(errorMsg);
e.AddMoreInformation(tr("Error in line %1 column %2").arg(errorLine).arg(errorColumn));
throw e;
pattern.close();
const QString errorMsg(tr("Can't open schema file %1:\n%2.").arg(schema).arg(fileSchema.errorString()));
throw VException(errorMsg);
}
MessageHandler messageHandler;
@ -294,30 +288,41 @@ void VDomDocument::ValidatePattern(const QString &schema, const QString &fileNam
if (errorOccurred)
{
pattern.close();
fileSchema.close();
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;
}
pattern.close();
fileSchema.close();
}
void VDomDocument::setContent(QIODevice *dev)
void VDomDocument::setContent(const QString &fileName)
{
QString errorMsg;
int errorLine = 0;
int errorColumn = 0;
if (QDomDocument::setContent(dev, &errorMsg, &errorLine, &errorColumn) == false)
QFile file(fileName);
if (file.open(QIODevice::ReadOnly) == false)
{
VException e(errorMsg);
e.AddMoreInformation(tr("Error in line %1 column %2").arg(errorLine).arg(errorColumn));
throw e;
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);
e.AddMoreInformation(tr("Parcing error in line %1 column %2").arg(errorLine).arg(errorColumn));
throw e;
}
}
Valentina::Units VDomDocument::Units(const QString &unit)
Valentina::Units VDomDocument::StrToUnits(const QString &unit)
{
QStringList units;
units << UnitMM << UnitCM << UnitIN;
units << UnitMM << UnitCM << UnitINCH;
Valentina::Units result = Valentina::Cm;
switch (units.indexOf(unit))
{
@ -327,8 +332,8 @@ Valentina::Units VDomDocument::Units(const QString &unit)
case 1:// cm
result = Valentina::Cm;
break;
case 2:// in
result = Valentina::In;
case 2:// inch
result = Valentina::Inch;
break;
default:
result = Valentina::Cm;
@ -336,3 +341,24 @@ Valentina::Units VDomDocument::Units(const QString &unit)
}
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 UnitMM;
static const QString UnitCM;
static const QString UnitIN;
static const QString UnitINCH;
/**
* @brief VDomDocument constructor.
* @param data container with variables.
@ -111,22 +111,24 @@ public:
qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) 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 fileName name of pattern file.
* @param fileName name of xml file.
* @param errorMsg error message.
* @param errorLine number error line.
* @param errorColumn number error column.
* @return true if validation successful.
*/
static void ValidatePattern(const QString &schema, const QString &fileName);
void setContent(QIODevice * dev);
static void ValidateXML(const QString &schema, const QString &fileName);
void setContent(const QString &fileName);
static Valentina::Units StrToUnits(const QString &unit);
static QString UnitsToStr(const Valentina::Units &unit);
protected:
/**
* @brief data container with data.
*/
VContainer *data;
Valentina::Units Units(const QString &unit);
private:
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
#pragma GCC diagnostic pop
#endif

View File

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

View File

@ -35,6 +35,8 @@
#include "../exception/vexceptionobjecterror.h"
#include "../exception/vexceptionwrongid.h"
#include "../exception/vexceptionconversionerror.h"
#include "vstandardmeasurements.h"
#include "vindividualmeasurements.h"
#include <QMessageBox>
@ -85,7 +87,7 @@ void VPattern::CreateEmptyFile(const QString &tablePath)
patternElement.appendChild(createElement(TagNotes));
QDomElement measurements = createElement(TagMeasurements);
SetAttribute(measurements, AttrUnit, qApp->patternUnit());
SetAttribute(measurements, AttrUnit, UnitsToStr(qApp->patternUnit()));
SetAttribute(measurements, AttrType, qApp->patternType());
SetAttribute(measurements, AttrPath, tablePath);
patternElement.appendChild(measurements);
@ -417,7 +419,7 @@ bool VPattern::GetActivNodeElement(const QString &name, QDomElement &element)
QString VPattern::MPath() const
{
QDomNodeList list = elementsByTagName(VPattern::TagMeasurements);
QDomNodeList list = elementsByTagName(TagMeasurements);
QDomElement element = list.at(0).toElement();
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
{
QDomNodeList list = elementsByTagName(VPattern::TagMeasurements);
@ -436,7 +452,7 @@ Valentina::Units VPattern::MUnit() const
if (element.isElement())
{
QStringList units;
units << "mm" << "cm" << "in";
units << "mm" << "cm" << "inch";
QString unit = GetParametrString(element, AttrUnit);
switch(units.indexOf(unit))
{
@ -447,7 +463,7 @@ Valentina::Units VPattern::MUnit() const
return Valentina::Cm;
break;
case 2:// in
return Valentina::In;
return Valentina::Inch;
break;
default:
return Valentina::Cm;
@ -1385,7 +1401,7 @@ void VPattern::PrepareForParse(const Document::Documents &parse, VMainGraphicsSc
{
TestUniqueId();
data->Clear();
emit UpdateMeasurements();
UpdateMeasurements();
nameActivDraw.clear();
sceneDraw->clear();
sceneDetail->clear();
@ -1400,3 +1416,20 @@ void VPattern::PrepareForParse(const Document::Documents &parse, VMainGraphicsSc
data->ClearDetails();
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);
QString MPath() const;
void SetPath(const QString &path);
Valentina::Units MUnit() const;
Pattern::Measurements MType() const;
static const QString TagPattern;
@ -224,7 +225,6 @@ signals:
* @param id tool id.
*/
void ChangedCursor(quint32 id);
void UpdateMeasurements();
public slots:
/**
* @brief FullUpdateTree lite parse file.
@ -382,6 +382,7 @@ private:
void CollectId(const QDomElement &node, QVector<quint32> &vector)const;
void PrepareForParse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw,
VMainGraphicsScene *sceneDetail);
void UpdateMeasurements();
};
inline QString VPattern::GetNameActivDraw() const

View File

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