forked from qt-creator/qt-creator
Add some exception handling to the style merger
Catches some of the model exceptions that may occur when processing the merge and just prints out some debug information. Task-number: QDS-2071 Change-Id: I6303c2ac1b9373f7d594aaf811e99cb4badf36ad Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -26,6 +26,9 @@
|
|||||||
|
|
||||||
#include <abstractview.h>
|
#include <abstractview.h>
|
||||||
#include <bindingproperty.h>
|
#include <bindingproperty.h>
|
||||||
|
#include <invalididexception.h>
|
||||||
|
#include <invalidmodelnodeexception.h>
|
||||||
|
#include <invalidreparentingexception.h>
|
||||||
#include <modelmerger.h>
|
#include <modelmerger.h>
|
||||||
#include <nodeabstractproperty.h>
|
#include <nodeabstractproperty.h>
|
||||||
#include <nodelistproperty.h>
|
#include <nodelistproperty.h>
|
||||||
@@ -194,6 +197,8 @@ QPoint parentPosition(const ModelNode &node)
|
|||||||
|
|
||||||
void StylesheetMerger::preprocessStyleSheet()
|
void StylesheetMerger::preprocessStyleSheet()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
RewriterTransaction transaction(m_styleView, "preprocess-stylesheet");
|
||||||
for (ModelNode currentStyleNode : m_styleView->rootModelNode().directSubModelNodes()) {
|
for (ModelNode currentStyleNode : m_styleView->rootModelNode().directSubModelNodes()) {
|
||||||
QString id = currentStyleNode.id();
|
QString id = currentStyleNode.id();
|
||||||
|
|
||||||
@@ -233,6 +238,21 @@ void StylesheetMerger::preprocessStyleSheet()
|
|||||||
if (templateParentIndex >= 0 && styleParentIndex != templateParentIndex)
|
if (templateParentIndex >= 0 && styleParentIndex != templateParentIndex)
|
||||||
newParentProperty.slide(styleParentIndex, templateParentIndex);
|
newParentProperty.slide(styleParentIndex, templateParentIndex);
|
||||||
}
|
}
|
||||||
|
transaction.commit();
|
||||||
|
}catch (InvalidIdException &ide) {
|
||||||
|
qDebug().noquote() << "Invalid id exception while preprocessing the style sheet.";
|
||||||
|
ide.createWarning();
|
||||||
|
} catch (InvalidReparentingException &rpe) {
|
||||||
|
qDebug().noquote() << "Invalid reparenting exception while preprocessing the style sheet.";
|
||||||
|
rpe.createWarning();
|
||||||
|
} catch (InvalidModelNodeException &mne) {
|
||||||
|
qDebug().noquote() << "Invalid model node exception while preprocessing the style sheet.";
|
||||||
|
mne.createWarning();
|
||||||
|
} catch (Exception &e) {
|
||||||
|
qDebug().noquote() << "Exception while preprocessing the style sheet.";
|
||||||
|
e.createWarning();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StylesheetMerger::replaceNode(ModelNode &replacedNode, ModelNode &newNode)
|
void StylesheetMerger::replaceNode(ModelNode &replacedNode, ModelNode &newNode)
|
||||||
@@ -269,6 +289,8 @@ void StylesheetMerger::replaceNode(ModelNode &replacedNode, ModelNode &newNode)
|
|||||||
|
|
||||||
void StylesheetMerger::replaceRootNode(ModelNode& templateRootNode)
|
void StylesheetMerger::replaceRootNode(ModelNode& templateRootNode)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
RewriterTransaction transaction(m_templateView, "replace-root-node");
|
||||||
ModelMerger merger(m_templateView);
|
ModelMerger merger(m_templateView);
|
||||||
QString rootId = templateRootNode.id();
|
QString rootId = templateRootNode.id();
|
||||||
// If we shall replace the root node of the template with the style,
|
// If we shall replace the root node of the template with the style,
|
||||||
@@ -279,6 +301,20 @@ void StylesheetMerger::replaceRootNode(ModelNode& templateRootNode)
|
|||||||
// Then reset the id to the old root's one.
|
// Then reset the id to the old root's one.
|
||||||
ModelNode newRoot = m_templateView->rootModelNode();
|
ModelNode newRoot = m_templateView->rootModelNode();
|
||||||
newRoot.setIdWithoutRefactoring(rootId);
|
newRoot.setIdWithoutRefactoring(rootId);
|
||||||
|
transaction.commit();
|
||||||
|
} catch (InvalidIdException &ide) {
|
||||||
|
qDebug().noquote() << "Invalid id exception while replacing root node of template.";
|
||||||
|
ide.createWarning();
|
||||||
|
} catch (InvalidReparentingException &rpe) {
|
||||||
|
qDebug().noquote() << "Invalid reparenting exception while replacing root node of template.";
|
||||||
|
rpe.createWarning();
|
||||||
|
} catch (InvalidModelNodeException &mne) {
|
||||||
|
qDebug().noquote() << "Invalid model node exception while replacing root node of template.";
|
||||||
|
mne.createWarning();
|
||||||
|
} catch (Exception &e) {
|
||||||
|
qDebug().noquote() << "Exception while replacing root node of template.";
|
||||||
|
e.createWarning();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the newly created nodes to the correct position in the parent node
|
// Move the newly created nodes to the correct position in the parent node
|
||||||
@@ -366,6 +402,7 @@ void StylesheetMerger::merge()
|
|||||||
|
|
||||||
// create the replacement nodes for the styled nodes
|
// create the replacement nodes for the styled nodes
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
RewriterTransaction transaction(m_templateView, "create-replacement-node");
|
RewriterTransaction transaction(m_templateView, "create-replacement-node");
|
||||||
|
|
||||||
ModelNode replacedNode = m_templateView->modelNodeForId(currentNode.id());
|
ModelNode replacedNode = m_templateView->modelNodeForId(currentNode.id());
|
||||||
@@ -375,9 +412,27 @@ void StylesheetMerger::merge()
|
|||||||
|
|
||||||
replaceNode(replacedNode, replacementNode);
|
replaceNode(replacedNode, replacementNode);
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
|
} catch (InvalidIdException &ide) {
|
||||||
|
qDebug().noquote() << "Invalid id exception while replacing template node";
|
||||||
|
ide.createWarning();
|
||||||
|
continue;
|
||||||
|
} catch (InvalidReparentingException &rpe) {
|
||||||
|
qDebug().noquote() << "Invalid reparenting exception while replacing template node";
|
||||||
|
rpe.createWarning();
|
||||||
|
continue;
|
||||||
|
} catch (InvalidModelNodeException &mne) {
|
||||||
|
qDebug().noquote() << "Invalid model node exception while replacing template node";
|
||||||
|
mne.createWarning();
|
||||||
|
continue;
|
||||||
|
} catch (Exception &e) {
|
||||||
|
qDebug().noquote() << "Exception while replacing template node.";
|
||||||
|
e.createWarning();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// sync the properties from the stylesheet
|
// sync the properties from the stylesheet
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
RewriterTransaction transaction(m_templateView, "sync-style-node-properties");
|
RewriterTransaction transaction(m_templateView, "sync-style-node-properties");
|
||||||
ModelNode templateNode = m_templateView->modelNodeForId(currentNode.id());
|
ModelNode templateNode = m_templateView->modelNodeForId(currentNode.id());
|
||||||
applyStyleProperties(templateNode, currentNode);
|
applyStyleProperties(templateNode, currentNode);
|
||||||
@@ -399,6 +454,23 @@ void StylesheetMerger::merge()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
|
} catch (InvalidIdException &ide) {
|
||||||
|
qDebug().noquote() << "Invalid id exception while syncing style properties to template";
|
||||||
|
ide.createWarning();
|
||||||
|
continue;
|
||||||
|
} catch (InvalidReparentingException &rpe) {
|
||||||
|
qDebug().noquote() << "Invalid reparenting exception while syncing style properties to template";
|
||||||
|
rpe.createWarning();
|
||||||
|
continue;
|
||||||
|
} catch (InvalidModelNodeException &mne) {
|
||||||
|
qDebug().noquote() << "Invalid model node exception while syncing style properties to template";
|
||||||
|
mne.createWarning();
|
||||||
|
continue;
|
||||||
|
} catch (Exception &e) {
|
||||||
|
qDebug().noquote() << "Exception while syncing style properties.";
|
||||||
|
e.createWarning();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user