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 "modelnodecontextmenu_helper.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <QMessageBox>
|
||||
#include <QByteArray>
|
||||
#include <nodeabstractproperty.h>
|
||||
#include <nodemetainfo.h>
|
||||
@@ -50,11 +47,6 @@ namespace QmlDesigner {
|
||||
|
||||
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)
|
||||
{
|
||||
QList<QmlItemNode> siblingList;
|
||||
@@ -191,7 +183,7 @@ void toFront(const SelectionContext &selectionState)
|
||||
node.setVariantProperty("z", maximumZ);
|
||||
}
|
||||
} 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
|
||||
showError(e);
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +221,7 @@ void raise(const SelectionContext &selectionState)
|
||||
}
|
||||
}
|
||||
} 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
|
||||
showError(e);
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +266,7 @@ void setVisible(const SelectionContext &selectionState)
|
||||
try {
|
||||
selectionState.selectedModelNodes().first().variantProperty("visible").setValue(selectionState.toggled());
|
||||
} catch (RewritingException &e) { //better save then sorry
|
||||
showError(e);
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,7 +279,7 @@ void setFillWidth(const SelectionContext &selectionState)
|
||||
try {
|
||||
selectionState.firstSelectedModelNode().variantProperty("Layout.fillWidth").setValue(selectionState.toggled());
|
||||
} catch (RewritingException &e) { //better save then sorry
|
||||
showError(e);
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +292,7 @@ void setFillHeight(const SelectionContext &selectionState)
|
||||
try {
|
||||
selectionState.firstSelectedModelNode().variantProperty("Layout.fillHeight").setValue(selectionState.toggled());
|
||||
} catch (RewritingException &e) { //better save then sorry
|
||||
showError(e);
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,7 +308,7 @@ void resetSize(const SelectionContext &selectionState)
|
||||
node.removeProperty("height");
|
||||
}
|
||||
} catch (RewritingException &e) { //better save then sorry
|
||||
showError(e);
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +324,7 @@ void resetPosition(const SelectionContext &selectionState)
|
||||
node.removeProperty("y");
|
||||
}
|
||||
} catch (RewritingException &e) { //better save then sorry
|
||||
showError(e);
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,7 +389,7 @@ void anchorsFill(const SelectionContext &selectionState)
|
||||
|
||||
transaction.commit();
|
||||
} catch (RewritingException &e) { //better save then sorry
|
||||
showError(e);
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,12 +35,9 @@
|
||||
#include <metainfo.h>
|
||||
#include <rewritingexception.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QDebug>
|
||||
#include <QMimeData>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
||||
namespace QmlDesigner {
|
||||
@@ -277,7 +274,7 @@ void DragTool::commitTransaction()
|
||||
try {
|
||||
m_rewriterTransaction.commit();
|
||||
} catch (RewritingException &e) {
|
||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,10 +32,6 @@
|
||||
|
||||
#include <rewritingexception.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
ImportManagerView::ImportManagerView(QObject *parent) :
|
||||
@@ -254,7 +250,7 @@ void ImportManagerView::removeImport(const Import &import)
|
||||
model()->changeImports(QList<Import>(), QList<Import>() << import);
|
||||
}
|
||||
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>());
|
||||
}
|
||||
catch (RewritingException &e) {
|
||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include <viewmanager.h>
|
||||
#include <nodeinstanceview.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/target.h>
|
||||
@@ -53,7 +52,6 @@
|
||||
#include <QUrl>
|
||||
#include <QDebug>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QApplication>
|
||||
|
||||
@@ -366,7 +364,7 @@ void DesignDocument::deleteSelected()
|
||||
}
|
||||
|
||||
} 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
|
||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ void PropertyEditorView::changeValue(const QString &name)
|
||||
m_locked = true;
|
||||
value->setValue(m_selectedNode.id());
|
||||
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
|
||||
if (rewriterView())
|
||||
@@ -227,7 +227,7 @@ void PropertyEditorView::changeValue(const QString &name)
|
||||
}
|
||||
}
|
||||
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) {
|
||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include "stateseditormodel.h"
|
||||
#include <rewritingexception.h>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <math.h>
|
||||
|
||||
@@ -43,8 +42,6 @@
|
||||
|
||||
#include <qmlitemnode.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
@@ -161,7 +158,7 @@ void StatesEditorView::removeState(int nodeId)
|
||||
stateNode.destroy();
|
||||
}
|
||||
} 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);
|
||||
setCurrentState(newState);
|
||||
} 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);
|
||||
}
|
||||
} catch (RewritingException &e) {
|
||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
||||
e.showException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,11 @@
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QMessageBox>
|
||||
|
||||
|
||||
/*!
|
||||
\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));
|
||||
}
|
||||
|
||||
/*!
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
|
||||
virtual QString type() const = 0;
|
||||
virtual QString description() const;
|
||||
virtual void showException(const QString &title = QString()) const;
|
||||
|
||||
int line() const;
|
||||
QString function() const;
|
||||
|
||||
@@ -42,9 +42,6 @@
|
||||
#include "modelmerger.h"
|
||||
#include "rewritingexception.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QUrl>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QFileInfo>
|
||||
@@ -176,7 +173,7 @@ QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibrary
|
||||
Q_ASSERT(newQmlItemNode.isValid());
|
||||
}
|
||||
catch (RewritingException &e) {
|
||||
QMessageBox::warning(Core::ICore::dialogParent(), "Error", e.description());
|
||||
e.showException();
|
||||
}
|
||||
|
||||
Q_ASSERT(newQmlItemNode.isValid());
|
||||
|
||||
Reference in New Issue
Block a user