Don't show msg boxes while saving ui forms

Currently creator assumes that "save" is synchronous
and doesn't enter internal event loop.

Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Task-number: QTCREATORBUG-3678
This commit is contained in:
Jarek Kobus
2011-02-04 09:34:10 +01:00
parent a4fa2911f0
commit 8c65637407
7 changed files with 265 additions and 5 deletions

View File

@@ -41,6 +41,7 @@
#include <QtDesigner/QDesignerFormWindowInterface>
#include <QtDesigner/QDesignerFormWindowManagerInterface>
#include <QtDesigner/QDesignerFormEditorInterface>
#include "qt_private/qsimpleresource_p.h"
#include <QtGui/QMessageBox>
#include <QtGui/QMainWindow>
@@ -80,7 +81,10 @@ bool FormWindowFile::save(const QString &name /* = QString() */)
m_formWindow->setFileName(formName);
QString errorString;
if (!writeFile(actualName, errorString)) {
const bool warningsEnabled = qdesigner_internal::QSimpleResource::setWarningsEnabled(false);
const bool writeOK = writeFile(actualName, errorString);
qdesigner_internal::QSimpleResource::setWarningsEnabled(warningsEnabled);
if (!writeOK) {
QMessageBox::critical(0, tr("Error saving %1").arg(formName), errorString);
m_formWindow->setFileName(oldFormName);
return false;

View File

@@ -187,7 +187,7 @@ private slots:
private:
void syncGridFeature();
FormWindowBasePrivate *m_d;
FormWindowBasePrivate *m_d;
};
} // namespace qdesigner_internal

View File

@@ -46,9 +46,11 @@
#define PLUGINMANAGER_H
#include "shared_global_p.h"
#include "shared_enums_p.h"
#include <QtCore/QSharedDataPointer>
#include <QtCore/QMap>
#include <QtCore/QPair>
#include <QtCore/QStringList>
QT_BEGIN_NAMESPACE
@@ -62,6 +64,9 @@ class QDesignerCustomWidgetSharedData;
/* Information contained in the Dom XML of a custom widget. */
class QDESIGNER_SHARED_EXPORT QDesignerCustomWidgetData {
public:
// StringPropertyType: validation mode and translatable flag.
typedef QPair<qdesigner_internal::TextPropertyValidationMode, bool> StringPropertyType;
explicit QDesignerCustomWidgetData(const QString &pluginPath = QString());
enum ParseResult { ParseOk, ParseWarning, ParseError };
@@ -85,6 +90,8 @@ public:
QString xmlExtends() const;
// Optional. The name to be used in the widget box.
QString xmlDisplayName() const;
// Type of a string property
bool xmlStringPropertyType(const QString &name, StringPropertyType *type) const;
private:
QSharedDataPointer<QDesignerCustomWidgetSharedData> m_d;
@@ -120,6 +127,7 @@ public:
CustomWidgetList registeredCustomWidgets() const;
QDesignerCustomWidgetData customWidgetData(QDesignerCustomWidgetInterface *w) const;
QDesignerCustomWidgetData customWidgetData(const QString &className) const;
bool registerNewPlugins();

View File

@@ -0,0 +1,156 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of Qt Designer. This header
// file may change from version to version without notice, or even be removed.
//
// We mean it.
//
#ifndef QSIMPLERESOURCE_H
#define QSIMPLERESOURCE_H
#include "shared_global_p.h"
#include "abstractformbuilder.h"
#include <QtCore/QStringList>
QT_BEGIN_NAMESPACE
class DomScript;
class DomCustomWidgets;
class DomCustomWidget;
class DomSlots;
class QDesignerFormEditorInterface;
namespace qdesigner_internal {
class WidgetDataBaseItem;
class QDESIGNER_SHARED_EXPORT QSimpleResource : public QAbstractFormBuilder
{
public:
explicit QSimpleResource(QDesignerFormEditorInterface *core);
virtual ~QSimpleResource();
QBrush setupBrush(DomBrush *brush);
DomBrush *saveBrush(const QBrush &brush);
inline QDesignerFormEditorInterface *core() const
{ return m_core; }
// Query extensions for additional data
static void addExtensionDataToDOM(QAbstractFormBuilder *afb,
QDesignerFormEditorInterface *core,
DomWidget *ui_widget, QWidget *widget);
static void applyExtensionDataFromDOM(QAbstractFormBuilder *afb,
QDesignerFormEditorInterface *core,
DomWidget *ui_widget, QWidget *widget,
bool applyState);
// Enable warnings while saving. Turn off for backups.
static bool setWarningsEnabled(bool warningsEnabled);
static bool warningsEnabled();
// Return the script returned by the CustomWidget codeTemplate API
static QString customWidgetScript(QDesignerFormEditorInterface *core, QObject *object);
static QString customWidgetScript(QDesignerFormEditorInterface *core, const QString &className);
static bool hasCustomWidgetScript(QDesignerFormEditorInterface *core, QObject *object);
// Implementation for FormBuilder::createDomCustomWidgets() that adds
// the custom widgets to the widget database
static void handleDomCustomWidgets(const QDesignerFormEditorInterface *core,
const DomCustomWidgets *dom_custom_widgets);
protected:
virtual QIcon nameToIcon(const QString &filePath, const QString &qrcPath);
virtual QString iconToFilePath(const QIcon &pm) const;
virtual QString iconToQrcPath(const QIcon &pm) const;
virtual QPixmap nameToPixmap(const QString &filePath, const QString &qrcPath);
virtual QString pixmapToFilePath(const QPixmap &pm) const;
virtual QString pixmapToQrcPath(const QPixmap &pm) const;
enum ScriptSource { ScriptDesigner, ScriptExtension, ScriptCustomWidgetPlugin };
static DomScript*createScript(const QString &script, ScriptSource source);
typedef QList<DomScript*> DomScripts;
static void addScript(const QString &script, ScriptSource source, DomScripts &domScripts);
static bool addFakeMethods(const DomSlots *domSlots, QStringList &fakeSlots, QStringList &fakeSignals);
private:
static void addCustomWidgetsToWidgetDatabase(const QDesignerFormEditorInterface *core,
QList<DomCustomWidget*>& custom_widget_list);
static void addFakeMethodsToWidgetDataBase(const DomCustomWidget *domCustomWidget, WidgetDataBaseItem *item);
static bool m_warningsEnabled;
QDesignerFormEditorInterface *m_core;
};
// Contents of clipboard for formbuilder copy and paste operations
// (Actions and widgets)
struct QDESIGNER_SHARED_EXPORT FormBuilderClipboard {
typedef QList<QAction*> ActionList;
FormBuilderClipboard() {}
FormBuilderClipboard(QWidget *w);
bool empty() const;
QWidgetList m_widgets;
ActionList m_actions;
};
// Base class for a form builder used in the editor that
// provides copy and paste.(move into base interface)
class QDESIGNER_SHARED_EXPORT QEditorFormBuilder : public QSimpleResource
{
public:
explicit QEditorFormBuilder(QDesignerFormEditorInterface *core) : QSimpleResource(core) {}
virtual bool copy(QIODevice *dev, const FormBuilderClipboard &selection) = 0;
virtual DomUI *copy(const FormBuilderClipboard &selection) = 0;
// A widget parent needs to be specified, otherwise, the widget factory cannot locate the form window via parent
// and thus is not able to construct special widgets (QLayoutWidget).
virtual FormBuilderClipboard paste(DomUI *ui, QWidget *widgetParent, QObject *actionParent = 0) = 0;
virtual FormBuilderClipboard paste(QIODevice *dev, QWidget *widgetParent, QObject *actionParent = 0) = 0;
};
} // namespace qdesigner_internal
QT_END_NAMESPACE
#endif

View File

@@ -48,6 +48,7 @@
#include "shared_global_p.h"
#include <QtCore/QMap>
#include <QtCore/QObject>
#include <QtCore/QScopedPointer>
QT_BEGIN_NAMESPACE
@@ -79,7 +80,7 @@ private:
~QtResourceSet();
friend class QtResourceModel;
class QtResourceSetPrivate *d_ptr;
QScopedPointer<class QtResourceSetPrivate> d_ptr;
Q_DECLARE_PRIVATE(QtResourceSet)
Q_DISABLE_COPY(QtResourceSet)
};
@@ -124,7 +125,7 @@ signals:
private:
friend class QtResourceSet;
class QtResourceModelPrivate *d_ptr;
QScopedPointer<class QtResourceModelPrivate> d_ptr;
Q_DECLARE_PRIVATE(QtResourceModel)
Q_DISABLE_COPY(QtResourceModel)

