From ab78ee255030dcfe68507bc0e30ee5c2316f00a9 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Wed, 9 Mar 2016 20:59:08 +0200 Subject: [PATCH 01/26] Fixed build on Win7 --HG-- branch : feature --- src/libs/vtools/dialogs/tools/dialogtool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index 1b35bf530..9d8e60796 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -32,7 +32,7 @@ #include "../vmisc/vabstractapplication.h" #include "../vmisc/logging.h" #include "../vwidgets/vmaingraphicsscene.h" -#include "../../visualization/visualization.h" +#include "visualization/visualization.h" #include "../ifc/xml/vabstractpattern.h" #include From 821bafbdee9db1ba212f5072be192deef18959ff Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Wed, 9 Mar 2016 21:01:37 +0200 Subject: [PATCH 02/26] Now we can add image to file.val --HG-- branch : feature --- .../dialogs/dialogpatternproperties.cpp | 48 ++ .../dialogs/dialogpatternproperties.h | 2 + .../dialogs/dialogpatternproperties.ui | 70 ++- src/app/valentina/xml/vpattern.cpp | 14 +- src/libs/ifc/schema.qrc | 1 + src/libs/ifc/schema/pattern/v0.2.8.xsd | 442 ++++++++++++++++++ src/libs/ifc/xml/vabstractpattern.cpp | 27 +- src/libs/ifc/xml/vabstractpattern.h | 4 + src/libs/ifc/xml/vpatternconverter.cpp | 22 +- src/libs/ifc/xml/vpatternconverter.h | 1 + 10 files changed, 612 insertions(+), 19 deletions(-) create mode 100644 src/libs/ifc/schema/pattern/v0.2.8.xsd diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 702e7eaf4..8412ccc34 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -28,7 +28,9 @@ #include "dialogpatternproperties.h" #include "ui_dialogpatternproperties.h" +#include #include +#include #include "../xml/vpattern.h" #include "../vpatterndb/vcontainer.h" #include "../core/vapplication.h" @@ -62,6 +64,8 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat ui->plainTextEditTechNotes->setPlainText(doc->GetNotes()); connect(ui->plainTextEditTechNotes, &QPlainTextEdit::textChanged, this, &DialogPatternProperties::DescEdited); + InitImage(); + connect(ui->buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &DialogPatternProperties::Ok); connect(ui->buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &DialogPatternProperties::Apply); @@ -603,3 +607,47 @@ void DialogPatternProperties::InitComboBox(QComboBox *box, const QMapGetImage().toUtf8()); + QByteArray ba = QByteArray::fromBase64(byteArray); + QBuffer buffer(&ba); + buffer.open(QIODevice::ReadOnly); + image.load(&buffer, "PNG"); // writes image into ba in PNG format + ui->imageLabel->setPixmap(QPixmap::fromImage(image)); + connect(ui->changeImageButton, &QPushButton::clicked, this, &DialogPatternProperties::SetNewImage); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::SetNewImage() +{ + const QString fileName = QFileDialog::getOpenFileName(this, tr("Image for pattern"), QString(), tr("Images (*.png)")); + QImage image; + if (fileName.isEmpty()) + { + return; + } + else + { + if (!image.load(fileName)) + { + return; + } + ui->imageLabel->setPixmap(QPixmap::fromImage(image)); + + QByteArray byteArray; + QBuffer buffer(&byteArray); + buffer.open(QIODevice::WriteOnly); + image.save(&buffer, "PNG"); // writes the image in PNG format inside the buffer + QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data()); + + // save our image to file.val + doc->SetImage(iconBase64); + } + +} diff --git a/src/app/valentina/dialogs/dialogpatternproperties.h b/src/app/valentina/dialogs/dialogpatternproperties.h index f97f0a50b..3453f570f 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.h +++ b/src/app/valentina/dialogs/dialogpatternproperties.h @@ -57,6 +57,7 @@ public slots: void CheckStateHeight(int state); void CheckStateSize(int state); void DescEdited(); + void SetNewImage(); protected: virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; private slots: @@ -99,6 +100,7 @@ private: void UpdateDefHeight(); void UpdateDefSize(); + void InitImage(); }; #endif // DIALOGPATTERNPROPERTIES_H diff --git a/src/app/valentina/dialogs/dialogpatternproperties.ui b/src/app/valentina/dialogs/dialogpatternproperties.ui index 97e241854..ac9be310b 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.ui +++ b/src/app/valentina/dialogs/dialogpatternproperties.ui @@ -43,20 +43,70 @@ - + + + 0 + + + QLayout::SetMaximumSize + + + 0 + + + 0 + + + 0 + - - - Pattern description - - + + + + + Pattern description + + + + + + + + + + + - - - + + + 6 - + + 0 + + + + + Image + + + + + + + No image + + + + + + + change image + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 10eb79d79..6302d7989 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -86,6 +86,7 @@ void VPattern::CreateEmptyFile() patternElement.appendChild(createElement(TagAuthor)); patternElement.appendChild(createElement(TagDescription)); patternElement.appendChild(createElement(TagNotes)); + patternElement.appendChild(createElement(TagImage)); patternElement.appendChild(createElement(TagMeasurements)); patternElement.appendChild(createElement(TagIncrements)); @@ -127,7 +128,7 @@ void VPattern::Parse(const Document &parse) SCASSERT(sceneDraw != nullptr); SCASSERT(sceneDetail != nullptr); QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes - << TagMeasurements << TagVersion << TagGradation << TagUnit; + << TagImage << TagMeasurements << TagVersion << TagGradation << TagUnit; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -172,16 +173,19 @@ void VPattern::Parse(const Document &parse) case 4: // TagNotes qCDebug(vXML, "Tag notes."); break; - case 5: // TagMeasurements + case 5: // TagImage + qCDebug(vXML, "Tag image."); + break; + case 6: // TagMeasurements qCDebug(vXML, "Tag measurements."); break; - case 6: // TagVersion + case 7: // TagVersion qCDebug(vXML, "Tag version."); break; - case 7: // TagGradation + case 8: // TagGradation qCDebug(vXML, "Tag gradation."); break; - case 8: // TagUnit + case 9: // TagUnit qCDebug(vXML, "Tag unit."); break; default: diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 1fe74a4c7..c7ad3e335 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -22,5 +22,6 @@ 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.8.xsd diff --git a/src/libs/ifc/schema/pattern/v0.2.8.xsd b/src/libs/ifc/schema/pattern/v0.2.8.xsd new file mode 100644 index 000000000..0e7fe7f7a --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.2.8.xsd @@ -0,0 +1,442 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 32220e939..31acb5d69 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -39,6 +39,7 @@ const QString VAbstractPattern::TagDetails = QStringLiteral("details"); const QString VAbstractPattern::TagAuthor = QStringLiteral("author"); const QString VAbstractPattern::TagDescription = QStringLiteral("description"); const QString VAbstractPattern::TagNotes = QStringLiteral("notes"); +const QString VAbstractPattern::TagImage = QStringLiteral("image"); const QString VAbstractPattern::TagMeasurements = QStringLiteral("measurements"); const QString VAbstractPattern::TagIncrements = QStringLiteral("increments"); const QString VAbstractPattern::TagIncrement = QStringLiteral("increment"); @@ -916,6 +917,21 @@ void VAbstractPattern::SetNotes(const QString &text) emit patternChanged(false); } +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractPattern::GetImage() const +{ + return UniqueTagText(TagImage); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetImage(const QString &text) +{ + CheckTagExists(TagImage); + setTagText(TagImage, text); + modified = true; + emit patternChanged(false); +} + //--------------------------------------------------------------------------------------------------------------------- QString VAbstractPattern::GetVersion() const { @@ -988,7 +1004,8 @@ void VAbstractPattern::CheckTagExists(const QString &tag) QDomNodeList list = elementsByTagName(tag); if (list.size() == 0) { - QStringList tags = QStringList() << TagVersion << TagAuthor << TagDescription << TagNotes << TagGradation; + QStringList tags = QStringList() << TagVersion << TagAuthor << TagDescription << TagNotes << TagImage + << TagGradation; QDomElement pattern = documentElement(); switch (tags.indexOf(tag)) { @@ -1026,7 +1043,13 @@ void VAbstractPattern::CheckTagExists(const QString &tag) SetVersion(); break; } - case 4: //TagGradation + case 4: //TagImage + { + pattern.insertAfter(createElement(TagImage), elementsByTagName(TagVersion).at(0)); + SetVersion(); + break; + } + case 5: //TagGradation { QDomElement gradation = createElement(TagGradation); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 46c99eb85..4ce8ad334 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -106,6 +106,9 @@ public: QString GetNotes() const; void SetNotes(const QString &text); + QString GetImage() const; + void SetImage(const QString &text); + QString GetVersion() const; void SetVersion(); @@ -120,6 +123,7 @@ public: static const QString TagDetails; static const QString TagAuthor; static const QString TagDescription; + static const QString TagImage; static const QString TagNotes; static const QString TagMeasurements; static const QString TagIncrements; diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index f725d1d65..4d2c4c99f 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.7"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.7.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.2.8"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.8.xsd"); //--------------------------------------------------------------------------------------------------------------------- VPatternConverter::VPatternConverter(const QString &fileName) @@ -111,6 +111,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000206): return QStringLiteral("://schema/pattern/v0.2.6.xsd"); case (0x000207): + return QStringLiteral("://schema/pattern/v0.2.7.xsd"); + case (0x000208): return CurrentSchema; default: InvalidVersion(ver); @@ -210,6 +212,13 @@ void VPatternConverter::ApplyPatches() V_FALLTHROUGH } case (0x000207): + { + ToV0_2_8(); + const QString schema = XSDSchema(0x000208); + ValidateXML(schema, fileName); + V_FALLTHROUGH + } + case (0x000208): break; default: break; @@ -331,6 +340,15 @@ void VPatternConverter::ToV0_2_7() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_2_8() +{ + SetVersion(QStringLiteral("0.2.8")); + QDomElement pattern = documentElement(); + pattern.insertAfter(createElement("image"), pattern.firstChildElement("notes")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index d1a0be553..bae6e282e 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -68,6 +68,7 @@ private: void ToV0_2_5(); void ToV0_2_6(); void ToV0_2_7(); + void ToV0_2_8(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); From ae66acd4d62ce505c99d67a154c7b4ba74a8425b Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sun, 13 Mar 2016 21:13:58 +0200 Subject: [PATCH 03/26] Fixed schema version --HG-- branch : feature --- src/libs/ifc/schema.qrc | 1 - src/libs/ifc/schema/pattern/v0.2.7.xsd | 1 + src/libs/ifc/schema/pattern/v0.2.8.xsd | 442 ------------------------- src/libs/ifc/xml/vabstractpattern.cpp | 20 +- src/libs/ifc/xml/vpatternconverter.cpp | 22 +- src/libs/ifc/xml/vpatternconverter.h | 1 - 6 files changed, 13 insertions(+), 474 deletions(-) delete mode 100644 src/libs/ifc/schema/pattern/v0.2.8.xsd diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index c7ad3e335..1fe74a4c7 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -22,6 +22,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.8.xsd diff --git a/src/libs/ifc/schema/pattern/v0.2.7.xsd b/src/libs/ifc/schema/pattern/v0.2.7.xsd index 3db42ee88..807f16b77 100644 --- a/src/libs/ifc/schema/pattern/v0.2.7.xsd +++ b/src/libs/ifc/schema/pattern/v0.2.7.xsd @@ -5,6 +5,7 @@ + diff --git a/src/libs/ifc/schema/pattern/v0.2.8.xsd b/src/libs/ifc/schema/pattern/v0.2.8.xsd deleted file mode 100644 index 0e7fe7f7a..000000000 --- a/src/libs/ifc/schema/pattern/v0.2.8.xsd +++ /dev/null @@ -1,442 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 31acb5d69..223733165 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1004,18 +1004,24 @@ void VAbstractPattern::CheckTagExists(const QString &tag) QDomNodeList list = elementsByTagName(tag); if (list.size() == 0) { - QStringList tags = QStringList() << TagVersion << TagAuthor << TagDescription << TagNotes << TagImage + QStringList tags = QStringList() << TagVersion << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation; QDomElement pattern = documentElement(); switch (tags.indexOf(tag)) { case 0: //TagVersion break;// Mandatory tag - case 1: //TagAuthor + case 1: //TagImage + { + pattern.insertAfter(createElement(TagImage), elementsByTagName(TagVersion).at(0)); + SetVersion(); + break; + } + case 2: //TagAuthor pattern.insertAfter(createElement(TagAuthor), elementsByTagName(TagVersion).at(0)); SetVersion(); break; - case 2: //TagDescription + case 3: //TagDescription { for (int i = tags.indexOf(tag)-1; i >= 0; --i) { @@ -1029,7 +1035,7 @@ void VAbstractPattern::CheckTagExists(const QString &tag) SetVersion(); break; } - case 3: //TagNotes + case 4: //TagNotes { for (int i = tags.indexOf(tag)-1; i >= 0; --i) { @@ -1043,12 +1049,6 @@ void VAbstractPattern::CheckTagExists(const QString &tag) SetVersion(); break; } - case 4: //TagImage - { - pattern.insertAfter(createElement(TagImage), elementsByTagName(TagVersion).at(0)); - SetVersion(); - break; - } case 5: //TagGradation { QDomElement gradation = createElement(TagGradation); diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 4d2c4c99f..f725d1d65 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.8"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.8.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.2.7"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.7.xsd"); //--------------------------------------------------------------------------------------------------------------------- VPatternConverter::VPatternConverter(const QString &fileName) @@ -111,8 +111,6 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000206): return QStringLiteral("://schema/pattern/v0.2.6.xsd"); case (0x000207): - return QStringLiteral("://schema/pattern/v0.2.7.xsd"); - case (0x000208): return CurrentSchema; default: InvalidVersion(ver); @@ -212,13 +210,6 @@ void VPatternConverter::ApplyPatches() V_FALLTHROUGH } case (0x000207): - { - ToV0_2_8(); - const QString schema = XSDSchema(0x000208); - ValidateXML(schema, fileName); - V_FALLTHROUGH - } - case (0x000208): break; default: break; @@ -340,15 +331,6 @@ void VPatternConverter::ToV0_2_7() Save(); } -//--------------------------------------------------------------------------------------------------------------------- -void VPatternConverter::ToV0_2_8() -{ - SetVersion(QStringLiteral("0.2.8")); - QDomElement pattern = documentElement(); - pattern.insertAfter(createElement("image"), pattern.firstChildElement("notes")); - Save(); -} - //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index bae6e282e..d1a0be553 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -68,7 +68,6 @@ private: void ToV0_2_5(); void ToV0_2_6(); void ToV0_2_7(); - void ToV0_2_8(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); From d2e0c7822f2df63546fa263b25ef911b890e191c Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Tue, 15 Mar 2016 20:32:52 +0200 Subject: [PATCH 04/26] Added delete button --HG-- branch : feature --- .../valentina/dialogs/dialogpatternproperties.cpp | 9 ++++++++- .../valentina/dialogs/dialogpatternproperties.h | 1 + .../valentina/dialogs/dialogpatternproperties.ui | 7 +++++++ src/app/valentina/xml/vpattern.cpp | 3 +-- src/libs/ifc/xml/vabstractpattern.cpp | 14 ++++++++++++++ src/libs/ifc/xml/vabstractpattern.h | 1 + 6 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 8412ccc34..9b5e739a7 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -65,6 +65,7 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat connect(ui->plainTextEditTechNotes, &QPlainTextEdit::textChanged, this, &DialogPatternProperties::DescEdited); InitImage(); + connect(ui->deleteImageButton, &QPushButton::clicked, this, &DialogPatternProperties::DeleteImage); connect(ui->buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &DialogPatternProperties::Ok); connect(ui->buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, @@ -649,5 +650,11 @@ void DialogPatternProperties::SetNewImage() // save our image to file.val doc->SetImage(iconBase64); } - +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::DeleteImage() +{ + doc->DeleteImage(); + ui->imageLabel->setText("Change image"); } diff --git a/src/app/valentina/dialogs/dialogpatternproperties.h b/src/app/valentina/dialogs/dialogpatternproperties.h index 3453f570f..4e504b840 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.h +++ b/src/app/valentina/dialogs/dialogpatternproperties.h @@ -64,6 +64,7 @@ private slots: void ToggleComboBox(); void DefValueChanged(); void SecurityValueChanged(); + void DeleteImage(); private: Q_DISABLE_COPY(DialogPatternProperties) Ui::DialogPatternProperties *ui; diff --git a/src/app/valentina/dialogs/dialogpatternproperties.ui b/src/app/valentina/dialogs/dialogpatternproperties.ui index ac9be310b..e814be49a 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.ui +++ b/src/app/valentina/dialogs/dialogpatternproperties.ui @@ -106,6 +106,13 @@ + + + + delete image + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 6302d7989..d36482adf 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -86,7 +86,6 @@ void VPattern::CreateEmptyFile() patternElement.appendChild(createElement(TagAuthor)); patternElement.appendChild(createElement(TagDescription)); patternElement.appendChild(createElement(TagNotes)); - patternElement.appendChild(createElement(TagImage)); patternElement.appendChild(createElement(TagMeasurements)); patternElement.appendChild(createElement(TagIncrements)); @@ -128,7 +127,7 @@ void VPattern::Parse(const Document &parse) SCASSERT(sceneDraw != nullptr); SCASSERT(sceneDetail != nullptr); QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes - << TagImage << TagMeasurements << TagVersion << TagGradation << TagUnit; + << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 223733165..424d4dd9f 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -932,6 +932,20 @@ void VAbstractPattern::SetImage(const QString &text) emit patternChanged(false); } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::DeleteImage() +{ + QDomElement pattern = documentElement(); + QDomNodeList images = this->elementsByTagName(TagImage); + for (int i=0; i Date: Thu, 17 Mar 2016 16:34:40 +0200 Subject: [PATCH 05/26] Added context menu --HG-- branch : feature --- .../dialogs/dialogpatternproperties.cpp | 26 ++++++++++++++++++- .../dialogs/dialogpatternproperties.h | 5 ++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 9b5e739a7..bab98d197 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "../xml/vpattern.h" #include "../vpatterndb/vcontainer.h" #include "../core/vapplication.h" @@ -65,7 +66,6 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat connect(ui->plainTextEditTechNotes, &QPlainTextEdit::textChanged, this, &DialogPatternProperties::DescEdited); InitImage(); - connect(ui->deleteImageButton, &QPushButton::clicked, this, &DialogPatternProperties::DeleteImage); connect(ui->buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &DialogPatternProperties::Ok); connect(ui->buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, @@ -620,8 +620,20 @@ void DialogPatternProperties::InitImage() QBuffer buffer(&ba); buffer.open(QIODevice::ReadOnly); image.load(&buffer, "PNG"); // writes image into ba in PNG format + ui->imageLabel->setPixmap(QPixmap::fromImage(image)); + ui->imageLabel->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->changeImageButton, &QPushButton::clicked, this, &DialogPatternProperties::SetNewImage); + connect(ui->deleteImageButton, &QPushButton::clicked, this, &DialogPatternProperties::DeleteImage); + connect(ui->imageLabel, &QWidget::customContextMenuRequested, this, &DialogPatternProperties::ShowContextMenu); + + deleteAction = new QAction("Delete image", this); + changeImageAction = new QAction("Change image", this); + saveImageAction = new QAction("Save image to file", this); + showImageAction = new QAction("Show image", this); + connect(deleteAction, &QAction::triggered, this, &DialogPatternProperties::DeleteImage); + connect(changeImageAction, &QAction::triggered, this, &DialogPatternProperties::SetNewImage); } //--------------------------------------------------------------------------------------------------------------------- @@ -658,3 +670,15 @@ void DialogPatternProperties::DeleteImage() doc->DeleteImage(); ui->imageLabel->setText("Change image"); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::ShowContextMenu() +{ + QMenu menu(this); + menu.addAction(deleteAction); + menu.addAction(changeImageAction); + menu.addAction(saveImageAction); + menu.addAction(showImageAction); + menu.exec(QCursor::pos()); + menu.show(); +} diff --git a/src/app/valentina/dialogs/dialogpatternproperties.h b/src/app/valentina/dialogs/dialogpatternproperties.h index 4e504b840..80c58bc66 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.h +++ b/src/app/valentina/dialogs/dialogpatternproperties.h @@ -58,6 +58,7 @@ public slots: void CheckStateSize(int state); void DescEdited(); void SetNewImage(); + void ShowContextMenu(); protected: virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; private slots: @@ -80,6 +81,10 @@ private: bool defaultChanged; bool securityChanged; bool isInitialized; + QAction *deleteAction; + QAction *changeImageAction; + QAction *saveImageAction; + QAction *showImageAction; void SetHeightsChecked(bool enabled); void SetSizesChecked(bool enabled); From a2619d8584dd7b199deeb95e2a40df36e5506a17 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Fri, 18 Mar 2016 20:23:19 +0200 Subject: [PATCH 06/26] Added saveImage button to context menu --HG-- branch : feature --- .../dialogs/dialogpatternproperties.cpp | 18 ++++++++++++++++++ .../dialogs/dialogpatternproperties.h | 1 + 2 files changed, 19 insertions(+) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index bab98d197..7dbca591e 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -634,6 +634,7 @@ void DialogPatternProperties::InitImage() showImageAction = new QAction("Show image", this); connect(deleteAction, &QAction::triggered, this, &DialogPatternProperties::DeleteImage); connect(changeImageAction, &QAction::triggered, this, &DialogPatternProperties::SetNewImage); + connect(saveImageAction, &QAction::triggered, this, &DialogPatternProperties::SaveImage); } //--------------------------------------------------------------------------------------------------------------------- @@ -671,6 +672,23 @@ void DialogPatternProperties::DeleteImage() ui->imageLabel->setText("Change image"); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::SaveImage() +{ + QByteArray byteArray; + byteArray.append(doc->GetImage().toUtf8()); + QByteArray ba = QByteArray::fromBase64(byteArray); + + QString extension = ".PNG"; + QString filename = QFileDialog::getSaveFileName(this, tr("Save File")); + QFile file(filename + extension); + if (file.open(QIODevice::WriteOnly)) + { + file.write(ba); + file.close(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::ShowContextMenu() { diff --git a/src/app/valentina/dialogs/dialogpatternproperties.h b/src/app/valentina/dialogs/dialogpatternproperties.h index 80c58bc66..ae1b8cbc1 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.h +++ b/src/app/valentina/dialogs/dialogpatternproperties.h @@ -66,6 +66,7 @@ private slots: void DefValueChanged(); void SecurityValueChanged(); void DeleteImage(); + void SaveImage(); private: Q_DISABLE_COPY(DialogPatternProperties) Ui::DialogPatternProperties *ui; From 7d8a959c563dd49583db1019e9655bbfa236e000 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Fri, 18 Mar 2016 20:23:42 +0200 Subject: [PATCH 07/26] Fixed size of imageLabel --HG-- branch : feature --- .../dialogs/dialogpatternproperties.cpp | 1 + .../dialogs/dialogpatternproperties.ui | 45 +++++++++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 7dbca591e..c05fac8b9 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -623,6 +623,7 @@ void DialogPatternProperties::InitImage() ui->imageLabel->setPixmap(QPixmap::fromImage(image)); ui->imageLabel->setContextMenuPolicy(Qt::CustomContextMenu); + ui->imageLabel->setScaledContents(true); connect(ui->changeImageButton, &QPushButton::clicked, this, &DialogPatternProperties::SetNewImage); connect(ui->deleteImageButton, &QPushButton::clicked, this, &DialogPatternProperties::DeleteImage); diff --git a/src/app/valentina/dialogs/dialogpatternproperties.ui b/src/app/valentina/dialogs/dialogpatternproperties.ui index e814be49a..5479e827b 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.ui +++ b/src/app/valentina/dialogs/dialogpatternproperties.ui @@ -85,20 +85,6 @@ 0 - - - - Image - - - - - - - No image - - - @@ -113,6 +99,37 @@ + + + + + 200 + 200 + + + + + 150 + 200 + + + + + 200 + 200 + + + + No image + + + Qt::AutoText + + + Qt::AlignCenter + + + From 2efe06f4442e074fd6268d5a787e4cd43f445b07 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sat, 19 Mar 2016 10:36:16 +0200 Subject: [PATCH 08/26] Added tr for all strings --HG-- branch : feature --- src/app/valentina/dialogs/dialogpatternproperties.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index c05fac8b9..84d1e4a94 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -629,10 +629,10 @@ void DialogPatternProperties::InitImage() connect(ui->deleteImageButton, &QPushButton::clicked, this, &DialogPatternProperties::DeleteImage); connect(ui->imageLabel, &QWidget::customContextMenuRequested, this, &DialogPatternProperties::ShowContextMenu); - deleteAction = new QAction("Delete image", this); - changeImageAction = new QAction("Change image", this); - saveImageAction = new QAction("Save image to file", this); - showImageAction = new QAction("Show image", this); + deleteAction = new QAction(tr("Delete image"), this); + changeImageAction = new QAction(tr("Change image"), this); + saveImageAction = new QAction(tr("Save image to file"), this); + showImageAction = new QAction(tr("Show image"), this); connect(deleteAction, &QAction::triggered, this, &DialogPatternProperties::DeleteImage); connect(changeImageAction, &QAction::triggered, this, &DialogPatternProperties::SetNewImage); connect(saveImageAction, &QAction::triggered, this, &DialogPatternProperties::SaveImage); @@ -670,7 +670,7 @@ void DialogPatternProperties::SetNewImage() void DialogPatternProperties::DeleteImage() { doc->DeleteImage(); - ui->imageLabel->setText("Change image"); + ui->imageLabel->setText(tr("Change image")); } //--------------------------------------------------------------------------------------------------------------------- From 1d959cb747dc2a76385d0a9fcc3e6205441856e1 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Tue, 22 Mar 2016 12:18:05 +0200 Subject: [PATCH 09/26] Now we can use PNG, JPG, JPEG and BMP images --HG-- branch : feature --- .../dialogs/dialogpatternproperties.cpp | 35 +++++++++++----- src/libs/ifc/schema/pattern/v0.2.7.xsd | 10 ++++- src/libs/ifc/xml/vabstractpattern.cpp | 40 ++++++++++++++++++- src/libs/ifc/xml/vabstractpattern.h | 3 +- 4 files changed, 75 insertions(+), 13 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 84d1e4a94..50ecacea1 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -619,7 +619,12 @@ void DialogPatternProperties::InitImage() QByteArray ba = QByteArray::fromBase64(byteArray); QBuffer buffer(&ba); buffer.open(QIODevice::ReadOnly); - image.load(&buffer, "PNG"); // writes image into ba in PNG format + QString extension = doc->GetImageExtension(); + if (extension.isEmpty()) + { + extension = "PNG"; + } + image.load(&buffer, extension.toLatin1().data()); // writes image into ba in PNG format ui->imageLabel->setPixmap(QPixmap::fromImage(image)); ui->imageLabel->setContextMenuPolicy(Qt::CustomContextMenu); @@ -641,7 +646,8 @@ void DialogPatternProperties::InitImage() //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::SetNewImage() { - const QString fileName = QFileDialog::getOpenFileName(this, tr("Image for pattern"), QString(), tr("Images (*.png)")); + const QString fileName = QFileDialog::getOpenFileName(this, tr("Image for pattern"), QString(), + tr("Images (*.png *.jpg *.jpeg *.bmp)")); QImage image; if (fileName.isEmpty()) { @@ -654,15 +660,24 @@ void DialogPatternProperties::SetNewImage() return; } ui->imageLabel->setPixmap(QPixmap::fromImage(image)); + QFileInfo f(fileName); + QString extension = f.suffix().toUpper(); - QByteArray byteArray; - QBuffer buffer(&byteArray); - buffer.open(QIODevice::WriteOnly); - image.save(&buffer, "PNG"); // writes the image in PNG format inside the buffer - QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data()); + if (extension == "JPEG") + { + extension = "JPG"; + } + if (extension == "PNG" || extension == "JPG" || extension == "BMP") + { + QByteArray byteArray; + QBuffer buffer(&byteArray); + buffer.open(QIODevice::WriteOnly); + image.save(&buffer, extension.toLatin1().data()); // writes the image in 'extension' format inside the buffer + QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data()); - // save our image to file.val - doc->SetImage(iconBase64); + // save our image to file.val + doc->SetImage(iconBase64, extension); + } } } @@ -680,7 +695,7 @@ void DialogPatternProperties::SaveImage() byteArray.append(doc->GetImage().toUtf8()); QByteArray ba = QByteArray::fromBase64(byteArray); - QString extension = ".PNG"; + QString extension = "." + doc->GetImageExtension(); QString filename = QFileDialog::getSaveFileName(this, tr("Save File")); QFile file(filename + extension); if (file.open(QIODevice::WriteOnly)) diff --git a/src/libs/ifc/schema/pattern/v0.2.7.xsd b/src/libs/ifc/schema/pattern/v0.2.7.xsd index 807f16b77..f7e6a556e 100644 --- a/src/libs/ifc/schema/pattern/v0.2.7.xsd +++ b/src/libs/ifc/schema/pattern/v0.2.7.xsd @@ -5,7 +5,15 @@ - + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 424d4dd9f..5e38b33b7 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -924,10 +924,48 @@ QString VAbstractPattern::GetImage() const } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetImage(const QString &text) +QString VAbstractPattern::GetImageExtension() const +{ + const QString defExt = "PNG"; + const QDomNodeList nodeList = this->elementsByTagName(TagImage); + if (nodeList.isEmpty()) + { + return defExt; + } + else + { + const QDomNode domNode = nodeList.at(0); + if (domNode.isNull() == false && domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + const QString ext = domElement.attribute(QString("extension"), ""); + if (ext.isEmpty()) + { + return defExt; + } + else + { + return ext; + } + } + } + } + return defExt; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetImage(const QString &text, const QString &extension) { CheckTagExists(TagImage); setTagText(TagImage, text); + QDomNodeList list = elementsByTagName(TagImage); + for (int i=0; i < list.size(); ++i) + { + QDomElement dom = list.at(i).toElement(); + dom.setAttribute(QString("extension"), extension); + } modified = true; emit patternChanged(false); } diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 6cb575803..aeb0a9d97 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -107,7 +107,8 @@ public: void SetNotes(const QString &text); QString GetImage() const; - void SetImage(const QString &text); + QString GetImageExtension() const; + void SetImage(const QString &text, const QString &extension); void DeleteImage(); QString GetVersion() const; From ecfdafddfcef30c897cd8fa7d4e30cf33daff7d6 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Tue, 22 Mar 2016 20:46:17 +0200 Subject: [PATCH 10/26] Little optimization --HG-- branch : feature --- src/app/valentina/dialogs/dialogpatternproperties.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 50ecacea1..3970ae562 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -663,16 +663,16 @@ void DialogPatternProperties::SetNewImage() QFileInfo f(fileName); QString extension = f.suffix().toUpper(); - if (extension == "JPEG") + if (extension == QLatin1String("JPEG")) { extension = "JPG"; } - if (extension == "PNG" || extension == "JPG" || extension == "BMP") + if (extension == QLatin1String("PNG") || extension == QLatin1String("JPG") || extension == QLatin1String("BMP")) { QByteArray byteArray; QBuffer buffer(&byteArray); buffer.open(QIODevice::WriteOnly); - image.save(&buffer, extension.toLatin1().data()); // writes the image in 'extension' format inside the buffer + image.save(&buffer, extension.toLatin1().data()); //writes the image in 'extension' format inside the buffer QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data()); // save our image to file.val From fc27fa7feff874c7a6579d3b79f677eb40c77113 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Wed, 23 Mar 2016 14:32:15 +0200 Subject: [PATCH 11/26] Created a custom type imageExtension --HG-- branch : feature --- src/libs/ifc/schema/pattern/v0.2.7.xsd | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libs/ifc/schema/pattern/v0.2.7.xsd b/src/libs/ifc/schema/pattern/v0.2.7.xsd index f7e6a556e..519b9e296 100644 --- a/src/libs/ifc/schema/pattern/v0.2.7.xsd +++ b/src/libs/ifc/schema/pattern/v0.2.7.xsd @@ -9,7 +9,7 @@ - + @@ -349,6 +349,13 @@ + + + + + + + From ae53e505c472cf6e349e0f3cd6171d2e8d34126c Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Fri, 25 Mar 2016 01:58:00 +0200 Subject: [PATCH 12/26] Save image with correct extension --HG-- branch : feature --- src/app/valentina/dialogs/dialogpatternproperties.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 3970ae562..8664171fd 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -694,10 +694,14 @@ void DialogPatternProperties::SaveImage() QByteArray byteArray; byteArray.append(doc->GetImage().toUtf8()); QByteArray ba = QByteArray::fromBase64(byteArray); - QString extension = "." + doc->GetImageExtension(); - QString filename = QFileDialog::getSaveFileName(this, tr("Save File")); - QFile file(filename + extension); + QString filter = "Images (*" + extension + ")"; + QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), "untitled", filter, &filter); + if (not filename.endsWith(extension.toUpper())) + { + filename.append(extension); + } + QFile file(filename); if (file.open(QIODevice::WriteOnly)) { file.write(ba); From 5fda012b864f6c26f751e6c1adbb748e7e797ee2 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sun, 27 Mar 2016 14:22:16 +0300 Subject: [PATCH 13/26] Added showImage to context menu --HG-- branch : feature --- .../dialogs/dialogpatternproperties.cpp | 24 +++++++++++++++---- .../dialogs/dialogpatternproperties.h | 2 ++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 8664171fd..b9b9bcf55 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -610,7 +610,7 @@ void DialogPatternProperties::InitComboBox(QComboBox *box, const QMapimageLabel->setPixmap(QPixmap::fromImage(image)); +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::InitImage() +{ + ui->imageLabel->setPixmap(QPixmap::fromImage(GetImage())); ui->imageLabel->setContextMenuPolicy(Qt::CustomContextMenu); ui->imageLabel->setScaledContents(true); @@ -641,6 +646,7 @@ void DialogPatternProperties::InitImage() connect(deleteAction, &QAction::triggered, this, &DialogPatternProperties::DeleteImage); connect(changeImageAction, &QAction::triggered, this, &DialogPatternProperties::SetNewImage); connect(saveImageAction, &QAction::triggered, this, &DialogPatternProperties::SaveImage); + connect(showImageAction, &QAction::triggered, this, &DialogPatternProperties::ShowImage); } //--------------------------------------------------------------------------------------------------------------------- @@ -695,7 +701,7 @@ void DialogPatternProperties::SaveImage() byteArray.append(doc->GetImage().toUtf8()); QByteArray ba = QByteArray::fromBase64(byteArray); QString extension = "." + doc->GetImageExtension(); - QString filter = "Images (*" + extension + ")"; + QString filter = tr("Images (*") + extension + ")"; QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), "untitled", filter, &filter); if (not filename.endsWith(extension.toUpper())) { @@ -709,6 +715,16 @@ void DialogPatternProperties::SaveImage() } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::ShowImage() +{ + QLabel *label = new QLabel(this, Qt::Window); + QImage image = GetImage(); + label->setPixmap(QPixmap::fromImage(image)); + label->setGeometry(QRect(QCursor::pos(), image.size())); + label->show(); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::ShowContextMenu() { diff --git a/src/app/valentina/dialogs/dialogpatternproperties.h b/src/app/valentina/dialogs/dialogpatternproperties.h index ae1b8cbc1..14d737ba6 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.h +++ b/src/app/valentina/dialogs/dialogpatternproperties.h @@ -67,6 +67,7 @@ private slots: void SecurityValueChanged(); void DeleteImage(); void SaveImage(); + void ShowImage(); private: Q_DISABLE_COPY(DialogPatternProperties) Ui::DialogPatternProperties *ui; @@ -108,6 +109,7 @@ private: void UpdateDefHeight(); void UpdateDefSize(); void InitImage(); + QImage GetImage(); }; #endif // DIALOGPATTERNPROPERTIES_H From e838ae811ec87d48f2c310e059ae6c5edeacb403 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sun, 27 Mar 2016 14:39:52 +0300 Subject: [PATCH 14/26] Little fixes --HG-- branch : feature --- src/app/valentina/dialogs/dialogpatternproperties.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index b9b9bcf55..43d40b67e 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -700,9 +700,9 @@ void DialogPatternProperties::SaveImage() QByteArray byteArray; byteArray.append(doc->GetImage().toUtf8()); QByteArray ba = QByteArray::fromBase64(byteArray); - QString extension = "." + doc->GetImageExtension(); + const QString extension = "." + doc->GetImageExtension(); QString filter = tr("Images (*") + extension + ")"; - QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), "untitled", filter, &filter); + QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), tr("untitled"), filter, &filter); if (not filename.endsWith(extension.toUpper())) { filename.append(extension); @@ -719,7 +719,7 @@ void DialogPatternProperties::SaveImage() void DialogPatternProperties::ShowImage() { QLabel *label = new QLabel(this, Qt::Window); - QImage image = GetImage(); + const QImage image = GetImage(); label->setPixmap(QPixmap::fromImage(image)); label->setGeometry(QRect(QCursor::pos(), image.size())); label->show(); From b22c5b656a12ff7dc508bb5468ec1c415f8548fd Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sun, 27 Mar 2016 14:51:36 +0300 Subject: [PATCH 15/26] Fixed little bug when we try to save image --HG-- branch : feature --- .../dialogs/dialogpatternproperties.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 43d40b67e..710ddc0f7 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -703,15 +703,18 @@ void DialogPatternProperties::SaveImage() const QString extension = "." + doc->GetImageExtension(); QString filter = tr("Images (*") + extension + ")"; QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), tr("untitled"), filter, &filter); - if (not filename.endsWith(extension.toUpper())) + if (not filename.isEmpty()) { - filename.append(extension); - } - QFile file(filename); - if (file.open(QIODevice::WriteOnly)) - { - file.write(ba); - file.close(); + if (not filename.endsWith(extension.toUpper())) + { + filename.append(extension); + } + QFile file(filename); + if (file.open(QIODevice::WriteOnly)) + { + file.write(ba); + file.close(); + } } } From bb98eeb54bdab04586d21fb88911f1e621b81f12 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Mon, 28 Mar 2016 13:08:20 +0300 Subject: [PATCH 16/26] Little fixes --HG-- branch : feature --- src/app/valentina/dialogs/dialogpatternproperties.cpp | 8 ++++---- src/app/valentina/dialogs/dialogpatternproperties.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 710ddc0f7..569b6837f 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -635,7 +635,7 @@ void DialogPatternProperties::InitImage() ui->imageLabel->setContextMenuPolicy(Qt::CustomContextMenu); ui->imageLabel->setScaledContents(true); - connect(ui->changeImageButton, &QPushButton::clicked, this, &DialogPatternProperties::SetNewImage); + connect(ui->changeImageButton, &QPushButton::clicked, this, &DialogPatternProperties::ChangeImage); connect(ui->deleteImageButton, &QPushButton::clicked, this, &DialogPatternProperties::DeleteImage); connect(ui->imageLabel, &QWidget::customContextMenuRequested, this, &DialogPatternProperties::ShowContextMenu); @@ -644,13 +644,13 @@ void DialogPatternProperties::InitImage() saveImageAction = new QAction(tr("Save image to file"), this); showImageAction = new QAction(tr("Show image"), this); connect(deleteAction, &QAction::triggered, this, &DialogPatternProperties::DeleteImage); - connect(changeImageAction, &QAction::triggered, this, &DialogPatternProperties::SetNewImage); + connect(changeImageAction, &QAction::triggered, this, &DialogPatternProperties::ChangeImage); connect(saveImageAction, &QAction::triggered, this, &DialogPatternProperties::SaveImage); connect(showImageAction, &QAction::triggered, this, &DialogPatternProperties::ShowImage); } //--------------------------------------------------------------------------------------------------------------------- -void DialogPatternProperties::SetNewImage() +void DialogPatternProperties::ChangeImage() { const QString fileName = QFileDialog::getOpenFileName(this, tr("Image for pattern"), QString(), tr("Images (*.png *.jpg *.jpeg *.bmp)")); @@ -701,7 +701,7 @@ void DialogPatternProperties::SaveImage() byteArray.append(doc->GetImage().toUtf8()); QByteArray ba = QByteArray::fromBase64(byteArray); const QString extension = "." + doc->GetImageExtension(); - QString filter = tr("Images (*") + extension + ")"; + QString filter = tr("Images") + " (*" + extension + ")"; QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), tr("untitled"), filter, &filter); if (not filename.isEmpty()) { diff --git a/src/app/valentina/dialogs/dialogpatternproperties.h b/src/app/valentina/dialogs/dialogpatternproperties.h index 14d737ba6..ce8f07291 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.h +++ b/src/app/valentina/dialogs/dialogpatternproperties.h @@ -57,7 +57,7 @@ public slots: void CheckStateHeight(int state); void CheckStateSize(int state); void DescEdited(); - void SetNewImage(); + void ChangeImage(); void ShowContextMenu(); protected: virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; From 55a2da02cc6b4b7e079a5617ba441384b057918a Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Tue, 29 Mar 2016 01:08:07 +0300 Subject: [PATCH 17/26] Little optimization --HG-- branch : feature --- src/app/valentina/dialogs/dialogpatternproperties.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 569b6837f..e60553be1 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -701,7 +701,7 @@ void DialogPatternProperties::SaveImage() byteArray.append(doc->GetImage().toUtf8()); QByteArray ba = QByteArray::fromBase64(byteArray); const QString extension = "." + doc->GetImageExtension(); - QString filter = tr("Images") + " (*" + extension + ")"; + QString filter = tr("Images") + QLatin1String(" (*") + extension + QLatin1String(")"); QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), tr("untitled"), filter, &filter); if (not filename.isEmpty()) { From ebab22d6ca7ddee89e7f844a39079ff527d288c6 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sat, 2 Apr 2016 03:00:00 +0300 Subject: [PATCH 18/26] Little fixes --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 12 ++-- src/libs/ifc/schema/pattern/v0.2.7.xsd | 2 +- src/libs/ifc/xml/vabstractpattern.cpp | 80 ++++++++++---------------- src/libs/ifc/xml/vabstractpattern.h | 2 + 4 files changed, 40 insertions(+), 56 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index d36482adf..96e00edf4 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -172,18 +172,18 @@ void VPattern::Parse(const Document &parse) case 4: // TagNotes qCDebug(vXML, "Tag notes."); break; - case 5: // TagImage - qCDebug(vXML, "Tag image."); - break; - case 6: // TagMeasurements + case 5: // TagMeasurements qCDebug(vXML, "Tag measurements."); break; - case 7: // TagVersion + case 6: // TagVersion qCDebug(vXML, "Tag version."); break; - case 8: // TagGradation + case 7: // TagGradation qCDebug(vXML, "Tag gradation."); break; + case 8: // TagImage + qCDebug(vXML, "Tag image."); + break; case 9: // TagUnit qCDebug(vXML, "Tag unit."); break; diff --git a/src/libs/ifc/schema/pattern/v0.2.7.xsd b/src/libs/ifc/schema/pattern/v0.2.7.xsd index 519b9e296..eb5b3c144 100644 --- a/src/libs/ifc/schema/pattern/v0.2.7.xsd +++ b/src/libs/ifc/schema/pattern/v0.2.7.xsd @@ -5,6 +5,7 @@ + @@ -14,7 +15,6 @@ - diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 5e38b33b7..2b4eff537 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -100,6 +100,7 @@ const QString VAbstractPattern::AttrS56 = QStringLiteral("s56"); const QString VAbstractPattern::AttrCustom = QStringLiteral("custom"); const QString VAbstractPattern::AttrDefHeight = QStringLiteral("defHeight"); const QString VAbstractPattern::AttrDefSize = QStringLiteral("defSize"); +const QString VAbstractPattern::AttrExtension = QStringLiteral("extension"); const QString VAbstractPattern::IncrementName = QStringLiteral("name"); const QString VAbstractPattern::IncrementFormula = QStringLiteral("formula"); @@ -926,7 +927,7 @@ QString VAbstractPattern::GetImage() const //--------------------------------------------------------------------------------------------------------------------- QString VAbstractPattern::GetImageExtension() const { - const QString defExt = "PNG"; + const QString defExt = QStringLiteral("PNG"); const QDomNodeList nodeList = this->elementsByTagName(TagImage); if (nodeList.isEmpty()) { @@ -940,15 +941,8 @@ QString VAbstractPattern::GetImageExtension() const const QDomElement domElement = domNode.toElement(); if (domElement.isNull() == false) { - const QString ext = domElement.attribute(QString("extension"), ""); - if (ext.isEmpty()) - { - return defExt; - } - else - { - return ext; - } + const QString ext = domElement.attribute(AttrExtension, defExt); + return ext; } } } @@ -964,7 +958,7 @@ void VAbstractPattern::SetImage(const QString &text, const QString &extension) for (int i=0; i < list.size(); ++i) { QDomElement dom = list.at(i).toElement(); - dom.setAttribute(QString("extension"), extension); + dom.setAttribute(AttrExtension, extension); } modified = true; emit patternChanged(false); @@ -1056,49 +1050,30 @@ void VAbstractPattern::CheckTagExists(const QString &tag) QDomNodeList list = elementsByTagName(tag); if (list.size() == 0) { - QStringList tags = QStringList() << TagVersion << TagImage << TagAuthor << TagDescription << TagNotes + const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation; - QDomElement pattern = documentElement(); switch (tags.indexOf(tag)) { - case 0: //TagVersion + case 0: //TagUnit break;// Mandatory tag case 1: //TagImage { - pattern.insertAfter(createElement(TagImage), elementsByTagName(TagVersion).at(0)); - SetVersion(); + InsertTag(tags, createElement(TagImage)); break; } case 2: //TagAuthor - pattern.insertAfter(createElement(TagAuthor), elementsByTagName(TagVersion).at(0)); - SetVersion(); + { + InsertTag(tags, createElement(TagAuthor)); break; + } case 3: //TagDescription { - for (int i = tags.indexOf(tag)-1; i >= 0; --i) - { - QDomNodeList list = elementsByTagName(tags.at(i)); - if (list.isEmpty()) - { - continue; - } - pattern.insertAfter(createElement(TagDescription), list.at(0)); - } - SetVersion(); + InsertTag(tags, createElement(TagDescription)); break; } case 4: //TagNotes { - for (int i = tags.indexOf(tag)-1; i >= 0; --i) - { - QDomNodeList list = elementsByTagName(tags.at(i)); - if (list.isEmpty()) - { - continue; - } - pattern.insertAfter(createElement(TagNotes), list.at(0)); - } - SetVersion(); + InsertTag(tags, createElement(TagNotes)); break; } case 5: //TagGradation @@ -1113,17 +1088,7 @@ void VAbstractPattern::CheckTagExists(const QString &tag) sizes.setAttribute(AttrAll, QLatin1Literal("true")); gradation.appendChild(sizes); - for (int i = tags.indexOf(tag)-1; i >= 0; --i) - { - QDomNodeList list = elementsByTagName(tags.at(i)); - if (list.isEmpty()) - { - continue; - } - pattern.insertAfter(gradation, list.at(0)); - break; - } - SetVersion(); + InsertTag(tags, gradation); break; } default: @@ -1132,6 +1097,23 @@ void VAbstractPattern::CheckTagExists(const QString &tag) } } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::InsertTag(QStringList tags, QDomElement element) +{ + QDomElement pattern = documentElement(); + for (int i = tags.indexOf(element.tagName())-1; i >= 0; --i) + { + QDomNodeList list = elementsByTagName(tags.at(i)); + if (list.isEmpty()) + { + continue; + } + pattern.insertAfter(element, list.at(0)); + return; + } + SetVersion(); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VAbstractPattern::ListIncrements() const { diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index aeb0a9d97..675f1160f 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -187,6 +187,7 @@ public: static const QString AttrCustom; static const QString AttrDefHeight; static const QString AttrDefSize; + static const QString AttrExtension; static const QString IncrementName; static const QString IncrementFormula; @@ -264,6 +265,7 @@ protected: void SetActivPP(const QString& name); void CheckTagExists(const QString &tag); + void InsertTag(QStringList tags, QDomElement element); private: Q_DISABLE_COPY(VAbstractPattern) From 56db3f6f1aa9a4539d4255fbe59c3673f9c5b035 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sat, 2 Apr 2016 10:25:21 +0300 Subject: [PATCH 19/26] Optimization. Make const in InsertTag method --HG-- branch : feature --- src/libs/ifc/xml/vabstractpattern.cpp | 5 ++--- src/libs/ifc/xml/vabstractpattern.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 2b4eff537..452986f9e 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1098,18 +1098,17 @@ void VAbstractPattern::CheckTagExists(const QString &tag) } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::InsertTag(QStringList tags, QDomElement element) +void VAbstractPattern::InsertTag(const QStringList tags, const QDomElement element) { QDomElement pattern = documentElement(); for (int i = tags.indexOf(element.tagName())-1; i >= 0; --i) { - QDomNodeList list = elementsByTagName(tags.at(i)); + const QDomNodeList list = elementsByTagName(tags.at(i)); if (list.isEmpty()) { continue; } pattern.insertAfter(element, list.at(0)); - return; } SetVersion(); } diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 675f1160f..98d254d57 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -265,7 +265,7 @@ protected: void SetActivPP(const QString& name); void CheckTagExists(const QString &tag); - void InsertTag(QStringList tags, QDomElement element); + void InsertTag(const QStringList tags, const QDomElement element); private: Q_DISABLE_COPY(VAbstractPattern) From 84d6e157bb09edf46e53ed3f06627c35e5edf398 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sat, 2 Apr 2016 11:37:37 +0300 Subject: [PATCH 20/26] Fixed InsertTag method --HG-- branch : feature --- src/libs/ifc/xml/vabstractpattern.cpp | 3 ++- src/libs/ifc/xml/vabstractpattern.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 452986f9e..343fb335b 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1098,7 +1098,7 @@ void VAbstractPattern::CheckTagExists(const QString &tag) } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::InsertTag(const QStringList tags, const QDomElement element) +void VAbstractPattern::InsertTag(const QStringList &tags, const QDomElement &element) { QDomElement pattern = documentElement(); for (int i = tags.indexOf(element.tagName())-1; i >= 0; --i) @@ -1109,6 +1109,7 @@ void VAbstractPattern::InsertTag(const QStringList tags, const QDomElement eleme continue; } pattern.insertAfter(element, list.at(0)); + break; } SetVersion(); } diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 98d254d57..e22cca707 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -265,7 +265,7 @@ protected: void SetActivPP(const QString& name); void CheckTagExists(const QString &tag); - void InsertTag(const QStringList tags, const QDomElement element); + void InsertTag(const QStringList &tags, const QDomElement &element); private: Q_DISABLE_COPY(VAbstractPattern) From c002aec49acb81f3fb79dcb41bf89523fef0f93c Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Mon, 4 Apr 2016 20:57:36 +0300 Subject: [PATCH 21/26] Little fixes --HG-- branch : feature --- src/app/valentina/dialogs/dialogpatternproperties.cpp | 8 ++------ src/libs/ifc/xml/vabstractpattern.cpp | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index e60553be1..2da40283c 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -620,10 +620,6 @@ QImage DialogPatternProperties::GetImage() QBuffer buffer(&ba); buffer.open(QIODevice::ReadOnly); QString extension = doc->GetImageExtension(); - if (extension.isEmpty()) - { - extension = "PNG"; - } image.load(&buffer, extension.toLatin1().data()); // writes image into ba in 'extension' format return image; } @@ -661,7 +657,7 @@ void DialogPatternProperties::ChangeImage() } else { - if (!image.load(fileName)) + if (not image.load(fileName)) { return; } @@ -700,7 +696,7 @@ void DialogPatternProperties::SaveImage() QByteArray byteArray; byteArray.append(doc->GetImage().toUtf8()); QByteArray ba = QByteArray::fromBase64(byteArray); - const QString extension = "." + doc->GetImageExtension(); + const QString extension = QLatin1String(".") + doc->GetImageExtension(); QString filter = tr("Images") + QLatin1String(" (*") + extension + QLatin1String(")"); QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), tr("untitled"), filter, &filter); if (not filename.isEmpty()) diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 343fb335b..a14e95b8e 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -968,7 +968,7 @@ void VAbstractPattern::SetImage(const QString &text, const QString &extension) void VAbstractPattern::DeleteImage() { QDomElement pattern = documentElement(); - QDomNodeList images = this->elementsByTagName(TagImage); + const QDomNodeList images = this->elementsByTagName(TagImage); for (int i=0; i Date: Wed, 6 Apr 2016 04:11:14 +0300 Subject: [PATCH 22/26] Optimization --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 6 +++--- src/libs/ifc/xml/vabstractpattern.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 96e00edf4..93dc710c4 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2751,7 +2751,7 @@ void VPattern::SetDefCustom(bool value) { CheckTagExists(TagGradation); QDomNodeList tags = elementsByTagName(TagGradation); - if (tags.size() == 0) + if (tags.isEmpty()) { qDebug()<<"Can't save attribute "< &options) { CheckTagExists(TagGradation); QDomNodeList tags = elementsByTagName(TagGradation); - if (tags.size() == 0) + if (tags.isEmpty()) { qDebug()<<"Can't save tag "< &options) { CheckTagExists(TagGradation); QDomNodeList tags = elementsByTagName(TagGradation); - if (tags.size() == 0) + if (tags.isEmpty()) { qDebug()<<"Can't save tag "< Date: Wed, 6 Apr 2016 05:31:42 +0300 Subject: [PATCH 23/26] CheckTagExists returns QDomElement --HG-- branch : feature --- src/libs/ifc/xml/vabstractpattern.cpp | 32 +++++++++++++++++---------- src/libs/ifc/xml/vabstractpattern.h | 2 +- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 5c84c535e..84587b9c4 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1045,56 +1045,64 @@ void VAbstractPattern::SetActivPP(const QString &name) } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::CheckTagExists(const QString &tag) +QDomElement VAbstractPattern::CheckTagExists(const QString &tag) { - QDomNodeList list = elementsByTagName(tag); - if (list.size() == 0) + const QDomNodeList list = elementsByTagName(tag); + QDomElement element; + if (list.isEmpty()) { const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation; switch (tags.indexOf(tag)) { case 0: //TagUnit + { + return QDomElement(); break;// Mandatory tag + } case 1: //TagImage { - InsertTag(tags, createElement(TagImage)); + element = createElement(TagImage); break; } case 2: //TagAuthor { - InsertTag(tags, createElement(TagAuthor)); + element = createElement(TagAuthor); break; } case 3: //TagDescription { - InsertTag(tags, createElement(TagDescription)); + element = createElement(TagDescription); break; } case 4: //TagNotes { - InsertTag(tags, createElement(TagNotes)); + element = createElement(TagNotes); break; } case 5: //TagGradation { - QDomElement gradation = createElement(TagGradation); + element = createElement(TagGradation); QDomElement heights = createElement(TagHeights); heights.setAttribute(AttrAll, QLatin1Literal("true")); - gradation.appendChild(heights); + element.appendChild(heights); QDomElement sizes = createElement(TagSizes); sizes.setAttribute(AttrAll, QLatin1Literal("true")); - gradation.appendChild(sizes); - - InsertTag(tags, gradation); + element.appendChild(sizes); break; } default: + { + return QDomElement(); break; + } } + InsertTag(tags, element); + return element; } + return list.at(0).toElement(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index e22cca707..a48dd24bf 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -264,7 +264,7 @@ protected: void SetActivPP(const QString& name); - void CheckTagExists(const QString &tag); + QDomElement CheckTagExists(const QString &tag); void InsertTag(const QStringList &tags, const QDomElement &element); private: From 8911fb5e1100170b778b7bbb4572b65dbdd1e3ac Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Wed, 6 Apr 2016 05:34:08 +0300 Subject: [PATCH 24/26] Overrided setTagText method --HG-- branch : feature --- src/libs/ifc/xml/vabstractpattern.cpp | 18 ++++----------- src/libs/ifc/xml/vdomdocument.cpp | 32 ++++++++++++++++----------- src/libs/ifc/xml/vdomdocument.h | 1 + 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 84587b9c4..2a5a0579b 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -952,14 +952,9 @@ QString VAbstractPattern::GetImageExtension() const //--------------------------------------------------------------------------------------------------------------------- void VAbstractPattern::SetImage(const QString &text, const QString &extension) { - CheckTagExists(TagImage); - setTagText(TagImage, text); - QDomNodeList list = elementsByTagName(TagImage); - for (int i=0; i < list.size(); ++i) - { - QDomElement dom = list.at(i).toElement(); - dom.setAttribute(AttrExtension, extension); - } + QDomElement imageElement = CheckTagExists(TagImage); + setTagText(imageElement, text); + CheckTagExists(TagImage).setAttribute(AttrExtension, extension); modified = true; emit patternChanged(false); } @@ -968,12 +963,7 @@ void VAbstractPattern::SetImage(const QString &text, const QString &extension) void VAbstractPattern::DeleteImage() { QDomElement pattern = documentElement(); - const QDomNodeList images = this->elementsByTagName(TagImage); - for (int i=0; i Date: Thu, 7 Apr 2016 02:51:11 +0300 Subject: [PATCH 25/26] Better looks if we have just one button "change image" --HG-- branch : feature --- src/app/valentina/dialogs/dialogpatternproperties.cpp | 1 - src/app/valentina/dialogs/dialogpatternproperties.ui | 7 ------- 2 files changed, 8 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 2da40283c..65ef62770 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -632,7 +632,6 @@ void DialogPatternProperties::InitImage() ui->imageLabel->setScaledContents(true); connect(ui->changeImageButton, &QPushButton::clicked, this, &DialogPatternProperties::ChangeImage); - connect(ui->deleteImageButton, &QPushButton::clicked, this, &DialogPatternProperties::DeleteImage); connect(ui->imageLabel, &QWidget::customContextMenuRequested, this, &DialogPatternProperties::ShowContextMenu); deleteAction = new QAction(tr("Delete image"), this); diff --git a/src/app/valentina/dialogs/dialogpatternproperties.ui b/src/app/valentina/dialogs/dialogpatternproperties.ui index 5479e827b..9c82ef7d5 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.ui +++ b/src/app/valentina/dialogs/dialogpatternproperties.ui @@ -92,13 +92,6 @@ - - - - delete image - - - From d42a39de106d76d28a5246da1c549fa742c7b2ce Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Thu, 7 Apr 2016 03:20:15 +0300 Subject: [PATCH 26/26] Disable save, show and delete actions when we have no image --HG-- branch : feature --- .../dialogs/dialogpatternproperties.cpp | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 65ef62770..175efe559 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -627,10 +627,8 @@ QImage DialogPatternProperties::GetImage() //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::InitImage() { - ui->imageLabel->setPixmap(QPixmap::fromImage(GetImage())); ui->imageLabel->setContextMenuPolicy(Qt::CustomContextMenu); ui->imageLabel->setScaledContents(true); - connect(ui->changeImageButton, &QPushButton::clicked, this, &DialogPatternProperties::ChangeImage); connect(ui->imageLabel, &QWidget::customContextMenuRequested, this, &DialogPatternProperties::ShowContextMenu); @@ -638,10 +636,23 @@ void DialogPatternProperties::InitImage() changeImageAction = new QAction(tr("Change image"), this); saveImageAction = new QAction(tr("Save image to file"), this); showImageAction = new QAction(tr("Show image"), this); + connect(deleteAction, &QAction::triggered, this, &DialogPatternProperties::DeleteImage); connect(changeImageAction, &QAction::triggered, this, &DialogPatternProperties::ChangeImage); connect(saveImageAction, &QAction::triggered, this, &DialogPatternProperties::SaveImage); connect(showImageAction, &QAction::triggered, this, &DialogPatternProperties::ShowImage); + + const QImage image = GetImage(); + if (not image.isNull()) + { + ui->imageLabel->setPixmap(QPixmap::fromImage(image)); + } + else + { + deleteAction->setEnabled(false); + saveImageAction->setEnabled(false); + showImageAction->setEnabled(false); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -679,6 +690,9 @@ void DialogPatternProperties::ChangeImage() // save our image to file.val doc->SetImage(iconBase64, extension); } + deleteAction->setEnabled(true); + saveImageAction->setEnabled(true); + showImageAction->setEnabled(true); } } @@ -687,6 +701,9 @@ void DialogPatternProperties::DeleteImage() { doc->DeleteImage(); ui->imageLabel->setText(tr("Change image")); + deleteAction->setEnabled(false); + saveImageAction->setEnabled(false); + showImageAction->setEnabled(false); } //---------------------------------------------------------------------------------------------------------------------