Commit 2e3e97c4 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner: adding a nice dialog for warnings



This patch also includes options to turn the warnings off.

Change-Id: I540bc19f5a4f23f441af0fd08b072dbcbf067a20
Reviewed-by: default avatarMarco Bubke <marco.bubke@digia.com>
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 091d1116
......@@ -13,7 +13,8 @@ SOURCES += \
$$PWD/objectlengthcalculator.cpp \
$$PWD/firstdefinitionfinder.cpp \
$$PWD/moveobjectbeforeobjectvisitor.cpp \
$$PWD/changeimportsvisitor.cpp
$$PWD/changeimportsvisitor.cpp \
$$PWD/qmlwarningdialog.cpp
HEADERS += \
$$PWD/qmlrewriter.h \
$$PWD/qmlrefactoring.h \
......@@ -29,4 +30,8 @@ HEADERS += \
$$PWD/objectlengthcalculator.h \
$$PWD/firstdefinitionfinder.h \
$$PWD/moveobjectbeforeobjectvisitor.h \
$$PWD/changeimportsvisitor.h
$$PWD/changeimportsvisitor.h \
$$PWD/qmlwarningdialog.h
FORMS += \
$$PWD/qmlwarningdialog.ui
#include "qmlwarningdialog.h"
#include "ui_qmlwarningdialog.h"
#include <qmldesignerplugin.h>
namespace QmlDesigner {
namespace Internal {
QmlWarningDialog::QmlWarningDialog(QWidget *parent, const QStringList &warnings) :
QDialog(parent),
ui(new Ui::QmlWarningDialog),
m_warnings(warnings)
{
ui->setupUi(this);
setResult (0);
ui->checkBox->setChecked(true);
connect(ui->ignoreButton, SIGNAL(clicked()), this, SLOT(ignoreButtonPressed()));
connect(ui->okButton, SIGNAL(clicked()), this, SLOT(okButtonPressed()));
connect(ui->checkBox, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled(bool)));
connect(ui->warnings, SIGNAL(linkActivated(QString)), this, SLOT(linkClicked(QString)));
QString warningText;
foreach (const QString &string, warnings)
warningText += QLatin1String(" ") + string + QLatin1String("\n");
ui->warnings->setText(warningText);
ui->warnings->setForegroundRole(QPalette::ToolTipText);
ui->warnings->setBackgroundRole(QPalette::ToolTipBase);
ui->warnings->setAutoFillBackground(true);
}
QmlWarningDialog::~QmlWarningDialog()
{
delete ui;
}
void QmlWarningDialog::ignoreButtonPressed()
{
done(0);
}
void QmlWarningDialog::okButtonPressed()
{
done(-1);
}
bool QmlWarningDialog::warningsEnabled() const
{
DesignerSettings settings = BauhausPlugin::pluginInstance()->settings();
return settings.warningsInDesigner;
}
void QmlWarningDialog::checkBoxToggled(bool b)
{
DesignerSettings settings = BauhausPlugin::pluginInstance()->settings();
settings.warningsInDesigner = b;
BauhausPlugin::pluginInstance()->setSettings(settings);
}
void QmlWarningDialog::linkClicked(const QString &link)
{
done(link.toInt());
}
} //Internal
} //QmlDesigner
#ifndef QMLWARNINGDIALOG_H
#define QMLWARNINGDIALOG_H
#include <QDialog>
namespace Ui {
class QmlWarningDialog;
}
namespace QmlDesigner {
namespace Internal {
class QmlWarningDialog : public QDialog
{
Q_OBJECT
public:
explicit QmlWarningDialog(QWidget *parent, const QStringList &warnings);
~QmlWarningDialog();
bool warningsEnabled() const;
public slots:
void ignoreButtonPressed();
void okButtonPressed();
void checkBoxToggled(bool);
void linkClicked(const QString &link);
private:
Ui::QmlWarningDialog *ui;
const QStringList m_warnings;
};
} //Internal
} //QmlDesigner
#endif // QMLWARNINGDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QmlWarningDialog</class>
<widget class="QDialog" name="QmlWarningDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>458</width>
<height>229</height>
</rect>
</property>
<property name="windowTitle">
<string>Warning</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>12</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>440</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>This QML file contains features which are not supported by Qt Quick Designer</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="warnings">
<property name="minimumSize">
<size>
<width>0</width>
<height>120</height>
</size>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="margin">
<number>6</number>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Warn about QML features which are not properly supported by the Qt Quick Designer</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>88</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="ignoreButton">
<property name="toolTip">
<string>Ignore this warning and open the file</string>
</property>
<property name="text">
<string>Ignore</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="okButton">
<property name="text">
<string>Ok</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -32,6 +32,7 @@
#include "filemanager/firstdefinitionfinder.h"
#include "filemanager/objectlengthcalculator.h"
#include "filemanager/qmlrefactoring.h"
#include "filemanager/qmlwarningdialog.h"
#include "rewriteaction.h"
#include "nodeproperty.h"
#include "propertyparser.h"
......@@ -800,13 +801,16 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
QString title = QCoreApplication::translate("QmlDesigner::TextToModelMerger warning message", "This .qml file contains features"
"which are not supported by Qt Quick Designer");
QString message;
QStringList message;
foreach (const RewriterView::Error &warning, warnings) {
message += QLatin1String("Line: ") + QString::number(warning.line()) + ": " + warning.description() + QLatin1String("\n");
QString string = QLatin1String("Line: ") + QString::number(warning.line()) + QLatin1String(": ") + warning.description();
//string += QLatin1String(" <a href=\"") + QString::number(warning.line()) + QLatin1String("\">Go to error</a>") + QLatin1String("<p>");
message << string;
}
if (QMessageBox::warning(0, title, message, QMessageBox::Ignore | QMessageBox::Cancel) == QMessageBox::Cancel) {
QmlWarningDialog warningDialog(0, message);
if (warningDialog.warningsEnabled() && warningDialog.exec()) {
m_rewriterView->setErrors(warnings);
setActive(false);
return false;
......
......@@ -39,7 +39,9 @@ DesignerSettings::DesignerSettings()
itemSpacing(0),
snapMargin(0),
canvasWidth(10000),
canvasHeight(10000)
canvasHeight(10000),
warningsInDesigner(true),
designerWarningsInEditor(false)
{}
void DesignerSettings::fromSettings(QSettings *settings)
......@@ -55,6 +57,11 @@ void DesignerSettings::fromSettings(QSettings *settings)
QLatin1String(QmlDesigner::Constants::QML_SNAPMARGIN_KEY), QVariant(0)).toInt();
canvasWidth = settings->value(QLatin1String(QmlDesigner::Constants::QML_CANVASWIDTH_KEY), QVariant(10000)).toInt();
canvasHeight = settings->value(QLatin1String(QmlDesigner::Constants::QML_CANVASHEIGHT_KEY), QVariant(10000)).toInt();
warningsInDesigner = settings->value(
QLatin1String(QmlDesigner::Constants::QML_WARNIN_FOR_FEATURES_IN_DESIGNER_KEY), QVariant(true)).toBool();
designerWarningsInEditor = settings->value(
QLatin1String(QmlDesigner::Constants::QML_WARNIN_FOR_DESIGNER_FEATURES_IN_EDITOR_KEY), QVariant(false)).toBool();
settings->endGroup();
settings->endGroup();
}
......@@ -68,6 +75,9 @@ void DesignerSettings::toSettings(QSettings *settings) const
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_SNAPMARGIN_KEY), snapMargin);
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_CANVASWIDTH_KEY), canvasWidth);
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_CANVASHEIGHT_KEY), canvasHeight);
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_WARNIN_FOR_FEATURES_IN_DESIGNER_KEY), warningsInDesigner);
settings->setValue(QLatin1String(QmlDesigner::Constants::QML_WARNIN_FOR_DESIGNER_FEATURES_IN_EDITOR_KEY), designerWarningsInEditor);
settings->endGroup();
settings->endGroup();
}
......@@ -77,5 +87,7 @@ bool DesignerSettings::equals(const DesignerSettings &other) const
return openDesignMode == other.openDesignMode
&& snapMargin == other.snapMargin
&& canvasWidth == other.canvasWidth
&& canvasHeight == other.canvasHeight;
&& canvasHeight == other.canvasHeight
&& warningsInDesigner == other.warningsInDesigner
&& designerWarningsInEditor == other.designerWarningsInEditor;
}
......@@ -52,6 +52,8 @@ public:
int snapMargin;
int canvasWidth;
int canvasHeight;
bool warningsInDesigner;
bool designerWarningsInEditor;
};
inline bool operator==(const DesignerSettings &s1, const DesignerSettings &s2)
......
......@@ -60,6 +60,8 @@ const char QML_CANVASWIDTH_KEY[] = "CanvasWidth";
const char QML_CANVASHEIGHT_KEY[] = "CanvasHeight";
const char QML_CONTEXTPANE_KEY[] = "ContextPaneEnabled";
const char QML_CONTEXTPANEPIN_KEY[] = "ContextPanePinned";
const char QML_WARNIN_FOR_FEATURES_IN_DESIGNER_KEY[] = "WarnAboutQtQuickFeaturesInDesigner";
const char QML_WARNIN_FOR_DESIGNER_FEATURES_IN_EDITOR_KEY[] = "WarnAboutQtQuickDesignerFeaturesInCodeEditor";
enum { QML_OPENDESIGNMODE_DEFAULT = 0 }; // 0 for text mode, 1 for design mode
const char SETTINGS_CATEGORY_QML_ICON[] = ":/core/images/category_qml.png";
......
......@@ -369,8 +369,9 @@ void BauhausPlugin::switchTextDesign()
}
}
DesignerSettings BauhausPlugin::settings() const
DesignerSettings BauhausPlugin::settings()
{
m_settings.fromSettings(Core::ICore::settings());
return m_settings;
}
......
......@@ -72,7 +72,7 @@ public:
static BauhausPlugin *pluginInstance();
DesignerSettings settings() const;
DesignerSettings settings();
void setSettings(const DesignerSettings &s);
private slots:
......
......@@ -53,6 +53,9 @@ DesignerSettings SettingsPageWidget::settings() const
ds.snapMargin = m_ui.spinSnapMargin->value();
ds.canvasWidth = m_ui.spinCanvasWidth->value();
ds.canvasHeight = m_ui.spinCanvasHeight->value();
ds.warningsInDesigner = m_ui.designerWarningsCheckBox->isChecked();
ds.designerWarningsInEditor = m_ui.designerWarningsInEditorCheckBox->isChecked();
return ds;
}
......@@ -62,6 +65,8 @@ void SettingsPageWidget::setSettings(const DesignerSettings &s)
m_ui.spinSnapMargin->setValue(s.snapMargin);
m_ui.spinCanvasWidth->setValue(s.canvasWidth);
m_ui.spinCanvasHeight->setValue(s.canvasHeight);
m_ui.designerWarningsCheckBox->setChecked(s.warningsInDesigner);
m_ui.designerWarningsInEditorCheckBox->setChecked(s.designerWarningsInEditor);
}
QString SettingsPageWidget::searchKeywords() const
......
......@@ -6,15 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>275</width>
<height>275</height>
<width>574</width>
<height>472</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Snapping</string>
......@@ -67,7 +67,7 @@
</layout>
</widget>
</item>
<item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Canvas</string>
......@@ -132,7 +132,40 @@
</layout>
</widget>
</item>
<item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Warnings</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="1">
<widget class="QCheckBox" name="designerWarningsCheckBox">
<property name="toolTip">
<string>Warn about QML features which are not properly supported by the Qt Quick Designer</string>
</property>
<property name="text">
<string>Warn about unsupported features in the Qt Quick Designer</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="designerWarningsInEditorCheckBox">
<property name="toolTip">
<string>Also warn in the code editor about QML features which are not properly supported by the Qt Quick Designer</string>
</property>
<property name="text">
<string>Warn about unsupported features of Qt Quick Designer in the code editor</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment