forked from qt-creator/qt-creator
QmlDesigner: Consolidate exception handling code
And translate the message box title. Change-Id: I9d805c10940e5e3dbaa17323a913a4a55fc61a2d Reviewed-by: Marco Bubke <marco.bubke@digia.com> Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
@@ -30,10 +30,7 @@
|
|||||||
#include "modelnodeoperations.h"
|
#include "modelnodeoperations.h"
|
||||||
#include "modelnodecontextmenu_helper.h"
|
#include "modelnodecontextmenu_helper.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <nodeabstractproperty.h>
|
#include <nodeabstractproperty.h>
|
||||||
#include <nodemetainfo.h>
|
#include <nodemetainfo.h>
|
||||||
@@ -50,11 +47,6 @@ namespace QmlDesigner {
|
|||||||
|
|
||||||
const PropertyName auxDataString("anchors_");
|
const PropertyName auxDataString("anchors_");
|
||||||
|
|
||||||
static void showError(const RewritingException &e)
|
|
||||||
{
|
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline QList<QmlItemNode> siblingsForNode(const QmlItemNode &itemNode)
|
static inline QList<QmlItemNode> siblingsForNode(const QmlItemNode &itemNode)
|
||||||
{
|
{
|
||||||
QList<QmlItemNode> siblingList;
|
QList<QmlItemNode> siblingList;
|
||||||
@@ -191,7 +183,7 @@ void toFront(const SelectionContext &selectionState)
|
|||||||
node.setVariantProperty("z", maximumZ);
|
node.setVariantProperty("z", maximumZ);
|
||||||
}
|
}
|
||||||
} catch (RewritingException &e) { //better save then sorry
|
} catch (RewritingException &e) { //better save then sorry
|
||||||
showError(e);
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +201,7 @@ void toBack(const SelectionContext &selectionState)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (RewritingException &e) { //better save then sorry
|
} catch (RewritingException &e) { //better save then sorry
|
||||||
showError(e);
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +221,7 @@ void raise(const SelectionContext &selectionState)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (RewritingException &e) { //better save then sorry
|
} catch (RewritingException &e) { //better save then sorry
|
||||||
showError(e);
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +242,7 @@ void lower(const SelectionContext &selectionState)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (RewritingException &e) { //better save then sorry
|
} catch (RewritingException &e) { //better save then sorry
|
||||||
showError(e);
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +266,7 @@ void setVisible(const SelectionContext &selectionState)
|
|||||||
try {
|
try {
|
||||||
selectionState.selectedModelNodes().first().variantProperty("visible").setValue(selectionState.toggled());
|
selectionState.selectedModelNodes().first().variantProperty("visible").setValue(selectionState.toggled());
|
||||||
} catch (RewritingException &e) { //better save then sorry
|
} catch (RewritingException &e) { //better save then sorry
|
||||||
showError(e);
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,7 +279,7 @@ void setFillWidth(const SelectionContext &selectionState)
|
|||||||
try {
|
try {
|
||||||
selectionState.firstSelectedModelNode().variantProperty("Layout.fillWidth").setValue(selectionState.toggled());
|
selectionState.firstSelectedModelNode().variantProperty("Layout.fillWidth").setValue(selectionState.toggled());
|
||||||
} catch (RewritingException &e) { //better save then sorry
|
} catch (RewritingException &e) { //better save then sorry
|
||||||
showError(e);
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +292,7 @@ void setFillHeight(const SelectionContext &selectionState)
|
|||||||
try {
|
try {
|
||||||
selectionState.firstSelectedModelNode().variantProperty("Layout.fillHeight").setValue(selectionState.toggled());
|
selectionState.firstSelectedModelNode().variantProperty("Layout.fillHeight").setValue(selectionState.toggled());
|
||||||
} catch (RewritingException &e) { //better save then sorry
|
} catch (RewritingException &e) { //better save then sorry
|
||||||
showError(e);
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,7 +308,7 @@ void resetSize(const SelectionContext &selectionState)
|
|||||||
node.removeProperty("height");
|
node.removeProperty("height");
|
||||||
}
|
}
|
||||||
} catch (RewritingException &e) { //better save then sorry
|
} catch (RewritingException &e) { //better save then sorry
|
||||||
showError(e);
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,7 +324,7 @@ void resetPosition(const SelectionContext &selectionState)
|
|||||||
node.removeProperty("y");
|
node.removeProperty("y");
|
||||||
}
|
}
|
||||||
} catch (RewritingException &e) { //better save then sorry
|
} catch (RewritingException &e) { //better save then sorry
|
||||||
showError(e);
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,7 +389,7 @@ void anchorsFill(const SelectionContext &selectionState)
|
|||||||
|
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
} catch (RewritingException &e) { //better save then sorry
|
} catch (RewritingException &e) { //better save then sorry
|
||||||
showError(e);
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,12 +35,9 @@
|
|||||||
#include <metainfo.h>
|
#include <metainfo.h>
|
||||||
#include <rewritingexception.h>
|
#include <rewritingexception.h>
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
|
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
@@ -277,7 +274,7 @@ void DragTool::commitTransaction()
|
|||||||
try {
|
try {
|
||||||
m_rewriterTransaction.commit();
|
m_rewriterTransaction.commit();
|
||||||
} catch (RewritingException &e) {
|
} catch (RewritingException &e) {
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,10 +32,6 @@
|
|||||||
|
|
||||||
#include <rewritingexception.h>
|
#include <rewritingexception.h>
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
|
|
||||||
#include <QMessageBox>
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
ImportManagerView::ImportManagerView(QObject *parent) :
|
ImportManagerView::ImportManagerView(QObject *parent) :
|
||||||
@@ -254,7 +250,7 @@ void ImportManagerView::removeImport(const Import &import)
|
|||||||
model()->changeImports(QList<Import>(), QList<Import>() << import);
|
model()->changeImports(QList<Import>(), QList<Import>() << import);
|
||||||
}
|
}
|
||||||
catch (RewritingException &e) {
|
catch (RewritingException &e) {
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +261,7 @@ void ImportManagerView::addImport(const Import &import)
|
|||||||
model()->changeImports(QList<Import>() << import, QList<Import>());
|
model()->changeImports(QList<Import>() << import, QList<Import>());
|
||||||
}
|
}
|
||||||
catch (RewritingException &e) {
|
catch (RewritingException &e) {
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,6 @@
|
|||||||
#include <viewmanager.h>
|
#include <viewmanager.h>
|
||||||
#include <nodeinstanceview.h>
|
#include <nodeinstanceview.h>
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
@@ -53,7 +52,6 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
@@ -366,7 +364,7 @@ void DesignDocument::deleteSelected()
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (RewritingException &e) {
|
} catch (RewritingException &e) {
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), tr("Error"), e.description());
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -580,7 +580,7 @@ void NavigatorTreeModel::moveNodesInteractive(NodeAbstractProperty parentPropert
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (RewritingException &e) { //better safe than sorry! There always might be cases where we fail
|
} catch (RewritingException &e) { //better safe than sorry! There always might be cases where we fail
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ void PropertyEditorView::changeValue(const QString &name)
|
|||||||
m_locked = true;
|
m_locked = true;
|
||||||
value->setValue(m_selectedNode.id());
|
value->setValue(m_selectedNode.id());
|
||||||
m_locked = false;
|
m_locked = false;
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), tr("Invalid Id"), e.description());
|
e.showException(tr("Invalid Id"));
|
||||||
}
|
}
|
||||||
} else { //there is already an id, so we refactor
|
} else { //there is already an id, so we refactor
|
||||||
if (rewriterView())
|
if (rewriterView())
|
||||||
@@ -227,7 +227,7 @@ void PropertyEditorView::changeValue(const QString &name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (RewritingException &e) {
|
catch (RewritingException &e) {
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ void PropertyEditorView::changeExpression(const QString &propertyName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
catch (RewritingException &e) {
|
catch (RewritingException &e) {
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@
|
|||||||
#include "stateseditormodel.h"
|
#include "stateseditormodel.h"
|
||||||
#include <rewritingexception.h>
|
#include <rewritingexception.h>
|
||||||
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@@ -43,8 +42,6 @@
|
|||||||
|
|
||||||
#include <qmlitemnode.h>
|
#include <qmlitemnode.h>
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -161,7 +158,7 @@ void StatesEditorView::removeState(int nodeId)
|
|||||||
stateNode.destroy();
|
stateNode.destroy();
|
||||||
}
|
}
|
||||||
} catch (RewritingException &e) {
|
} catch (RewritingException &e) {
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +209,7 @@ void StatesEditorView::addState()
|
|||||||
ModelNode newState = rootStateGroup().addState(newStateName);
|
ModelNode newState = rootStateGroup().addState(newStateName);
|
||||||
setCurrentState(newState);
|
setCurrentState(newState);
|
||||||
} catch (RewritingException &e) {
|
} catch (RewritingException &e) {
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,7 +304,7 @@ void StatesEditorView::renameState(int nodeId, const QString &newName)
|
|||||||
setCurrentState(oldState);
|
setCurrentState(oldState);
|
||||||
}
|
}
|
||||||
} catch (RewritingException &e) {
|
} catch (RewritingException &e) {
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
e.showException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,11 @@
|
|||||||
#include <cxxabi.h>
|
#include <cxxabi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\defgroup CoreExceptions
|
\defgroup CoreExceptions
|
||||||
@@ -145,6 +150,15 @@ QString Exception::description() const
|
|||||||
return QString("file: %1, function: %2, line: %3").arg(m_file, m_function, QString::number(m_line));
|
return QString("file: %1, function: %2, line: %3").arg(m_file, m_function, QString::number(m_line));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Shows message in a message box.
|
||||||
|
*/
|
||||||
|
void Exception::showException(const QString &title) const
|
||||||
|
{
|
||||||
|
QString t = title.isEmpty() ? QCoreApplication::translate("QmlDesigner", "Error") : title;
|
||||||
|
QMessageBox::warning(Core::ICore::dialogParent(), t, description());
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns the line number where this exception was thrown as an integer.
|
Returns the line number where this exception was thrown as an integer.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public:
|
|||||||
|
|
||||||
virtual QString type() const = 0;
|
virtual QString type() const = 0;
|
||||||
virtual QString description() const;
|
virtual QString description() const;
|
||||||
|
virtual void showException(const QString &title = QString()) const;
|
||||||
|
|
||||||
int line() const;
|
int line() const;
|
||||||
QString function() const;
|
QString function() const;
|
||||||
|
|||||||
@@ -42,9 +42,6 @@
|
|||||||
#include "modelmerger.h"
|
#include "modelmerger.h"
|
||||||
#include "rewritingexception.h"
|
#include "rewritingexception.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@@ -176,7 +173,7 @@ QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibrary
|
|||||||
Q_ASSERT(newQmlItemNode.isValid());
|
Q_ASSERT(newQmlItemNode.isValid());
|
||||||
}
|
}
|
||||||
catch (RewritingException &e) {
|
catch (RewritingException &e) {
|
||||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
e.showException();
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_ASSERT(newQmlItemNode.isValid());
|
Q_ASSERT(newQmlItemNode.isValid());
|
||||||
|
|||||||
Reference in New Issue
Block a user