From 821bafbdee9db1ba212f5072be192deef18959ff Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Wed, 9 Mar 2016 21:01:37 +0200 Subject: [PATCH] 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();