View File

@@ -0,0 +1,91 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of Qt Designer. This header
// file may change from version to version without notice, or even be removed.
//
// We mean it.
//
#ifndef SHAREDENUMS_H
#define SHAREDENUMS_H
#include "shared_global_p.h"
QT_BEGIN_NAMESPACE
namespace qdesigner_internal {
// Validation mode of text property line edits
enum TextPropertyValidationMode {
// Allow for multiline editing using literal "\n".
ValidationMultiLine,
// Allow for HTML rich text including multiline editing using literal "\n".
ValidationRichText,
// Validate a stylesheet
ValidationStyleSheet,
// Single line mode, suppresses newlines
ValidationSingleLine,
// Allow only for identifier characters
ValidationObjectName,
// Allow only for identifier characters and colons
ValidationObjectNameScope,
// URL
ValidationURL
};
// Container types
enum ContainerType {
// A container with pages, at least one of which one must always be present (for example, QTabWidget)
PageContainer,
// Mdi type container. All pages may be deleted, no concept of page order
MdiContainer,
// Wizard container
WizardContainer
};
enum AuxiliaryItemDataRoles {
// item->flags while being edited
ItemFlagsShadowRole = 0x13370551
};
}
QT_END_NAMESPACE
#endif // SHAREDENUMS_H

View File

@@ -35,7 +35,7 @@
REQUIRED_HEADERS="pluginmanager_p.h iconloader_p.h qdesigner_formwindowmanager_p.h formwindowbase_p.h
abstractnewformwidget_p.h qtresourcemodel_p.h abstractoptionspage_p.h
shared_global_p.h abstractsettings_p.h qdesigner_integration_p.h"
shared_global_p.h abstractsettings_p.h qdesigner_integration_p.h qsimpleresource_p.h shared_enums_p.h"
echo Using $QTDIR