⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qdesigner_resource.cpp

📁 QT 开发环境里面一个很重要的文件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    m_copyWidget = true;    DomUI *ui = new DomUI();    ui->setAttributeVersion(QLatin1String("4.0"));    DomWidget *ui_widget = new DomWidget();    QList<DomWidget*> ui_widget_list;    ui_widget->setAttributeName(QLatin1String("__qt_fake_top_level"));    for (int i=0; i<selection.size(); ++i) {        QWidget *w = selection.at(i);        m_selected = w;        DomWidget *ui_child = createDom(w, ui_widget);        m_selected = 0;        if (!ui_child)            continue;        ui_widget_list.append(ui_child);    }    ui_widget->setElementWidget(ui_widget_list);    ui->setElementWidget(ui_widget);    m_laidout.clear();    m_copyWidget = false;    return ui;}QList<QWidget*> QDesignerResource::paste(DomUI *ui, QWidget *parentWidget){    int saved = m_isMainWidget;    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;    return createdWidgets;}QList<QWidget*> QDesignerResource::paste(QIODevice *dev, QWidget *parentWidget){    QDomDocument doc;    if (!doc.setContent(dev))        return QList<QWidget*>();    QDomElement root = doc.firstChild().toElement();    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);    QLayoutWidget *layoutWidget = qobject_cast<QLayoutWidget*>(parent);    if (layoutWidget && margin) {        if (*margin == INT_MIN)            *margin = 1;        else            *margin = *margin + 1;    }}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 (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;    QList<DomCustomWidget*> custom_widget_list;    foreach (QDesignerWidgetDataBaseItemInterface *item, m_usedCustomWidgets.keys()) {        DomCustomWidget *custom_widget = new DomCustomWidget;        custom_widget->setElementClass(item->name());        if (item->isContainer())            custom_widget->setElementContainer(item->isContainer());        if (!item->includeFile().isEmpty()) {            DomHeader *header = new DomHeader;            header->setText(item->includeFile());            custom_widget->setElementHeader(header);            custom_widget->setElementExtends(item->extends());        }        custom_widget_list.append(custom_widget);    }    DomCustomWidgets *customWidgets = new DomCustomWidgets;    customWidgets->setElementCustomWidget(custom_widget_list);    return customWidgets;}QList<DomProperty*> QDesignerResource::computeProperties(QObject *object){    QList<DomProperty*> properties;    if (QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), object)) {        for (int index = 0; index < sheet->count(); ++index) {            QString propertyName = sheet->propertyName(index);            QVariant value = sheet->property(index);            if (QLayout *layout = qobject_cast<QLayout*>(object)) {                if (propertyName == QLatin1String("margin") && qobject_cast<QLayoutWidget*>(layout->parentWidget()))                    value = value.toInt() - 1;            }            if (!sheet->isChanged(index))                continue;            if (DomProperty *p = createProperty(object, propertyName, value)) {                if (p->kind() == DomProperty::String && qobject_cast<MetaDataBase*>(core()->metaDataBase())) {                    MetaDataBaseItem *item = static_cast<MetaDataBaseItem*>(core()->metaDataBase()->item(object));                    if (item && !item->propertyComment(propertyName).isEmpty()) {                        p->elementString()->setAttributeComment(item->propertyComment(propertyName));                    }                }                properties.append(p);            }        }    }    return properties;}DomProperty *QDesignerResource::createProperty(QObject *object, const QString &propertyName, const QVariant &value){    if (!checkProperty(object, propertyName)) {        return 0;    }    QExtensionManager *mgr = core()->extensionManager();    QDesignerLanguageExtension *lang = qt_extension<QDesignerLanguageExtension*> (mgr, core());    if (qVariantCanConvert<EnumType>(value)) {        EnumType e = qvariant_cast<EnumType>(value);        int v = e.value.toInt();        QMapIterator<QString, QVariant> it(e.items);        while (it.hasNext()) {            if (it.next().value().toInt() != v)                continue;            DomProperty *p = new DomProperty;            // check if we have a standard cpp set function            const QMetaObject *meta = object->metaObject();            int pindex = meta->indexOfProperty(propertyName.toLatin1());            if (pindex != -1) {                QMetaProperty meta_property = meta->property(pindex);                if (!meta_property.hasStdCppSet())                    p->setAttributeStdset(0);            }            p->setAttributeName(propertyName);            QString id = it.key();            if (lang)                id = lang->neutralEnumerator(id);            p->setElementEnum(id);            return p;        }        return 0;    } else if (qVariantCanConvert<FlagType>(value)) {        FlagType f = qvariant_cast<FlagType>(value);        uint v = f.value.toUInt();        QMapIterator<QString, QVariant> it(f.items);        QStringList keys;        while (it.hasNext()) {            uint x = it.next().value().toUInt();            QString id = it.key();            if (lang)                id = lang->neutralEnumerator(id);            if (v == x) {                DomProperty *p = new DomProperty;                // check if we have a standard cpp set function                const QMetaObject *meta = object->metaObject();                int pindex = meta->indexOfProperty(propertyName.toLatin1());                if (pindex != -1) {                    QMetaProperty meta_property = meta->property(pindex);                    if (!meta_property.hasStdCppSet())                        p->setAttributeStdset(0);                }                p->setAttributeName(propertyName);                p->setElementSet(id);                return p;            }            if ((v & x) == x)                keys.push_back(id);        }        if (keys.isEmpty())            return 0;        DomProperty *p = new DomProperty;        p->setAttributeName(propertyName);        p->setElementSet(keys.join(QLatin1String("|")));        return p;    }    return QAbstractFormBuilder::createProperty(object, propertyName, value);}void QDesignerResource::createResources(DomResources *resources){    if (resources == 0)        return;    QList<DomResource*> dom_include = resources->elementInclude();    foreach (DomResource *res, dom_include) {        QString path = m_formWindow->absoluteDir().absoluteFilePath(res->attributeLocation());        while (!QFile::exists(path)) {            if (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),                QApplication::translate("qdesigner_internal::QDesignerResource", "&Yes", 0, QApplication::UnicodeUTF8),                QApplication::translate("qdesigner_internal::QDesignerResource", "&No", 0, QApplication::UnicodeUTF8),                QString(), 0, 1) == 0) {                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(){    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){    if (QDesignerPromotedWidget *promoted = qobject_cast<QDesignerPromotedWidget*>(widget))        widget = promoted->child();    QAbstractFormBuilder::loadExtraInfo(ui_widget, widget, parentWidget);}

⌨️ 快捷键说明

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