diff --git a/src/app/tape/main.cpp b/src/app/tape/main.cpp index 8ff30dd66..7b768b2ea 100644 --- a/src/app/tape/main.cpp +++ b/src/app/tape/main.cpp @@ -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"); diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 0a9845811..e10223979 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -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 + QListlist = 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() { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 1ad30c398..924bc0667 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -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 diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index 2b8cb6e2f..132354401 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -579,7 +579,10 @@ File - + + + + @@ -629,7 +632,6 @@ false - @@ -656,14 +658,14 @@ false - + - + - Open ... + Open individual ... @@ -766,6 +768,16 @@ Read only + + + Open standard ... + + + + + Open template + + diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index aa5dc9e80..de07f5252 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -6,6 +6,8 @@ schema/pattern/v0.1.3.xsd schema/pattern/v0.1.4.xsd schema/standard_measurements/v0.3.0.xsd + schema/standard_measurements/v0.4.0.xsd schema/individual_measurements/v0.2.0.xsd + schema/individual_measurements/v0.3.0.xsd diff --git a/src/libs/ifc/schema/individual_measurements/v0.3.0.xsd b/src/libs/ifc/schema/individual_measurements/v0.3.0.xsd new file mode 100644 index 000000000..6f2a3248c --- /dev/null +++ b/src/libs/ifc/schema/individual_measurements/v0.3.0.xsd @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/schema/standard_measurements/v0.4.0.xsd b/src/libs/ifc/schema/standard_measurements/v0.4.0.xsd new file mode 100644 index 000000000..fa14bdda1 --- /dev/null +++ b/src/libs/ifc/schema/standard_measurements/v0.4.0.xsd @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index c50ddc419..67f705374 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -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 { diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index 55fea0115..8c670765a 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -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; }; diff --git a/src/libs/vmisc/vtapesettings.cpp b/src/libs/vmisc/vtapesettings.cpp index cf5de9470..79129ba3e 100644 --- a/src/libs/vmisc/vtapesettings.cpp +++ b/src/libs/vmisc/vtapesettings.cpp @@ -31,6 +31,8 @@ #include #include +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); +} diff --git a/src/libs/vmisc/vtapesettings.h b/src/libs/vmisc/vtapesettings.h index da35b6d77..48c5b5c47 100644 --- a/src/libs/vmisc/vtapesettings.h +++ b/src/libs/vmisc/vtapesettings.h @@ -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