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 <bindingproperty.h>
|
||||
#include <invalididexception.h>
|
||||
#include <invalidmodelnodeexception.h>
|
||||
#include <invalidreparentingexception.h>
|
||||
#include <modelmerger.h>
|
||||
#include <nodeabstractproperty.h>
|
||||
#include <nodelistproperty.h>
|
||||
@@ -194,6 +197,8 @@ QPoint parentPosition(const ModelNode &node)
|
||||
|
||||
void StylesheetMerger::preprocessStyleSheet()
|
||||
{
|
||||
try {
|
||||
RewriterTransaction transaction(m_styleView, "preprocess-stylesheet");
|
||||
for (ModelNode currentStyleNode : m_styleView->rootModelNode().directSubModelNodes()) {
|
||||
QString id = currentStyleNode.id();
|
||||
|
||||
@@ -233,6 +238,21 @@ void StylesheetMerger::preprocessStyleSheet()
|
||||
if (templateParentIndex >= 0 && 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)
|
||||
@@ -269,6 +289,8 @@ void StylesheetMerger::replaceNode(ModelNode &replacedNode, ModelNode &newNode)
|
||||
|
||||
void StylesheetMerger::replaceRootNode(ModelNode& templateRootNode)
|
||||
{
|
||||
try {
|
||||
RewriterTransaction transaction(m_templateView, "replace-root-node");
|
||||
ModelMerger merger(m_templateView);
|
||||
QString rootId = templateRootNode.id();
|
||||
// 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.
|
||||
ModelNode newRoot = m_templateView->rootModelNode();
|
||||
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
|
||||
@@ -366,6 +402,7 @@ void StylesheetMerger::merge()
|
||||
|
||||
// create the replacement nodes for the styled nodes
|
||||
{
|
||||
try {
|
||||
RewriterTransaction transaction(m_templateView, "create-replacement-node");
|
||||
|
||||
ModelNode replacedNode = m_templateView->modelNodeForId(currentNode.id());
|
||||
@@ -375,9 +412,27 @@ void StylesheetMerger::merge()
|
||||
|
||||
replaceNode(replacedNode, replacementNode);
|
||||
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
|
||||
{
|
||||
try {
|
||||
RewriterTransaction transaction(m_templateView, "sync-style-node-properties");
|
||||
ModelNode templateNode = m_templateView->modelNodeForId(currentNode.id());
|
||||
applyStyleProperties(templateNode, currentNode);
|
||||
@@ -399,6 +454,23 @@ void StylesheetMerger::merge()
|
||||
}
|
||||
}
|
||||
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