diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index be15a5143..0ca3e84dc 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -41,7 +41,7 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat QDialog(parent), ui(new Ui::DialogPatternProperties), doc(doc), pattern(pattern), heightsChecked(MAX_HEIGHTS), sizesChecked(MAX_SIZES), heights (QMap()), sizes(QMap()), data(QMap()), descriptionChanged(false), gradationChanged(false), defaultChanged(false), - isInitialized(false) + securityChanged(false), isInitialized(false) { ui->setupUi(this); @@ -104,9 +104,22 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat connect(ui->comboBoxSize, static_cast(&QComboBox::currentIndexChanged), this, &DialogPatternProperties::DefValueChanged); + const bool readOnly = doc->IsReadOnly(); + ui->checkBoxPatternReadOnly->setChecked(readOnly); + if (not readOnly) + { + connect(ui->checkBoxPatternReadOnly, &QRadioButton::toggled, this, + &DialogPatternProperties::SecurityValueChanged); + } + else + { + ui->checkBoxPatternReadOnly->setDisabled(true); + } + //Initialization change value. Set to default value after initialization gradationChanged = false; defaultChanged = false; + securityChanged = false; } //--------------------------------------------------------------------------------------------------------------------- @@ -132,6 +145,11 @@ void DialogPatternProperties::Apply() defaultChanged = false; emit doc->patternChanged(false); break; + case 2: + doc->SetReadOnly(ui->checkBoxPatternReadOnly->isChecked()); + securityChanged = false; + emit doc->patternChanged(false); + break; default: break; } @@ -161,6 +179,13 @@ void DialogPatternProperties::Ok() emit doc->patternChanged(false); } + if (securityChanged) + { + doc->SetReadOnly(ui->checkBoxPatternReadOnly->isChecked()); + securityChanged = false; + emit doc->patternChanged(false); + } + close(); } @@ -329,6 +354,12 @@ void DialogPatternProperties::DefValueChanged() defaultChanged = true; } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::SecurityValueChanged() +{ + securityChanged = true; +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::SetHeightsChecked(bool enabled) { diff --git a/src/app/valentina/dialogs/dialogpatternproperties.h b/src/app/valentina/dialogs/dialogpatternproperties.h index 76a3a020e..f97f0a50b 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.h +++ b/src/app/valentina/dialogs/dialogpatternproperties.h @@ -62,6 +62,7 @@ protected: private slots: void ToggleComboBox(); void DefValueChanged(); + void SecurityValueChanged(); private: Q_DISABLE_COPY(DialogPatternProperties) Ui::DialogPatternProperties *ui; @@ -75,6 +76,7 @@ private: bool descriptionChanged; bool gradationChanged; bool defaultChanged; + bool securityChanged; bool isInitialized; void SetHeightsChecked(bool enabled); diff --git a/src/app/valentina/dialogs/dialogpatternproperties.ui b/src/app/valentina/dialogs/dialogpatternproperties.ui index 13e78abfe..97e241854 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.ui +++ b/src/app/valentina/dialogs/dialogpatternproperties.ui @@ -21,7 +21,7 @@ - 1 + 0 @@ -911,6 +911,20 @@ + + + Security + + + + + + Open only for read + + + + + diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 2c94b4cd7..1d15bc4a5 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -98,7 +98,8 @@ const QString autosavePrefix = QStringLiteral(".autosave"); MainWindow::MainWindow(QWidget *parent) :MainWindowsNoGUI(parent), ui(new Ui::MainWindow), watcher(new QFileSystemWatcher(this)), currentTool(Tool::Arrow), lastUsedTool(Tool::Arrow), sceneDraw(nullptr), sceneDetails(nullptr), - mouseCoordinate(nullptr), helpLabel(nullptr), isInitialized(false), mChanges(false), dialogTable(nullptr), + mouseCoordinate(nullptr), helpLabel(nullptr), isInitialized(false), mChanges(false), patternReadOnly(false), + dialogTable(nullptr), dialogTool(nullptr), dialogHistory(nullptr), comboBoxDraws(nullptr), patternPieceLabel(nullptr), mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true), recentFileActs(), @@ -2099,6 +2100,25 @@ bool MainWindow::SaveAs() } } + if (curFile == fileName && patternReadOnly) + { + const QString message = QString("Failed to save the pattern '%1'. Error writing. The document is read-only.") + .arg(fileName); + QMessageBox messageBox; + messageBox.setIcon(QMessageBox::Critical); + messageBox.setInformativeText(message); + messageBox.setDefaultButton(QMessageBox::Ok); + messageBox.setStandardButtons(QMessageBox::Ok); + messageBox.exec(); + + return false; + } + + // Need for restoring previous state in case of failure + const bool wasModified = doc->IsModified(); // Need because SetReadOnly() will change internal state + const bool readOnly = doc->IsReadOnly(); + + doc->SetReadOnly(false);// Save as... disable read only state QString error; const bool result = SavePattern(fileName, error); if (result == false) @@ -2111,9 +2131,15 @@ bool MainWindow::SaveAs() messageBox.setStandardButtons(QMessageBox::Ok); messageBox.exec(); + // Restoring previous state + doc->SetReadOnly(readOnly); + doc->SetModified(wasModified); + return result; } + patternReadOnly = false; + qCDebug(vMainWindow, "Locking file"); VlpCreateLock(lock, fileName); @@ -2416,6 +2442,7 @@ void MainWindow::FullParseFile() GlobalChangePP(patternPiece); SetEnableTool(comboBoxDraws->count() > 0); + patternReadOnly = doc->IsReadOnly(); SetEnableWidgets(true); } @@ -2489,10 +2516,14 @@ void MainWindow::SetEnableWidgets(bool enable) { comboBoxDraws->setEnabled(enable); ui->actionOptionDraw->setEnabled(enable); - if (enable && not curFile.isEmpty()) + if (enable && not curFile.isEmpty() && not patternReadOnly) { ui->actionSave->setEnabled(enable); } + else + { + ui->actionSave->setEnabled(false); + } ui->actionSaveAs->setEnabled(enable); ui->actionPattern_properties->setEnabled(enable); ui->actionEdit_pattern_code->setEnabled(enable); @@ -2654,7 +2685,7 @@ void MainWindow::PatternWasModified(bool saved) { const bool state = doc->IsModified() || !saved; setWindowModified(state); - ui->actionSave->setEnabled(state); + not patternReadOnly ? ui->actionSave->setEnabled(state): ui->actionSave->setEnabled(false); isLayoutStale = true; } } diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 03eb6f7b6..34eea7aa2 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -209,6 +209,8 @@ private: /** @brief mChanges true if measurement file was changed. */ bool mChanges; + bool patternReadOnly; + DialogIncrements *dialogTable; DialogTool *dialogTool; DialogHistory *dialogHistory; diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 30ceb3220..49b4f7656 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -49,6 +49,8 @@ #include #include +const QString VPattern::AttrReadOnly = QStringLiteral("readOnly"); + //--------------------------------------------------------------------------------------------------------------------- VPattern::VPattern(VContainer *data, Draw *mode, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, QObject *parent) @@ -2683,6 +2685,38 @@ void VPattern::SetDefCustomSize(int value) } } +//--------------------------------------------------------------------------------------------------------------------- +bool VPattern::IsReadOnly() const +{ + const QDomElement pattern = documentElement(); + + if (pattern.isNull()) + { + return false; + } + + return GetParametrBool(pattern, AttrReadOnly, QStringLiteral("false")); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::SetReadOnly(bool rOnly) +{ + QDomElement pattern = documentElement(); + + if (not pattern.isNull()) + { + if (rOnly) + { + SetAttribute(pattern, AttrReadOnly, rOnly); + } + else + {// For better backward compatibility + pattern.removeAttribute(AttrReadOnly); + } + modified = true; + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPattern::PrepareForParse(const Document &parse) { diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 9072159d6..bd71a8190 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -87,6 +87,11 @@ public: int GetDefCustomSize() const; void SetDefCustomSize(int value); + bool IsReadOnly() const; + void SetReadOnly(bool rOnly); + + static const QString AttrReadOnly; + public slots: void LiteParseTree(const Document &parse); diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index f3ac287da..73c86c494 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -9,6 +9,8 @@ schema/pattern/v0.2.1.xsd schema/pattern/v0.2.2.xsd schema/pattern/v0.2.3.xsd + schema/pattern/v0.2.4.xsd + schema/pattern/v0.2.5.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd @@ -18,6 +20,5 @@ schema/individual_measurements/v0.3.1.xsd schema/individual_measurements/v0.3.2.xsd schema/individual_measurements/v0.3.3.xsd - schema/pattern/v0.2.4.xsd diff --git a/src/libs/ifc/schema/pattern/v0.2.5.xsd b/src/libs/ifc/schema/pattern/v0.2.5.xsd new file mode 100644 index 000000000..76d366e5f --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.2.5.xsd @@ -0,0 +1,424 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index be8889d56..78bd24f0d 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1322,6 +1322,12 @@ bool VAbstractPattern::IsModified() const return modified; } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetModified(bool modified) +{ + this->modified = modified; +} + //--------------------------------------------------------------------------------------------------------------------- QDomElement VAbstractPattern::GetDraw(const QString &name) const { diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index bd7bfef1c..30acc67c5 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -104,6 +104,7 @@ public: void SetVersion(); bool IsModified() const; + void SetModified(bool modified); QDomElement GetDraw(const QString &name) const; diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 4239e4fe0..84e02bf87 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -43,8 +43,8 @@ */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.2.4"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.4.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.2.5"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.5.xsd"); //--------------------------------------------------------------------------------------------------------------------- VPatternConverter::VPatternConverter(const QString &fileName) @@ -105,6 +105,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000203): return QStringLiteral("://schema/pattern/v0.2.3.xsd"); case (0x000204): + return QStringLiteral("://schema/pattern/v0.2.4.xsd"); + case (0x000205): return CurrentSchema; default: InvalidVersion(ver); @@ -183,6 +185,13 @@ void VPatternConverter::ApplyPatches() V_FALLTHROUGH } case (0x000204): + { + ToV0_2_5(); + const QString schema = XSDSchema(0x000205); + ValidateXML(schema, fileName); + V_FALLTHROUGH + } + case (0x000205): break; default: break; @@ -283,6 +292,13 @@ void VPatternConverter::ToV0_2_4() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_2_5() +{ + SetVersion(QStringLiteral("0.2.5")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index ee6ff32a1..e49f04c19 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -65,6 +65,7 @@ private: void ToV0_2_2(); void ToV0_2_3(); void ToV0_2_4(); + void ToV0_2_5(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0();