formbuilder.cpp

来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 515 行 · 第 1/2 页

CPP
515
字号
{    return QAbstractFormBuilder::addItem(ui_item, item, layout);}/*!    \internal*/bool QFormBuilder::addItem(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget){    return QAbstractFormBuilder::addItem(ui_widget, widget, parentWidget);}/*!    \internal*/QWidget *QFormBuilder::widgetByName(QWidget *topLevel, const QString &name){    Q_ASSERT(topLevel);    if (topLevel->objectName() == name)        return topLevel;    return qFindChild<QWidget*>(topLevel, name);}static QObject *objectByName(QWidget *topLevel, const QString &name){    Q_ASSERT(topLevel);    if (topLevel->objectName() == name)        return topLevel;    return qFindChild<QObject*>(topLevel, name);}/*!    \internal*/void QFormBuilder::createConnections(DomConnections *ui_connections, QWidget *widget){    typedef QList<DomConnection*> DomConnectionList;    Q_ASSERT(widget != 0);    if (ui_connections == 0)        return;    const DomConnectionList connections = ui_connections->elementConnection();    if (!connections.empty()) {        const DomConnectionList::const_iterator cend = connections.constEnd();        for (DomConnectionList::const_iterator it = connections.constBegin(); it != cend; ++it) {            QObject *sender = objectByName(widget, (*it)->elementSender());            QObject *receiver = objectByName(widget, (*it)->elementReceiver());            if (!sender || !receiver)                continue;            QByteArray sig = (*it)->elementSignal().toUtf8();            sig.prepend("2");            QByteArray sl = (*it)->elementSlot().toUtf8();            sl.prepend("1");            QObject::connect(sender, sig, receiver, sl);        }    }}/*!    \internal*/QWidget *QFormBuilder::create(DomUI *ui, QWidget *parentWidget){    return QAbstractFormBuilder::create(ui, parentWidget);}/*!    \internal*/QLayout *QFormBuilder::create(DomLayout *ui_layout, QLayout *layout, QWidget *parentWidget){    bool layoutWidget = QFormBuilderExtra::instance(this)->processingLayoutWidget();    QLayout *l = QAbstractFormBuilder::create(ui_layout, layout, parentWidget);    if (layoutWidget) {        int left, top, right, bottom;        left = top = right = bottom = 0;        const DomPropertyHash properties = propertyMap(ui_layout->elementProperty());        if (DomProperty *prop = properties.value(QLatin1String("leftMargin")))            left = prop->elementNumber();        if (DomProperty *prop = properties.value(QLatin1String("topMargin")))            top = prop->elementNumber();        if (DomProperty *prop = properties.value(QLatin1String("rightMargin")))            right = prop->elementNumber();        if (DomProperty *prop = properties.value(QLatin1String("bottomMargin")))            bottom = prop->elementNumber();        l->setContentsMargins(left, top, right, bottom);        QFormBuilderExtra::instance(this)->setProcessingLayoutWidget(false);    }    return l;}/*!    \internal*/QLayoutItem *QFormBuilder::create(DomLayoutItem *ui_layoutItem, QLayout *layout, QWidget *parentWidget){    return QAbstractFormBuilder::create(ui_layoutItem, layout, parentWidget);}/*!    \internal*/QAction *QFormBuilder::create(DomAction *ui_action, QObject *parent){    return QAbstractFormBuilder::create(ui_action, parent);}/*!    \internal*/QActionGroup *QFormBuilder::create(DomActionGroup *ui_action_group, QObject *parent){    return QAbstractFormBuilder::create(ui_action_group, parent);}/*!    Returns the list of paths the form builder searches for plugins.    \sa addPluginPath()*/QStringList QFormBuilder::pluginPaths() const{    return m_pluginPaths;}/*!    Clears the list of paths that the form builder uses to search for    custom widget plugins.    \sa pluginPaths()*/void QFormBuilder::clearPluginPaths(){    m_pluginPaths.clear();    updateCustomWidgets();}/*!    Adds a new plugin path specified by \a pluginPath to the list of    paths that will be searched by the form builder when loading a    custom widget plugin.    \sa setPluginPath(), clearPluginPaths()*/void QFormBuilder::addPluginPath(const QString &pluginPath){    m_pluginPaths.append(pluginPath);    updateCustomWidgets();}/*!    Sets the list of plugin paths to the list specified by \a pluginPaths.    \sa addPluginPath()*/void QFormBuilder::setPluginPath(const QStringList &pluginPaths){    m_pluginPaths = pluginPaths;    updateCustomWidgets();}/*!    \internal*/void QFormBuilder::updateCustomWidgets(){    m_customWidgets.clear();    foreach (QString path, m_pluginPaths) {        const QDir dir(path);        const QStringList candidates = dir.entryList(QDir::Files);        foreach (QString plugin, candidates) {            if (!QLibrary::isLibrary(plugin))                continue;            QString loaderPath = path;            loaderPath += QLatin1Char('/');            loaderPath += plugin;            QPluginLoader loader(loaderPath);            if (loader.load()) {                // step 1) try with a normal plugin                QDesignerCustomWidgetInterface *iface = qobject_cast<QDesignerCustomWidgetInterface *>(loader.instance());                if (iface != 0) {                    m_customWidgets.insert(iface->name(), iface);                    continue;                }                // step 2) try with a collection of plugins                QDesignerCustomWidgetCollectionInterface *c = qobject_cast<QDesignerCustomWidgetCollectionInterface *>(loader.instance());                if (c != 0) {                    foreach (QDesignerCustomWidgetInterface *iface, c->customWidgets()) {                        m_customWidgets.insert(iface->name(), iface);                    }                }            }        }    }}/*!    \fn QList<QDesignerCustomWidgetInterface*> QFormBuilder::customWidgets() const    Returns a list of the available plugins.*/QList<QDesignerCustomWidgetInterface*> QFormBuilder::customWidgets() const{    return m_customWidgets.values();}/*!    \internal*/void QFormBuilder::applyProperties(QObject *o, const QList<DomProperty*> &properties){    typedef QList<DomProperty*> DomPropertyList;    if (properties.empty())        return;    QFormBuilderExtra *fb = QFormBuilderExtra::instance(this);    const DomPropertyList::const_iterator cend = properties.constEnd();    for (DomPropertyList::const_iterator it = properties.constBegin(); it != cend; ++it) {        const QVariant v = toVariant(o->metaObject(), *it);        if (v.isNull())            continue;        const QString attributeName = (*it)->attributeName();        if (o == fb->rootWidget() && attributeName == QLatin1String("geometry")) {            // apply only the size for the rootWidget            fb->rootWidget()->resize(qvariant_cast<QRect>(v).size());        } else if (fb->applyPropertyInternally(o, attributeName, v)) {        } else if (!qstrcmp("QFrame", o->metaObject()->className ()) && attributeName == QLatin1String("orientation")) {            // ### special-casing for Line (QFrame) -- try to fix me            o->setProperty("frameShape", v); // v is of QFrame::Shape enum        } else {            o->setProperty(attributeName.toUtf8(), v);        }    }}#ifdef QFORMINTERNAL_NAMESPACE} // namespace QFormInternal#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?