summaryrefslogtreecommitdiff
path: root/src/plugins/qnx/bardescriptordocument.cpp
diff options
context:
space:
mode:
authorFrantisek Vacek <fvacek@blackberry.com>2014-02-05 08:49:29 +0100
committerFanda Vacek <fvacek@blackberry.com>2014-02-05 11:39:48 +0100
commitb254313c686d07057acba243198100e49159e6e5 (patch)
tree4b34e9e0897f944fd3b60a4e80c1a1ecda2981d6 /src/plugins/qnx/bardescriptordocument.cpp
parente24b5c17d6ea598e27dbb8e0e2a1d6ac88b3501d (diff)
downloadqt-creator-b254313c686d07057acba243198100e49159e6e5.tar.gz
QNX: Use BarDescriptorDocument API to prepare bar-descriptor for deployment
Patch is refactoring create package step to use new BarDescriptorDocument class when bar-descriptor.xml is prepared for deployment. BarDescriptorDocument API is extended to allow this. Change-Id: If00fba3310c5acf1cc8feefe0cf919aa2a05637e Reviewed-by: Tobias Nätterlund <tobias.naetterlund@kdab.com> Reviewed-by: Mehdi Fekari <mfekari@blackberry.com> Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
Diffstat (limited to 'src/plugins/qnx/bardescriptordocument.cpp')
-rw-r--r--src/plugins/qnx/bardescriptordocument.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/plugins/qnx/bardescriptordocument.cpp b/src/plugins/qnx/bardescriptordocument.cpp
index b07c92daee..92b80f06f8 100644
--- a/src/plugins/qnx/bardescriptordocument.cpp
+++ b/src/plugins/qnx/bardescriptordocument.cpp
@@ -40,6 +40,7 @@
#include <QFileInfo>
#include <QMetaEnum>
#include <QTextCodec>
+#include <QSet>
using namespace Qnx;
using namespace Qnx::Internal;
@@ -573,3 +574,122 @@ void BarDescriptorDocument::emitAllChanged()
emit changed(tag, value(tag));
}
}
+
+QString BarDescriptorDocument::bannerComment() const
+{
+ QDomNode nd = m_barDocument.firstChild();
+ QDomProcessingInstruction pi = nd.toProcessingInstruction();
+ if (!pi.isNull())
+ nd = pi.nextSibling();
+
+ return nd.toComment().data();
+}
+
+void BarDescriptorDocument::setBannerComment(const QString &commentText)
+{
+ QDomNode nd = m_barDocument.firstChild();
+ QDomProcessingInstruction pi = nd.toProcessingInstruction();
+ if (!pi.isNull())
+ nd = pi.nextSibling();
+
+ bool oldDirty = m_dirty;
+ QDomComment cnd = nd.toComment();
+ if (cnd.isNull()) {
+ if (!commentText.isEmpty()) {
+ cnd = m_barDocument.createComment(commentText);
+ m_barDocument.insertBefore(cnd, nd);
+ m_dirty = true;
+ }
+ } else {
+ if (commentText.isEmpty()) {
+ m_barDocument.removeChild(cnd);
+ m_dirty = true;
+ } else {
+ if (cnd.data() != commentText) {
+ cnd.setData(commentText);
+ m_dirty = true;
+ }
+ }
+ }
+ if (m_dirty != oldDirty)
+ emit Core::IDocument::changed();
+}
+
+int BarDescriptorDocument::tagForElement(const QDomElement &element)
+{
+ QMetaEnum tags = metaObject()->enumerator(metaObject()->enumeratorOffset());
+ QDomElement el = element;
+ while (!el.isNull()) {
+ bool ok;
+ int n = tags.keyToValue(el.tagName().toLatin1().constData(), &ok);
+ if (ok)
+ return n;
+ el = el.parentNode().toElement();
+ }
+ return -1;
+}
+
+bool BarDescriptorDocument::expandPlaceHolder_helper(const QDomElement &el,
+ const QString &placeholderKey,
+ const QString &placeholderText,
+ QSet<BarDescriptorDocument::Tag> &changedTags)
+{
+ // replace attributes
+ bool elementChanged = false;
+ QDomNamedNodeMap attrs = el.attributes();
+ for (int i = 0; i < attrs.count(); ++i) {
+ QDomAttr attr = attrs.item(i).toAttr();
+ if (!attr.isNull()) {
+ QString s = attr.value();
+ s.replace(placeholderKey, placeholderText);
+ if (s != attr.value()) {
+ attr.setValue(s);
+ elementChanged = true;
+ }
+ }
+ }
+
+ bool documentChanged = false;
+ // replace text
+ for (QDomNode nd = el.firstChild(); !nd.isNull(); nd = nd.nextSibling()) {
+ QDomText txtnd = nd.toText();
+ if (!txtnd.isNull()) {
+ QString s = txtnd.data();
+ s.replace(placeholderKey, placeholderText);
+ if (s != txtnd.data()) {
+ txtnd.setData(s);
+ elementChanged = true;
+ }
+ }
+ QDomElement child = nd.toElement();
+ if (!child.isNull()) {
+ bool hit = expandPlaceHolder_helper(child, placeholderKey, placeholderText, changedTags);
+ documentChanged = documentChanged || hit;
+ }
+ }
+ if (elementChanged) {
+ int n = tagForElement(el);
+ if (n >= 0)
+ changedTags << static_cast<Tag>(n);
+ }
+ documentChanged = documentChanged || elementChanged;
+ return documentChanged;
+}
+
+void BarDescriptorDocument::expandPlaceHolders(const QHash<QString, QString> &placeholdersKeyVals)
+{
+ QSet<Tag> changedTags;
+ QHashIterator<QString, QString> it(placeholdersKeyVals);
+ bool docChanged = false;
+ while (it.hasNext()) {
+ it.next();
+ bool expanded = expandPlaceHolder_helper(m_barDocument.documentElement(),
+ it.key(), it.value(), changedTags);
+ docChanged = docChanged || expanded;
+ }
+ m_dirty = m_dirty || docChanged;
+ foreach (Tag tag, changedTags)
+ emit changed(tag, value(tag));
+ if (docChanged)
+ emit Core::IDocument::changed();
+}