Open measurement file.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-07-25 15:59:40 +03:00
parent 5697d45b2d
commit 19b787b111
11 changed files with 395 additions and 21 deletions

View File

@ -36,6 +36,7 @@ int main(int argc, char *argv[])
Q_INIT_RESOURCE(tapeicon);
Q_INIT_RESOURCE(theme);
Q_INIT_RESOURCE(icon);
Q_INIT_RESOURCE(schema);
QT_REQUIRE_VERSION(argc, argv, "5.0.0");

View File

@ -32,6 +32,8 @@
#include "dialogs/dialognewmeasurements.h"
#include "../vpatterndb/calculator.h"
#include "../ifc/ifcdef.h"
#include "../ifc/xml/vvitconverter.h"
#include "../ifc/xml/vvstconverter.h"
#include "../qmuparser/qmudef.h"
#include "../vtools/dialogs/support/dialogeditwrongformula.h"
#include "mapplication.h" // Should be last because of definning qApp
@ -71,16 +73,108 @@ TMainWindow::TMainWindow(QWidget *parent)
//---------------------------------------------------------------------------------------------------------------------
TMainWindow::~TMainWindow()
{
delete data;
delete m;
if (data != nullptr)
{
delete data;
}
if (m != nullptr)
{
delete m;
}
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString TMainWindow::CurrentFile() const
{
return curFile;
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::LoadFile(const QString &path)
{
ui->labelToolTip->setVisible(false);
ui->tabWidget->setVisible(true);
if (m == nullptr)
{
// Check if file already opened
QList<TMainWindow*>list = qApp->MainWindows();
for (int i = 0; i < list.size(); ++i)
{
if (list.at(i)->CurrentFile() == path)
{
list.at(i)->activateWindow();
return;
}
}
try
{
data = new VContainer(qApp->TrVars(), &mUnit);
m = new VMeasurements(data);
m->setXMLContent(path);
mType = m->Type();
if (mType == MeasurementsType::Unknown)
{
VException e("File has unknown format.");
throw e;
}
if (mType == MeasurementsType::Standard)
{
VVSTConverter converter(path);
converter.Convert();
VDomDocument::ValidateXML(VVSTConverter::CurrentSchema, path);
}
else
{
VVITConverter converter(path);
converter.Convert();
VDomDocument::ValidateXML(VVITConverter::CurrentSchema, path);
}
mUnit = m->MUnit();
data->SetHeight(m->BaseHeight());
data->SetSize(m->BaseSize());
ui->labelToolTip->setVisible(false);
ui->tabWidget->setVisible(true);
SetCurrentFile(path);
InitWindow();
RefreshData();
ReadOnly(m->ReadOnly());
if (ui->tableWidget->rowCount() > 0)
{
ui->tableWidget->selectRow(0);
}
}
catch (VException &e)
{
e.CriticalMessageBox(tr("File error."), this);
ui->labelToolTip->setVisible(true);
ui->tabWidget->setVisible(false);
delete m;
m = nullptr;
delete data;
data = nullptr;
return;
}
}
else
{
qApp->NewMainWindow();
qApp->MainWindow()->LoadFile(path);
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -123,16 +217,53 @@ void TMainWindow::FileNew()
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::FileOpen()
void TMainWindow::OpenIndividual()
{
if (m == nullptr)
{
const QString filter = tr("Individual measurements (*.vit);;Standard measurements (*.vst)");
//Use standard path to individual measurements
const QString pathTo = qApp->TapeSettings()->GetPathIndividualMeasurements();
Open(pathTo, filter);
}
else
{
qApp->NewMainWindow();
qApp->MainWindow()->FileOpen();
qApp->MainWindow()->OpenIndividual();
}
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::OpenStandard()
{
if (m == nullptr)
{
const QString filter = tr("Standard measurements (*.vst);;Individual measurements (*.vit)");
//Use standard path to individual measurements
const QString pathTo = qApp->TapeSettings()->GetPathStandardMeasurements();
Open(pathTo, filter);
}
else
{
qApp->NewMainWindow();
qApp->MainWindow()->OpenStandard();
}
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::OpenTemplate()
{
if (m == nullptr)
{
const QString filter = tr("Measurements (*.vst, *.vit)");
//Use standard path to individual measurements
const QString pathTo = qApp->TapeSettings()->GetPathTemplate();
Open(pathTo, filter);
}
else
{
qApp->NewMainWindow();
qApp->MainWindow()->OpenTemplate();
}
}
@ -181,14 +312,14 @@ void TMainWindow::FileSaveAs()
QString suffix;
if (mType == MeasurementsType::Individual)
{
filters = tr("Standard measurements (*.vst)");
suffix = "vst";
filters = tr("Individual measurements (*.vit)");
suffix = "vit";
fName += "." + suffix;
}
else
{
filters = tr("Individual measurements (*.vit)");
suffix = "vit";
filters = tr("Standard measurements (*.vst)");
suffix = "vst";
fName += "." + suffix;
}
@ -197,11 +328,11 @@ void TMainWindow::FileSaveAs()
{
if (mType == MeasurementsType::Individual)
{
dir = qApp->TapeSettings()->GetPathStandardMeasurements() + "/" + fName;
dir = qApp->TapeSettings()->GetPathIndividualMeasurements() + "/" + fName;
}
else
{
dir = qApp->TapeSettings()->GetPathIndividualMeasurements() + "/" + fName;
dir = qApp->TapeSettings()->GetPathStandardMeasurements() + "/" + fName;
}
}
@ -974,8 +1105,9 @@ void TMainWindow::SetupMenu()
connect(ui->actionNew, &QAction::triggered, this, &TMainWindow::FileNew);
ui->actionNew->setShortcuts(QKeySequence::New);
connect(ui->actionOpen, &QAction::triggered, this, &TMainWindow::FileOpen);
ui->actionOpen->setShortcuts(QKeySequence::Open);
connect(ui->actionOpenIndividual, &QAction::triggered, this, &TMainWindow::OpenIndividual);
connect(ui->actionOpenStandard, &QAction::triggered, this, &TMainWindow::OpenStandard);
connect(ui->actionOpenTemplate, &QAction::triggered, this, &TMainWindow::OpenTemplate);
connect(ui->actionSave, &QAction::triggered, this, &TMainWindow::FileSave);
ui->actionSave->setShortcuts(QKeySequence::Save);
@ -1482,6 +1614,21 @@ void TMainWindow::EvalFormula(const QString &formula, VContainer *data, QLabel *
}
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::Open(const QString &pathTo, const QString &filter)
{
const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), pathTo, filter);
if (mPath.isEmpty())
{
return;
}
else
{
LoadFile(mPath);
}
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SetDecimals()
{

View File

@ -51,10 +51,14 @@ public:
explicit TMainWindow(QWidget *parent = 0);
virtual ~TMainWindow() Q_DECL_OVERRIDE;
QString CurrentFile() const;
public slots:
void LoadFile(const QString &path);
void FileNew();
void FileOpen();
void OpenIndividual();
void OpenStandard();
void OpenTemplate();
protected:
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
@ -137,6 +141,8 @@ private:
QString ClearCustomName(const QString &name) const;
void EvalFormula(const QString &formula, VContainer *data, QLabel *label);
void Open(const QString &pathTo, const QString &filter);
};
#endif // TMAINWINDOW_H

View File

@ -579,7 +579,10 @@
<string>File</string>
</property>
<addaction name="actionNew"/>
<addaction name="actionOpen"/>
<addaction name="separator"/>
<addaction name="actionOpenIndividual"/>
<addaction name="actionOpenStandard"/>
<addaction name="actionOpenTemplate"/>
<addaction name="separator"/>
<addaction name="actionSave"/>
<addaction name="actionSaveAs"/>
@ -629,7 +632,6 @@
<bool>false</bool>
</attribute>
<addaction name="actionNew"/>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="actionAddKnown"/>
<addaction name="actionAddCustom"/>
@ -656,14 +658,14 @@
<bool>false</bool>
</attribute>
</widget>
<action name="actionOpen">
<action name="actionOpenIndividual">
<property name="icon">
<iconset theme="document-open">
<iconset>
<normaloff/>
</iconset>
</property>
<property name="text">
<string>Open ...</string>
<string>Open individual ...</string>
</property>
</action>
<action name="actionSave">
@ -766,6 +768,16 @@
<string>Read only</string>
</property>
</action>
<action name="actionOpenStandard">
<property name="text">
<string>Open standard ...</string>
</property>
</action>
<action name="actionOpenTemplate">
<property name="text">
<string>Open template</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>

View File

@ -6,6 +6,8 @@
<file>schema/pattern/v0.1.3.xsd</file>
<file>schema/pattern/v0.1.4.xsd</file>
<file>schema/standard_measurements/v0.3.0.xsd</file>
<file>schema/standard_measurements/v0.4.0.xsd</file>
<file>schema/individual_measurements/v0.2.0.xsd</file>
<file>schema/individual_measurements/v0.3.0.xsd</file>
</qresource>
</RCC>

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="vit">
<xs:complexType>
<xs:sequence>
<xs:element name="version" type="formatVersion"></xs:element>
<xs:element name="read-only" type="xs:boolean"></xs:element>
<xs:element name="unit" type="units"></xs:element>
<xs:element name="notes" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="personal" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="family-name" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="given-name" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="birth-date" type="xs:date" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="sex" type="sex" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="email" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="body-measurements">
<xs:complexType>
<xs:sequence>
<xs:element name="m" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="shortName" use="required"></xs:attribute>
<xs:attribute name="value" type="xs:string" use="required"></xs:attribute>
<xs:attribute name="full_name" type="xs:string"></xs:attribute>
<xs:attribute name="description" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="shortName">
<xs:restriction base="xs:string">
<xs:pattern value="^([^0-9*/^+\-=\s()?%:;!.,`'\&quot;]){1,1}([^*/^+\-=\s()?%:;!.,`'\&quot;]){0,}$"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="formatVersion">
<xs:restriction base="xs:string">
<xs:pattern value="^(0|([1-9][0-9]*))\.(0|([1-9][0-9]*))\.(0|([1-9][0-9]*))$"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="units">
<xs:restriction base="xs:string">
<xs:enumeration value="mm"/>
<xs:enumeration value="cm"/>
<xs:enumeration value="inch"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="sex">
<xs:restriction base="xs:string">
<xs:enumeration value="male"/>
<xs:enumeration value="female"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="vst">
<xs:complexType>
<xs:sequence>
<xs:element name="version" type="formatVersion"></xs:element>
<xs:element name="read-only" type="xs:boolean"></xs:element>
<xs:element name="notes" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="unit" type="units"></xs:element>
<xs:element name="size">
<xs:complexType>
<xs:attribute name="base" type="xs:double" use="required"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="height">
<xs:complexType>
<xs:attribute name="base" type="xs:double" use="required"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="body-measurements">
<xs:complexType>
<xs:sequence>
<xs:element name="m" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="shortName" use="required"></xs:attribute>
<xs:attribute name="base" type="xs:double" use="required"></xs:attribute>
<xs:attribute name="height_increase" type="xs:double" use="required"></xs:attribute>
<xs:attribute name="size_increase" type="xs:double" use="required"></xs:attribute>
<xs:attribute name="full_name" type="xs:string"></xs:attribute>
<xs:attribute name="description" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="shortName">
<xs:restriction base="xs:string">
<xs:pattern value="^([^0-9*/^+\-=\s()?%:;!.,`'\&quot;]){1,1}([^*/^+\-=\s()?%:;!.,`'\&quot;]){0,}$"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="units">
<xs:restriction base="xs:string">
<xs:enumeration value="mm"/>
<xs:enumeration value="cm"/>
<xs:enumeration value="inch"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="formatVersion">
<xs:restriction base="xs:string">
<xs:pattern value="^(0|([1-9][0-9]*))\.(0|([1-9][0-9]*))\.(0|([1-9][0-9]*))$"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

View File

@ -96,6 +96,13 @@ VMeasurements::~VMeasurements()
{
}
//---------------------------------------------------------------------------------------------------------------------
void VMeasurements::setXMLContent(const QString &fileName)
{
VDomDocument::setXMLContent(fileName);
type = ReadType();
}
//---------------------------------------------------------------------------------------------------------------------
void VMeasurements::AddEmpty(const QString &name)
{
@ -614,6 +621,24 @@ QDomElement VMeasurements::FindM(const QString &name) const
return QDomElement();
}
//---------------------------------------------------------------------------------------------------------------------
MeasurementsType VMeasurements::ReadType() const
{
QDomElement root = documentElement();
if (root.tagName() == TagVST)
{
return MeasurementsType::Standard;
}
else if (root.tagName() == TagVIT)
{
return MeasurementsType::Individual;
}
else
{
return MeasurementsType::Unknown;
}
}
//---------------------------------------------------------------------------------------------------------------------
qreal VMeasurements::EvalFormula(VContainer *data, const QString &formula, bool *ok) const
{

View File

@ -43,6 +43,8 @@ public:
VMeasurements(Unit unit, int baseSize, int baseHeight, VContainer *data);
virtual ~VMeasurements() Q_DECL_OVERRIDE;
void setXMLContent(const QString &fileName);
void AddEmpty(const QString &name);
void AddEmptyAfter(const QString &after, const QString &name);
void Remove(const QString &name);
@ -130,6 +132,7 @@ private:
QDomElement MakeEmpty(const QString &name);
QDomElement FindM(const QString &name) const;
MeasurementsType ReadType() const;
qreal EvalFormula(VContainer *data, const QString &formula, bool *ok) const;
};

View File

@ -31,6 +31,8 @@
#include <QApplication>
#include <QDir>
const QString VTapeSettings::SettingPathsTemplates = QStringLiteral("paths/templates");
//---------------------------------------------------------------------------------------------------------------------
VTapeSettings::VTapeSettings(Format format, Scope scope, const QString &organization, const QString &application,
QObject *parent)
@ -106,3 +108,56 @@ QString VTapeSettings::StandardTablesPath() const
#endif
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QString VTapeSettings::TemplatesPath() const
{
const QString stPath = QStringLiteral("/tables/template");
#ifdef Q_OS_WIN
return QApplication::applicationDirPath() + stPath;
#elif defined(Q_OS_MAC)
QDir dirBundle(QApplication::applicationDirPath() + QStringLiteral("/../Resources") + stPath);
if (dirBundle.exists())
{
return dirBundle.absolutePath();
}
else
{
QDir dir(QApplication::applicationDirPath() + stPath);
if (dir.exists())
{
return dir.absolutePath();
}
else
{
return QStringLiteral("/usr/share/valentina/tables/template");
}
}
#else // Unix
#ifdef QT_DEBUG
return QApplication::applicationDirPath() + stPath;
#else
QDir dir(QApplication::applicationDirPath() + stPath);
if (dir.exists())
{
return dir.absolutePath();
}
else
{
return QStringLiteral("/usr/share/valentina/tables/template");
}
#endif
#endif
}
//---------------------------------------------------------------------------------------------------------------------
QString VTapeSettings::GetPathTemplate() const
{
return value(SettingPathsTemplates, TemplatesPath()).toString();
}
//---------------------------------------------------------------------------------------------------------------------
void VTapeSettings::SetPathTemplate(const QString &value)
{
setValue(SettingPathsTemplates, value);
}

View File

@ -39,9 +39,15 @@ public:
QObject *parent = 0);
virtual QString StandardTablesPath()const Q_DECL_OVERRIDE;
QString TemplatesPath() const;
QString GetPathTemplate() const;
void SetPathTemplate(const QString &value);
private:
Q_DISABLE_COPY(VTapeSettings)
static const QString SettingPathsTemplates;
};
#endif // VTAPESETTINGS_H