qdesigner_resource.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 1,680 行 · 第 1/5 页
CPP
1,680 行
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the Qt Designer of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qdesigner_resource.h"#include "formwindow.h"#include "dynamicpropertysheet.h"#include "qdesigner_tabwidget_p.h"#include "qdesigner_toolbox_p.h"#include "qdesigner_stackedbox_p.h"#include "qdesigner_toolbar_p.h"#include "qdesigner_dockwidget_p.h"#include "qdesigner_menu_p.h"#include "qdesigner_menubar_p.h"#include <ui4_p.h>#include <formbuilderextra_p.h>// shared#include <widgetdatabase_p.h>#include <metadatabase_p.h>#include <layout_p.h>#include <layoutinfo_p.h>#include <spacer_widget_p.h>#include <resourcefile_p.h>#include <pluginmanager_p.h>#include <widgetfactory_p.h>#include <abstractlanguage.h>#include <qlayout_widget_p.h>#include <qdesigner_utils_p.h>#include <ui4_p.h>// sdk#include <QtDesigner/QDesignerPropertySheetExtension>#include <QtDesigner/QDesignerFormEditorInterface>#include <QtDesigner/QDesignerExtraInfoExtension>#include <QtDesigner/QDesignerFormWindowToolInterface>#include <QtDesigner/QExtensionManager>#include <QtDesigner/QDesignerContainerExtension>#include <QtGui/QMenu>#include <QtGui/QMessageBox>#include <QtGui/QLayout>#include <QtGui/QTabWidget>#include <QtGui/QToolBox>#include <QtGui/QToolBar>#include <QtGui/QTabBar>#include <QtGui/QAction>#include <QtGui/QActionGroup>#include <QtGui/QApplication>#include <QtGui/QMainWindow>#include <QtGui/QSplitter>#include <QtGui/QMenuBar>#include <QtGui/QFileDialog>#include <QtCore/QBuffer>#include <QtCore/QDir>#include <QtCore/QMetaProperty>#include <QtCore/qdebug.h>#include <QtXml/QDomDocument>Q_DECLARE_METATYPE(QWidgetList)namespace { typedef QList<DomProperty*> DomPropertyList;}namespace qdesigner_internal {QDesignerResource::QDesignerResource(FormWindow *formWindow) : QSimpleResource(formWindow->core()), m_formWindow(formWindow){ setWorkingDirectory(formWindow->absoluteDir()); m_topLevelSpacerCount = 0; m_copyWidget = false; m_selected = 0; // ### generalise const QString designerWidget = QLatin1String("QDesignerWidget"); const QString layoutWidget = QLatin1String("QLayoutWidget"); const QString widget = QLatin1String("QWidget"); m_internal_to_qt.insert(layoutWidget, widget); m_internal_to_qt.insert(designerWidget, widget); m_internal_to_qt.insert(QLatin1String("QDesignerStackedWidget"), QLatin1String("QStackedWidget")); m_internal_to_qt.insert(QLatin1String("QDesignerTabWidget"), QLatin1String("QTabWidget")); m_internal_to_qt.insert(QLatin1String("QDesignerDialog"), QLatin1String("QDialog")); m_internal_to_qt.insert(QLatin1String("QDesignerToolBox"), QLatin1String("QToolBox")); m_internal_to_qt.insert(QLatin1String("QDesignerMenuBar"), QLatin1String("QMenuBar")); m_internal_to_qt.insert(QLatin1String("QDesignerMenu"), QLatin1String("QMenu")); m_internal_to_qt.insert(QLatin1String("QDesignerDockWidget"), QLatin1String("QDockWidget")); m_internal_to_qt.insert(QLatin1String("QDesignerQ3WidgetStack"), QLatin1String("Q3WidgetStack")); // invert QHash<QString, QString>::const_iterator cend = m_internal_to_qt.constEnd(); for (QHash<QString, QString>::const_iterator it = m_internal_to_qt.constBegin();it != cend; ++it ) { if (it.value() != designerWidget && it.value() != layoutWidget) m_qt_to_internal.insert(it.value(), it.key()); }}QDesignerResource::~QDesignerResource(){}void QDesignerResource::save(QIODevice *dev, QWidget *widget){ m_topLevelSpacerCount = 0; QAbstractFormBuilder::save(dev, widget); if (QSimpleResource::warningsEnabled() && m_topLevelSpacerCount != 0) { QMessageBox::warning(widget->window(), QApplication::translate("Designer", "Qt Designer"), QApplication::translate("Designer", "This file contains top level spacers.<br>" "They have <b>NOT</b> been saved into the form.<br>" "Perhaps you forgot to create a layout?"), QMessageBox::Ok, 0); }}void QDesignerResource::saveDom(DomUI *ui, QWidget *widget){ QAbstractFormBuilder::saveDom(ui, widget); QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), widget); Q_ASSERT(sheet != 0); ui->setElementClass(sheet->property(sheet->indexOf(QLatin1String("objectName"))).toString()); for (int index = 0; index < m_formWindow->toolCount(); ++index) { QDesignerFormWindowToolInterface *tool = m_formWindow->tool(index); Q_ASSERT(tool != 0); tool->saveToDom(ui, widget); } const QString author = m_formWindow->author(); if (!author.isEmpty()) { ui->setElementAuthor(author); } const QString comment = m_formWindow->comment(); if (!comment.isEmpty()) { ui->setElementComment(comment); } const QString exportMacro = m_formWindow->exportMacro(); if (!exportMacro.isEmpty()) { ui->setElementExportMacro(exportMacro); } const QVariantMap designerFormData = m_formWindow->formData(); if (!designerFormData.empty()) { DomPropertyList domPropertyList; const QVariantMap::const_iterator cend = designerFormData.constEnd(); for (QVariantMap::const_iterator it = designerFormData.constBegin(); it != cend; ++it) { if (DomProperty *prop = variantToDomProperty(this, widget, it.key(), it.value())) domPropertyList += prop; } if (!domPropertyList.empty()) { DomDesignerData* domDesignerFormData = new DomDesignerData; domDesignerFormData->setElementProperty(domPropertyList); ui->setElementDesignerdata(domDesignerFormData); } } if (!m_formWindow->includeHints().isEmpty()) { const QString local = QLatin1String("local"); const QString global = QLatin1String("global"); QList<DomInclude*> ui_includes; foreach (QString includeHint, m_formWindow->includeHints()) { if (includeHint.isEmpty()) continue; DomInclude *incl = new DomInclude; const QString location = includeHint.at(0) == QLatin1Char('<') ? global : local; includeHint.remove(QLatin1Char('"')); includeHint.remove(QLatin1Char('<')); includeHint.remove(QLatin1Char('>')); incl->setAttributeLocation(location); incl->setText(includeHint); ui_includes.append(incl); } DomIncludes *includes = new DomIncludes; includes->setElementInclude(ui_includes); ui->setElementIncludes(includes); } int defaultMargin = INT_MIN, defaultSpacing = INT_MIN; m_formWindow->layoutDefault(&defaultMargin, &defaultSpacing); if (defaultMargin != INT_MIN || defaultSpacing != INT_MIN) { DomLayoutDefault *def = new DomLayoutDefault; if (defaultMargin != INT_MIN) def->setAttributeMargin(defaultMargin); if (defaultSpacing != INT_MIN) def->setAttributeSpacing(defaultSpacing); ui->setElementLayoutDefault(def); } QString marginFunction, spacingFunction; m_formWindow->layoutFunction(&marginFunction, &spacingFunction); if (!marginFunction.isEmpty() || !spacingFunction.isEmpty()) { DomLayoutFunction *def = new DomLayoutFunction; if (!marginFunction.isEmpty()) def->setAttributeMargin(marginFunction); if (!spacingFunction.isEmpty()) def->setAttributeSpacing(spacingFunction); ui->setElementLayoutFunction(def); } QString pixFunction = m_formWindow->pixmapFunction(); if (!pixFunction.isEmpty()) { ui->setElementPixmapFunction(pixFunction); } if (QDesignerExtraInfoExtension *extra = qt_extension<QDesignerExtraInfoExtension*>(core()->extensionManager(), core())) extra->saveUiExtraInfo(ui);}namespace { enum LoadPreCheck { LoadPreCheckFailed, LoadPreCheckVersion3, LoadPreCheckVersionMismatch, LoadPreCheckOk }; // Pair of major, minor typedef QPair<int, int> 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;}// While loading a file, check language, version and extra extensionstatic LoadPreCheck loadPrecheck(QDesignerFormEditorInterface *core, DomUI *ui, QString &errorMessage){ // Check language unless extension present (Jambi) if (ui->hasAttributeLanguage() && !qt_extension<QDesignerLanguageExtension*>(core->extensionManager(), core)) { const QString language = ui->attributeLanguage(); 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 (ui->hasAttributeVersion()) { const QString versionString = ui->attributeVersion(); 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; } } // Load extra if (QDesignerExtraInfoExtension *extra = qt_extension<QDesignerExtraInfoExtension*>(core->extensionManager(), core)) { if (!extra->loadUiExtraInfo(ui)) { errorMessage = QApplication::translate("Designer", "This file cannot be read because the extra info extension failed to load."); return LoadPreCheckFailed; } } return LoadPreCheckOk;}QWidget *QDesignerResource::create(DomUI *ui, QWidget *parentWidget){ QString errorMessage; switch (loadPrecheck(core(), ui, errorMessage)) { case LoadPreCheckFailed: case LoadPreCheckVersionMismatch: QMessageBox::warning(parentWidget->window(), QApplication::translate("Designer", "Qt Designer"), errorMessage, QMessageBox::Ok, 0); return 0; case LoadPreCheckVersion3: { const QString version = ui->attributeVersion(); QWidget *w = 0; QByteArray ba; if (runUIC( m_formWindow->fileName(), UIC_ConvertV3, ba, errorMessage)) { QBuffer buffer(&ba); w = load(&buffer, parentWidget); if (w) { // Force the form to pop up a save file dialog
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?