widgetfactory.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 493 行 · 第 1/2 页
CPP
493 行
/******************************************************************************** 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.******************************************************************************//*TRANSLATOR qdesigner_internal::WidgetFactory*/#include "widgetfactory_p.h"#include "widgetdatabase_p.h"#include "metadatabase_p.h"#include "qlayout_widget_p.h"#include "qdesigner_widget_p.h"#include "qdesigner_tabwidget_p.h"#include "qdesigner_toolbox_p.h"#include "qdesigner_stackedbox_p.h"#include "qdesigner_toolbar_p.h"#include "qdesigner_menubar_p.h"#include "qdesigner_menu_p.h"#include "qdesigner_dockwidget_p.h"#include "qdesigner_utils_p.h"#include "abstractformwindow.h"// shared#include "layoutinfo_p.h"#include "spacer_widget_p.h"#include "layout_p.h"// sdk#include <QtDesigner/QDesignerFormEditorInterface>#include <QtDesigner/QDesignerContainerExtension>#include <QtDesigner/QDesignerCustomWidgetInterface>#include <QtDesigner/QExtensionManager>#include <QtDesigner/QDesignerPropertySheetExtension>#include <QtDesigner/QDesignerLanguageExtension>#include <QtGui/QtGui>#include <QtCore/qdebug.h>namespace qdesigner_internal {QPointer<QWidget> *WidgetFactory::m_lastPassiveInteractor = new QPointer<QWidget>();bool WidgetFactory::m_lastWasAPassiveInteractor = false;WidgetFactory::WidgetFactory(QDesignerFormEditorInterface *core, QObject *parent) : QDesignerWidgetFactoryInterface(parent), m_core(core), m_formWindow(0){}WidgetFactory::~WidgetFactory(){}QDesignerFormWindowInterface *WidgetFactory::currentFormWindow(QDesignerFormWindowInterface *fw){ QDesignerFormWindowInterface *was = m_formWindow; m_formWindow = fw; return was;}void WidgetFactory::loadPlugins(){ m_customFactory.clear(); QDesignerPluginManager *pluginManager = m_core->pluginManager(); QList<QDesignerCustomWidgetInterface*> lst = pluginManager->registeredCustomWidgets(); foreach (QDesignerCustomWidgetInterface *c, lst) { m_customFactory.insert(c->name(), c); }}// Convencience to create non-widget objects. Returns 0 if unknownQObject* WidgetFactory::createObject(const QString &className, QObject* parent) const{ if (className == QLatin1String("QAction")) return new QAction(parent); return 0;}QWidget* WidgetFactory::createCustomWidget(const QString &className, QWidget *parentWidget) const{ CustomWidgetFactoryMap::const_iterator it = m_customFactory.constFind(className); if (it == m_customFactory.constEnd()) return 0; QDesignerCustomWidgetInterface *factory = it.value(); QWidget *rc = factory->createWidget(parentWidget); // shouldn't happen if (!rc) { designerWarning(QObject::tr("The custom widget factory registered for widgets of class %1 returned 0.").arg(className)); return 0; } // Since a language plugin may lie about its names, like Qt Jambi // does, return immediatly here... QDesignerLanguageExtension *lang = qt_extension<QDesignerLanguageExtension *>(m_core->extensionManager(), m_core); if (lang) return rc; // Check for mismatched class names which is hard to track. // Perform literal comparison first for QAxWidget, for which a meta object hack is in effect. const char *createdClassNameC = rc->metaObject()->className(); const QByteArray classNameB = className.toUtf8(); const char *classNameC = classNameB.constData(); if (qstrcmp(createdClassNameC, classNameC) && !rc->inherits(classNameC)) designerWarning(QObject::tr("A class name mismatch occurred when creating a widget using the custom widget factory registered for widgets of class %1." " It returned a widget of class %2.").arg(className).arg(QString::fromUtf8(createdClassNameC))); return rc;}QWidget *WidgetFactory::createWidget(const QString &widgetName, QWidget *parentWidget) const{ QDesignerFormWindowInterface *fw = m_formWindow; if (! fw) fw = QDesignerFormWindowInterface::findFormWindow(parentWidget); QWidget *w = createCustomWidget(widgetName, parentWidget); if (w) { } else if (widgetName == QLatin1String("Line")) { w = new Line(parentWidget); } else if (widgetName == QLatin1String("QDockWidget")) { w = new QDesignerDockWidget(parentWidget); } else if (widgetName == QLatin1String("QTabWidget")) { w = new QDesignerTabWidget(parentWidget); } else if (widgetName == QLatin1String("QStackedWidget")) { w = new QDesignerStackedWidget(parentWidget); } else if (widgetName == QLatin1String("QToolBox")) { w = new QDesignerToolBox(parentWidget); } else if (widgetName == QLatin1String("QToolBar")) { QToolBar *tb = new QToolBar(parentWidget); w = tb; ToolBarEventFilter::install(tb); } else if (widgetName == QLatin1String("QMenuBar")) { w = new QDesignerMenuBar(parentWidget); } else if (widgetName == QLatin1String("QMenu")) { w = new QDesignerMenu(parentWidget); } else if (widgetName == QLatin1String("Spacer")) { w = new Spacer(parentWidget); } else if (widgetName == QLatin1String("QDockWidget")) { w = new QDesignerDockWidget(parentWidget); } else if (widgetName == QLatin1String("QLayoutWidget")) { w = fw ? new QLayoutWidget(fw, parentWidget) : new QWidget(parentWidget); } else if (widgetName == QLatin1String("QDialog")) { if (fw) { w = new QDesignerDialog(fw, parentWidget); } else { w = new QDialog(parentWidget); } } else if (widgetName == QLatin1String("QWidget")) { if (fw && parentWidget && (qobject_cast<QDesignerFormWindowInterface*>(parentWidget) || qt_extension<QDesignerContainerExtension*>(m_core->extensionManager(), parentWidget))) { w = new QDesignerWidget(fw, parentWidget); } else { w = new QWidget(parentWidget); } }#define DECLARE_LAYOUT(L, C)#define DECLARE_COMPAT_WIDGET(W, C) /*DECLARE_WIDGET(W, C)*/#define DECLARE_WIDGET(W, C) else if (widgetName == QLatin1String(#W)) { Q_ASSERT(w == 0); w = new W(parentWidget); }#define DECLARE_WIDGET_1(W, C) else if (widgetName == QLatin1String(#W)) { Q_ASSERT(w == 0); w = new W(0, parentWidget); }#include "widgets.table"#undef DECLARE_COMPAT_WIDGET#undef DECLARE_LAYOUT#undef DECLARE_WIDGET#undef DECLARE_WIDGET_1 if (w == 0) { const QLatin1String fallBackBaseClass("QWidget"); QDesignerWidgetDataBaseInterface *db = core()->widgetDataBase(); QDesignerWidgetDataBaseItemInterface *item = db->item(db->indexOfClassName(widgetName)); if (item == 0) { // Emergency: Create, derived from QWidget QString includeFile = widgetName.toLower(); includeFile += QLatin1String(".h"); item = appendDerived(db,widgetName,tr("%1 Widget").arg(widgetName),fallBackBaseClass, includeFile, true, true); Q_ASSERT(item); } QString baseClass = item->extends(); if (baseClass.isEmpty()) { // Currently happens in the case of Q3-Support widgets baseClass =fallBackBaseClass; } w = createWidget(baseClass, parentWidget); promoteWidget(core(),w,widgetName); } Q_ASSERT(w != 0); if (fw != 0) initialize(w); return w;}QString WidgetFactory::classNameOf(QDesignerFormEditorInterface *c, QObject* o){ if (o == 0) return QString(); // check promoted before designer special if (o->isWidgetType()) { const QString customClassName = promotedCustomClassName(c,qobject_cast<QWidget*>(o)); if (!customClassName.isEmpty()) return customClassName;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?