Merge with develop.
--HG-- branch : feature
This commit is contained in:
commit
a0842b0f48
|
@ -28,7 +28,10 @@
|
|||
|
||||
#include "dialogpatternproperties.h"
|
||||
#include "ui_dialogpatternproperties.h"
|
||||
#include <QBuffer>
|
||||
#include <QPushButton>
|
||||
#include <QFileDialog>
|
||||
#include <QMenu>
|
||||
#include "../xml/vpattern.h"
|
||||
#include "../vpatterndb/vcontainer.h"
|
||||
#include "../core/vapplication.h"
|
||||
|
@ -41,7 +44,11 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat
|
|||
QDialog(parent), ui(new Ui::DialogPatternProperties), doc(doc), pattern(pattern), heightsChecked(MAX_HEIGHTS),
|
||||
sizesChecked(MAX_SIZES), heights (QMap<GHeights, bool>()), sizes(QMap<GSizes, bool>()),
|
||||
data(QMap<QCheckBox *, int>()), descriptionChanged(false), gradationChanged(false), defaultChanged(false),
|
||||
securityChanged(false), isInitialized(false)
|
||||
securityChanged(false), isInitialized(false),
|
||||
deleteAction(nullptr),
|
||||
changeImageAction(nullptr),
|
||||
saveImageAction(nullptr),
|
||||
showImageAction(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
@ -62,6 +69,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 +612,145 @@ void DialogPatternProperties::InitComboBox(QComboBox *box, const QMap<GVal, bool
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QImage DialogPatternProperties::GetImage()
|
||||
{
|
||||
// we set an image from file.val
|
||||
QImage image;
|
||||
QByteArray byteArray;
|
||||
byteArray.append(doc->GetImage().toUtf8());
|
||||
QByteArray ba = QByteArray::fromBase64(byteArray);
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
QString extension = doc->GetImageExtension();
|
||||
image.load(&buffer, extension.toLatin1().data()); // writes image into ba in 'extension' format
|
||||
return image;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogPatternProperties::InitImage()
|
||||
{
|
||||
ui->imageLabel->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
ui->imageLabel->setScaledContents(true);
|
||||
connect(ui->imageLabel, &QWidget::customContextMenuRequested, this, &DialogPatternProperties::ShowContextMenu);
|
||||
|
||||
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::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);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogPatternProperties::ChangeImage()
|
||||
{
|
||||
const QString fileName = QFileDialog::getOpenFileName(this, tr("Image for pattern"), QString(),
|
||||
tr("Images (*.png *.jpg *.jpeg *.bmp)"));
|
||||
QImage image;
|
||||
if (fileName.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (not image.load(fileName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
ui->imageLabel->setPixmap(QPixmap::fromImage(image));
|
||||
QFileInfo f(fileName);
|
||||
QString extension = f.suffix().toUpper();
|
||||
|
||||
if (extension == QLatin1String("JPEG"))
|
||||
{
|
||||
extension = "JPG";
|
||||
}
|
||||
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
|
||||
QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data());
|
||||
|
||||
// save our image to file.val
|
||||
doc->SetImage(iconBase64, extension);
|
||||
}
|
||||
deleteAction->setEnabled(true);
|
||||
saveImageAction->setEnabled(true);
|
||||
showImageAction->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogPatternProperties::DeleteImage()
|
||||
{
|
||||
doc->DeleteImage();
|
||||
ui->imageLabel->setText(tr("Change image"));
|
||||
deleteAction->setEnabled(false);
|
||||
saveImageAction->setEnabled(false);
|
||||
showImageAction->setEnabled(false);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogPatternProperties::SaveImage()
|
||||
{
|
||||
QByteArray byteArray;
|
||||
byteArray.append(doc->GetImage().toUtf8());
|
||||
QByteArray ba = QByteArray::fromBase64(byteArray);
|
||||
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())
|
||||
{
|
||||
if (not filename.endsWith(extension.toUpper()))
|
||||
{
|
||||
filename.append(extension);
|
||||
}
|
||||
QFile file(filename);
|
||||
if (file.open(QIODevice::WriteOnly))
|
||||
{
|
||||
file.write(ba);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogPatternProperties::ShowImage()
|
||||
{
|
||||
QLabel *label = new QLabel(this, Qt::Window);
|
||||
const QImage image = GetImage();
|
||||
label->setPixmap(QPixmap::fromImage(image));
|
||||
label->setGeometry(QRect(QCursor::pos(), image.size()));
|
||||
label->show();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogPatternProperties::ShowContextMenu()
|
||||
{
|
||||
QMenu menu(this);
|
||||
menu.addAction(deleteAction);
|
||||
menu.addAction(changeImageAction);
|
||||
menu.addAction(saveImageAction);
|
||||
menu.addAction(showImageAction);
|
||||
menu.exec(QCursor::pos());
|
||||
menu.show();
|
||||
}
|
||||
|
|
|
@ -57,12 +57,17 @@ public slots:
|
|||
void CheckStateHeight(int state);
|
||||
void CheckStateSize(int state);
|
||||
void DescEdited();
|
||||
void ChangeImage();
|
||||
void ShowContextMenu();
|
||||
protected:
|
||||
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
|
||||
private slots:
|
||||
void ToggleComboBox();
|
||||
void DefValueChanged();
|
||||
void SecurityValueChanged();
|
||||
void DeleteImage();
|
||||
void SaveImage();
|
||||
void ShowImage();
|
||||
private:
|
||||
Q_DISABLE_COPY(DialogPatternProperties)
|
||||
Ui::DialogPatternProperties *ui;
|
||||
|
@ -78,6 +83,10 @@ private:
|
|||
bool defaultChanged;
|
||||
bool securityChanged;
|
||||
bool isInitialized;
|
||||
QAction *deleteAction;
|
||||
QAction *changeImageAction;
|
||||
QAction *saveImageAction;
|
||||
QAction *showImageAction;
|
||||
|
||||
void SetHeightsChecked(bool enabled);
|
||||
void SetSizesChecked(bool enabled);
|
||||
|
@ -99,6 +108,8 @@ private:
|
|||
|
||||
void UpdateDefHeight();
|
||||
void UpdateDefSize();
|
||||
void InitImage();
|
||||
QImage GetImage();
|
||||
};
|
||||
|
||||
#endif // DIALOGPATTERNPROPERTIES_H
|
||||
|
|
|
@ -42,6 +42,23 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMaximumSize</enum>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
|
@ -60,6 +77,55 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_11">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="imageLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>200</horstretch>
|
||||
<verstretch>200</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Call context menu for edit</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>No image</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::AutoText</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
|
|
|
@ -129,7 +129,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;
|
||||
<< TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit;
|
||||
PrepareForParse(parse);
|
||||
QDomNode domNode = documentElement().firstChild();
|
||||
while (domNode.isNull() == false)
|
||||
|
@ -183,7 +183,10 @@ void VPattern::Parse(const Document &parse)
|
|||
case 7: // TagGradation
|
||||
qCDebug(vXML, "Tag gradation.");
|
||||
break;
|
||||
case 8: // TagUnit
|
||||
case 8: // TagImage
|
||||
qCDebug(vXML, "Tag image.");
|
||||
break;
|
||||
case 9: // TagUnit
|
||||
qCDebug(vXML, "Tag unit.");
|
||||
break;
|
||||
default:
|
||||
|
@ -2899,7 +2902,7 @@ void VPattern::SetDefCustom(bool value)
|
|||
{
|
||||
CheckTagExists(TagGradation);
|
||||
QDomNodeList tags = elementsByTagName(TagGradation);
|
||||
if (tags.size() == 0)
|
||||
if (tags.isEmpty())
|
||||
{
|
||||
qDebug()<<"Can't save attribute "<<AttrCustom<<Q_FUNC_INFO;
|
||||
return;
|
||||
|
@ -2960,7 +2963,7 @@ void VPattern::SetDefCustomHeight(int value)
|
|||
{
|
||||
CheckTagExists(TagGradation);
|
||||
QDomNodeList tags = elementsByTagName(TagGradation);
|
||||
if (tags.size() == 0)
|
||||
if (tags.isEmpty())
|
||||
{
|
||||
qDebug()<<"Can't save attribute "<<AttrDefHeight<<Q_FUNC_INFO;
|
||||
return;
|
||||
|
@ -3019,7 +3022,7 @@ void VPattern::SetDefCustomSize(int value)
|
|||
{
|
||||
CheckTagExists(TagGradation);
|
||||
QDomNodeList tags = elementsByTagName(TagGradation);
|
||||
if (tags.size() == 0)
|
||||
if (tags.isEmpty())
|
||||
{
|
||||
qDebug()<<"Can't save attribute "<<AttrDefSize<<Q_FUNC_INFO;
|
||||
return;
|
||||
|
|
|
@ -6,6 +6,15 @@
|
|||
<xs:sequence minOccurs="1" maxOccurs="unbounded">
|
||||
<xs:element name="version" type="formatVersion"></xs:element>
|
||||
<xs:element name="unit" type="units"></xs:element>
|
||||
<xs:element name="image" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
<xs:attribute name="extension" type="imageExtension"></xs:attribute>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="author" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
|
||||
<xs:element name="description" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
|
||||
<xs:element name="notes" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
|
||||
|
@ -342,6 +351,13 @@
|
|||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="^(0|([1-9][0-9]*))\.(0|([1-9][0-9]*))\.(0|([1-9][0-9]*))$"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="imageExtension">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="PNG"/>
|
||||
<xs:enumeration value="JPG"/>
|
||||
<xs:enumeration value="BMP"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="colors">
|
||||
<xs:restriction base="xs:string">
|
||||
|
|
|
@ -41,6 +41,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");
|
||||
|
@ -107,6 +108,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");
|
||||
|
@ -701,7 +703,7 @@ void VAbstractPattern::SetGradationHeights(const QMap<GHeights, bool> &options)
|
|||
{
|
||||
CheckTagExists(TagGradation);
|
||||
QDomNodeList tags = elementsByTagName(TagGradation);
|
||||
if (tags.size() == 0)
|
||||
if (tags.isEmpty())
|
||||
{
|
||||
qDebug()<<"Can't save tag "<<TagGradation<<Q_FUNC_INFO;
|
||||
return;
|
||||
|
@ -867,7 +869,7 @@ void VAbstractPattern::SetGradationSizes(const QMap<GSizes, bool> &options)
|
|||
{
|
||||
CheckTagExists(TagGradation);
|
||||
QDomNodeList tags = elementsByTagName(TagGradation);
|
||||
if (tags.size() == 0)
|
||||
if (tags.isEmpty())
|
||||
{
|
||||
qDebug()<<"Can't save tag "<<TagGradation<<Q_FUNC_INFO;
|
||||
return;
|
||||
|
@ -974,6 +976,56 @@ void VAbstractPattern::SetNotes(const QString &text)
|
|||
emit patternChanged(false);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VAbstractPattern::GetImage() const
|
||||
{
|
||||
return UniqueTagText(TagImage);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VAbstractPattern::GetImageExtension() const
|
||||
{
|
||||
const QString defExt = QStringLiteral("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(AttrExtension, defExt);
|
||||
return ext;
|
||||
}
|
||||
}
|
||||
}
|
||||
return defExt;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractPattern::SetImage(const QString &text, const QString &extension)
|
||||
{
|
||||
QDomElement imageElement = CheckTagExists(TagImage);
|
||||
setTagText(imageElement, text);
|
||||
CheckTagExists(TagImage).setAttribute(AttrExtension, extension);
|
||||
modified = true;
|
||||
emit patternChanged(false);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractPattern::DeleteImage()
|
||||
{
|
||||
QDomElement pattern = documentElement();
|
||||
pattern.removeChild(CheckTagExists(TagImage));
|
||||
modified = true;
|
||||
emit patternChanged(false);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VAbstractPattern::GetVersion() const
|
||||
{
|
||||
|
@ -1041,78 +1093,81 @@ 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())
|
||||
{
|
||||
QStringList tags = QStringList() << TagVersion << TagAuthor << TagDescription << TagNotes << TagGradation;
|
||||
QDomElement pattern = documentElement();
|
||||
const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes
|
||||
<< TagGradation;
|
||||
switch (tags.indexOf(tag))
|
||||
{
|
||||
case 0: //TagVersion
|
||||
case 0: //TagUnit
|
||||
{
|
||||
return QDomElement();
|
||||
break;// Mandatory tag
|
||||
case 1: //TagAuthor
|
||||
pattern.insertAfter(createElement(TagAuthor), elementsByTagName(TagVersion).at(0));
|
||||
SetVersion();
|
||||
break;
|
||||
case 2: //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();
|
||||
case 1: //TagImage
|
||||
{
|
||||
element = createElement(TagImage);
|
||||
break;
|
||||
}
|
||||
case 3: //TagNotes
|
||||
case 2: //TagAuthor
|
||||
{
|
||||
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();
|
||||
element = createElement(TagAuthor);
|
||||
break;
|
||||
}
|
||||
case 4: //TagGradation
|
||||
case 3: //TagDescription
|
||||
{
|
||||
QDomElement gradation = createElement(TagGradation);
|
||||
element = createElement(TagDescription);
|
||||
break;
|
||||
}
|
||||
case 4: //TagNotes
|
||||
{
|
||||
element = createElement(TagNotes);
|
||||
break;
|
||||
}
|
||||
case 5: //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);
|
||||
|
||||
for (int i = tags.indexOf(tag)-1; i >= 0; --i)
|
||||
element.appendChild(sizes);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
QDomNodeList list = elementsByTagName(tags.at(i));
|
||||
return QDomElement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
InsertTag(tags, element);
|
||||
return element;
|
||||
}
|
||||
return list.at(0).toElement();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractPattern::InsertTag(const QStringList &tags, const QDomElement &element)
|
||||
{
|
||||
QDomElement pattern = documentElement();
|
||||
for (int i = tags.indexOf(element.tagName())-1; i >= 0; --i)
|
||||
{
|
||||
const QDomNodeList list = elementsByTagName(tags.at(i));
|
||||
if (list.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
pattern.insertAfter(gradation, list.at(0));
|
||||
pattern.insertAfter(element, list.at(0));
|
||||
break;
|
||||
}
|
||||
SetVersion();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -106,6 +106,11 @@ public:
|
|||
QString GetNotes() const;
|
||||
void SetNotes(const QString &text);
|
||||
|
||||
QString GetImage() const;
|
||||
QString GetImageExtension() const;
|
||||
void SetImage(const QString &text, const QString &extension);
|
||||
void DeleteImage();
|
||||
|
||||
QString GetVersion() const;
|
||||
void SetVersion();
|
||||
|
||||
|
@ -129,6 +134,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;
|
||||
|
@ -196,6 +202,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;
|
||||
|
@ -272,7 +279,8 @@ 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:
|
||||
Q_DISABLE_COPY(VAbstractPattern)
|
||||
|
|
|
@ -698,21 +698,26 @@ bool VDomDocument::setTagText(const QString &tag, const QString &text)
|
|||
if (domNode.isNull() == false && domNode.isElement())
|
||||
{
|
||||
const QDomElement domElement = domNode.toElement();
|
||||
return setTagText(domElement, text);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VDomDocument::setTagText(const QDomElement &domElement, const QString &text)
|
||||
{
|
||||
if (domElement.isNull() == false)
|
||||
{
|
||||
QDomElement parent = domElement.parentNode().toElement();
|
||||
QDomElement newTag = createElement(tag);
|
||||
if (not text.isEmpty())
|
||||
{
|
||||
QDomElement newTag = createElement(domElement.tagName());
|
||||
|
||||
const QDomText newTagText = createTextNode(text);
|
||||
newTag.appendChild(newTagText);
|
||||
}
|
||||
|
||||
parent.replaceChild(newTag, domElement);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,6 +115,7 @@ public:
|
|||
|
||||
protected:
|
||||
bool setTagText(const QString &tag, const QString &text);
|
||||
bool setTagText(const QDomElement &domElement, const QString &text);
|
||||
QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const;
|
||||
|
||||
void TestUniqueId() const;
|
||||
|
|
|
@ -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 <QDialog>
|
||||
|
|
Loading…
Reference in New Issue
Block a user