summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Naetterlund <tobias.naetterlund.qnx@kdab.com>2013-12-23 15:36:42 +0100
committerTobias Nätterlund <tobias.naetterlund@kdab.com>2014-01-27 06:52:23 +0100
commit3994e698cd9c59a2bbc0ab2578df9f322f54cf7f (patch)
treeab6d6455f88cc510cf5c881cbaa4df66171389a3
parent717e384bb58d5522ad17402ecd12a336c389188f (diff)
downloadqt-creator-3994e698cd9c59a2bbc0ab2578df9f322f54cf7f.tar.gz
BlackBerry: Refactored BarDescriptorDocument
The BarDescriptorDocument now operates directly on the underlying QDomDocument, and is much better at keeping the tags on their original lines. Any new values are appended to the end of the document. A generic API is provided for changing the values inside the document, BarDescriptorDocument::setValue(..). BarDescriptorDocument no longer depends on the BarDescriptorEditorWidget, which should make it easier to implement splitting of the editor. Task-number: QTCREATORBUG-11012 Change-Id: Icfd681e3af016ea819b99b8cad2cede46600e910 Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com> Reviewed-by: Mehdi Fekari <mfekari@blackberry.com> Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
-rw-r--r--src/plugins/qnx/bardescriptordocument.cpp499
-rw-r--r--src/plugins/qnx/bardescriptordocument.h74
-rw-r--r--src/plugins/qnx/bardescriptordocumentnodehandlers.cpp708
-rw-r--r--src/plugins/qnx/bardescriptordocumentnodehandlers.h302
-rw-r--r--src/plugins/qnx/bardescriptoreditor.cpp39
-rw-r--r--src/plugins/qnx/bardescriptoreditorabstractpanelwidget.cpp88
-rw-r--r--src/plugins/qnx/bardescriptoreditorabstractpanelwidget.h27
-rw-r--r--src/plugins/qnx/bardescriptoreditorassetswidget.cpp70
-rw-r--r--src/plugins/qnx/bardescriptoreditorassetswidget.h15
-rw-r--r--src/plugins/qnx/bardescriptoreditorauthorinformationwidget.cpp33
-rw-r--r--src/plugins/qnx/bardescriptoreditorauthorinformationwidget.h9
-rw-r--r--src/plugins/qnx/bardescriptoreditorentrypointwidget.cpp102
-rw-r--r--src/plugins/qnx/bardescriptoreditorentrypointwidget.h18
-rw-r--r--src/plugins/qnx/bardescriptoreditorenvironmentwidget.cpp31
-rw-r--r--src/plugins/qnx/bardescriptoreditorenvironmentwidget.h7
-rw-r--r--src/plugins/qnx/bardescriptoreditorgeneralwidget.cpp95
-rw-r--r--src/plugins/qnx/bardescriptoreditorgeneralwidget.h16
-rw-r--r--src/plugins/qnx/bardescriptoreditorpackageinformationwidget.cpp49
-rw-r--r--src/plugins/qnx/bardescriptoreditorpackageinformationwidget.h11
-rw-r--r--src/plugins/qnx/bardescriptoreditorpermissionswidget.cpp36
-rw-r--r--src/plugins/qnx/bardescriptoreditorpermissionswidget.h6
-rw-r--r--src/plugins/qnx/bardescriptoreditorwidget.cpp129
-rw-r--r--src/plugins/qnx/bardescriptoreditorwidget.h30
-rw-r--r--src/plugins/qnx/qnx.pro2
-rw-r--r--src/plugins/qnx/qnx.qbs2
-rw-r--r--src/plugins/qnx/qnxplugin.cpp197
-rw-r--r--src/plugins/qnx/qnxplugin.h6
27 files changed, 1012 insertions, 1589 deletions
diff --git a/src/plugins/qnx/bardescriptordocument.cpp b/src/plugins/qnx/bardescriptordocument.cpp
index bee30de62d..b07c92daee 100644
--- a/src/plugins/qnx/bardescriptordocument.cpp
+++ b/src/plugins/qnx/bardescriptordocument.cpp
@@ -32,47 +32,21 @@
#include "bardescriptordocument.h"
#include "qnxconstants.h"
-#include "bardescriptoreditor.h"
-#include "bardescriptoreditorwidget.h"
-#include "bardescriptordocumentnodehandlers.h"
-#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/editormanager/editormanager.h>
#include <utils/qtcassert.h>
-#include <QFile>
-#include <QFileInfo>
#include <QDir>
+#include <QFileInfo>
+#include <QMetaEnum>
#include <QTextCodec>
using namespace Qnx;
using namespace Qnx::Internal;
-BarDescriptorDocument::BarDescriptorDocument(BarDescriptorEditorWidget *editorWidget)
- : Core::TextDocument(editorWidget)
- , m_nodeHandlers(QList<BarDescriptorDocumentAbstractNodeHandler *>())
- , m_editorWidget(editorWidget)
+BarDescriptorDocument::BarDescriptorDocument(QObject *parent)
+ : Core::TextDocument(parent)
{
- // General
- registerNodeHandler(new BarDescriptorDocumentIdNodeHandler(m_editorWidget));
- registerNodeHandler(new BarDescriptorDocumentVersionNumberNodeHandler(m_editorWidget));
- registerNodeHandler(new BarDescriptorDocumentBuildIdNodeHandler(m_editorWidget));
- registerNodeHandler(new BarDescriptorDocumentAuthorNodeHandler(m_editorWidget));
- registerNodeHandler(new BarDescriptorDocumentAuthorIdNodeHandler(m_editorWidget));
-
- // Application
- registerNodeHandler(new BarDescriptorDocumentApplicationNameNodeHandler(m_editorWidget));
- registerNodeHandler(new BarDescriptorDocumentApplicationDescriptionNodeHandler(m_editorWidget));
- registerNodeHandler(new BarDescriptorDocumentApplicationIconNodeHandler(m_editorWidget));
- registerNodeHandler(new BarDescriptorDocumentSplashScreenNodeHandler(m_editorWidget));
- registerNodeHandler(new BarDescriptorDocumentInitialWindowNodeHandler(m_editorWidget));
- registerNodeHandler(new BarDescriptorDocumentArgNodeHandler(m_editorWidget));
- registerNodeHandler(new BarDescriptorDocumentActionNodeHandler(m_editorWidget));
- registerNodeHandler(new BarDescriptorDocumentEnvNodeHandler(m_editorWidget));
-
- // Assets
- registerNodeHandler(new BarDescriptorDocumentAssetNodeHandler(m_editorWidget));
-
// blackberry-nativepackager requires the XML file to be in UTF-8 encoding,
// force if possible
if (QTextCodec *defaultUTF8 = QTextCodec::codecForName("UTF-8"))
@@ -83,10 +57,6 @@ BarDescriptorDocument::BarDescriptorDocument(BarDescriptorEditorWidget *editorWi
BarDescriptorDocument::~BarDescriptorDocument()
{
- while (!m_nodeHandlers.isEmpty()) {
- BarDescriptorDocumentAbstractNodeHandler *nodeHandler = m_nodeHandlers.takeFirst();
- delete nodeHandler;
- }
}
bool BarDescriptorDocument::open(QString *errorString, const QString &fileName) {
@@ -95,9 +65,8 @@ bool BarDescriptorDocument::open(QString *errorString, const QString &fileName)
return false;
setFilePath(fileName);
- m_editorWidget->setFilePath(fileName);
- bool result = loadContent(contents);
+ const bool result = loadContent(contents, false);
if (!result)
*errorString = tr("%1 does not appear to be a valid application descriptor file").arg(QDir::toNativeSeparators(fileName));
@@ -110,12 +79,12 @@ bool BarDescriptorDocument::save(QString *errorString, const QString &fn, bool a
QTC_ASSERT(!autoSave, return false);
QTC_ASSERT(fn.isEmpty(), return false);
- bool result = write(filePath(), xmlSource(), errorString);
+ const bool result = write(filePath(), xmlSource(), errorString);
if (!result)
return false;
- m_editorWidget->setDirty(false);
- emit changed();
+ m_dirty = false;
+ emit Core::IDocument::changed();
return true;
}
@@ -143,7 +112,7 @@ bool BarDescriptorDocument::shouldAutoSave() const
bool BarDescriptorDocument::isModified() const
{
- return m_editorWidget->isDirty();
+ return m_dirty;
}
bool BarDescriptorDocument::isSaveAsAllowed() const
@@ -172,91 +141,435 @@ bool BarDescriptorDocument::reload(QString *errorString, Core::IDocument::Reload
QString BarDescriptorDocument::xmlSource() const
{
- BarDescriptorEditor *editor = qobject_cast<BarDescriptorEditor*>(m_editorWidget->editor());
- QTC_ASSERT(editor, return QString());
+ const int indent = 4;
+ return m_barDocument.toString(indent);
+}
+
+bool BarDescriptorDocument::loadContent(const QString &xmlCode, bool setDirty, QString *errorMessage, int *errorLine)
+{
+ if (xmlCode == xmlSource())
+ return true;
+
+ bool result = m_barDocument.setContent(xmlCode, errorMessage, errorLine);
+
+ m_dirty = setDirty;
+
+ emitAllChanged();
+ emit Core::IDocument::changed();
+ return result;
+}
+
+QVariant BarDescriptorDocument::value(BarDescriptorDocument::Tag tag) const
+{
+ const QString tagName = QString::fromLatin1(metaObject()->enumerator(metaObject()->enumeratorOffset()).valueToKey(tag));
+
+ switch (tag) {
+ case id:
+ case versionNumber:
+ case buildId:
+ case name:
+ case description:
+ case author:
+ case publisher:
+ case authorId:
+ return stringValue(tagName);
+ case icon:
+ return childStringListValue(tagName, QLatin1String("image")).value(0);
+ case splashScreens:
+ return childStringListValue(tagName, QLatin1String("image"));
+ case asset: {
+ QVariant var;
+ var.setValue(assets());
+ return var;
+ }
+ case aspectRatio:
+ case autoOrients:
+ case systemChrome:
+ return childStringListValue(QLatin1String("initialWindow"), tagName).value(0);
+ case transparent:
+ return childStringListValue(QLatin1String("initialWindow"), tagName).value(0) == QLatin1String("true");
+ case arg:
+ case action:
+ return stringListValue(tagName);
+ case env:
+ QVariant var;
+ var.setValue(environment());
+ return var;
+ }
+
+ return QVariant();
+}
+
+void BarDescriptorDocument::setValue(BarDescriptorDocument::Tag tag, const QVariant &value)
+{
+ const QMetaEnum tagEnum = metaObject()->enumerator(metaObject()->enumeratorOffset());
+ const QString tagName = QString::fromLatin1(tagEnum.valueToKey(tag));
+
+ switch (tag) {
+ case id:
+ case versionNumber:
+ case buildId:
+ case name:
+ case description:
+ case authorId:
+ setStringValue(tagName, value.toString());
+ break;
+ case icon:
+ case splashScreens:
+ setChildStringListValue(tagName, QLatin1String("image"), value.toStringList());
+ break;
+ case asset:
+ setAssets(value.value<BarDescriptorAssetList>());
+ break;
+ case aspectRatio:
+ case autoOrients:
+ case systemChrome:
+ setChildStringListValue(QLatin1String("initialWindow"), tagName, value.toStringList());
+ break;
+ case transparent:
+ setChildStringListValue(QLatin1String("initialWindow"), tagName, QStringList() << (value.toBool() ? QLatin1String("true") : QLatin1String("false")));
+ break;
+ case arg:
+ case action:
+ setStringListValue(tagName, value.toStringList());
+ break;
+ case env:
+ setEnvironment(value.value<QList<Utils::EnvironmentItem> >());
+ break;
+ case author:
+ case publisher:
+ // Unset <publisher> when setting <author> as only one should be used
+ setStringValue(QString::fromLatin1(tagEnum.valueToKey(author)), value.toString());
+ setStringValue(QString::fromLatin1(tagEnum.valueToKey(publisher)), QLatin1String(""));
+ break;
+ }
+
+ m_dirty = true;
+ emit changed(tag, value);
+ emit Core::IDocument::changed();
+}
+
+QString BarDescriptorDocument::stringValue(const QString &tagName) const
+{
+ QDomNodeList nodes = m_barDocument.elementsByTagName(tagName);
+ if (nodes.isEmpty() || nodes.size() > 1)
+ return QString();
+
+ QDomNode node = nodes.item(0);
+ QDomText textNode = node.firstChild().toText();
+ if (textNode.isNull())
+ return QString();
+
+ return textNode.data();
+}
+
+void BarDescriptorDocument::setStringValue(const QString &tagName, const QString &value)
+{
+ QDomNodeList nodes = m_barDocument.elementsByTagName(tagName);
+
+ if (nodes.size() > 1)
+ return;
- if (editor->activePage() == BarDescriptorEditor::Source) {
- return m_editorWidget->xmlSource();
+ QDomNode existingNode = nodes.item(0);
+ if (existingNode.isNull() && value.isEmpty())
+ return;
+
+ if (!existingNode.isNull() && value.isEmpty()) {
+ m_barDocument.documentElement().removeChild(existingNode);
+ } else if (existingNode.isNull()) {
+ QDomElement newNode = m_barDocument.createElement(tagName);
+ newNode.appendChild(m_barDocument.createTextNode(value));
+ m_barDocument.documentElement().appendChild(newNode);
} else {
- QDomDocument doc;
- doc.appendChild(doc.createProcessingInstruction(QLatin1String("xml"), QLatin1String("version='1.0' encoding='") + QLatin1String(codec()->name()) + QLatin1String("' standalone='no'")));
+ QDomText textNode = existingNode.firstChild().toText();
+ if (textNode.isNull())
+ return;
+ textNode.setData(value);
+ }
+}
- // QNX
- QDomElement rootElem = doc.createElement(QLatin1String("qnx"));
- rootElem.setAttribute(QLatin1String("xmlns"), QLatin1String("http://www.qnx.com/schemas/application/1.0"));
+QStringList BarDescriptorDocument::childStringListValue(const QString &tagName, const QString &childTagName) const
+{
+ QDomNodeList nodes = m_barDocument.elementsByTagName(tagName);
+ if (nodes.isEmpty() || nodes.size() > 1)
+ return QStringList();
- QMap<int, BarDescriptorDocumentAbstractNodeHandler*> nodeHandlerMap;
- foreach (BarDescriptorDocumentAbstractNodeHandler *nodeHandler, m_nodeHandlers)
- nodeHandlerMap.insertMulti(nodeHandler->order(), nodeHandler);
+ QDomNode parentNode = nodes.item(0);
+ QDomElement childElm = parentNode.firstChildElement(childTagName);
+ if (childElm.isNull())
+ return QStringList();
- QList<BarDescriptorDocumentAbstractNodeHandler*> nodeHandlers = nodeHandlerMap.values();
- foreach (BarDescriptorDocumentAbstractNodeHandler *nodeHandler, nodeHandlers)
- rootElem.appendChild(nodeHandler->toNode(doc));
+ QStringList result;
+ while (!childElm.isNull()) {
+ QDomText textNode = childElm.firstChild().toText();
+ if (textNode.isNull())
+ return QStringList();
- doc.appendChild(rootElem);
+ result.append(textNode.data());
- return doc.toString(4);
+ childElm = childElm.nextSiblingElement(childTagName);
}
+
+ return result;
}
-bool BarDescriptorDocument::loadContent(const QString &xmlSource, QString *errorMessage, int *errorLine)
+void BarDescriptorDocument::setChildStringListValue(const QString &tagName, const QString &childTagName, const QStringList &stringList)
{
- QDomDocument doc;
- bool result = doc.setContent(xmlSource, errorMessage, errorLine);
- if (!result)
- return false;
+ QDomNodeList nodes = m_barDocument.elementsByTagName(tagName);
- QDomElement docElem = doc.documentElement();
- if (docElem.tagName() != QLatin1String("qnx"))
- return false;
+ if (nodes.size() > 1)
+ return;
- m_editorWidget->clear();
+ QDomNode existingNode = nodes.item(0);
- removeUnknownNodeHandlers();
- foreach (BarDescriptorDocumentAbstractNodeHandler *nodeHandler, m_nodeHandlers)
- nodeHandler->clear();
+ if (existingNode.isNull()) {
+ QDomElement newParentNode = m_barDocument.createElement(tagName);
- QDomNode node = docElem.firstChildElement();
- while (!node.isNull()) {
- BarDescriptorDocumentAbstractNodeHandler *nodeHandler = nodeHandlerForDomNode(node);
- if (!nodeHandler) {
- nodeHandler = new BarDescriptorDocumentUnknownNodeHandler(m_editorWidget);
- registerNodeHandler(nodeHandler);
+ foreach (const QString &value, stringList) {
+ QDomElement newChildNode = m_barDocument.createElement(childTagName);
+ QDomText newTextNode = m_barDocument.createTextNode(value);
+ newChildNode.appendChild(newTextNode);
+ newParentNode.appendChild(newChildNode);
+ }
+ m_barDocument.documentElement().appendChild(newParentNode);
+ } else {
+ QStringList values = stringList;
+ QDomElement childElm = existingNode.firstChildElement(childTagName);
+ if (!childElm.isNull()) {
+ // Loop through existing elements, remove the existing nodes
+ // that no longer are in "values", and remove from "values"
+ // the existing nodes that don't need re-creation
+ while (!childElm.isNull()) {
+ QDomText textNode = childElm.firstChild().toText();
+ if (textNode.isNull())
+ continue;
+
+ QDomElement toRemove;
+ if (!values.contains(textNode.data()))
+ toRemove = childElm;
+ else
+ values.removeAll(textNode.data());
+
+ childElm = childElm.nextSiblingElement(childTagName);
+
+ if (!toRemove.isNull())
+ existingNode.removeChild(toRemove);
+ }
}
- if (!nodeHandler->handle(node))
- return false;
+ // Add the new elements
+ int newElementCount = 0;
+ foreach (const QString &value, values) {
+ if (value.isEmpty())
+ continue;
+ QDomElement newChildNode = m_barDocument.createElement(childTagName);
+ newChildNode.appendChild(m_barDocument.createTextNode(value));
+ existingNode.appendChild(newChildNode);
+ ++newElementCount;
+ }
- node = node.nextSibling();
+ if (newElementCount == 0)
+ m_barDocument.documentElement().removeChild(existingNode);
}
+}
- m_editorWidget->setXmlSource(xmlSource);
+QStringList BarDescriptorDocument::stringListValue(const QString &tagName) const
+{
+ QStringList result;
- return true;
+ QDomElement childElm = m_barDocument.documentElement().firstChildElement(tagName);
+ while (!childElm.isNull()) {
+ QDomText textNode = childElm.firstChild().toText();
+ if (textNode.isNull())
+ continue;
+
+ result.append(textNode.data());
+
+ childElm = childElm.nextSiblingElement(tagName);
+ }
+
+ return result;
}
-void BarDescriptorDocument::registerNodeHandler(BarDescriptorDocumentAbstractNodeHandler *nodeHandler)
+void BarDescriptorDocument::setStringListValue(const QString &tagName, const QStringList &stringList)
{
- m_nodeHandlers << nodeHandler;
+ QStringList values = stringList;
+ QDomElement childElm = m_barDocument.documentElement().firstChildElement(tagName);
+ if (!childElm.isNull()) {
+ // Loop through existing elements, remove the existing nodes
+ // that no longer are in "values", and remove from "values"
+ // the existing nodes that don't need re-creation
+ while (!childElm.isNull()) {
+ QDomText textNode = childElm.firstChild().toText();
+ if (textNode.isNull())
+ continue;
+
+ QDomElement toRemove;
+ if (!values.contains(textNode.data()))
+ toRemove = childElm;
+ else
+ values.removeAll(textNode.data());
+
+ childElm = childElm.nextSiblingElement(tagName);
+
+ if (!toRemove.isNull())
+ m_barDocument.documentElement().removeChild(toRemove);
+ }
+ }
+
+ // Add the new elements
+ foreach (const QString &value, values) {
+ if (value.isEmpty())
+ continue;
+ QDomElement newChildNode = m_barDocument.createElement(tagName);
+ newChildNode.appendChild(m_barDocument.createTextNode(value));
+ m_barDocument.documentElement().appendChild(newChildNode);
+ }
}
-BarDescriptorDocumentAbstractNodeHandler *BarDescriptorDocument::nodeHandlerForDomNode(const QDomNode &node)
+BarDescriptorAssetList BarDescriptorDocument::assets() const
{
- foreach (BarDescriptorDocumentAbstractNodeHandler *handler, m_nodeHandlers) {
- if (handler->canHandle(node) && !dynamic_cast<BarDescriptorDocumentUnknownNodeHandler*>(handler))
- return handler;
+ BarDescriptorAssetList result;
+ QDomNodeList nodes = m_barDocument.elementsByTagName(QLatin1String("asset"));
+ if (nodes.isEmpty())
+ return result;
+
+ for (int i = 0; i < nodes.size(); ++i) {
+ QDomElement assetElm = nodes.item(i).toElement();
+ if (assetElm.isNull())
+ continue;
+
+ QDomText textNode = assetElm.firstChild().toText();
+ if (textNode.isNull())
+ continue;
+
+ QString path = assetElm.attribute(QLatin1String("path"));
+ QString entry = assetElm.attribute(QLatin1String("entry"));
+ QString dest = textNode.data();
+
+ BarDescriptorAsset asset;
+ asset.source = path;
+ asset.destination = dest;
+ asset.entry = entry == QLatin1String("true");
+ result.append(asset);
}
- return 0;
+ return result;
}
-void BarDescriptorDocument::removeUnknownNodeHandlers()
+void BarDescriptorDocument::setAssets(const BarDescriptorAssetList &assets)
{
- for (int i = m_nodeHandlers.size() - 1; i >= 0; --i) {
- BarDescriptorDocumentUnknownNodeHandler *nodeHandler = dynamic_cast<BarDescriptorDocumentUnknownNodeHandler*>(m_nodeHandlers[i]);
- if (nodeHandler) {
- m_nodeHandlers.removeAt(i);
- delete nodeHandler;
+ QDomNodeList nodes = m_barDocument.elementsByTagName(QLatin1String("asset"));
+
+ BarDescriptorAssetList newAssets = assets;
+ QList<QDomNode> toRemove;
+
+ for (int i = 0; i < nodes.size(); ++i) {
+ QDomElement assetElm = nodes.at(i).toElement();
+ if (assetElm.isNull())
+ continue;
+
+ QDomText textNode = assetElm.firstChild().toText();
+ if (textNode.isNull())
+ continue;
+
+ QString source = assetElm.attribute(QLatin1String("path"));
+ bool found = false;
+ foreach (const BarDescriptorAsset &asset, newAssets) {
+ if (asset.source == source) {
+ found = true;
+ if (asset.entry) {
+ assetElm.setAttribute(QLatin1String("type"), QLatin1String("Qnx/Elf"));
+ assetElm.setAttribute(QLatin1String("entry"), QLatin1String("true"));
+ } else {
+ assetElm.removeAttribute(QLatin1String("type"));
+ assetElm.removeAttribute(QLatin1String("entry"));
+ }
+ textNode.setData(asset.destination);
+
+ newAssets.removeAll(asset);
+ break;
+ }
+ }
+
+ if (!found)
+ toRemove.append(assetElm);
+ }
+
+ foreach (const QDomNode &node, toRemove)
+ m_barDocument.documentElement().removeChild(node);
+
+ foreach (const BarDescriptorAsset &asset, newAssets) {
+ QDomElement assetElm = m_barDocument.createElement(QLatin1String("asset"));
+ assetElm.setAttribute(QLatin1String("path"), asset.source);
+ if (asset.entry) {
+ assetElm.setAttribute(QLatin1String("type"), QLatin1String("Qnx/Elf"));
+ assetElm.setAttribute(QLatin1String("entry"), QLatin1String("true"));
}
+ assetElm.appendChild(m_barDocument.createTextNode(asset.destination));
+ m_barDocument.documentElement().appendChild(assetElm);
+ }
+}
+
+QList<Utils::EnvironmentItem> BarDescriptorDocument::environment() const
+{
+ QList<Utils::EnvironmentItem> result;
+
+ QDomElement envElm = m_barDocument.documentElement().firstChildElement(QLatin1String("env"));
+ while (!envElm.isNull()) {
+ QString var = envElm.attribute(QLatin1String("var"));
+ QString value = envElm.attribute(QLatin1String("value"));
+
+ Utils::EnvironmentItem item(var, value);
+ result.append(item);
+
+ envElm = envElm.nextSiblingElement(QLatin1String("env"));
+ }
+ return result;
+}
+
+void BarDescriptorDocument::setEnvironment(const QList<Utils::EnvironmentItem> &environment)
+{
+ QDomNodeList envNodes = m_barDocument.elementsByTagName(QLatin1String("env"));
+
+ QList<Utils::EnvironmentItem> newEnvironment = environment;
+ QList<QDomElement> toRemove;
+ for (int i = 0; i < envNodes.size(); ++i) {
+ QDomElement elm = envNodes.at(i).toElement();
+ if (elm.isNull())
+ continue;
+
+ QString var = elm.attribute(QLatin1String("var"));
+ bool found = false;
+ foreach (const Utils::EnvironmentItem item, newEnvironment) {
+ if (item.name == var) {
+ found = true;
+ elm.setAttribute(QLatin1String("value"), item.value);
+ newEnvironment.removeAll(item);
+ break;
+ }
+ }
+
+ if (!found)
+ toRemove.append(elm);
+ }
+
+ foreach (const QDomNode &node, toRemove)
+ m_barDocument.documentElement().removeChild(node);
+
+ foreach (const Utils::EnvironmentItem item, newEnvironment) {
+ QDomElement elm = m_barDocument.createElement(QLatin1String("env"));
+ elm.setAttribute(QLatin1String("var"), item.name);
+ elm.setAttribute(QLatin1String("value"), item.value);
+ m_barDocument.documentElement().appendChild(elm);
+ }
+}
+
+void BarDescriptorDocument::emitAllChanged()
+{
+ QMetaEnum tags = metaObject()->enumerator(metaObject()->enumeratorOffset());
+ for (int i = 0; i < tags.keyCount(); ++i) {
+ Tag tag = static_cast<Tag>(tags.value(i));
+ emit changed(tag, value(tag));
}
}
diff --git a/src/plugins/qnx/bardescriptordocument.h b/src/plugins/qnx/bardescriptordocument.h
index 89b0ef64ea..05c135f777 100644
--- a/src/plugins/qnx/bardescriptordocument.h
+++ b/src/plugins/qnx/bardescriptordocument.h
@@ -33,8 +33,10 @@
#define QNX_INTERNAL_BARDESCRIPTORDOCUMENT_H
#include <coreplugin/textdocument.h>
+#include <utils/environment.h>
-#include <QDomNode>
+#include <QDomDocument>
+#include <QMetaType>
namespace Qnx {
namespace Internal {
@@ -44,16 +46,44 @@ public:
QString source;
QString destination;
bool entry;
+
+ bool operator==(const BarDescriptorAsset &asset) const
+ {
+ return source == asset.source && destination == asset.destination;
+ }
};
-class BarDescriptorEditorWidget;
-class BarDescriptorDocumentAbstractNodeHandler;
+typedef QList<BarDescriptorAsset> BarDescriptorAssetList;
class BarDescriptorDocument : public Core::TextDocument
{
Q_OBJECT
+
+ Q_ENUMS(Tag)
+
public:
- explicit BarDescriptorDocument(BarDescriptorEditorWidget *editorWidget);
+ enum Tag {
+ id = 0,
+ versionNumber,
+ buildId,
+ name,
+ description,
+ icon,
+ splashScreens,
+ asset,
+ aspectRatio,
+ autoOrients,
+ systemChrome,
+ transparent,
+ arg,
+ action,
+ env,
+ author,
+ publisher,
+ authorId
+ };
+
+ explicit BarDescriptorDocument(QObject *parent = 0);
~BarDescriptorDocument();
bool open(QString *errorString, const QString &fileName);
@@ -71,19 +101,43 @@ public:
bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
QString xmlSource() const;
- bool loadContent(const QString &xmlSource, QString *errorMessage = 0, int *errorLine = 0);
+ bool loadContent(const QString &xmlCode, bool setDirty, QString *errorMessage = 0, int *errorLine = 0);
+
+ QVariant value(Tag tag) const;
+
+signals:
+ void changed(BarDescriptorDocument::Tag tag, const QVariant &value);
+
+public slots:
+ void setValue(BarDescriptorDocument::Tag tag, const QVariant &value);
private:
- void registerNodeHandler(BarDescriptorDocumentAbstractNodeHandler *nodeHandler);
- BarDescriptorDocumentAbstractNodeHandler *nodeHandlerForDomNode(const QDomNode &node);
- void removeUnknownNodeHandlers();
+ QString stringValue(const QString &tagName) const;
+ void setStringValue(const QString &tagName, const QString &value);
- QList<BarDescriptorDocumentAbstractNodeHandler *> m_nodeHandlers;
+ QStringList childStringListValue(const QString &tagName, const QString &childTagName) const;
+ void setChildStringListValue(const QString &tagName, const QString &childTagName, const QStringList &stringList);
- BarDescriptorEditorWidget *m_editorWidget;
+ QStringList stringListValue(const QString &tagName) const;
+ void setStringListValue(const QString &tagName, const QStringList &stringList);
+
+ BarDescriptorAssetList assets() const;
+ void setAssets(const BarDescriptorAssetList &assets);
+
+ QList<Utils::EnvironmentItem> environment() const;
+ void setEnvironment(const QList<Utils::EnvironmentItem> &environment);
+
+ void emitAllChanged();
+
+ bool m_dirty;
+ QDomDocument m_barDocument;
};
} // namespace Internal
} // namespace Qnx
+Q_DECLARE_METATYPE(Qnx::Internal::BarDescriptorAssetList)
+Q_DECLARE_METATYPE(QList<Utils::EnvironmentItem>)
+Q_DECLARE_METATYPE(Qnx::Internal::BarDescriptorDocument::Tag)
+
#endif // QNX_INTERNAL_BARDESCRIPTORDOCUMENT_H
diff --git a/src/plugins/qnx/bardescriptordocumentnodehandlers.cpp b/src/plugins/qnx/bardescriptordocumentnodehandlers.cpp
deleted file mode 100644
index 1f3262830a..0000000000
--- a/src/plugins/qnx/bardescriptordocumentnodehandlers.cpp
+++ /dev/null
@@ -1,708 +0,0 @@
-/**************************************************************************
-**
-** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
-**
-** Contact: BlackBerry (qt@blackberry.com)
-** Contact: KDAB (info@kdab.com)
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#include "bardescriptordocumentnodehandlers.h"
-#include "bardescriptoreditorwidget.h"
-#include "bardescriptoreditorassetswidget.h"
-#include "bardescriptoreditorauthorinformationwidget.h"
-#include "bardescriptoreditorentrypointwidget.h"
-#include "bardescriptoreditorenvironmentwidget.h"
-#include "bardescriptoreditorgeneralwidget.h"
-#include "bardescriptoreditorpackageinformationwidget.h"
-#include "bardescriptoreditorpermissionswidget.h"
-
-#include <utils/environment.h>
-#include <utils/qtcassert.h>
-
-#include <QDomNode>
-
-using namespace Qnx;
-using namespace Qnx::Internal;
-
-BarDescriptorDocumentAbstractNodeHandler::BarDescriptorDocumentAbstractNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : m_editorWidget(editorWidget)
- , m_order(0xFFFF)
-{
-}
-
-BarDescriptorDocumentAbstractNodeHandler::~BarDescriptorDocumentAbstractNodeHandler()
-{
-}
-
-bool BarDescriptorDocumentAbstractNodeHandler::handle(const QDomNode &node)
-{
- if (m_order == 0xFFFF)
- m_order = node.lineNumber();
-
- return fromNode(node);
-}
-
-void BarDescriptorDocumentAbstractNodeHandler::clear()
-{
- m_order = 0xFFFF;
-}
-
-int BarDescriptorDocumentAbstractNodeHandler::order() const
-{
- return m_order;
-}
-
-BarDescriptorEditorPackageInformationWidget *BarDescriptorDocumentAbstractNodeHandler::packageInformationWidget() const
-{
- return m_editorWidget->packageInformationWidget();
-}
-
-BarDescriptorEditorAuthorInformationWidget *BarDescriptorDocumentAbstractNodeHandler::authorInformationWidget() const
-{
- return m_editorWidget->authorInformationWidget();
-}
-
-BarDescriptorEditorEntryPointWidget *BarDescriptorDocumentAbstractNodeHandler::entryPointWidget() const
-{
- return m_editorWidget->entryPointWidget();
-}
-
-BarDescriptorEditorGeneralWidget *BarDescriptorDocumentAbstractNodeHandler::generalWidget() const
-{
- return m_editorWidget->generalWidget();
-}
-
-BarDescriptorEditorPermissionsWidget *BarDescriptorDocumentAbstractNodeHandler::permissionsWidget() const
-{
- return m_editorWidget->permissionsWidget();
-}
-
-BarDescriptorEditorEnvironmentWidget *BarDescriptorDocumentAbstractNodeHandler::environmentWidget() const
-{
- return m_editorWidget->environmentWidget();
-}
-
-BarDescriptorEditorAssetsWidget *BarDescriptorDocumentAbstractNodeHandler::assetsWidget() const
-{
- return m_editorWidget->assetsWidget();
-}
-
-bool BarDescriptorDocumentAbstractNodeHandler::canHandleSimpleTextElement(const QDomNode &node, const QString &tagName) const
-{
- QDomElement element = node.toElement();
- if (element.isNull())
- return false;
-
- if (element.tagName().toLower() != tagName.toLower())
- return false;
-
- QDomText textNode = element.firstChild().toText();
- if (textNode.isNull())
- return false;
-
- return true;
-}
-
-QString BarDescriptorDocumentAbstractNodeHandler::loadSimpleTextElement(const QDomNode &node)
-{
- QDomElement element = node.toElement();
- QDomText textNode = element.firstChild().toText();
- return textNode.data();
-}
-
-QDomElement BarDescriptorDocumentAbstractNodeHandler::createSimpleTextElement(QDomDocument &doc, const QString &tagName, const QString &textValue) const
-{
- if (textValue.isEmpty())
- return QDomElement();
-
- QDomElement elem = doc.createElement(tagName);
- elem.appendChild(doc.createTextNode(textValue));
- return elem;
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentIdNodeHandler::BarDescriptorDocumentIdNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentIdNodeHandler::canHandle(const QDomNode &node) const
-{
- return canHandleSimpleTextElement(node, QLatin1String("id"));
-}
-
-bool BarDescriptorDocumentIdNodeHandler::fromNode(const QDomNode &node)
-{
- if (!canHandle(node))
- return false;
-
- packageInformationWidget()->setPackageId(loadSimpleTextElement(node));
- return true;
-}
-
-QDomNode BarDescriptorDocumentIdNodeHandler::toNode(QDomDocument &doc) const
-{
- return createSimpleTextElement(doc, QLatin1String("id"), packageInformationWidget()->packageId());
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentVersionNumberNodeHandler::BarDescriptorDocumentVersionNumberNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentVersionNumberNodeHandler::canHandle(const QDomNode &node) const
-{
- return canHandleSimpleTextElement(node, QLatin1String("versionNumber"));
-}
-
-bool BarDescriptorDocumentVersionNumberNodeHandler::fromNode(const QDomNode &node)
-{
- if (!canHandle(node))
- return false;
-
- packageInformationWidget()->setPackageVersion(loadSimpleTextElement(node));
- return true;
-}
-
-QDomNode BarDescriptorDocumentVersionNumberNodeHandler::toNode(QDomDocument &doc) const
-{
- return createSimpleTextElement(doc, QLatin1String("versionNumber"), packageInformationWidget()->packageVersion());
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentBuildIdNodeHandler::BarDescriptorDocumentBuildIdNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentBuildIdNodeHandler::canHandle(const QDomNode &node) const
-{
- return canHandleSimpleTextElement(node, QLatin1String("buildId"));
-}
-
-bool BarDescriptorDocumentBuildIdNodeHandler::fromNode(const QDomNode &node)
-{
- if (!canHandle(node))
- return false;
-
- packageInformationWidget()->setPackageBuildId(loadSimpleTextElement(node));
- return true;
-}
-
-QDomNode BarDescriptorDocumentBuildIdNodeHandler::toNode(QDomDocument &doc) const
-{
- return createSimpleTextElement(doc, QLatin1String("buildId"), packageInformationWidget()->packageBuildId());
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentApplicationNameNodeHandler::BarDescriptorDocumentApplicationNameNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentApplicationNameNodeHandler::canHandle(const QDomNode &node) const
-{
- return canHandleSimpleTextElement(node, QLatin1String("name"));
-}
-
-bool BarDescriptorDocumentApplicationNameNodeHandler::fromNode(const QDomNode &node)
-{
- // TODO: Add support for localization
-
- if (!canHandle(node))
- return false;
-
- entryPointWidget()->setApplicationName(loadSimpleTextElement(node));
- return true;
-}
-
-QDomNode BarDescriptorDocumentApplicationNameNodeHandler::toNode(QDomDocument &doc) const
-{
- // TODO: Add support for localization
-
- return createSimpleTextElement(doc, QLatin1String("name"), entryPointWidget()->applicationName());
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentApplicationDescriptionNodeHandler::BarDescriptorDocumentApplicationDescriptionNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentApplicationDescriptionNodeHandler::canHandle(const QDomNode &node) const
-{
- return canHandleSimpleTextElement(node, QLatin1String("description"));
-}
-
-bool BarDescriptorDocumentApplicationDescriptionNodeHandler::fromNode(const QDomNode &node)
-{
- // TODO: Add support for localization
-
- if (!canHandle(node))
- return false;
-
- entryPointWidget()->setApplicationDescription(loadSimpleTextElement(node));
- return true;
-}
-
-QDomNode BarDescriptorDocumentApplicationDescriptionNodeHandler::toNode(QDomDocument &doc) const
-{
- return createSimpleTextElement(doc, QLatin1String("description"), entryPointWidget()->applicationDescription());
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentApplicationIconNodeHandler::BarDescriptorDocumentApplicationIconNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentApplicationIconNodeHandler::canHandle(const QDomNode &node) const
-{
- QDomElement element = node.toElement();
- if (element.isNull())
- return false;
-
- if (element.tagName() != QLatin1String("icon"))
- return false;
-
- QDomElement imageElement = element.firstChild().toElement();
- if (imageElement.isNull())
- return false;
-
- if (imageElement.tagName() != QLatin1String("image"))
- return false;
-
- QDomText imageTextNode = imageElement.firstChild().toText();
- if (imageTextNode.isNull())
- return false;
-
- return true;
-}
-
-bool BarDescriptorDocumentApplicationIconNodeHandler::fromNode(const QDomNode &node)
-{
- // TODO: Add support for localization
-
- if (!canHandle(node))
- return false;
-
- QDomNode imageNode = node.firstChild();
- QDomText imageTextNode = imageNode.firstChild().toText();
- entryPointWidget()->setApplicationIcon(imageTextNode.data());
- return true;
-}
-
-QDomNode BarDescriptorDocumentApplicationIconNodeHandler::toNode(QDomDocument &doc) const
-{
- // TODO: Add support for localization
- const QString iconFileName = entryPointWidget()->applicationIconFileName();
- if (iconFileName.isEmpty())
- return QDomElement();
-
- QDomElement iconElement = doc.createElement(QLatin1String("icon"));
- iconElement.appendChild(createSimpleTextElement(doc, QLatin1String("image"), iconFileName));
- return iconElement;
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentSplashScreenNodeHandler::BarDescriptorDocumentSplashScreenNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentSplashScreenNodeHandler::canHandle(const QDomNode &node) const
-{
- QDomElement element = node.toElement();
- if (element.isNull())
- return false;
-
- if (element.tagName().toLower() != QLatin1String("splashscreens"))
- return false;
-
- QDomElement imageElement = element.firstChild().toElement();
- if (imageElement.isNull())
- return false;
-
- if (imageElement.tagName().toLower() != QLatin1String("image"))
- return false;
-
- QDomText imageTextNode = imageElement.firstChild().toText();
- if (imageTextNode.isNull())
- return false;
-
- return true;
-}
-
-bool BarDescriptorDocumentSplashScreenNodeHandler::fromNode(const QDomNode &node)
-{
- if (!canHandle(node))
- return false;
-
- QDomElement imageNode = node.firstChildElement();
- while (!imageNode.isNull()) {
- if (imageNode.tagName().toLower() == QLatin1String("image")) {
- QDomText imageTextNode = imageNode.firstChild().toText();
- entryPointWidget()->appendSplashScreen(imageTextNode.data());
- }
- imageNode = imageNode.nextSiblingElement();
- }
- return true;
-}
-
-QDomNode BarDescriptorDocumentSplashScreenNodeHandler::toNode(QDomDocument &doc) const
-{
- QStringList splashScreens = entryPointWidget()->splashScreens();
- if (splashScreens.isEmpty())
- return QDomElement();
-
- QDomElement splashScreenElement = doc.createElement(QLatin1String("splashScreens"));
- foreach (const QString &splashScreen, splashScreens)
- splashScreenElement.appendChild(createSimpleTextElement(doc, QLatin1String("image"), splashScreen));
-
- return splashScreenElement;
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentAssetNodeHandler::BarDescriptorDocumentAssetNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentAssetNodeHandler::canHandle(const QDomNode &node) const
-{
- return canHandleSimpleTextElement(node, QLatin1String("asset"));
-}
-
-bool BarDescriptorDocumentAssetNodeHandler::fromNode(const QDomNode &node)
-{
- if (!canHandle(node))
- return false;
-
- QDomElement element = node.toElement();
-
- QString path = element.attribute(QLatin1String("path"));
- QString entry = element.attribute(QLatin1String("entry"));
- QDomText destNode = element.firstChild().toText();
- QString dest = destNode.data();
-
- BarDescriptorAsset asset;
- asset.source = path;
- asset.destination = dest;
- asset.entry = entry == QLatin1String("true");
-
- assetsWidget()->addAsset(asset);
- return true;
-}
-
-QDomNode BarDescriptorDocumentAssetNodeHandler::toNode(QDomDocument &doc) const
-{
- QDomDocumentFragment fragment = doc.createDocumentFragment();
-
- QList<BarDescriptorAsset> assets = assetsWidget()->assets();
- foreach (const BarDescriptorAsset &asset, assets) {
- QDomElement assetElem = doc.createElement(QLatin1String("asset"));
- assetElem.setAttribute(QLatin1String("path"), asset.source);
- if (asset.entry) {
- assetElem.setAttribute(QLatin1String("type"), QLatin1String("Qnx/Elf"));
- assetElem.setAttribute(QLatin1String("entry"), QLatin1String("true"));
- }
- assetElem.appendChild(doc.createTextNode(asset.destination));
- fragment.appendChild(assetElem);
- }
-
- return fragment;
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentInitialWindowNodeHandler::BarDescriptorDocumentInitialWindowNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentInitialWindowNodeHandler::canHandle(const QDomNode &node) const
-{
- QDomElement element = node.toElement();
- if (element.isNull())
- return false;
-
- if (element.tagName() != QLatin1String("initialWindow"))
- return false;
-
- return true;
-}
-
-bool BarDescriptorDocumentInitialWindowNodeHandler::fromNode(const QDomNode &node)
-{
- if (!canHandle(node))
- return false;
-
- QDomElement child = node.firstChildElement();
- while (!child.isNull()) {
- if (child.tagName() == QLatin1String("aspectRatio")) {
- generalWidget()->setOrientation(loadSimpleTextElement(child));
- } else if (child.tagName() == QLatin1String("autoOrients")) {
- if (loadSimpleTextElement(child) == QLatin1String("true"))
- generalWidget()->setOrientation(QLatin1String("auto-orient"));
- } else if (child.tagName() == QLatin1String("systemChrome")) {
- generalWidget()->setChrome(loadSimpleTextElement(child));
- } else if (child.tagName() == QLatin1String("transparent")) {
- const QString transparent = loadSimpleTextElement(child);
- generalWidget()->setTransparent(transparent == QLatin1String("true"));
- }
- child = child.nextSiblingElement();
- }
-
- return true;
-}
-
-QDomNode BarDescriptorDocumentInitialWindowNodeHandler::toNode(QDomDocument &doc) const
-{
- QDomElement element = doc.createElement(QLatin1String("initialWindow"));
-
- if (generalWidget()->orientation() == QLatin1String("auto-orient")) {
- element.appendChild(createSimpleTextElement(doc, QLatin1String("autoOrients"), QLatin1String("true")));
- } else if (!generalWidget()->orientation().isEmpty()) {
- element.appendChild(createSimpleTextElement(doc, QLatin1String("aspectRatio"), generalWidget()->orientation()));
- element.appendChild(createSimpleTextElement(doc, QLatin1String("autoOrients"), QLatin1String("false")));
- }
- element.appendChild(createSimpleTextElement(doc, QLatin1String("systemChrome"), generalWidget()->chrome()));
- element.appendChild(createSimpleTextElement(doc, QLatin1String("transparent"), generalWidget()->transparent() ? QLatin1String("true") : QLatin1String("false")));
-
- return element;
-}
-
-// ----------------------------------------------------------------------------
-
-
-BarDescriptorDocumentActionNodeHandler::BarDescriptorDocumentActionNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentActionNodeHandler::canHandle(const QDomNode &node) const
-{
- return canHandleSimpleTextElement(node, QLatin1String("action"));
-}
-
-bool BarDescriptorDocumentActionNodeHandler::fromNode(const QDomNode &node)
-{
- if (!canHandle(node))
- return false;
-
- QString value = loadSimpleTextElement(node);
- if (value != QLatin1String("run_native")) // This has no representation in the GUI, and is always added
- permissionsWidget()->checkPermission(value);
-
- return true;
-}
-
-QDomNode BarDescriptorDocumentActionNodeHandler::toNode(QDomDocument &doc) const
-{
- QDomDocumentFragment frag = doc.createDocumentFragment();
-
- QDomElement runNativeElement = doc.createElement(QLatin1String("action"));
- runNativeElement.setAttribute(QLatin1String("system"), QLatin1String("true"));
- runNativeElement.appendChild(doc.createTextNode(QLatin1String("run_native")));
- frag.appendChild(runNativeElement);
-
- QStringList checkedIdentifiers = permissionsWidget()->checkedPermissions();
- foreach (const QString &identifier, checkedIdentifiers)
- frag.appendChild(createSimpleTextElement(doc, QLatin1String("action"), identifier));
-
- return frag;
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentArgNodeHandler::BarDescriptorDocumentArgNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentArgNodeHandler::canHandle(const QDomNode &node) const
-{
- return canHandleSimpleTextElement(node, QLatin1String("arg"));
-}
-
-bool BarDescriptorDocumentArgNodeHandler::fromNode(const QDomNode &node)
-{
- if (!canHandle(node))
- return false;
-
- generalWidget()->appendApplicationArgument(loadSimpleTextElement(node));
- return true;
-}
-
-QDomNode BarDescriptorDocumentArgNodeHandler::toNode(QDomDocument &doc) const
-{
- QDomDocumentFragment frag = doc.createDocumentFragment();
-
- QStringList arguments = generalWidget()->applicationArguments();
- foreach (const QString &argument, arguments)
- frag.appendChild(createSimpleTextElement(doc, QLatin1String("arg"), argument));
-
- return frag;
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentEnvNodeHandler::BarDescriptorDocumentEnvNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentEnvNodeHandler::canHandle(const QDomNode &node) const
-{
- QDomElement element = node.toElement();
- if (element.isNull())
- return false;
-
- if (element.tagName() != QLatin1String("env"))
- return false;
-
- if (!element.hasAttribute(QLatin1String("var")) || !element.hasAttribute(QLatin1String("value")))
- return false;
-
- return true;
-}
-
-bool BarDescriptorDocumentEnvNodeHandler::fromNode(const QDomNode &node)
-{
- if (!canHandle(node))
- return false;
-
- QDomElement element = node.toElement();
-
- QString var = element.attribute(QLatin1String("var"));
- QString value = element.attribute(QLatin1String("value"));
-
- Utils::EnvironmentItem item(var, value);
- environmentWidget()->appendEnvironmentItem(item);
- return true;
-}
-
-QDomNode BarDescriptorDocumentEnvNodeHandler::toNode(QDomDocument &doc) const
-{
- QDomDocumentFragment frag = doc.createDocumentFragment();
- QList<Utils::EnvironmentItem> environmentItems = environmentWidget()->environment();
-
- foreach (const Utils::EnvironmentItem &item, environmentItems) {
- QDomElement element = doc.createElement(QLatin1String("env"));
- element.setAttribute(QLatin1String("var"), item.name);
- element.setAttribute(QLatin1String("value"), item.value);
- frag.appendChild(element);
- }
-
- return frag;
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentAuthorNodeHandler::BarDescriptorDocumentAuthorNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentAuthorNodeHandler::canHandle(const QDomNode &node) const
-{
- return canHandleSimpleTextElement(node, QLatin1String("author"))
- || canHandleSimpleTextElement(node, QLatin1String("publisher"));
-}
-
-bool BarDescriptorDocumentAuthorNodeHandler::fromNode(const QDomNode &node)
-{
- if (!canHandle(node))
- return false;
-
- authorInformationWidget()->setAuthor(loadSimpleTextElement(node));
- return true;
-}
-
-QDomNode BarDescriptorDocumentAuthorNodeHandler::toNode(QDomDocument &doc) const
-{
- return createSimpleTextElement(doc, QLatin1String("author"), authorInformationWidget()->author());
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentAuthorIdNodeHandler::BarDescriptorDocumentAuthorIdNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentAuthorIdNodeHandler::canHandle(const QDomNode &node) const
-{
- return canHandleSimpleTextElement(node, QLatin1String("authorId"));
-}
-
-bool BarDescriptorDocumentAuthorIdNodeHandler::fromNode(const QDomNode &node)
-{
- if (!canHandle(node))
- return false;
-
- authorInformationWidget()->setAuthorId(loadSimpleTextElement(node));
- return true;
-}
-
-QDomNode BarDescriptorDocumentAuthorIdNodeHandler::toNode(QDomDocument &doc) const
-{
- return createSimpleTextElement(doc, QLatin1String("authorId"), authorInformationWidget()->authorId());
-}
-
-// ----------------------------------------------------------------------------
-
-BarDescriptorDocumentUnknownNodeHandler::BarDescriptorDocumentUnknownNodeHandler(BarDescriptorEditorWidget *editorWidget)
- : BarDescriptorDocumentAbstractNodeHandler(editorWidget)
-{
-}
-
-bool BarDescriptorDocumentUnknownNodeHandler::canHandle(const QDomNode &node) const
-{
- Q_UNUSED(node);
- return true;
-}
-
-bool BarDescriptorDocumentUnknownNodeHandler::fromNode(const QDomNode &node)
-{
- m_node = node.cloneNode();
- return true;
-}
-
-QDomNode BarDescriptorDocumentUnknownNodeHandler::toNode(QDomDocument &doc) const
-{
- Q_UNUSED(doc);
- return m_node;
-}
diff --git a/src/plugins/qnx/bardescriptordocumentnodehandlers.h b/src/plugins/qnx/bardescriptordocumentnodehandlers.h
deleted file mode 100644
index d76917ab60..0000000000
--- a/src/plugins/qnx/bardescriptordocumentnodehandlers.h
+++ /dev/null
@@ -1,302 +0,0 @@
-/**************************************************************************
-**
-** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
-**
-** Contact: BlackBerry (qt@blackberry.com)
-** Contact: KDAB (info@kdab.com)
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#ifndef QNX_INTERNAL_BARDESCRIPTORDOCUMENTNODEHANDLERS_H
-#define QNX_INTERNAL_BARDESCRIPTORDOCUMENTNODEHANDLERS_H
-
-#include <QDomNode>
-#include <QSharedPointer>
-
-namespace Qnx {
-namespace Internal {
-
-class BarDescriptorEditorWidget;
-class BarDescriptorEditorAssetsWidget;
-class BarDescriptorEditorAuthorInformationWidget;
-class BarDescriptorEditorEntryPointWidget;
-class BarDescriptorEditorEnvironmentWidget;
-class BarDescriptorEditorGeneralWidget;
-class BarDescriptorEditorPackageInformationWidget;
-class BarDescriptorEditorPermissionsWidget;
-
-class BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentAbstractNodeHandler(BarDescriptorEditorWidget *editorWidget);
- virtual ~BarDescriptorDocumentAbstractNodeHandler();
-
- virtual bool canHandle(const QDomNode &node) const = 0;
- bool handle(const QDomNode &node);
- virtual QDomNode toNode(QDomDocument &doc) const = 0;
-
- void clear();
- int order() const;
-
-protected:
- BarDescriptorEditorPackageInformationWidget *packageInformationWidget() const;
- BarDescriptorEditorAuthorInformationWidget *authorInformationWidget() const;
-
- BarDescriptorEditorEntryPointWidget *entryPointWidget() const;
- BarDescriptorEditorGeneralWidget *generalWidget() const;
- BarDescriptorEditorPermissionsWidget *permissionsWidget() const;
- BarDescriptorEditorEnvironmentWidget *environmentWidget() const;
-
- BarDescriptorEditorAssetsWidget *assetsWidget() const;
-
- virtual bool fromNode(const QDomNode &node) = 0;
-
- bool canHandleSimpleTextElement(const QDomNode &node, const QString &tagName) const;
- QString loadSimpleTextElement(const QDomNode &node);
- QDomElement createSimpleTextElement(QDomDocument &doc, const QString &tagName, const QString &textValue) const;
-
-private:
- BarDescriptorEditorWidget *m_editorWidget;
-
- int m_order;
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentIdNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentIdNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentVersionNumberNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentVersionNumberNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentBuildIdNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentBuildIdNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentApplicationNameNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentApplicationNameNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentApplicationDescriptionNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentApplicationDescriptionNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentApplicationIconNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentApplicationIconNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentSplashScreenNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentSplashScreenNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentAssetNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentAssetNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentInitialWindowNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentInitialWindowNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentActionNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentActionNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentArgNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentArgNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentEnvNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentEnvNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentAuthorNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentAuthorNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentAuthorIdNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentAuthorIdNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-};
-
-// ----------------------------------------------------------------------------
-
-class BarDescriptorDocumentUnknownNodeHandler : public BarDescriptorDocumentAbstractNodeHandler
-{
-public:
- BarDescriptorDocumentUnknownNodeHandler(BarDescriptorEditorWidget *editorWidget);
-
- bool canHandle(const QDomNode &node) const;
- QDomNode toNode(QDomDocument &doc) const;
-
-protected:
- bool fromNode(const QDomNode &node);
-
-private:
- QDomNode m_node;
-};
-
-} // namespace Internal
-} // namespace Qnx
-
-#endif // QNX_INTERNAL_BARDESCRIPTORDOCUMENTNODEHANDLERS_H
diff --git a/src/plugins/qnx/bardescriptoreditor.cpp b/src/plugins/qnx/bardescriptoreditor.cpp
index 55dce2f47f..dfdfff6771 100644
--- a/src/plugins/qnx/bardescriptoreditor.cpp
+++ b/src/plugins/qnx/bardescriptoreditor.cpp
@@ -56,10 +56,10 @@ namespace Internal {
BarDescriptorEditor::BarDescriptorEditor()
{
+ m_file = new BarDescriptorDocument(this);
+
BarDescriptorEditorWidget *editorWidget = new BarDescriptorEditorWidget(this);
setWidget(editorWidget);
- m_file = new BarDescriptorDocument(editorWidget);
- connect(editorWidget, SIGNAL(changed()), m_file, SIGNAL(changed()));
m_toolBar = new QToolBar(editorWidget);
@@ -106,7 +106,15 @@ BarDescriptorEditor::BarDescriptorEditor()
bool BarDescriptorEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
{
QTC_ASSERT(fileName == realFileName, return false);
- return m_file->open(errorString, fileName);
+
+ bool result = m_file->open(errorString, fileName);
+ if (result) {
+ BarDescriptorEditorWidget *editorWidget = qobject_cast<BarDescriptorEditorWidget *>(widget());
+ QTC_ASSERT(editorWidget, return false);
+ editorWidget->setFilePath(fileName);
+ }
+
+ return result;
}
Core::IDocument *BarDescriptorEditor::document()
@@ -142,31 +150,6 @@ void BarDescriptorEditor::setActivePage(BarDescriptorEditor::EditorPage page)
BarDescriptorEditorWidget *editorWidget = qobject_cast<BarDescriptorEditorWidget *>(widget());
QTC_ASSERT(editorWidget, return);
- int prevPage = editorWidget->currentIndex();
-
- if (prevPage == page)
- return;
-
- if (page == Source) {
- editorWidget->setXmlSource(m_file->xmlSource());
- updateCursorPosition();
- } else if (prevPage == Source) {
- TaskHub::clearTasks(Constants::QNX_TASK_CATEGORY_BARDESCRIPTOR);
- QString errorMsg;
- int errorLine;
- if (!m_file->loadContent(editorWidget->xmlSource(), &errorMsg, &errorLine)) {
- TaskHub::addTask(Task::Error, errorMsg, Constants::QNX_TASK_CATEGORY_BARDESCRIPTOR,
- Utils::FileName::fromString(m_file->filePath()), errorLine);
- TaskHub::requestPopup();
-
- foreach (QAction *action, m_actionGroup->actions())
- if (action->data().toInt() == Source)
- action->setChecked(true);
-
- return;
- }
- }
-
m_cursorPositionAction->setVisible(page == Source);
editorWidget->setCurrentIndex(page);
}
diff --git a/src/plugins/qnx/bardescriptoreditorabstractpanelwidget.cpp b/src/plugins/qnx/bardescriptoreditorabstractpanelwidget.cpp
index 55919d1db1..31b4ef3d87 100644
--- a/src/plugins/qnx/bardescriptoreditorabstractpanelwidget.cpp
+++ b/src/plugins/qnx/bardescriptoreditorabstractpanelwidget.cpp
@@ -32,10 +32,12 @@
#include "bardescriptoreditorabstractpanelwidget.h"
#include <utils/pathchooser.h>
+#include <utils/qtcassert.h>
#include <QCheckBox>
#include <QComboBox>
#include <QLineEdit>
+#include <QSignalMapper>
#include <QTextEdit>
using namespace Qnx;
@@ -44,40 +46,86 @@ using namespace Qnx::Internal;
BarDescriptorEditorAbstractPanelWidget::BarDescriptorEditorAbstractPanelWidget(QWidget *parent) :
QWidget(parent)
{
+ m_signalMapper = new QSignalMapper(this);
+ connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(handleSignalMapped(int)));
}
+void BarDescriptorEditorAbstractPanelWidget::setValue(BarDescriptorDocument::Tag tag, const QVariant &value)
+{
+ if (m_blockedSignals.contains(tag))
+ return;
+
+ blockSignalMapping(tag);
+ updateWidgetValue(tag, value);
+ unblockSignalMapping(tag);
+}
-void BarDescriptorEditorAbstractPanelWidget::setComboBoxBlocked(QComboBox *comboBox, int index)
+void BarDescriptorEditorAbstractPanelWidget::addSignalMapping(BarDescriptorDocument::Tag tag, QObject *object, const char *signal)
{
- bool blocked = comboBox->blockSignals(true);
- comboBox->setCurrentIndex(index);
- comboBox->blockSignals(blocked);
+ m_signalMapper->setMapping(object, tag);
+ connect(object, signal, m_signalMapper, SLOT(map()));
}
-void BarDescriptorEditorAbstractPanelWidget::setCheckBoxBlocked(QCheckBox *checkBox, bool checked)
+void BarDescriptorEditorAbstractPanelWidget::blockSignalMapping(BarDescriptorDocument::Tag tag)
{
- bool blocked = checkBox->blockSignals(true);
- checkBox->setChecked(checked);
- checkBox->blockSignals(blocked);
+ m_blockedSignals.prepend(tag);
}
-void BarDescriptorEditorAbstractPanelWidget::setLineEditBlocked(QLineEdit *lineEdit, const QString &text)
+void BarDescriptorEditorAbstractPanelWidget::unblockSignalMapping(BarDescriptorDocument::Tag tag)
{
- bool blocked = lineEdit->blockSignals(true);
- lineEdit->setText(text);
- lineEdit->blockSignals(blocked);
+ BarDescriptorDocument::Tag removedTag = m_blockedSignals.takeFirst();
+ QTC_CHECK(removedTag == tag);
}
-void BarDescriptorEditorAbstractPanelWidget::setTextEditBlocked(QTextEdit *textEdit, const QString &text)
+void BarDescriptorEditorAbstractPanelWidget::updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value)
{
- bool blocked = textEdit->blockSignals(true);
- textEdit->setPlainText(text);
- textEdit->blockSignals(blocked);
+ QObject *object = m_signalMapper->mapping(static_cast<int>(tag));
+ if (!object)
+ return;
+
+ if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(object))
+ lineEdit->setText(value.toString());
+ else if (QTextEdit *textEdit = qobject_cast<QTextEdit *>(object))
+ textEdit->setPlainText(value.toString());
+ else if (Utils::PathChooser *pathChooser = qobject_cast<Utils::PathChooser *>(object))
+ pathChooser->setPath(value.toString());
+ else if (QComboBox *comboBox = qobject_cast<QComboBox *>(object))
+ comboBox->setCurrentIndex(comboBox->findData(value.toString()));
+ else if (QCheckBox *checkBox = qobject_cast<QCheckBox *>(object))
+ checkBox->setChecked(value.toBool());
+ else
+ QTC_CHECK(false);
}
-void BarDescriptorEditorAbstractPanelWidget::setPathChooserBlocked(Utils::PathChooser *pathChooser, const QString &path)
+void BarDescriptorEditorAbstractPanelWidget::emitChanged(BarDescriptorDocument::Tag tag)
{
- bool blocked = pathChooser->blockSignals(true);
- pathChooser->setPath(path);
- pathChooser->blockSignals(blocked);
+ QObject *sender = m_signalMapper->mapping(tag);
+
+ if (!sender)
+ return;
+
+ if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(sender))
+ emit changed(tag, lineEdit->text());
+ else if (QTextEdit *textEdit = qobject_cast<QTextEdit *>(sender))
+ emit changed(tag, textEdit->toPlainText());
+ else if (Utils::PathChooser *pathChooser = qobject_cast<Utils::PathChooser *>(sender))
+ emit changed(tag, pathChooser->path());
+ else if (QComboBox *comboBox = qobject_cast<QComboBox *>(sender))
+ emit changed(tag, comboBox->itemData(comboBox->currentIndex()));
+ else if (QCheckBox *checkBox = qobject_cast<QCheckBox *>(sender))
+ emit changed(tag, checkBox->isChecked());
+ else
+ QTC_CHECK(false);
+}
+
+void BarDescriptorEditorAbstractPanelWidget::handleSignalMapped(int id)
+{
+ BarDescriptorDocument::Tag tag = static_cast<BarDescriptorDocument::Tag>(id);
+
+ if (m_blockedSignals.contains(tag))
+ return;
+
+ blockSignalMapping(tag);
+ emitChanged(tag);
+ unblockSignalMapping(tag);
}
diff --git a/src/plugins/qnx/bardescriptoreditorabstractpanelwidget.h b/src/plugins/qnx/bardescriptoreditorabstractpanelwidget.h
index c6f4d0e7ae..d45075de03 100644
--- a/src/plugins/qnx/bardescriptoreditorabstractpanelwidget.h
+++ b/src/plugins/qnx/bardescriptoreditorabstractpanelwidget.h
@@ -34,6 +34,8 @@
#include <QWidget>
+#include "bardescriptordocument.h"
+
namespace Utils {
class PathChooser;
}
@@ -42,6 +44,8 @@ QT_BEGIN_NAMESPACE
class QCheckBox;
class QComboBox;
class QLineEdit;
+class QSignalMapper;
+class QStringListModel;
class QTextEdit;
QT_END_NAMESPACE
@@ -54,17 +58,26 @@ class BarDescriptorEditorAbstractPanelWidget : public QWidget
public:
explicit BarDescriptorEditorAbstractPanelWidget(QWidget *parent = 0);
- virtual void clear() = 0;
+public slots:
+ void setValue(BarDescriptorDocument::Tag tag, const QVariant &value);
signals:
- void changed();
+ void changed(BarDescriptorDocument::Tag tag, const QVariant &value);
protected:
- void setComboBoxBlocked(QComboBox *comboBox, int index);
- void setCheckBoxBlocked(QCheckBox *checkBox, bool checked);
- void setLineEditBlocked(QLineEdit *lineEdit, const QString &text);
- void setTextEditBlocked(QTextEdit *textEdit, const QString &text);
- void setPathChooserBlocked(Utils::PathChooser *pathChooser, const QString &path);
+ virtual void updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value);
+ virtual void emitChanged(BarDescriptorDocument::Tag tag);
+
+ void addSignalMapping(BarDescriptorDocument::Tag tag, QObject *object, const char *signal);
+ void blockSignalMapping(BarDescriptorDocument::Tag tag);
+ void unblockSignalMapping(BarDescriptorDocument::Tag tag);
+
+private slots:
+ void handleSignalMapped(int id);
+
+private:
+ QSignalMapper *m_signalMapper;
+ QList<BarDescriptorDocument::Tag> m_blockedSignals;
};
} // namespace Internal
diff --git a/src/plugins/qnx/bardescriptoreditorassetswidget.cpp b/src/plugins/qnx/bardescriptoreditorassetswidget.cpp
index ad79c431f0..53c076c0da 100644
--- a/src/plugins/qnx/bardescriptoreditorassetswidget.cpp
+++ b/src/plugins/qnx/bardescriptoreditorassetswidget.cpp
@@ -57,7 +57,10 @@ BarDescriptorEditorAssetsWidget::BarDescriptorEditorAssetsWidget(QWidget *parent
connect(m_ui->addAsset, SIGNAL(clicked()), this, SLOT(addNewAsset()));
connect(m_ui->removeAsset, SIGNAL(clicked()), this, SLOT(removeSelectedAsset()));
connect(m_assetsModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updateEntryCheckState(QStandardItem*)));
- connectAssetsModel();
+
+ addSignalMapping(BarDescriptorDocument::asset, m_assetsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
+ addSignalMapping(BarDescriptorDocument::asset, m_assetsModel, SIGNAL(rowsInserted(QModelIndex,int,int)));
+ addSignalMapping(BarDescriptorDocument::asset, m_assetsModel, SIGNAL(rowsRemoved(QModelIndex,int,int)));
}
BarDescriptorEditorAssetsWidget::~BarDescriptorEditorAssetsWidget()
@@ -67,37 +70,27 @@ BarDescriptorEditorAssetsWidget::~BarDescriptorEditorAssetsWidget()
void BarDescriptorEditorAssetsWidget::clear()
{
- // We can't just block signals, as the view depends on them
- disconnectAssetsModel();
+ blockSignalMapping(BarDescriptorDocument::asset);
m_assetsModel->removeRows(0, m_assetsModel->rowCount());
- connectAssetsModel();
+ unblockSignalMapping(BarDescriptorDocument::asset);
}
-void BarDescriptorEditorAssetsWidget::addAsset(const BarDescriptorAsset &asset)
+QStandardItemModel *BarDescriptorEditorAssetsWidget::assetsModel() const
{
- disconnectAssetsModel();
- addAssetInternal(asset);
- connectAssetsModel();
+ return m_assetsModel;
}
-QList<BarDescriptorAsset> BarDescriptorEditorAssetsWidget::assets() const
+void BarDescriptorEditorAssetsWidget::updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value)
{
- QList<BarDescriptorAsset> result;
-
- for (int i = 0; i < m_assetsModel->rowCount(); ++i) {
- BarDescriptorAsset asset;
- asset.source = m_assetsModel->item(i, 0)->text();
- asset.destination = m_assetsModel->item(i, 1)->text();
- asset.entry = m_assetsModel->item(i, 2)->checkState() == Qt::Checked;
- result << asset;
+ if (tag != BarDescriptorDocument::asset) {
+ BarDescriptorEditorAbstractPanelWidget::updateWidgetValue(tag, value);
+ return;
}
- return result;
-}
-
-QStandardItemModel *BarDescriptorEditorAssetsWidget::assetsModel() const
-{
- return m_assetsModel;
+ clear();
+ BarDescriptorAssetList assets = value.value<BarDescriptorAssetList>();
+ foreach (const BarDescriptorAsset asset, assets)
+ addAsset(asset);
}
void BarDescriptorEditorAssetsWidget::addAsset(const QString &fullPath)
@@ -109,7 +102,7 @@ void BarDescriptorEditorAssetsWidget::addAsset(const QString &fullPath)
asset.source = fullPath;
asset.destination = QFileInfo(fullPath).fileName();
asset.entry = false;
- addAssetInternal(asset);
+ addAsset(asset);
}
void BarDescriptorEditorAssetsWidget::removeAsset(const QString &fullPath)
@@ -157,21 +150,28 @@ void BarDescriptorEditorAssetsWidget::updateEntryCheckState(QStandardItem *item)
connect(m_assetsModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updateEntryCheckState(QStandardItem*)));
}
-void BarDescriptorEditorAssetsWidget::connectAssetsModel()
+void BarDescriptorEditorAssetsWidget::emitChanged(BarDescriptorDocument::Tag tag)
{
- connect(m_assetsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
- connect(m_assetsModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(changed()));
- connect(m_assetsModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(changed()));
-}
+ if (tag != BarDescriptorDocument::asset) {
+ BarDescriptorEditorAbstractPanelWidget::emitChanged(tag);
+ return;
+ }
-void BarDescriptorEditorAssetsWidget::disconnectAssetsModel()
-{
- disconnect(m_assetsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
- disconnect(m_assetsModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(changed()));
- disconnect(m_assetsModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(changed()));
+ BarDescriptorAssetList result;
+ for (int i = 0; i < m_assetsModel->rowCount(); ++i) {
+ BarDescriptorAsset asset;
+ asset.source = m_assetsModel->item(i, 0)->text();
+ asset.destination = m_assetsModel->item(i, 1)->text();
+ asset.entry = m_assetsModel->item(i, 2)->checkState() == Qt::Checked;
+ result.append(asset);
+ }
+
+ QVariant var;
+ var.setValue(result);
+ emit changed(tag, var);
}
-void BarDescriptorEditorAssetsWidget::addAssetInternal(const BarDescriptorAsset &asset)
+void BarDescriptorEditorAssetsWidget::addAsset(const BarDescriptorAsset &asset)
{
const QString path = asset.source;
const QString dest = asset.destination;
diff --git a/src/plugins/qnx/bardescriptoreditorassetswidget.h b/src/plugins/qnx/bardescriptoreditorassetswidget.h
index eb08f4a143..c03293c653 100644
--- a/src/plugins/qnx/bardescriptoreditorassetswidget.h
+++ b/src/plugins/qnx/bardescriptoreditorassetswidget.h
@@ -56,27 +56,24 @@ public:
explicit BarDescriptorEditorAssetsWidget(QWidget *parent = 0);
~BarDescriptorEditorAssetsWidget();
- void clear();
-
- void addAsset(const BarDescriptorAsset &asset);
- QList<BarDescriptorAsset> assets() const;
-
QStandardItemModel *assetsModel() const;
public slots:
void addAsset(const QString &fullPath);
void removeAsset(const QString &fullPath);
+protected:
+ void updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value);
+ void emitChanged(BarDescriptorDocument::Tag tag);
+
private slots:
void addNewAsset();
void removeSelectedAsset();
void updateEntryCheckState(QStandardItem *item);
private:
- void connectAssetsModel();
- void disconnectAssetsModel();
-
- void addAssetInternal(const BarDescriptorAsset &asset);
+ void clear();
+ void addAsset(const BarDescriptorAsset &asset);
bool hasAsset(const BarDescriptorAsset &asset);
Ui::BarDescriptorEditorAssetsWidget *m_ui;
diff --git a/src/plugins/qnx/bardescriptoreditorauthorinformationwidget.cpp b/src/plugins/qnx/bardescriptoreditorauthorinformationwidget.cpp
index 127b289e8d..59df42e589 100644
--- a/src/plugins/qnx/bardescriptoreditorauthorinformationwidget.cpp
+++ b/src/plugins/qnx/bardescriptoreditorauthorinformationwidget.cpp
@@ -53,8 +53,8 @@ BarDescriptorEditorAuthorInformationWidget::BarDescriptorEditorAuthorInformation
m_ui->setFromDebugToken->setVisible(BlackBerryDebugTokenReader::isSupported());
- connect(m_ui->author, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
- connect(m_ui->authorId, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
+ addSignalMapping(BarDescriptorDocument::author, m_ui->author, SIGNAL(textChanged(QString)));
+ addSignalMapping(BarDescriptorDocument::authorId, m_ui->authorId, SIGNAL(textChanged(QString)));
connect(m_ui->setFromDebugToken, SIGNAL(clicked()), this, SLOT(setAuthorFromDebugToken()));
}
@@ -63,30 +63,13 @@ BarDescriptorEditorAuthorInformationWidget::~BarDescriptorEditorAuthorInformatio
delete m_ui;
}
-void BarDescriptorEditorAuthorInformationWidget::clear()
+void BarDescriptorEditorAuthorInformationWidget::updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value)
{
- setLineEditBlocked(m_ui->author, QString());
- setLineEditBlocked(m_ui->authorId, QString());
-}
-
-QString BarDescriptorEditorAuthorInformationWidget::author() const
-{
- return m_ui->author->text();
-}
-
-void BarDescriptorEditorAuthorInformationWidget::setAuthor(const QString &author)
-{
- setLineEditBlocked(m_ui->author, author);
-}
-
-QString BarDescriptorEditorAuthorInformationWidget::authorId() const
-{
- return m_ui->authorId->text();
-}
-
-void BarDescriptorEditorAuthorInformationWidget::setAuthorId(const QString &authorId)
-{
- setLineEditBlocked(m_ui->authorId, authorId);
+ if (tag == BarDescriptorDocument::publisher && !value.toString().isEmpty())
+ // <publisher> is deprecated and hence not connected to the author field as we only want to read it from the XML
+ m_ui->author->setText(value.toString());
+ else
+ BarDescriptorEditorAbstractPanelWidget::updateWidgetValue(tag, value);
}
void BarDescriptorEditorAuthorInformationWidget::setAuthorFromDebugToken()
diff --git a/src/plugins/qnx/bardescriptoreditorauthorinformationwidget.h b/src/plugins/qnx/bardescriptoreditorauthorinformationwidget.h
index 2220403948..2bc2def1f7 100644
--- a/src/plugins/qnx/bardescriptoreditorauthorinformationwidget.h
+++ b/src/plugins/qnx/bardescriptoreditorauthorinformationwidget.h
@@ -49,13 +49,8 @@ public:
explicit BarDescriptorEditorAuthorInformationWidget(QWidget *parent = 0);
~BarDescriptorEditorAuthorInformationWidget();
- void clear();
-
- QString author() const;
- void setAuthor(const QString &author);
-
- QString authorId() const;
- void setAuthorId(const QString &authorId);
+protected:
+ void updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value);
private slots:
void setAuthorFromDebugToken();
diff --git a/src/plugins/qnx/bardescriptoreditorentrypointwidget.cpp b/src/plugins/qnx/bardescriptoreditorentrypointwidget.cpp
index 59a2cbbe1d..d857fec75b 100644
--- a/src/plugins/qnx/bardescriptoreditorentrypointwidget.cpp
+++ b/src/plugins/qnx/bardescriptoreditorentrypointwidget.cpp
@@ -65,9 +65,6 @@ BarDescriptorEditorEntryPointWidget::BarDescriptorEditorEntryPointWidget(QWidget
m_ui->splashScreenWarningLabel->setVisible(false);
m_ui->splashScreenWarningPixmap->setVisible(false);
- connect(m_ui->applicationName, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
- connect(m_ui->applicationDescription, SIGNAL(textChanged()), this, SIGNAL(changed()));
-
connect(m_ui->iconFilePath, SIGNAL(changed(QString)), this, SLOT(handleIconChanged(QString)));
connect(m_ui->iconClearButton, SIGNAL(clicked()), this, SLOT(clearIcon()));
@@ -75,8 +72,14 @@ BarDescriptorEditorEntryPointWidget::BarDescriptorEditorEntryPointWidget(QWidget
m_ui->splashScreensView->setModel(m_splashScreenModel);
connect(m_ui->addSplashScreen, SIGNAL(clicked()), this, SLOT(browseForSplashScreen()));
connect(m_ui->removeSplashScreen, SIGNAL(clicked()), this, SLOT(removeSelectedSplashScreen()));
- connect(m_splashScreenModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
connect(m_ui->splashScreensView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(handleSplashScreenSelectionChanged(QItemSelection,QItemSelection)));
+
+ addSignalMapping(BarDescriptorDocument::name, m_ui->applicationName, SIGNAL(textChanged(QString)));
+ addSignalMapping(BarDescriptorDocument::description, m_ui->applicationDescription, SIGNAL(textChanged()));
+ addSignalMapping(BarDescriptorDocument::icon, m_ui->iconFilePath, SIGNAL(changed(QString)));
+ addSignalMapping(BarDescriptorDocument::splashScreens, m_splashScreenModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
+ addSignalMapping(BarDescriptorDocument::splashScreens, m_splashScreenModel, SIGNAL(rowsRemoved(QModelIndex,int,int)));
+ addSignalMapping(BarDescriptorDocument::splashScreens, m_splashScreenModel, SIGNAL(rowsInserted(QModelIndex,int,int)));
}
BarDescriptorEditorEntryPointWidget::~BarDescriptorEditorEntryPointWidget()
@@ -84,66 +87,38 @@ BarDescriptorEditorEntryPointWidget::~BarDescriptorEditorEntryPointWidget()
delete m_ui;
}
-void BarDescriptorEditorEntryPointWidget::clear()
-{
- setPathChooserBlocked(m_ui->iconFilePath, QString());
- setApplicationIconPreview(QString());
-
- disconnect(m_splashScreenModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
- m_splashScreenModel->setStringList(QStringList());
- connect(m_splashScreenModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
- setImagePreview(m_ui->splashScreenPreviewLabel, QString());
-}
-
-QString BarDescriptorEditorEntryPointWidget::applicationName() const
-{
- return m_ui->applicationName->text();
-}
-
-void BarDescriptorEditorEntryPointWidget::setApplicationName(const QString &applicationName)
-{
- setLineEditBlocked(m_ui->applicationName, applicationName);
-}
-
-QString BarDescriptorEditorEntryPointWidget::applicationDescription() const
-{
- return m_ui->applicationDescription->toPlainText();
-}
-
-void BarDescriptorEditorEntryPointWidget::setApplicationDescription(const QString &applicationDescription)
-{
- setTextEditBlocked(m_ui->applicationDescription, applicationDescription);
-}
-
-QString BarDescriptorEditorEntryPointWidget::applicationIconFileName() const
+void BarDescriptorEditorEntryPointWidget::setAssetsModel(QStandardItemModel *assetsModel)
{
- return QFileInfo(m_ui->iconFilePath->path()).fileName();
+ m_assetsModel = QWeakPointer<QStandardItemModel>(assetsModel);
}
-void BarDescriptorEditorEntryPointWidget::setApplicationIcon(const QString &iconPath)
+void BarDescriptorEditorEntryPointWidget::updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value)
{
// During file loading, the assets might not have been read yet
- QMetaObject::invokeMethod(this, "setApplicationIconDelayed", Qt::QueuedConnection, Q_ARG(QString, iconPath));
-}
-
-QStringList BarDescriptorEditorEntryPointWidget::splashScreens() const
-{
- QStringList result;
-
- foreach (const QString &splashScreen, m_splashScreenModel->stringList())
- result << QFileInfo(splashScreen).fileName();
-
- return result;
-}
-
-void BarDescriptorEditorEntryPointWidget::appendSplashScreen(const QString &splashScreenPath)
-{
- QMetaObject::invokeMethod(this, "appendSplashScreenDelayed", Qt::QueuedConnection, Q_ARG(QString, splashScreenPath));
+ if (tag == BarDescriptorDocument::icon) {
+ QMetaObject::invokeMethod(this, "setApplicationIconDelayed", Qt::QueuedConnection, Q_ARG(QString, value.toString()));
+ } else if (tag == BarDescriptorDocument::splashScreens) {
+ QStringList splashScreens = value.toStringList();
+ foreach (const QString &splashScreen, splashScreens)
+ QMetaObject::invokeMethod(this, "appendSplashScreenDelayed", Qt::QueuedConnection, Q_ARG(QString, splashScreen));
+ } else {
+ BarDescriptorEditorAbstractPanelWidget::updateWidgetValue(tag, value);
+ }
}
-void BarDescriptorEditorEntryPointWidget::setAssetsModel(QStandardItemModel *assetsModel)
+void BarDescriptorEditorEntryPointWidget::emitChanged(BarDescriptorDocument::Tag tag)
{
- m_assetsModel = QWeakPointer<QStandardItemModel>(assetsModel);
+ if (tag == BarDescriptorDocument::icon) {
+ emit changed(tag, QFileInfo(m_ui->iconFilePath->path()).fileName());
+ } else if (tag == BarDescriptorDocument::splashScreens) {
+ QStringList list;
+ foreach (const QString &splashScreen, m_splashScreenModel->stringList())
+ list << QFileInfo(splashScreen).fileName();
+
+ emit changed(tag, list);
+ } else {
+ BarDescriptorEditorAbstractPanelWidget::emitChanged(tag);
+ }
}
void BarDescriptorEditorEntryPointWidget::setApplicationIconPreview(const QString &path)
@@ -164,8 +139,8 @@ void BarDescriptorEditorEntryPointWidget::handleIconChanged(const QString &path)
setApplicationIconPreview(path);
validateIconSize(path);
- emit changed();
- emit imageRemoved(m_prevIconPath);
+ if (!m_splashScreenModel->stringList().contains(m_prevIconPath))
+ emit imageRemoved(m_prevIconPath);
m_prevIconPath = path;
if (QFileInfo(path).exists())
@@ -200,7 +175,8 @@ void BarDescriptorEditorEntryPointWidget::removeSelectedSplashScreen()
foreach (const QModelIndex &index, selectedIndexes) {
QString path = m_splashScreenModel->data(index, Qt::DisplayRole).toString();
- emit imageRemoved(path);
+ if (path != m_ui->iconFilePath->path())
+ emit imageRemoved(path);
m_splashScreenModel->removeRow(index.row());
}
@@ -230,11 +206,11 @@ void BarDescriptorEditorEntryPointWidget::appendSplashScreenDelayed(const QStrin
if (fullSplashScreenPath.isEmpty())
return;
- disconnect(m_splashScreenModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
+ blockSignalMapping(BarDescriptorDocument::splashScreens);
int rowCount = m_splashScreenModel->rowCount();
m_splashScreenModel->insertRow(rowCount);
m_splashScreenModel->setData(m_splashScreenModel->index(rowCount), fullSplashScreenPath);
- connect(m_splashScreenModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
+ unblockSignalMapping(BarDescriptorDocument::splashScreens);
}
void BarDescriptorEditorEntryPointWidget::setImagePreview(QLabel *previewLabel, const QString &path)
@@ -309,9 +285,11 @@ void BarDescriptorEditorEntryPointWidget::setApplicationIconDelayed(const QStrin
if (fullIconPath.isEmpty())
return;
- setPathChooserBlocked(m_ui->iconFilePath, fullIconPath);
+ blockSignalMapping(BarDescriptorDocument::icon);
+ m_ui->iconFilePath->setPath(fullIconPath);
setApplicationIconPreview(fullIconPath);
validateIconSize(fullIconPath);
+ unblockSignalMapping(BarDescriptorDocument::icon);
}
QString BarDescriptorEditorEntryPointWidget::localAssetPathFromDestination(const QString &destination)
diff --git a/src/plugins/qnx/bardescriptoreditorentrypointwidget.h b/src/plugins/qnx/bardescriptoreditorentrypointwidget.h
index 22bf825ed1..e0bb894eef 100644
--- a/src/plugins/qnx/bardescriptoreditorentrypointwidget.h
+++ b/src/plugins/qnx/bardescriptoreditorentrypointwidget.h
@@ -57,26 +57,16 @@ public:
explicit BarDescriptorEditorEntryPointWidget(QWidget *parent = 0);
~BarDescriptorEditorEntryPointWidget();
- void clear();
-
- QString applicationName() const;
- void setApplicationName(const QString &applicationName);
-
- QString applicationDescription() const;
- void setApplicationDescription(const QString &applicationDescription);
-
- QString applicationIconFileName() const;
- void setApplicationIcon(const QString &iconPath);
-
- QStringList splashScreens() const;
- void appendSplashScreen(const QString &splashScreenPath);
-
void setAssetsModel(QStandardItemModel *assetsModel);
signals:
void imageAdded(const QString &path);
void imageRemoved(const QString &path);
+protected:
+ void updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value);
+ void emitChanged(BarDescriptorDocument::Tag tag);
+
private slots:
void setApplicationIconDelayed(const QString &iconPath);
void setApplicationIconPreview(const QString &path);
diff --git a/src/plugins/qnx/bardescriptoreditorenvironmentwidget.cpp b/src/plugins/qnx/bardescriptoreditorenvironmentwidget.cpp
index 0f4015e3e1..79ebc6c81c 100644
--- a/src/plugins/qnx/bardescriptoreditorenvironmentwidget.cpp
+++ b/src/plugins/qnx/bardescriptoreditorenvironmentwidget.cpp
@@ -43,7 +43,7 @@ BarDescriptorEditorEnvironmentWidget::BarDescriptorEditorEnvironmentWidget(QWidg
m_ui->environmentWidget->setBaseEnvironmentText(tr("Device Environment"));
- connect(m_ui->environmentWidget, SIGNAL(userChangesChanged()), this, SIGNAL(changed()));
+ addSignalMapping(BarDescriptorDocument::env, m_ui->environmentWidget, SIGNAL(userChangesChanged()));
}
BarDescriptorEditorEnvironmentWidget::~BarDescriptorEditorEnvironmentWidget()
@@ -51,23 +51,24 @@ BarDescriptorEditorEnvironmentWidget::~BarDescriptorEditorEnvironmentWidget()
delete m_ui;
}
-void BarDescriptorEditorEnvironmentWidget::clear()
+void BarDescriptorEditorEnvironmentWidget::updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value)
{
- disconnect(m_ui->environmentWidget, SIGNAL(userChangesChanged()), this, SIGNAL(changed()));
- m_ui->environmentWidget->setUserChanges(QList<Utils::EnvironmentItem>());
- connect(m_ui->environmentWidget, SIGNAL(userChangesChanged()), this, SIGNAL(changed()));
-}
+ if (tag != BarDescriptorDocument::env) {
+ BarDescriptorEditorAbstractPanelWidget::updateWidgetValue(tag, value);
+ return;
+ }
-QList<Utils::EnvironmentItem> BarDescriptorEditorEnvironmentWidget::environment() const
-{
- return m_ui->environmentWidget->userChanges();
+ m_ui->environmentWidget->setUserChanges(value.value<QList<Utils::EnvironmentItem> >());
}
-void BarDescriptorEditorEnvironmentWidget::appendEnvironmentItem(const Utils::EnvironmentItem &envItem)
+void BarDescriptorEditorEnvironmentWidget::emitChanged(BarDescriptorDocument::Tag tag)
{
- disconnect(m_ui->environmentWidget, SIGNAL(userChangesChanged()), this, SIGNAL(changed()));
- QList<Utils::EnvironmentItem> items = m_ui->environmentWidget->userChanges();
- items.append(envItem);
- m_ui->environmentWidget->setUserChanges(items);
- connect(m_ui->environmentWidget, SIGNAL(userChangesChanged()), this, SIGNAL(changed()));
+ if (tag != BarDescriptorDocument::env) {
+ BarDescriptorEditorAbstractPanelWidget::emitChanged(tag);
+ return;
+ }
+
+ QVariant var;
+ var.setValue(m_ui->environmentWidget->userChanges());
+ emit changed(tag, var);
}
diff --git a/src/plugins/qnx/bardescriptoreditorenvironmentwidget.h b/src/plugins/qnx/bardescriptoreditorenvironmentwidget.h
index 88c74a67f7..36d3ca4f39 100644
--- a/src/plugins/qnx/bardescriptoreditorenvironmentwidget.h
+++ b/src/plugins/qnx/bardescriptoreditorenvironmentwidget.h
@@ -51,10 +51,9 @@ public:
explicit BarDescriptorEditorEnvironmentWidget(QWidget *parent = 0);
~BarDescriptorEditorEnvironmentWidget();
- void clear();
-
- QList<Utils::EnvironmentItem> environment() const;
- void appendEnvironmentItem(const Utils::EnvironmentItem &envItem);
+protected:
+ void updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value);
+ void emitChanged(BarDescriptorDocument::Tag tag);
private:
Ui::BarDescriptorEditorEnvironmentWidget *m_ui;
diff --git a/src/plugins/qnx/bardescriptoreditorgeneralwidget.cpp b/src/plugins/qnx/bardescriptoreditorgeneralwidget.cpp
index d8e26120e7..d03133c654 100644
--- a/src/plugins/qnx/bardescriptoreditorgeneralwidget.cpp
+++ b/src/plugins/qnx/bardescriptoreditorgeneralwidget.cpp
@@ -51,10 +51,10 @@ BarDescriptorEditorGeneralWidget::BarDescriptorEditorGeneralWidget(QWidget *pare
m_ui->chrome->addItem(tr("Standard"), QLatin1String("standard"));
m_ui->chrome->addItem(tr("None"), QLatin1String("none"));
- connect(m_ui->orientation, SIGNAL(currentIndexChanged(int)), this, SIGNAL(changed()));
- connect(m_ui->chrome, SIGNAL(currentIndexChanged(int)), this, SIGNAL(changed()));
- connect(m_ui->transparentMainWindow, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
- connect(m_ui->applicationArguments, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
+ addSignalMapping(BarDescriptorDocument::aspectRatio, m_ui->orientation, SIGNAL(currentIndexChanged(int)));
+ addSignalMapping(BarDescriptorDocument::systemChrome, m_ui->chrome, SIGNAL(currentIndexChanged(int)));
+ addSignalMapping(BarDescriptorDocument::transparent, m_ui->transparentMainWindow, SIGNAL(toggled(bool)));
+ addSignalMapping(BarDescriptorDocument::arg, m_ui->applicationArguments, SIGNAL(textChanged(QString)));
}
BarDescriptorEditorGeneralWidget::~BarDescriptorEditorGeneralWidget()
@@ -62,62 +62,41 @@ BarDescriptorEditorGeneralWidget::~BarDescriptorEditorGeneralWidget()
delete m_ui;
}
-void BarDescriptorEditorGeneralWidget::clear()
+void BarDescriptorEditorGeneralWidget::updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value)
{
- setComboBoxBlocked(m_ui->orientation, m_ui->orientation->findData(QLatin1String("")));
- setComboBoxBlocked(m_ui->chrome, m_ui->chrome->findData(QLatin1String("none")));
- setCheckBoxBlocked(m_ui->transparentMainWindow, false);
- setLineEditBlocked(m_ui->applicationArguments, QString());
+ if (tag == BarDescriptorDocument::aspectRatio) {
+ m_ui->orientation->setCurrentIndex(m_ui->orientation->findData(value));
+ } else if (tag == BarDescriptorDocument::autoOrients) {
+ if (value.toString() == QLatin1String("true")) {
+ blockSignalMapping(BarDescriptorDocument::aspectRatio);
+ m_ui->orientation->setCurrentIndex(m_ui->orientation->findData(QLatin1String("auto-orient")));
+ unblockSignalMapping(BarDescriptorDocument::aspectRatio);
+ }
+ } else if (tag == BarDescriptorDocument::arg) {
+ m_ui->applicationArguments->setText(value.toStringList().join(QLatin1String(" ")));
+ } else {
+ BarDescriptorEditorAbstractPanelWidget::updateWidgetValue(tag, value);
+ }
}
-QString BarDescriptorEditorGeneralWidget::orientation() const
+void BarDescriptorEditorGeneralWidget::emitChanged(BarDescriptorDocument::Tag tag)
{
- return m_ui->orientation->itemData(m_ui->orientation->currentIndex()).toString();
-}
-
-void BarDescriptorEditorGeneralWidget::setOrientation(const QString &orientation)
-{
- int index = m_ui->orientation->findData(orientation);
- QTC_ASSERT(index >= 0, return);
-
- setComboBoxBlocked(m_ui->orientation, index);
-}
-
-QString BarDescriptorEditorGeneralWidget::chrome() const
-{
- return m_ui->chrome->itemData(m_ui->chrome->currentIndex()).toString();
-}
-
-void BarDescriptorEditorGeneralWidget::setChrome(const QString &chrome)
-{
- int index = m_ui->chrome->findData(chrome);
- QTC_ASSERT(index >= 0, return);
-
- setComboBoxBlocked(m_ui->chrome, index);
-}
-
-bool BarDescriptorEditorGeneralWidget::transparent() const
-{
- return m_ui->transparentMainWindow->isChecked();
-}
-
-void BarDescriptorEditorGeneralWidget::setTransparent(bool transparent)
-{
- setCheckBoxBlocked(m_ui->transparentMainWindow, transparent);
-}
-
-void BarDescriptorEditorGeneralWidget::appendApplicationArgument(const QString &argument)
-{
- QString completeArguments = m_ui->applicationArguments->text();
- if (!completeArguments.isEmpty())
- completeArguments.append(QLatin1Char(' '));
- completeArguments.append(argument);
-
- setLineEditBlocked(m_ui->applicationArguments, completeArguments);
-}
-
-QStringList BarDescriptorEditorGeneralWidget::applicationArguments() const
-{
- // TODO: Should probably handle "argument with spaces within quotes"
- return m_ui->applicationArguments->text().split(QLatin1Char(' '));
+ if (tag == BarDescriptorDocument::aspectRatio) {
+ QString value = m_ui->orientation->itemData(m_ui->orientation->currentIndex()).toString();
+ if (value == QLatin1String("auto-orient")) {
+ emit changed(BarDescriptorDocument::aspectRatio, QLatin1String(""));
+ emit changed(BarDescriptorDocument::autoOrients, QLatin1String("true"));
+ return;
+ } else if (!value.isEmpty()) {
+ emit changed(BarDescriptorDocument::aspectRatio, value);
+ emit changed(BarDescriptorDocument::autoOrients, QLatin1String("false"));
+ } else {
+ emit changed(BarDescriptorDocument::aspectRatio, value);
+ emit changed(BarDescriptorDocument::autoOrients, QLatin1String(""));
+ }
+ } else if (tag == BarDescriptorDocument::arg) {
+ emit changed(tag, m_ui->applicationArguments->text().split(QLatin1Char(' ')));
+ } else {
+ BarDescriptorEditorAbstractPanelWidget::emitChanged(tag);
+ }
}
diff --git a/src/plugins/qnx/bardescriptoreditorgeneralwidget.h b/src/plugins/qnx/bardescriptoreditorgeneralwidget.h
index b5926f1993..1941ca469e 100644
--- a/src/plugins/qnx/bardescriptoreditorgeneralwidget.h
+++ b/src/plugins/qnx/bardescriptoreditorgeneralwidget.h
@@ -49,19 +49,9 @@ public:
explicit BarDescriptorEditorGeneralWidget(QWidget *parent = 0);
~BarDescriptorEditorGeneralWidget();
- void clear();
-
- QString orientation() const;
- void setOrientation(const QString &orientation);
-
- QString chrome() const;
- void setChrome(const QString &chrome);
-
- bool transparent() const;
- void setTransparent(bool transparent);
-
- void appendApplicationArgument(const QString &argument);
- QStringList applicationArguments() const;
+protected:
+ void updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value);
+ void emitChanged(BarDescriptorDocument::Tag tag);
private:
Ui::BarDescriptorEditorGeneralWidget *m_ui;
diff --git a/src/plugins/qnx/bardescriptoreditorpackageinformationwidget.cpp b/src/plugins/qnx/bardescriptoreditorpackageinformationwidget.cpp
index bc6b848b8d..d9e6c3d4cf 100644
--- a/src/plugins/qnx/bardescriptoreditorpackageinformationwidget.cpp
+++ b/src/plugins/qnx/bardescriptoreditorpackageinformationwidget.cpp
@@ -45,55 +45,12 @@ BarDescriptorEditorPackageInformationWidget::BarDescriptorEditorPackageInformati
QRegExpValidator *versionNumberValidator = new QRegExpValidator(versionNumberRegExp, this);
m_ui->packageVersion->setValidator(versionNumberValidator);
- connect(m_ui->packageId, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
- connect(m_ui->packageVersion, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
- connect(m_ui->packageBuildId, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
+ addSignalMapping(BarDescriptorDocument::id, m_ui->packageId, SIGNAL(textChanged(QString)));
+ addSignalMapping(BarDescriptorDocument::versionNumber, m_ui->packageVersion, SIGNAL(textChanged(QString)));
+ addSignalMapping(BarDescriptorDocument::buildId, m_ui->packageBuildId, SIGNAL(textChanged(QString)));
}
BarDescriptorEditorPackageInformationWidget::~BarDescriptorEditorPackageInformationWidget()
{
delete m_ui;
}
-
-void BarDescriptorEditorPackageInformationWidget::clear()
-{
- setLineEditBlocked(m_ui->packageId, QString());
- setLineEditBlocked(m_ui->packageVersion, QString());
- setLineEditBlocked(m_ui->packageBuildId, QString());
-}
-
-QString BarDescriptorEditorPackageInformationWidget::packageId() const
-{
- return m_ui->packageId->text();
-}
-
-void BarDescriptorEditorPackageInformationWidget::setPackageId(const QString &packageId)
-{
- setLineEditBlocked(m_ui->packageId, packageId);
-}
-
-QString BarDescriptorEditorPackageInformationWidget::packageVersion() const
-{
- QString version = m_ui->packageVersion->text();
- int pos = 0;
- if (m_ui->packageVersion->validator()->validate(version, pos) == QValidator::Intermediate) {
- if (version.endsWith(QLatin1Char('.')))
- version = version.left(version.size() - 1);
- }
- return version;
-}
-
-void BarDescriptorEditorPackageInformationWidget::setPackageVersion(const QString &packageVersion)
-{
- setLineEditBlocked(m_ui->packageVersion, packageVersion);
-}
-
-QString BarDescriptorEditorPackageInformationWidget::packageBuildId() const
-{
- return m_ui->packageBuildId->text();
-}
-
-void BarDescriptorEditorPackageInformationWidget::setPackageBuildId(const QString &packageBuildId)
-{
- setLineEditBlocked(m_ui->packageBuildId, packageBuildId);
-}
diff --git a/src/plugins/qnx/bardescriptoreditorpackageinformationwidget.h b/src/plugins/qnx/bardescriptoreditorpackageinformationwidget.h
index b5e192594d..6a46496405 100644
--- a/src/plugins/qnx/bardescriptoreditorpackageinformationwidget.h
+++ b/src/plugins/qnx/bardescriptoreditorpackageinformationwidget.h
@@ -49,17 +49,6 @@ public:
explicit BarDescriptorEditorPackageInformationWidget(QWidget *parent = 0);
~BarDescriptorEditorPackageInformationWidget();
- void clear();
-
- QString packageId() const;
- void setPackageId(const QString &packageId);
-
- QString packageVersion() const;
- void setPackageVersion(const QString &packageVersion);
-
- QString packageBuildId() const;
- void setPackageBuildId(const QString &packageBuildId);
-
private:
Ui::BarDescriptorEditorPackageInformationWidget *m_ui;
};
diff --git a/src/plugins/qnx/bardescriptoreditorpermissionswidget.cpp b/src/plugins/qnx/bardescriptoreditorpermissionswidget.cpp
index f49c4291ac..8789675ccb 100644
--- a/src/plugins/qnx/bardescriptoreditorpermissionswidget.cpp
+++ b/src/plugins/qnx/bardescriptoreditorpermissionswidget.cpp
@@ -48,7 +48,8 @@ BarDescriptorEditorPermissionsWidget::BarDescriptorEditorPermissionsWidget(QWidg
connect(m_ui->selectAllPermissions, SIGNAL(clicked()), m_permissionsModel, SLOT(checkAll()));
connect(m_ui->deselectAllPermissions, SIGNAL(clicked()), m_permissionsModel, SLOT(uncheckAll()));
- connect(m_permissionsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
+
+ addSignalMapping(BarDescriptorDocument::action, m_permissionsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
}
BarDescriptorEditorPermissionsWidget::~BarDescriptorEditorPermissionsWidget()
@@ -56,13 +57,6 @@ BarDescriptorEditorPermissionsWidget::~BarDescriptorEditorPermissionsWidget()
delete m_ui;
}
-void BarDescriptorEditorPermissionsWidget::clear()
-{
- disconnect(m_permissionsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
- m_permissionsModel->uncheckAll();
- connect(m_permissionsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
-}
-
QStringList BarDescriptorEditorPermissionsWidget::checkedPermissions() const
{
return m_permissionsModel->checkedIdentifiers();
@@ -70,7 +64,29 @@ QStringList BarDescriptorEditorPermissionsWidget::checkedPermissions() const
void BarDescriptorEditorPermissionsWidget::checkPermission(const QString &identifier)
{
- disconnect(m_permissionsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
+ blockSignalMapping(BarDescriptorDocument::action);
m_permissionsModel->checkPermission(identifier);
- connect(m_permissionsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
+ unblockSignalMapping(BarDescriptorDocument::action);
+}
+
+void BarDescriptorEditorPermissionsWidget::updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value)
+{
+ if (tag != BarDescriptorDocument::action) {
+ BarDescriptorEditorAbstractPanelWidget::updateWidgetValue(tag, value);
+ return;
+ }
+
+ QStringList permissions = value.toStringList();
+ Q_FOREACH (const QString &permission, permissions)
+ checkPermission(permission);
+}
+
+void BarDescriptorEditorPermissionsWidget::emitChanged(BarDescriptorDocument::Tag tag)
+{
+ if (tag != BarDescriptorDocument::action) {
+ BarDescriptorEditorAbstractPanelWidget::emitChanged(tag);
+ return;
+ }
+
+ emit changed(tag, checkedPermissions());
}
diff --git a/src/plugins/qnx/bardescriptoreditorpermissionswidget.h b/src/plugins/qnx/bardescriptoreditorpermissionswidget.h
index f2519904a7..5ee81abdb1 100644
--- a/src/plugins/qnx/bardescriptoreditorpermissionswidget.h
+++ b/src/plugins/qnx/bardescriptoreditorpermissionswidget.h
@@ -51,12 +51,14 @@ public:
explicit BarDescriptorEditorPermissionsWidget(QWidget *parent = 0);
~BarDescriptorEditorPermissionsWidget();
- void clear();
+protected:
+ void updateWidgetValue(BarDescriptorDocument::Tag tag, const QVariant &value);
+ void emitChanged(BarDescriptorDocument::Tag tag);
+private:
QStringList checkedPermissions() const;
void checkPermission(const QString &identifier);
-private:
Ui::BarDescriptorEditorPermissionsWidget *m_ui;
BarDescriptorPermissionsModel *m_permissionsModel;
diff --git a/src/plugins/qnx/bardescriptoreditorwidget.cpp b/src/plugins/qnx/bardescriptoreditorwidget.cpp
index 8a00efa22a..af1238e6ce 100644
--- a/src/plugins/qnx/bardescriptoreditorwidget.cpp
+++ b/src/plugins/qnx/bardescriptoreditorwidget.cpp
@@ -44,9 +44,12 @@
#include <coreplugin/icore.h>
#include <projectexplorer/iprojectproperties.h>
#include <projectexplorer/projectwindow.h>
+#include <projectexplorer/task.h>
+#include <projectexplorer/taskhub.h>
#include <texteditor/plaintexteditor.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/texteditorconstants.h>
+#include <utils/qtcassert.h>
using namespace Qnx;
using namespace Qnx::Internal;
@@ -54,7 +57,6 @@ using namespace Qnx::Internal;
BarDescriptorEditorWidget::BarDescriptorEditorWidget(BarDescriptorEditor *editor, QWidget *parent)
: QStackedWidget(parent)
, m_editor(editor)
- , m_dirty(false)
{
Core::IContext *myContext = new Core::IContext(this);
myContext->setWidget(this);
@@ -67,6 +69,25 @@ BarDescriptorEditorWidget::BarDescriptorEditorWidget(BarDescriptorEditor *editor
initSourcePage();
setCurrentIndex(0);
+
+ connect(m_entryPointWidget, SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+ connect(m_packageInformationWidget, SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+ connect(m_authorInformationWidget, SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+ connect(m_generalWidget, SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+ connect(m_permissionsWidget, SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+ connect(m_environmentWidget, SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+ connect(m_assetsWidget, SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), barDescriptorDocument(), SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+
+ connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_entryPointWidget, SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+ connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_packageInformationWidget, SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+ connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_authorInformationWidget, SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+ connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_generalWidget, SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+ connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_permissionsWidget, SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+ connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_environmentWidget, SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+ connect(barDescriptorDocument(), SIGNAL(changed(BarDescriptorDocument::Tag,QVariant)), m_assetsWidget, SLOT(setValue(BarDescriptorDocument::Tag,QVariant)));
+
+ connect(m_xmlSourceWidget, SIGNAL(textChanged()), this, SLOT(updateDocumentContent()));
+ connect(barDescriptorDocument(), SIGNAL(changed()), this, SLOT(updateSourceView()));
}
void BarDescriptorEditorWidget::initGeneralPage()
@@ -95,10 +116,6 @@ void BarDescriptorEditorWidget::initGeneralPage()
authorInformationPanel->setDisplayName(tr("Author Information"));
authorInformationPanel->setWidget(m_authorInformationWidget);
generalPanel->addPropertiesPanel(authorInformationPanel);
-
- connect(m_entryPointWidget, SIGNAL(changed()), this, SLOT(setDirty()));
- connect(m_packageInformationWidget, SIGNAL(changed()), this, SLOT(setDirty()));
- connect(m_authorInformationWidget, SIGNAL(changed()), this, SLOT(setDirty()));
}
void BarDescriptorEditorWidget::initApplicationPage()
@@ -127,10 +144,6 @@ void BarDescriptorEditorWidget::initApplicationPage()
environmentPanel->setDisplayName(tr("Environment"));
environmentPanel->setWidget(m_environmentWidget);
applicationPanel->addPropertiesPanel(environmentPanel);
-
- connect(m_generalWidget, SIGNAL(changed()), this, SLOT(setDirty()));
- connect(m_permissionsWidget, SIGNAL(changed()), this, SLOT(setDirty()));
- connect(m_environmentWidget, SIGNAL(changed()), this, SLOT(setDirty()));
}
void BarDescriptorEditorWidget::initAssetsPage()
@@ -145,8 +158,6 @@ void BarDescriptorEditorWidget::initAssetsPage()
assetsPropertiesPanel->setWidget(m_assetsWidget);
assetsPanel->addPropertiesPanel(assetsPropertiesPanel);
- connect(m_assetsWidget, SIGNAL(changed()), this, SLOT(setDirty()));
-
m_entryPointWidget->setAssetsModel(m_assetsWidget->assetsModel());
connect(m_entryPointWidget, SIGNAL(imageAdded(QString)), m_assetsWidget, SLOT(addAsset(QString)));
connect(m_entryPointWidget, SIGNAL(imageRemoved(QString)), m_assetsWidget, SLOT(removeAsset(QString)));
@@ -159,7 +170,6 @@ void BarDescriptorEditorWidget::initSourcePage()
TextEditor::TextEditorSettings::initializeEditor(m_xmlSourceWidget);
m_xmlSourceWidget->configure(QLatin1String(Constants::QNX_BAR_DESCRIPTOR_MIME_TYPE));
- connect(m_xmlSourceWidget, SIGNAL(textChanged()), this, SLOT(setDirty()));
}
void BarDescriptorEditorWidget::initPanelSize(ProjectExplorer::PanelsWidget *panelsWidget)
@@ -168,46 +178,6 @@ void BarDescriptorEditorWidget::initPanelSize(ProjectExplorer::PanelsWidget *pan
panelsWidget->widget()->setMinimumWidth(0);
}
-Core::IEditor *BarDescriptorEditorWidget::editor() const
-{
- return m_editor;
-}
-
-BarDescriptorEditorPackageInformationWidget *BarDescriptorEditorWidget::packageInformationWidget() const
-{
- return m_packageInformationWidget;
-}
-
-BarDescriptorEditorAuthorInformationWidget *BarDescriptorEditorWidget::authorInformationWidget() const
-{
- return m_authorInformationWidget;
-}
-
-BarDescriptorEditorEntryPointWidget *BarDescriptorEditorWidget::entryPointWidget() const
-{
- return m_entryPointWidget;
-}
-
-BarDescriptorEditorGeneralWidget *BarDescriptorEditorWidget::generalWidget() const
-{
- return m_generalWidget;
-}
-
-BarDescriptorEditorPermissionsWidget *BarDescriptorEditorWidget::permissionsWidget() const
-{
- return m_permissionsWidget;
-}
-
-BarDescriptorEditorEnvironmentWidget *BarDescriptorEditorWidget::environmentWidget() const
-{
- return m_environmentWidget;
-}
-
-BarDescriptorEditorAssetsWidget *BarDescriptorEditorWidget::assetsWidget() const
-{
- return m_assetsWidget;
-}
-
TextEditor::BaseTextEditorWidget *BarDescriptorEditorWidget::sourceWidget() const
{
return m_xmlSourceWidget;
@@ -216,51 +186,44 @@ TextEditor::BaseTextEditorWidget *BarDescriptorEditorWidget::sourceWidget() cons
void BarDescriptorEditorWidget::setFilePath(const QString &filePath)
{
Core::IDocument *doc = m_xmlSourceWidget->baseTextDocument();
- if (doc) {
+ if (doc)
doc->setFilePath(filePath);
- // setFilePath() call leads to a textChanged() signal emitted
- // and therefore having this editor-widget to become dirty
- // therefore we have to explicitly unset the dirty flag
- setDirty(false);
- }
}
-QString BarDescriptorEditorWidget::xmlSource() const
+void BarDescriptorEditorWidget::updateDocumentContent()
{
- return m_xmlSourceWidget->toPlainText();
-}
+ ProjectExplorer::TaskHub::clearTasks(Constants::QNX_TASK_CATEGORY_BARDESCRIPTOR);
+ QString errorMsg;
+ int errorLine;
-void BarDescriptorEditorWidget::setXmlSource(const QString &xmlSource)
-{
- bool blocked = m_xmlSourceWidget->blockSignals(true);
- m_xmlSourceWidget->setPlainText(xmlSource);
- m_xmlSourceWidget->blockSignals(blocked);
-}
+ disconnect(barDescriptorDocument(), SIGNAL(changed()), this, SLOT(updateSourceView()));
+ bool result = barDescriptorDocument()->loadContent(m_xmlSourceWidget->toPlainText(), true, &errorMsg, &errorLine);
+ connect(barDescriptorDocument(), SIGNAL(changed()), this, SLOT(updateSourceView()));
-bool BarDescriptorEditorWidget::isDirty() const
-{
- return m_dirty;
+ if (!result) {
+ ProjectExplorer::TaskHub::addTask(ProjectExplorer::Task::Error, errorMsg, Constants::QNX_TASK_CATEGORY_BARDESCRIPTOR,
+ Utils::FileName::fromString(barDescriptorDocument()->filePath()), errorLine);
+ ProjectExplorer::TaskHub::requestPopup();
+ }
}
-void BarDescriptorEditorWidget::clear()
+void BarDescriptorEditorWidget::updateSourceView()
{
- m_entryPointWidget->clear();
- m_packageInformationWidget->clear();
- m_authorInformationWidget->clear();
+ bool blocked = m_xmlSourceWidget->blockSignals(true);
- m_generalWidget->clear();
- m_permissionsWidget->clear();
- m_environmentWidget->clear();
+ int line;
+ int column;
+ int position = m_xmlSourceWidget->position();
+ m_xmlSourceWidget->convertPosition(position, &line, &column);
- m_assetsWidget->clear();
+ m_xmlSourceWidget->setPlainText(barDescriptorDocument()->xmlSource());
+
+ m_xmlSourceWidget->gotoLine(line, column);
- bool blocked = m_xmlSourceWidget->blockSignals(true);
- m_xmlSourceWidget->clear();
m_xmlSourceWidget->blockSignals(blocked);
}
-void BarDescriptorEditorWidget::setDirty(bool dirty)
+BarDescriptorDocument *BarDescriptorEditorWidget::barDescriptorDocument() const
{
- m_dirty = dirty;
- emit changed();
+ return qobject_cast<BarDescriptorDocument*>(m_editor->document());
}
diff --git a/src/plugins/qnx/bardescriptoreditorwidget.h b/src/plugins/qnx/bardescriptoreditorwidget.h
index 256546de83..1c67cb11cd 100644
--- a/src/plugins/qnx/bardescriptoreditorwidget.h
+++ b/src/plugins/qnx/bardescriptoreditorwidget.h
@@ -68,34 +68,20 @@ class BarDescriptorEditorWidget : public QStackedWidget
public:
explicit BarDescriptorEditorWidget(BarDescriptorEditor *editor, QWidget *parent = 0);
- Core::IEditor *editor() const;
-
- BarDescriptorEditorEntryPointWidget *entryPointWidget() const;
- BarDescriptorEditorPackageInformationWidget *packageInformationWidget() const;
- BarDescriptorEditorAuthorInformationWidget *authorInformationWidget() const;
-
- BarDescriptorEditorGeneralWidget *generalWidget() const;
- BarDescriptorEditorPermissionsWidget *permissionsWidget() const;
- BarDescriptorEditorEnvironmentWidget *environmentWidget() const;
-
- BarDescriptorEditorAssetsWidget *assetsWidget() const;
-
TextEditor::BaseTextEditorWidget *sourceWidget() const;
void setFilePath(const QString &filePath);
- QString xmlSource() const;
- void setXmlSource(const QString &xmlSource);
-
- bool isDirty() const;
- void clear();
-
-public slots:
- void setDirty(bool dirty = true);
signals:
- void changed();
+ void changed(BarDescriptorDocument::Tag tag, const QVariant &value);
+
+private slots:
+ void updateDocumentContent();
+ void updateSourceView();
private:
+ BarDescriptorDocument *barDescriptorDocument() const;
+
void initGeneralPage();
void initApplicationPage();
void initAssetsPage();
@@ -104,8 +90,6 @@ private:
Core::IEditor *m_editor;
- bool m_dirty;
-
// New UI
BarDescriptorEditorEntryPointWidget *m_entryPointWidget;
BarDescriptorEditorPackageInformationWidget *m_packageInformationWidget;
diff --git a/src/plugins/qnx/qnx.pro b/src/plugins/qnx/qnx.pro
index cfe15336c9..2d8d14afc9 100644
--- a/src/plugins/qnx/qnx.pro
+++ b/src/plugins/qnx/qnx.pro
@@ -57,7 +57,6 @@ SOURCES += qnxplugin.cpp \
bardescriptoreditor.cpp \
bardescriptoreditorwidget.cpp \
bardescriptordocument.cpp \
- bardescriptordocumentnodehandlers.cpp \
bardescriptorpermissionsmodel.cpp \
blackberrykeyswidget.cpp \
blackberrykeyspage.cpp \
@@ -156,7 +155,6 @@ HEADERS += qnxplugin.h\
bardescriptoreditor.h \
bardescriptoreditorwidget.h \
bardescriptordocument.h \
- bardescriptordocumentnodehandlers.h \
bardescriptorpermissionsmodel.h \
blackberrykeyswidget.h \
blackberrykeyspage.h \
diff --git a/src/plugins/qnx/qnx.qbs b/src/plugins/qnx/qnx.qbs
index a741da4e1f..8ee5a8414c 100644
--- a/src/plugins/qnx/qnx.qbs
+++ b/src/plugins/qnx/qnx.qbs
@@ -20,8 +20,6 @@ QtcPlugin {
files: [
"bardescriptordocument.cpp",
"bardescriptordocument.h",
- "bardescriptordocumentnodehandlers.cpp",
- "bardescriptordocumentnodehandlers.h",
"bardescriptoreditor.cpp",
"bardescriptoreditor.h",
"bardescriptoreditorabstractpanelwidget.cpp",
diff --git a/src/plugins/qnx/qnxplugin.cpp b/src/plugins/qnx/qnxplugin.cpp
index 8d0297d011..465086da8f 100644
--- a/src/plugins/qnx/qnxplugin.cpp
+++ b/src/plugins/qnx/qnxplugin.cpp
@@ -136,4 +136,201 @@ ExtensionSystem::IPlugin::ShutdownFlag QNXPlugin::aboutToShutdown()
return SynchronousShutdown;
}
+#ifdef WITH_TESTS
+#include <QTest>
+
+#include "bardescriptordocument.h"
+
+void QNXPlugin::testBarDescriptorDocumentSetValue_data()
+{
+ QTest::addColumn<BarDescriptorDocument::Tag>("tag");
+ QTest::addColumn<QVariant>("value");
+ QTest::addColumn<QString>("baseXml");
+ QTest::addColumn<QString>("xml");
+ QTest::addColumn<bool>("compareResultValue");
+
+ QTest::newRow("new-id") << BarDescriptorDocument::id
+ << QVariant(QString::fromLatin1("my-application-id"))
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\"/>\n")
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <id>my-application-id</id>\n"
+ "</qnx>\n")
+ << true;
+
+ QTest::newRow("changed-id") << BarDescriptorDocument::id
+ << QVariant(QString::fromLatin1("my-application-id"))
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <id>some-application-id</id>\n"
+ "</qnx>\n")
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <id>my-application-id</id>\n"
+ "</qnx>\n")
+ << true;
+
+
+ QTest::newRow("removed-id") << BarDescriptorDocument::id
+ << QVariant(QString::fromLatin1(""))
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <id>some-application-id</id>\n"
+ "</qnx>\n")
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\"/>\n")
+ << true;
+
+ QStringList splashScreens;
+ splashScreens << QLatin1String("image1.png")
+ << QLatin1String("image2.png");
+ QTest::newRow("new-splashScreens") << BarDescriptorDocument::splashScreens
+ << QVariant(splashScreens)
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\"/>\n")
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <splashScreens>\n"
+ " <image>image1.png</image>\n"
+ " <image>image2.png</image>\n"
+ " </splashScreens>\n"
+ "</qnx>\n")
+ << true;
+
+ QTest::newRow("changed-splashScreens") << BarDescriptorDocument::splashScreens
+ << QVariant(splashScreens)
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <splashScreens>\n"
+ " <image>image3.png</image>\n"
+ " <image>image4.png</image>\n"
+ " </splashScreens>\n"
+ "</qnx>\n")
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <splashScreens>\n"
+ " <image>image1.png</image>\n"
+ " <image>image2.png</image>\n"
+ " </splashScreens>\n"
+ "</qnx>\n")
+ << true;
+
+ QTest::newRow("removed-splashScreens") << BarDescriptorDocument::splashScreens
+ << QVariant(QStringList())
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <splashScreens>\n"
+ " <image>image1.png</image>\n"
+ " <image>image2.png</image>\n"
+ " </splashScreens>\n"
+ "</qnx>\n")
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\"/>\n")
+ << true;
+
+ BarDescriptorAsset asset1;
+ asset1.source = QLatin1String("/path/to/file");
+ asset1.destination = QLatin1String("file");
+ asset1.entry = false;
+
+ BarDescriptorAsset asset2;
+ asset2.source = QLatin1String("/path/to/file2");
+ asset2.destination = QLatin1String("file2");
+ asset2.entry = false; // Cannot test "true", as "type" and "entry" attributes show up in seemingly arbitrary order
+
+ BarDescriptorAssetList assetList1;
+ assetList1 << asset1 << asset2;
+
+ QVariant assets;
+ assets.setValue(assetList1);
+
+ QTest::newRow("new-assets") << BarDescriptorDocument::asset
+ << assets
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\"/>\n")
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <asset path=\"/path/to/file\">file</asset>\n"
+ " <asset path=\"/path/to/file2\">file2</asset>\n"
+ "</qnx>\n")
+ << false;
+
+ asset2.destination = QLatin1String("file3");
+ BarDescriptorAssetList assetList2;
+ assetList2 << asset1 << asset2;
+ assets.setValue(assetList2);
+
+ QTest::newRow("changed-assets") << BarDescriptorDocument::asset
+ << assets
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <asset path=\"/path/to/file\">file</asset>\n"
+ " <asset path=\"/path/to/file2\">file2</asset>\n"
+ "</qnx>\n")
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <asset path=\"/path/to/file\">file</asset>\n"
+ " <asset path=\"/path/to/file2\">file3</asset>\n"
+ "</qnx>\n")
+ << false;
+
+ QTest::newRow("maintain-position") << BarDescriptorDocument::id
+ << QVariant(QString::fromLatin1("my-application-id"))
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <asset path=\"/path/to/file\">file</asset>\n"
+ " <asset path=\"/path/to/file2\">file2</asset>\n"
+ " <id>some-application-id</id>\n"
+ " <splashScreens>\n"
+ " <image>image1.png</image>\n"
+ " <image>image2.png</image>\n"
+ " </splashScreens>\n"
+ "</qnx>\n")
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <asset path=\"/path/to/file\">file</asset>\n"
+ " <asset path=\"/path/to/file2\">file2</asset>\n"
+ " <id>my-application-id</id>\n"
+ " <splashScreens>\n"
+ " <image>image1.png</image>\n"
+ " <image>image2.png</image>\n"
+ " </splashScreens>\n"
+ "</qnx>\n")
+ << true;
+
+ QTest::newRow("removed-icon") << BarDescriptorDocument::icon
+ << QVariant(QString())
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
+ " <icon>\n"
+ " <image>icon1.png</image>\n"
+ " </icon>\n"
+ "</qnx>\n")
+ << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
+ "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\"/>\n")
+ << true;
+}
+
+void QNXPlugin::testBarDescriptorDocumentSetValue()
+{
+ QFETCH(BarDescriptorDocument::Tag, tag);
+ QFETCH(QVariant, value);
+ QFETCH(QString, baseXml);
+ QFETCH(QString, xml);
+ QFETCH(bool, compareResultValue);
+
+ BarDescriptorDocument doc;
+ doc.loadContent(baseXml, false);
+ QCOMPARE(doc.xmlSource(), baseXml);
+
+ doc.setValue(tag, value);
+ QCOMPARE(doc.xmlSource(), xml);
+ QCOMPARE(doc.isModified(), true);
+ if (compareResultValue)
+ QCOMPARE(doc.value(tag), value);
+}
+
+#endif
+
Q_EXPORT_PLUGIN2(QNX, QNXPlugin)
diff --git a/src/plugins/qnx/qnxplugin.h b/src/plugins/qnx/qnxplugin.h
index bebb92e1e0..9286464c8c 100644
--- a/src/plugins/qnx/qnxplugin.h
+++ b/src/plugins/qnx/qnxplugin.h
@@ -49,6 +49,12 @@ public:
bool initialize(const QStringList &arguments, QString *errorString);
void extensionsInitialized();
ShutdownFlag aboutToShutdown();
+
+#ifdef WITH_TESTS
+private slots:
+ void testBarDescriptorDocumentSetValue_data();
+ void testBarDescriptorDocumentSetValue();
+#endif
};
} // namespace Internal