qdesigner_resource.cpp

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

CPP
1,680
字号
    m_isMainWidget = false;    QList<QWidget*> createdWidgets;    DomWidget *topLevel = ui->elementWidget();    QList<DomWidget*> widgets = topLevel->elementWidget();    for (int i=0; i<widgets.size(); ++i) {        QWidget *w = create(widgets.at(i), parentWidget);        if (!w)            continue;        w->move(w->pos() + m_formWindow->grid());        // ### change the init properties of w        createdWidgets.append(w);    }    m_isMainWidget = saved;    if (QDesignerExtraInfoExtension *extra = qt_extension<QDesignerExtraInfoExtension*>(core()->extensionManager(), core()))        extra->loadUiExtraInfo(ui);    return createdWidgets;}QList<QWidget*> QDesignerResource::paste(QIODevice *dev, QWidget *parentWidget){    QDomDocument doc;    if (!doc.setContent(dev))        return QList<QWidget*>();    QDomElement root = doc.firstChildElement();    DomUI ui;    ui.read(root);    return paste(&ui, parentWidget);}void QDesignerResource::layoutInfo(DomLayout *layout, QObject *parent, int *margin, int *spacing){    QAbstractFormBuilder::layoutInfo(layout, parent, margin, spacing);}QString QDesignerResource::qtify(const QString &name){    QString qname = name;    if (qname.count() > 1 && qname.at(1).toUpper() == qname.at(1) && (qname.at(0) == QLatin1Char('Q') || qname.at(0) == QLatin1Char('K')))        qname = qname.mid(1);    int i=0;    while (i < qname.length()) {        if (i == 0 && qname.at(i).isDigit()) {            qname = qname.mid(1);        } else {            if (qname.at(i).toLower() != qname.at(i))                qname[i] = qname.at(i).toLower();            else                break;            ++i;        }    }    return qname;}DomCustomWidgets *QDesignerResource::saveCustomWidgets(){    if (m_usedCustomWidgets.isEmpty())        return 0;    // We would like the list to be in order of the widget database indexes     // to ensure that base classes come first (nice optics)    QDesignerFormEditorInterface *core = m_formWindow->core();    QDesignerWidgetDataBaseInterface *db = core->widgetDataBase();    typedef QMap<int,DomCustomWidget*>  OrderedDBIndexDomCustomWidgetMap;    OrderedDBIndexDomCustomWidgetMap orderedMap;    const QString global = QLatin1String("global");    foreach (QDesignerWidgetDataBaseItemInterface *item, m_usedCustomWidgets.keys()) {        const QString name = item->name();        DomCustomWidget *custom_widget = new DomCustomWidget;        custom_widget->setElementClass(name);        if (item->isContainer())            custom_widget->setElementContainer(item->isContainer());        if (!item->includeFile().isEmpty()) {            DomHeader *header = new DomHeader;            const  IncludeSpecification spec = includeSpecification(item->includeFile());            header->setText(spec.first);            if (spec.second == IncludeGlobal) {                header->setAttributeLocation(global);            }            custom_widget->setElementHeader(header);            custom_widget->setElementExtends(item->extends());        }        // Look up static per-class scripts of designer        if (DomScript *domScript = createScript( customWidgetScript(core, name), ScriptCustomWidgetPlugin))            custom_widget->setElementScript(domScript);        orderedMap.insert(db->indexOfClassName(name), custom_widget);    }    DomCustomWidgets *customWidgets = new DomCustomWidgets;    customWidgets->setElementCustomWidget(orderedMap.values());    return customWidgets;}QList<DomProperty*> QDesignerResource::computeProperties(QObject *object){    QList<DomProperty*> properties;    if (QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), object)) {        QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core()->extensionManager(), object);        for (int index = 0; index < sheet->count(); ++index) {            const QString propertyName = sheet->propertyName(index);            QVariant value = sheet->property(index);            if (!sheet->isChanged(index) && (!dynamicSheet || !dynamicSheet->isDynamicProperty(index)))                continue;            if (DomProperty *p = createProperty(object, propertyName, value)) {                if (p->kind() == DomProperty::String) {                    const QString property_comment = propertyComment(m_formWindow->core(), object, propertyName);                    if (!property_comment.isEmpty())                        p->elementString()->setAttributeComment(property_comment);                }                properties.append(p);            }        }    }    return properties;}DomProperty *QDesignerResource::applyProperStdSetAttribute(QObject *object, const QString &propertyName, DomProperty *property){    if (!property)        return 0;    QExtensionManager *mgr = core()->extensionManager();    if (QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(mgr, object)) {        QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(mgr, object);        if (dynamicSheet && dynamicSheet->isDynamicProperty(sheet->indexOf(propertyName)))            property->setAttributeStdset(0);    }    return property;}DomProperty *QDesignerResource::createProperty(QObject *object, const QString &propertyName, const QVariant &value){    if (!checkProperty(object, propertyName)) {        return 0;    }    if (qVariantCanConvert<EnumType>(value)) {        const EnumType e = qvariant_cast<EnumType>(value);        const QString id = e.id();        if (id.isEmpty())            return 0;        DomProperty *p = new DomProperty;        // check if we have a standard cpp set function        const QMetaObject *meta = object->metaObject();        const int pindex = meta->indexOfProperty(propertyName.toLatin1());        if (pindex != -1) {            const QMetaProperty meta_property = meta->property(pindex);            if (!meta_property.hasStdCppSet())                p->setAttributeStdset(0);        }        p->setAttributeName(propertyName);        p->setElementEnum(id);        return applyProperStdSetAttribute(object, propertyName, p);    } else if (qVariantCanConvert<FlagType>(value)) {        const FlagType f = qvariant_cast<FlagType>(value);        const QString flagString = f.flagString();        if (flagString.isEmpty())            return 0;        DomProperty *p = new DomProperty;        // check if we have a standard cpp set function        const QMetaObject *meta = object->metaObject();        const int pindex = meta->indexOfProperty(propertyName.toLatin1());        if (pindex != -1) {            const QMetaProperty meta_property = meta->property(pindex);            if (!meta_property.hasStdCppSet())                p->setAttributeStdset(0);        }        p->setAttributeName(propertyName);        p->setElementSet(flagString);        return applyProperStdSetAttribute(object, propertyName, p);    }    return applyProperStdSetAttribute(object, propertyName, QAbstractFormBuilder::createProperty(object, propertyName, value));}void QDesignerResource::createResources(DomResources *resources){    if (resources == 0)        return;    const QList<DomResource*> dom_include = resources->elementInclude();    foreach (DomResource *res, dom_include) {        QString path = m_formWindow->absoluteDir().absoluteFilePath(res->attributeLocation());        while (!QFile::exists(path)) {            const QMessageBox::StandardButton answer =                 QMessageBox::warning(m_formWindow->core()->topLevel(), QApplication::translate("qdesigner_internal::QDesignerResource",                "Loading qrc file", 0, QApplication::UnicodeUTF8),                QApplication::translate("qdesigner_internal::QDesignerResource",                "The specified qrc file <p><b>%1</b></p><p>could not be found. Do you want to update the file location?</p>", 0, QApplication::UnicodeUTF8).arg(path),                QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);            if (answer == QMessageBox::Yes) {                const QFileInfo fi(path);                path = QFileDialog::getOpenFileName(m_formWindow->core()->topLevel(),                    QApplication::translate("qdesigner_internal::QDesignerResource",                    "New location for %1", 0, QApplication::UnicodeUTF8).arg(fi.fileName()), fi.absolutePath(),                    QApplication::translate("qdesigner_internal::QDesignerResource", "Resource files (*.qrc)", 0, QApplication::UnicodeUTF8));                if (path.isEmpty())                    break;            } else {                break;            }        }        if (!path.isEmpty())            m_formWindow->addResourceFile(path);    }}DomResources *QDesignerResource::saveResources(){    const QStringList res_list = m_formWindow->resourceFiles();    QList<DomResource*> dom_include;    foreach (QString res, res_list) {        DomResource *dom_res = new DomResource;        QString conv_path = m_formWindow->absoluteDir().relativeFilePath(res);        dom_res->setAttributeLocation(conv_path.replace(QDir::separator(), QLatin1Char('/')));        dom_include.append(dom_res);    }    DomResources *dom_resources = new DomResources;    dom_resources->setElementInclude(dom_include);    return dom_resources;}DomAction *QDesignerResource::createDom(QAction *action){    if (!core()->metaDataBase()->item(action) || action->menu())        return 0;    return QAbstractFormBuilder::createDom(action);}DomActionGroup *QDesignerResource::createDom(QActionGroup *actionGroup){    if (core()->metaDataBase()->item(actionGroup) != 0) {        return QAbstractFormBuilder::createDom(actionGroup);    }    return 0;}QAction *QDesignerResource::create(DomAction *ui_action, QObject *parent){    if (QAction *action = QAbstractFormBuilder::create(ui_action, parent)) {        core()->metaDataBase()->add(action);        return action;    }    return 0;}QActionGroup *QDesignerResource::create(DomActionGroup *ui_action_group, QObject *parent){    if (QActionGroup *actionGroup = QAbstractFormBuilder::create(ui_action_group, parent)) {        core()->metaDataBase()->add(actionGroup);        return actionGroup;    }    return 0;}DomActionRef *QDesignerResource::createActionRefDom(QAction *action){    if (!core()->metaDataBase()->item(action)            || qobject_cast<SentinelAction*>(action)            || (!action->isSeparator() && !action->menu() && action->objectName().isEmpty()))        return 0;    return QAbstractFormBuilder::createActionRefDom(action);}void QDesignerResource::addMenuAction(QAction *action){    core()->metaDataBase()->add(action);}QAction *QDesignerResource::createAction(QObject *parent, const QString &name){    if (QAction *action = QAbstractFormBuilder::createAction(parent, name)) {        core()->metaDataBase()->add(action);        return action;    }    return 0;}QActionGroup *QDesignerResource::createActionGroup(QObject *parent, const QString &name){    if (QActionGroup *actionGroup = QAbstractFormBuilder::createActionGroup(parent, name)) {        core()->metaDataBase()->add(actionGroup);        return actionGroup;    }    return 0;}void QDesignerResource::loadExtraInfo(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget){    QAbstractFormBuilder::loadExtraInfo(ui_widget, widget, parentWidget);}// Add user defined scripts (dialog box) belonging to QWidget to DomWidget.void QDesignerResource::addUserDefinedScripts(QWidget *w, DomWidget *ui_widget){    QDesignerFormEditorInterface *core = m_formWindow->core();    DomScripts domScripts = ui_widget->elementScript();    // Look up user-defined scripts of designer    if (const qdesigner_internal::MetaDataBase *metaDataBase = qobject_cast<const qdesigner_internal::MetaDataBase *>(core->metaDataBase())) {        if (const qdesigner_internal::MetaDataBaseItem *metaItem = metaDataBase->metaDataBaseItem(w)) {            addScript(metaItem->script(), ScriptDesigner, domScripts);        }    }    if (!domScripts.empty())        ui_widget->setElementScript(domScripts);}}

⌨️ 快捷键说明

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