From cb6300f56754b92a972be39be08da019ee6e4b34 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 19 May 2011 09:04:51 +0200 Subject: [PATCH] Designer: Refactor save/load. No longer pop up message boxes in QDesignerFormWindowInterface:: contents(), introduce QDesignerFormWindowInterface::checkContents() instead that checks for orphaned top level spacers (use in Designer application). Give QDesignerFormWindowInterface::setContents() a bool return and pass an optional error string back for IDE integrations. Remove all Qt3 form conversion logic from the loading logic (since there is no more uic3); do not do any additional checks there since everything has been moved to QAbstractFormBuilder::load() (including language). Thus, QDesignerFormWindowInterface::setContents() no longer pops up message boxes, either. Dependent on: qtbase/449b8a93170ecc19f2f438b160d0bc4122999401 --- .../src/components/formeditor/formwindow.cpp | 20 ++- .../src/components/formeditor/formwindow.h | 4 +- .../components/formeditor/qdesigner_resource.cpp | 191 ++------------------- .../src/components/formeditor/qdesigner_resource.h | 3 +- src/designer/src/designer/qdesigner_actions.cpp | 11 +- src/designer/src/designer/qdesigner_actions.h | 2 +- src/designer/src/designer/qdesigner_workbench.cpp | 34 ++-- src/designer/src/designer/qdesigner_workbench.h | 2 +- src/designer/src/lib/sdk/abstractformwindow.cpp | 20 ++- src/designer/src/lib/sdk/abstractformwindow.h | 5 +- src/designer/src/lib/sdk/abstractlanguage.h | 8 + src/designer/src/lib/shared/codedialog.cpp | 2 +- src/designer/src/lib/shared/formwindowbase.cpp | 23 ++- src/designer/src/lib/shared/formwindowbase_p.h | 3 +- .../src/lib/shared/qdesigner_formbuilder.cpp | 10 -- .../src/lib/shared/qdesigner_formbuilder_p.h | 2 - src/designer/src/lib/shared/qdesigner_utils.cpp | 18 +- src/designer/src/lib/shared/qdesigner_utils_p.h | 3 +- src/designer/src/lib/shared/qsimpleresource.cpp | 12 -- src/designer/src/lib/shared/qsimpleresource_p.h | 3 - 20 files changed, 98 insertions(+), 278 deletions(-) diff --git a/src/designer/src/components/formeditor/formwindow.cpp b/src/designer/src/components/formeditor/formwindow.cpp index e39e36c..1abf7cd 100644 --- a/src/designer/src/components/formeditor/formwindow.cpp +++ b/src/designer/src/components/formeditor/formwindow.cpp @@ -2139,7 +2139,7 @@ bool FormWindow::handleContextMenu(QWidget *, QWidget *managedWidget, QContextMe return true; } -void FormWindow::setContents(QIODevice *dev) +bool FormWindow::setContents(QIODevice *dev, QString *errorMessageIn /* = 0 */) { UpdateBlocker ub(this); clearSelection(); @@ -2153,16 +2153,24 @@ void FormWindow::setContents(QIODevice *dev) QDesignerResource r(this); QWidget *w = r.load(dev, formContainer()); - setMainContainer(w); - emit changed(); + if (w) { + setMainContainer(w); + emit changed(); + } + if (errorMessageIn) + *errorMessageIn = r.errorString(); + return w != 0; } -void FormWindow::setContents(const QString &contents) +bool FormWindow::setContents(const QString &contents) { + QString errorMessage; QByteArray data = contents.toUtf8(); QBuffer b(&data); - if (b.open(QIODevice::ReadOnly)) - setContents(&b); + const bool success = b.open(QIODevice::ReadOnly) && setContents(&b, &errorMessage); + if (!success && !errorMessage.isEmpty()) + designerWarning(errorMessage); + return success; } void FormWindow::layoutContainer(QWidget *w, int type) diff --git a/src/designer/src/components/formeditor/formwindow.h b/src/designer/src/components/formeditor/formwindow.h index 405a631..707c7d8 100644 --- a/src/designer/src/components/formeditor/formwindow.h +++ b/src/designer/src/components/formeditor/formwindow.h @@ -124,8 +124,8 @@ public: virtual void setFileName(const QString &fileName); virtual QString contents() const; - virtual void setContents(const QString &contents); - virtual void setContents(QIODevice *dev); + virtual bool setContents(QIODevice *dev, QString *errorMessage = 0); + virtual bool setContents(const QString &); virtual QDir absoluteDir() const; diff --git a/src/designer/src/components/formeditor/qdesigner_resource.cpp b/src/designer/src/components/formeditor/qdesigner_resource.cpp index 1627d42..62957d3 100644 --- a/src/designer/src/components/formeditor/qdesigner_resource.cpp +++ b/src/designer/src/components/formeditor/qdesigner_resource.cpp @@ -411,11 +411,15 @@ DomProperty *QDesignerTextBuilder::saveText(const QVariant &value) const QDesignerResource::QDesignerResource(FormWindow *formWindow) : QEditorFormBuilder(formWindow->core()), m_formWindow(formWindow), - m_topLevelSpacerCount(0), m_copyWidget(false), m_selected(0), m_resourceBuilder(new QDesignerResourceBuilder(m_formWindow->core(), m_formWindow->pixmapCache(), m_formWindow->iconCache())) { + // Check language unless extension present (Jambi) + QDesignerFormEditorInterface *core = m_formWindow->core(); + if (const QDesignerLanguageExtension *le = qt_extension(core->extensionManager(), core)) + d->m_language = le->name(); + setWorkingDirectory(formWindow->absoluteDir()); setResourceBuilder(m_resourceBuilder); setTextBuilder(new QDesignerTextBuilder()); @@ -451,19 +455,7 @@ static inline QString messageBoxTitle() void QDesignerResource::save(QIODevice *dev, QWidget *widget) { - m_topLevelSpacerCount = 0; - QAbstractFormBuilder::save(dev, widget); - - if (QSimpleResource::warningsEnabled() && m_topLevelSpacerCount != 0) { - const QString message = QApplication::translate("Designer", "This file contains top level spacers.
" - "They have NOT been saved into the form."); - const QString infoMessage = QApplication::translate("Designer", "Perhaps you forgot to create a layout?"); - - core()->dialogGui()->message(widget->window(), QDesignerDialogGuiInterface::TopLevelSpacerMessage, - QMessageBox::Warning, messageBoxTitle(), message, infoMessage, - QMessageBox::Ok); - } } void QDesignerResource::saveDom(DomUI *ui, QWidget *widget) @@ -584,164 +576,10 @@ void QDesignerResource::saveDom(DomUI *ui, QWidget *widget) } } -namespace { - enum LoadPreCheck { LoadPreCheckFailed, LoadPreCheckVersion3, LoadPreCheckVersionMismatch, LoadPreCheckOk }; - // Pair of major, minor - typedef QPair UiVersion; -} - -static UiVersion uiVersion(const QString &attr) -{ - const QStringList versions = attr.split(QLatin1Char('.')); - if (versions.empty()) - return UiVersion(-1, -1); - - bool ok = false; - UiVersion rc(versions.at(0).toInt(&ok), 0); - - if (!ok) - return UiVersion(-1, -1); - - if (versions.size() > 1) { - const int minorVersion = versions.at(1).toInt(&ok); - if (ok) - rc.second = minorVersion; - } - return rc; -} - -// Read version and language attributes of an element. -static bool readUiAttributes(QIODevice *dev, QString *errorMessage, - QString *version, - QString *language) -{ - const QString uiElement = QLatin1String("ui"); - const QString versionAttribute = QLatin1String("version"); - const QString languageAttribute = QLatin1String("language"); - QXmlStreamReader reader(dev); - // Read up to first element - while (!reader.atEnd()) { - if (reader.readNext() == QXmlStreamReader::StartElement) { - const QStringRef tag = reader.name(); - if (reader.name().compare(uiElement, Qt::CaseInsensitive) == 0) { - const QXmlStreamAttributes attributes = reader.attributes(); - if (attributes.hasAttribute(versionAttribute)) - *version = attributes.value(versionAttribute).toString(); - if (attributes.hasAttribute(languageAttribute)) - *language = attributes.value(languageAttribute).toString(); - return true; - } else { - *errorMessage = QCoreApplication::translate("Designer", "Invalid UI file: The root element is missing."); - return false; - - } - } - } - *errorMessage = QCoreApplication::translate("Designer", "An error has occurred while reading the UI file at line %1, column %2: %3") - .arg(reader.lineNumber()).arg(reader.columnNumber()).arg(reader.errorString()); - return false; -} - -// While loading a file, check language, version and extra extension -static LoadPreCheck loadPrecheck(QDesignerFormEditorInterface *core, - QIODevice *dev, - QString *errorMessage, QString *versionString) -{ - QString language; - // Read attributes of and rewind - if (!readUiAttributes(dev, errorMessage, versionString, &language)) { - // XML error: Mimick the behaviour occurring if an XML error is - // detected later on, report to warning log and have embedding - // application display a dialog. - designerWarning(*errorMessage); - errorMessage->clear(); - return LoadPreCheckFailed; - } - dev->seek(0); - - // Check language unless extension present (Jambi) - if (!language.isEmpty() && !qt_extension(core->extensionManager(), core)) { - if (language.toLower() != QLatin1String("c++")) { - // Jambi?! - *errorMessage = QApplication::translate("Designer", "This file cannot be read because it was created using %1.").arg(language); - return LoadPreCheckFailed; - } - } - - // Version - if (!versionString->isEmpty()) { - const UiVersion version = uiVersion(*versionString); - switch (version.first) { - case 3: - return LoadPreCheckVersion3; - case 4: - break; - default: - *errorMessage = QApplication::translate("Designer", "This file was created using Designer from Qt-%1 and cannot be read.").arg(*versionString); - return LoadPreCheckVersionMismatch; - } - } - return LoadPreCheckOk; -} - QWidget *QDesignerResource::load(QIODevice *dev, QWidget *parentWidget) { - // Run loadPreCheck for version and language - QString errorMessage; - QString version; - switch (loadPrecheck(core(), dev, &errorMessage, &version)) { - case LoadPreCheckFailed: - case LoadPreCheckVersionMismatch: - if (!errorMessage.isEmpty()) - core()->dialogGui()->message(parentWidget->window(), QDesignerDialogGuiInterface::FormLoadFailureMessage, - QMessageBox::Warning, messageBoxTitle(), errorMessage, QMessageBox::Ok); - return 0; - case LoadPreCheckVersion3: { - QWidget *w = 0; - QByteArray ba; - if (runUIC( m_formWindow->fileName(), UIC_ConvertV3, ba, errorMessage)) { - QBuffer buffer(&ba); - buffer.open(QIODevice::ReadOnly); - w = load(&buffer, parentWidget); - if (w) { - // Force the form to pop up a save file dialog - m_formWindow->setFileName(QString()); - } else { - errorMessage = QApplication::translate("Designer", "The converted file could not be read."); - } - } - if (w) { - const QString message = QApplication::translate("Designer", - "This file was created using Designer from Qt-%1 and" - " will be converted to a new form by Qt Designer.").arg(version); - const QString infoMessage = QApplication::translate("Designer", - "The old form has not been touched, but you will have to save the form" - " under a new name."); - - core()->dialogGui()->message(parentWidget->window(), - QDesignerDialogGuiInterface::UiVersionMismatchMessage, - QMessageBox::Information, messageBoxTitle(), message, infoMessage, - QMessageBox::Ok); - return w; - } - - const QString message = QApplication::translate("Designer", - "This file was created using Designer from Qt-%1 and " - "could not be read:\n%2").arg(version).arg(errorMessage); - const QString infoMessage = QApplication::translate("Designer", - "Please run it through uic3 -convert to convert " - "it to Qt-4's ui format."); - core()->dialogGui()->message(parentWidget->window(), QDesignerDialogGuiInterface::FormLoadFailureMessage, - QMessageBox::Warning, messageBoxTitle(), message, infoMessage, - QMessageBox::Ok); - return 0; - } - - case LoadPreCheckOk: - break; - } QWidget *w = QEditorFormBuilder::load(dev, parentWidget); - if (w) // Store the class name as 'reset' value for the main container's object name. + if (w) // Store the class name as 'reset' value for the main container's object name. w->setProperty("_q_classname", w->objectName()); return w; } @@ -1005,7 +843,6 @@ QLayoutItem *QDesignerResource::create(DomLayoutItem *ui_layoutItem, QLayout *la { if (ui_layoutItem->kind() == DomLayoutItem::Spacer) { const DomSpacer *domSpacer = ui_layoutItem->elementSpacer(); - const QHash properties = propertyMap(domSpacer->elementProperty()); Spacer *spacer = static_cast(core()->widgetFactory()->createWidget(QLatin1String("Spacer"), parentWidget)); if (domSpacer->hasAttributeName()) changeObjectName(spacer, domSpacer->attributeName()); @@ -1239,10 +1076,8 @@ DomWidget *QDesignerResource::createDom(QWidget *widget, DomWidget *ui_parentWid if (!item) return 0; - if (qobject_cast(widget) && m_copyWidget == false) { - ++m_topLevelSpacerCount; + if (qobject_cast(widget) && m_copyWidget == false) return 0; - } const QDesignerWidgetDataBaseInterface *wdb = core()->widgetDataBase(); QDesignerWidgetDataBaseItemInterface *widgetInfo = 0; @@ -1453,8 +1288,7 @@ DomWidget *QDesignerResource::saveWidget(QWidget *widget, QDesignerContainerExte if (DomWidget *ui_page = createDom(page, ui_widget)) { ui_widget_list.append(ui_page); } else { - if (QSimpleResource::warningsEnabled()) - designerWarning(msgUnmanagedPage(core(), widget, i, page)); + designerWarning(msgUnmanagedPage(core(), widget, i, page)); } } @@ -1474,8 +1308,7 @@ DomWidget *QDesignerResource::saveWidget(QStackedWidget *widget, DomWidget *ui_p if (DomWidget *ui_page = createDom(page, ui_widget)) { ui_widget_list.append(ui_page); } else { - if (QSimpleResource::warningsEnabled()) - designerWarning(msgUnmanagedPage(core(), widget, i, page)); + designerWarning(msgUnmanagedPage(core(), widget, i, page)); } } } @@ -1572,8 +1405,7 @@ DomWidget *QDesignerResource::saveWidget(QTabWidget *widget, DomWidget *ui_paren DomWidget *ui_page = createDom(page, ui_widget); if (!ui_page) { - if (QSimpleResource::warningsEnabled()) - designerWarning(msgUnmanagedPage(core(), widget, i, page)); + designerWarning(msgUnmanagedPage(core(), widget, i, page)); continue; } QList ui_attribute_list; @@ -1640,8 +1472,7 @@ DomWidget *QDesignerResource::saveWidget(QToolBox *widget, DomWidget *ui_parentW DomWidget *ui_page = createDom(page, ui_widget); if (!ui_page) { - if (QSimpleResource::warningsEnabled()) - designerWarning(msgUnmanagedPage(core(), widget, i, page)); + designerWarning(msgUnmanagedPage(core(), widget, i, page)); continue; } diff --git a/src/designer/src/components/formeditor/qdesigner_resource.h b/src/designer/src/components/formeditor/qdesigner_resource.h index b7113d1..27a1250 100644 --- a/src/designer/src/components/formeditor/qdesigner_resource.h +++ b/src/designer/src/components/formeditor/qdesigner_resource.h @@ -89,7 +89,7 @@ public: bool saveRelative() const; void setSaveRelative(bool relative); - virtual QWidget *load(QIODevice *dev, QWidget *parentWidget = 0); + virtual QWidget *load(QIODevice *dev, QWidget *parentWidget); protected: using QEditorFormBuilder::create; @@ -165,7 +165,6 @@ private: QHash m_qt_to_internal; QStack m_chain; QHash m_usedCustomWidgets; - int m_topLevelSpacerCount; bool m_copyWidget; QWidget *m_selected; class QDesignerResourceBuilder *m_resourceBuilder; diff --git a/src/designer/src/designer/qdesigner_actions.cpp b/src/designer/src/designer/qdesigner_actions.cpp index 3232050..6eddeb9 100644 --- a/src/designer/src/designer/qdesigner_actions.cpp +++ b/src/designer/src/designer/qdesigner_actions.cpp @@ -55,7 +55,6 @@ #include #include #include -#include #include #include #include @@ -845,7 +844,7 @@ static void removeBackup(const QString &backupFile) QFile::remove(backupFile); } -bool QDesignerActions::writeOutForm(QDesignerFormWindowInterface *fw, const QString &saveFile) +bool QDesignerActions::writeOutForm(QDesignerFormWindowInterface *fw, const QString &saveFile, bool check) { Q_ASSERT(fw && !saveFile.isEmpty()); @@ -854,6 +853,12 @@ bool QDesignerActions::writeOutForm(QDesignerFormWindowInterface *fw, const QStr if (fi.exists()) backupFile = createBackup(saveFile); + if (check) { + const QStringList problems = fw->checkContents(); + if (!problems.isEmpty()) + QMessageBox::information(fw->window(), tr("Qt Designer"), problems.join(QLatin1String("
"))); + } + QString contents = fw->contents(); if (qdesigner_internal::FormWindowBase *fwb = qobject_cast(fw)) { if (fwb->lineTerminatorMode() == qdesigner_internal::FormWindowBase::CRLFLineTerminator) @@ -1121,7 +1126,6 @@ void QDesignerActions::backupForms() QStringList tmpFiles; QMap backupMap; QDir backupDir(m_backupPath); - const bool warningsEnabled = qdesigner_internal::QSimpleResource::setWarningsEnabled(false); for (int i = 0; i < count; ++i) { QDesignerFormWindow *fw = m_workbench->formWindow(i); QDesignerFormWindowInterface *fwi = fw->editor(); @@ -1153,7 +1157,6 @@ void QDesignerActions::backupForms() file.close(); } } - qdesigner_internal::QSimpleResource::setWarningsEnabled(warningsEnabled); if(!tmpFiles.isEmpty()) { const QStringList backupFiles = backupDir.entryList(QDir::Files); if(!backupFiles.isEmpty()) { diff --git a/src/designer/src/designer/qdesigner_actions.h b/src/designer/src/designer/qdesigner_actions.h index 910901b..4bd4de9 100644 --- a/src/designer/src/designer/qdesigner_actions.h +++ b/src/designer/src/designer/qdesigner_actions.h @@ -83,7 +83,7 @@ public: bool saveForm(QDesignerFormWindowInterface *fw); bool readInForm(const QString &fileName); - bool writeOutForm(QDesignerFormWindowInterface *formWindow, const QString &fileName); + bool writeOutForm(QDesignerFormWindowInterface *formWindow, const QString &fileName, bool check = true); QActionGroup *fileActions() const; QActionGroup *recentFilesActions() const; diff --git a/src/designer/src/designer/qdesigner_workbench.cpp b/src/designer/src/designer/qdesigner_workbench.cpp index d6c925d..0d64606 100644 --- a/src/designer/src/designer/qdesigner_workbench.cpp +++ b/src/designer/src/designer/qdesigner_workbench.cpp @@ -894,7 +894,6 @@ void QDesignerWorkbench::resizeForm(QDesignerFormWindow *fw, const QWidget *main QDesignerFormWindow * QDesignerWorkbench::loadForm(const QString &fileName, bool detectLineTermiantorMode, - bool *uic3Converted, QString *errorMessage) { QFile file(fileName); @@ -916,11 +915,10 @@ QDesignerFormWindow * QDesignerWorkbench::loadForm(const QString &fileName, } if (!file.open(QFile::ReadOnly|QFile::Text)) { - *errorMessage = tr("The file %1 could not be opened.").arg(file.fileName()); + *errorMessage = tr("The file %1 could not be opened: %1").arg(file.fileName(), file.errorString()); return 0; } - // Create a form QDesignerFormWindowManagerInterface *formWindowManager = m_core->formWindowManager(); @@ -932,7 +930,13 @@ QDesignerFormWindow * QDesignerWorkbench::loadForm(const QString &fileName, // Temporarily set the file name. It is needed when converting a UIC 3 file. // In this case, the file name will we be cleared on return to force a save box. editor->setFileName(fileName); - editor->setContents(&file); + + if (!editor->setContents(&file, errorMessage)) { + removeFormWindow(formWindow); + formWindowManager->removeFormWindow(editor); + m_core->metaDataBase()->remove(editor); + return 0; + } if (qdesigner_internal::FormWindowBase *fwb = qobject_cast(editor)) fwb->setLineTerminatorMode(mode); @@ -958,14 +962,6 @@ QDesignerFormWindow * QDesignerWorkbench::loadForm(const QString &fileName, break; } - if (!editor->mainContainer()) { - removeFormWindow(formWindow); - formWindowManager->removeFormWindow(editor); - m_core->metaDataBase()->remove(editor); - *errorMessage = tr("The file %1 is not a valid Designer UI file.").arg(file.fileName()); - return 0; - } - *uic3Converted = editor->fileName().isEmpty(); // Did user specify another (missing) resource path -> set dirty. const bool dirty = editor->property("_q_resourcepathchanged").toBool(); editor->setDirty(dirty); @@ -977,13 +973,10 @@ QDesignerFormWindow * QDesignerWorkbench::loadForm(const QString &fileName, QDesignerFormWindow * QDesignerWorkbench::openForm(const QString &fileName, QString *errorMessage) { - bool uic3Converted; - QDesignerFormWindow *rc =loadForm(fileName, true, &uic3Converted, errorMessage); + QDesignerFormWindow *rc = loadForm(fileName, true, errorMessage); if (!rc) return 0; - - if (!uic3Converted) - rc->editor()->setFileName(fileName); + rc->editor()->setFileName(fileName); rc->firstShow(); return rc; } @@ -992,14 +985,11 @@ QDesignerFormWindow * QDesignerWorkbench::openTemplate(const QString &templateFi const QString &editorFileName, QString *errorMessage) { - bool uic3Converted; - QDesignerFormWindow *rc =loadForm(templateFileName, false, &uic3Converted, errorMessage); + QDesignerFormWindow *rc = loadForm(templateFileName, false, errorMessage); if (!rc) return 0; - if (!uic3Converted) - rc->editor()->setFileName(editorFileName); - + rc->editor()->setFileName(editorFileName); rc->firstShow(); return rc; } diff --git a/src/designer/src/designer/qdesigner_workbench.h b/src/designer/src/designer/qdesigner_workbench.h index d174baa..edbb12a 100644 --- a/src/designer/src/designer/qdesigner_workbench.h +++ b/src/designer/src/designer/qdesigner_workbench.h @@ -148,7 +148,7 @@ private: QDesignerFormWindowManagerInterface *formWindowManager() const; void closeAllToolWindows(); QDesignerToolWindow *widgetBoxToolWindow() const; - QDesignerFormWindow *loadForm(const QString &fileName, bool detectLineTermiantorMode, bool *uic3Converted, QString *errorMessage); + QDesignerFormWindow *loadForm(const QString &fileName, bool detectLineTermiantorMode, QString *errorMessage); void resizeForm(QDesignerFormWindow *fw, const QWidget *mainContainer) const; void saveGeometriesForModeChange(); void saveGeometries(QDesignerSettings &settings) const; diff --git a/src/designer/src/lib/sdk/abstractformwindow.cpp b/src/designer/src/lib/sdk/abstractformwindow.cpp index 8e37b9f..bba78bf 100644 --- a/src/designer/src/lib/sdk/abstractformwindow.cpp +++ b/src/designer/src/lib/sdk/abstractformwindow.cpp @@ -328,9 +328,21 @@ void QDesignerFormWindowInterface::activateResourceFilePaths(const QStringList & */ /*! - \fn virtual void QDesignerFormWindowInterface::setContents(QIODevice *device) + \fn virtual QStringList QDesignerFormWindowInterface::checkContents() const - Sets the form's contents using data obtained from the given \a device. + Performs checks on the current form and returns a list of richtext warnings + about potential issues (for example, top level spacers on unlaid-out forms). + + IDE integrations can call this before handling starting a save operation. + + \since 5.0 +*/ + +/*! + \fn virtual bool QDesignerFormWindowInterface::setContents(QIODevice *device, QString *errorMessage = 0) + + Sets the form's contents using data obtained from the given \a device and returns whether + loading succeeded. If it fails, the error message is returned in \a errorMessage. Data can be read from QFile objects or any other subclass of QIODevice. */ @@ -742,10 +754,10 @@ void QDesignerFormWindowInterface::activateResourceFilePaths(const QStringList & */ /*! - \fn virtual void QDesignerFormWindowInterface::setContents(const QString &contents) + \fn virtual bool QDesignerFormWindowInterface::setContents(const QString &contents) Sets the contents of the form using data read from the specified - \a contents string. + \a contents string and returns whether the operation succeeded. \sa contents() */ diff --git a/src/designer/src/lib/sdk/abstractformwindow.h b/src/designer/src/lib/sdk/abstractformwindow.h index cf91864..ab0f241 100644 --- a/src/designer/src/lib/sdk/abstractformwindow.h +++ b/src/designer/src/lib/sdk/abstractformwindow.h @@ -85,7 +85,8 @@ public: virtual QDir absoluteDir() const = 0; virtual QString contents() const = 0; - virtual void setContents(QIODevice *dev) = 0; + virtual QStringList checkContents() const = 0; + virtual bool setContents(QIODevice *dev, QString *errorMessage = 0) = 0; virtual Feature features() const = 0; virtual bool hasFeature(Feature f) const = 0; @@ -168,7 +169,7 @@ public Q_SLOTS: virtual void selectWidget(QWidget *w, bool select = true) = 0; virtual void setGrid(const QPoint &grid) = 0; virtual void setFileName(const QString &fileName) = 0; - virtual void setContents(const QString &contents) = 0; + virtual bool setContents(const QString &contents) = 0; virtual void editWidgets() = 0; void activateResourceFilePaths(const QStringList &paths, int *errorCount = 0, QString *errorMessages = 0); diff --git a/src/designer/src/lib/sdk/abstractlanguage.h b/src/designer/src/lib/sdk/abstractlanguage.h index 37c0c5d..8026bad 100644 --- a/src/designer/src/lib/sdk/abstractlanguage.h +++ b/src/designer/src/lib/sdk/abstractlanguage.h @@ -70,6 +70,14 @@ class QDesignerLanguageExtension public: virtual ~QDesignerLanguageExtension() {} + /*! + Returns the name to be matched against the "language" attribute of the element. + + \since 5.0 + */ + + virtual QString name() const = 0; + virtual QDialog *createFormWindowSettingsDialog(QDesignerFormWindowInterface *formWindow, QWidget *parentWidget) = 0; virtual QDesignerResourceBrowserInterface *createResourceBrowser(QWidget *parentWidget) = 0; diff --git a/src/designer/src/lib/shared/codedialog.cpp b/src/designer/src/lib/shared/codedialog.cpp index 2420aa5..f6ea290 100644 --- a/src/designer/src/lib/shared/codedialog.cpp +++ b/src/designer/src/lib/shared/codedialog.cpp @@ -188,7 +188,7 @@ bool CodeDialog::generateCode(const QDesignerFormWindowInterface *fw, tempFormFile.close(); // Run uic QByteArray rc; - if (!runUIC(tempFormFileName, UIC_GenerateCode, rc, *errorMessage)) + if (!runUIC(tempFormFileName, rc, *errorMessage)) return false; *code = QString::fromUtf8(rc); return true; diff --git a/src/designer/src/lib/shared/formwindowbase.cpp b/src/designer/src/lib/shared/formwindowbase.cpp index 83bf057..5875ae9 100644 --- a/src/designer/src/lib/shared/formwindowbase.cpp +++ b/src/designer/src/lib/shared/formwindowbase.cpp @@ -50,8 +50,7 @@ #include "grid_p.h" #include "deviceprofile_p.h" #include "qdesigner_utils_p.h" - -#include "qsimpleresource_p.h" +#include "spacer_widget_p.h" #include #include @@ -487,12 +486,22 @@ void FormWindowBase::triggerDefaultAction(QWidget *widget) QTimer::singleShot(0, action, SIGNAL(triggered())); } -QString FormWindowBase::fileContents() const +QStringList FormWindowBase::checkContents() const { - const bool oldValue = QSimpleResource::setWarningsEnabled(false); - const QString rc = contents(); - QSimpleResource::setWarningsEnabled(oldValue); - return rc; + if (!mainContainer()) + return QStringList(tr("Invalid form")); + // Test for non-laid toplevel spacers, which will not be saved + // as not to throw off uic. + QStringList problems; + foreach (const Spacer *spacer, mainContainer()->findChildren()) { + if (spacer->parentWidget() && !spacer->parentWidget()->layout()) { + problems.push_back(tr("

This file contains top level spacers.
" + "They will not be saved.

" + "Perhaps you forgot to create a layout?

")); + break; + } + } + return problems; } } // namespace qdesigner_internal diff --git a/src/designer/src/lib/shared/formwindowbase_p.h b/src/designer/src/lib/shared/formwindowbase_p.h index 91f6a30..9521d06 100644 --- a/src/designer/src/lib/shared/formwindowbase_p.h +++ b/src/designer/src/lib/shared/formwindowbase_p.h @@ -89,8 +89,7 @@ public: QVariantMap formData(); void setFormData(const QVariantMap &vm); - // Return contents without warnings. Should be 'contents(bool quiet)' - QString fileContents() const; + virtual QStringList checkContents() const; // Deprecated virtual QPoint grid() const; diff --git a/src/designer/src/lib/shared/qdesigner_formbuilder.cpp b/src/designer/src/lib/shared/qdesigner_formbuilder.cpp index 59e32cd..a115147 100644 --- a/src/designer/src/lib/shared/qdesigner_formbuilder.cpp +++ b/src/designer/src/lib/shared/qdesigner_formbuilder.cpp @@ -133,14 +133,6 @@ QString QDesignerFormBuilder::systemStyle() const m_deviceProfile.style(); } -QWidget *QDesignerFormBuilder::createWidgetFromContents(const QString &contents, QWidget *parentWidget) -{ - QByteArray data = contents.toUtf8(); - QBuffer buffer(&data); - buffer.open(QIODevice::ReadOnly); - return load(&buffer, parentWidget); -} - QWidget *QDesignerFormBuilder::create(DomUI *ui, QWidget *parentWidget) { m_mainWidget = true; @@ -383,9 +375,7 @@ QWidget *QDesignerFormBuilder::createPreview(const QDesignerFormWindowInterface QDesignerFormBuilder builder(fw->core(), EnableScripts, deviceProfile); builder.setWorkingDirectory(fw->absoluteDir()); - const bool warningsEnabled = QSimpleResource::setWarningsEnabled(false); QByteArray bytes = fw->contents().toUtf8(); - QSimpleResource::setWarningsEnabled(warningsEnabled); QBuffer buffer(&bytes); buffer.open(QIODevice::ReadOnly); diff --git a/src/designer/src/lib/shared/qdesigner_formbuilder_p.h b/src/designer/src/lib/shared/qdesigner_formbuilder_p.h index 2f902e3..9595d20 100644 --- a/src/designer/src/lib/shared/qdesigner_formbuilder_p.h +++ b/src/designer/src/lib/shared/qdesigner_formbuilder_p.h @@ -90,8 +90,6 @@ public: Mode mode, const DeviceProfile &deviceProfile = DeviceProfile()); - QWidget *createWidgetFromContents(const QString &contents, QWidget *parentWidget = 0); - virtual QWidget *createWidget(DomWidget *ui_widget, QWidget *parentWidget = 0) { return QFormBuilder::create(ui_widget, parentWidget); } diff --git a/src/designer/src/lib/shared/qdesigner_utils.cpp b/src/designer/src/lib/shared/qdesigner_utils.cpp index 5f0a685..a7c11bd 100644 --- a/src/designer/src/lib/shared/qdesigner_utils.cpp +++ b/src/designer/src/lib/shared/qdesigner_utils.cpp @@ -774,23 +774,11 @@ namespace qdesigner_internal return action; } - QDESIGNER_SHARED_EXPORT bool runUIC(const QString &fileName, UIC_Mode mode, QByteArray& ba, QString &errorMessage) + QDESIGNER_SHARED_EXPORT bool runUIC(const QString &fileName, QByteArray& ba, QString &errorMessage) { - QStringList argv; - QString binary = QLibraryInfo::location(QLibraryInfo::BinariesPath); - binary += QDir::separator(); - switch (mode) { - case UIC_GenerateCode: - binary += QLatin1String("uic"); - break; - case UIC_ConvertV3: - binary += QLatin1String("uic3"); - argv += QLatin1String("-convert"); - break; - } - argv += fileName; + const QString binary = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/uic"); QProcess uic; - uic.start(binary, argv); + uic.start(binary, QStringList(fileName)); if (!uic.waitForStarted()) { errorMessage = QApplication::translate("Designer", "Unable to launch %1.").arg(binary); return false; diff --git a/src/designer/src/lib/shared/qdesigner_utils_p.h b/src/designer/src/lib/shared/qdesigner_utils_p.h index 1e48cf8..1c915e0 100644 --- a/src/designer/src/lib/shared/qdesigner_utils_p.h +++ b/src/designer/src/lib/shared/qdesigner_utils_p.h @@ -424,8 +424,7 @@ QDESIGNER_SHARED_EXPORT QDesignerFormWindowCommand *createTextPropertyCommand(co QDESIGNER_SHARED_EXPORT QAction *preferredEditAction(QDesignerFormEditorInterface *core, QWidget *managedWidget); // Convenience to run UIC -enum UIC_Mode { UIC_GenerateCode, UIC_ConvertV3 }; -QDESIGNER_SHARED_EXPORT bool runUIC(const QString &fileName, UIC_Mode mode, QByteArray& ba, QString &errorMessage); +QDESIGNER_SHARED_EXPORT bool runUIC(const QString &fileName, QByteArray& ba, QString &errorMessage); // Find a suitable variable name for a class. QDESIGNER_SHARED_EXPORT QString qtify(const QString &name); diff --git a/src/designer/src/lib/shared/qsimpleresource.cpp b/src/designer/src/lib/shared/qsimpleresource.cpp index 48c74b8..cced595 100644 --- a/src/designer/src/lib/shared/qsimpleresource.cpp +++ b/src/designer/src/lib/shared/qsimpleresource.cpp @@ -216,18 +216,6 @@ QString QSimpleResource::customWidgetScript(QDesignerFormEditorInterface *, cons return QString(); } -bool QSimpleResource::setWarningsEnabled(bool warningsEnabled) -{ - const bool rc = m_warningsEnabled; - m_warningsEnabled = warningsEnabled; - return rc; -} - -bool QSimpleResource::warningsEnabled() -{ - return m_warningsEnabled; -} - // Custom widgets handling helpers // Add unique fake slots and signals to lists diff --git a/src/designer/src/lib/shared/qsimpleresource_p.h b/src/designer/src/lib/shared/qsimpleresource_p.h index b4f85bd..e8f4f3f 100644 --- a/src/designer/src/lib/shared/qsimpleresource_p.h +++ b/src/designer/src/lib/shared/qsimpleresource_p.h @@ -90,9 +90,6 @@ public: 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); -- 2.7.4