Overrided setTagText method

--HG--
branch : feature
This commit is contained in:
Valentina Zhuravska 2016-04-06 05:34:08 +03:00
parent de221559f3
commit 8911fb5e11
3 changed files with 24 additions and 27 deletions

View File

@ -952,14 +952,9 @@ QString VAbstractPattern::GetImageExtension() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetImage(const QString &text, const QString &extension) void VAbstractPattern::SetImage(const QString &text, const QString &extension)
{ {
CheckTagExists(TagImage); QDomElement imageElement = CheckTagExists(TagImage);
setTagText(TagImage, text); setTagText(imageElement, text);
QDomNodeList list = elementsByTagName(TagImage); CheckTagExists(TagImage).setAttribute(AttrExtension, extension);
for (int i=0; i < list.size(); ++i)
{
QDomElement dom = list.at(i).toElement();
dom.setAttribute(AttrExtension, extension);
}
modified = true; modified = true;
emit patternChanged(false); emit patternChanged(false);
} }
@ -968,12 +963,7 @@ void VAbstractPattern::SetImage(const QString &text, const QString &extension)
void VAbstractPattern::DeleteImage() void VAbstractPattern::DeleteImage()
{ {
QDomElement pattern = documentElement(); QDomElement pattern = documentElement();
const QDomNodeList images = this->elementsByTagName(TagImage); pattern.removeChild(CheckTagExists(TagImage));
for (int i=0; i<images.count(); ++i)
{
QDomNode image = images.at(i);
pattern.removeChild(image);
}
modified = true; modified = true;
emit patternChanged(false); emit patternChanged(false);
} }

View File

@ -698,24 +698,30 @@ bool VDomDocument::setTagText(const QString &tag, const QString &text)
if (domNode.isNull() == false && domNode.isElement()) if (domNode.isNull() == false && domNode.isElement())
{ {
const QDomElement domElement = domNode.toElement(); const QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false) setTagText(domElement, text);
{
QDomElement parent = domElement.parentNode().toElement();
QDomElement newTag = createElement(tag);
if (not text.isEmpty())
{
const QDomText newTagText = createTextNode(text);
newTag.appendChild(newTagText);
}
parent.replaceChild(newTag, domElement);
return true;
}
} }
} }
return false; return false;
} }
//---------------------------------------------------------------------------------------------------------------------
bool VDomDocument::setTagText(const QDomElement &domElement, const QString &text)
{
if (domElement.isNull() == false)
{
QDomElement parent = domElement.parentNode().toElement();
QDomElement newTag = createElement(domElement.tagName());
if (not text.isEmpty())
{
const QDomText newTagText = createTextNode(text);
newTag.appendChild(newTagText);
}
parent.replaceChild(newTag, domElement);
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief RemoveAllChildren remove all children from file. * @brief RemoveAllChildren remove all children from file.

View File

@ -115,6 +115,7 @@ public:
protected: protected:
bool setTagText(const QString &tag, const QString &text); 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; QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const;
void TestUniqueId() const; void TestUniqueId() const;