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)
{
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<images.count(); ++i)
{
QDomNode image = images.at(i);
pattern.removeChild(image);
}
pattern.removeChild(CheckTagExists(TagImage));
modified = true;
emit patternChanged(false);
}

View File

@ -698,24 +698,30 @@ bool VDomDocument::setTagText(const QString &tag, const QString &text)
if (domNode.isNull() == false && domNode.isElement())
{
const QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
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;
}
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(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.

View File

@ -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;