📄 writeinitialization.cpp
字号:
spacing = properties.value(QLatin1String("spacing"))->elementNumber(); layoutProperties.removeAt(layoutProperties.indexOf(p)); } if (spacing != INT_MIN) { QString value = QString::number(spacing); if (!m_spacingFunction.isEmpty() && spacing == m_defaultSpacing) value = m_spacingFunction + QLatin1String("()"); output << option.indent << varName << "->setSpacing(" << value << ");\n"; } if (margin != INT_MIN) { QString value = QString::number(margin); if (!m_marginFunction.isEmpty() && margin == m_defaultMargin) value = m_marginFunction + QLatin1String("()"); output << option.indent << varName << "->setMargin(" << value << ");\n"; } } writeProperties(varName, className, layoutProperties); m_layoutChain.push(node); TreeWalker::acceptLayout(node); m_layoutChain.pop();}void WriteInitialization::acceptSpacer(DomSpacer *node){ QHash<QString, DomProperty *> properties = propertyMap(node->elementProperty()); QString varName = driver->findOrInsertSpacer(node); DomSize *sizeHint = properties.contains(QLatin1String("sizeHint")) ? properties.value(QLatin1String("sizeHint"))->elementSize() : 0; QString sizeType = properties.contains(QLatin1String("sizeType")) ? properties.value(QLatin1String("sizeType"))->elementEnum() : QString::fromLatin1("Expanding"); QString orientation = properties.contains(QLatin1String("orientation")) ? properties.value(QLatin1String("orientation"))->elementEnum() : QString(); bool isVspacer = orientation == QLatin1String("Qt::Vertical") || orientation == QLatin1String("Vertical"); output << option.indent << varName << " = new QSpacerItem("; if (sizeHint) output << sizeHint->elementWidth() << ", " << sizeHint->elementHeight() << ", "; if (sizeType.startsWith(QLatin1String("QSizePolicy::")) == false) sizeType.prepend(QLatin1String("QSizePolicy::")); if (isVspacer) output << "QSizePolicy::Minimum, " << sizeType << ");\n"; else output << sizeType << ", QSizePolicy::Minimum);\n"; TreeWalker::acceptSpacer(node);}void WriteInitialization::acceptLayoutItem(DomLayoutItem *node){ TreeWalker::acceptLayoutItem(node); DomLayout *layout = m_layoutChain.top(); if (!layout) return; QString varName = driver->findOrInsertLayoutItem(node); QString layoutName = driver->findOrInsertLayout(layout); QString opt; if (layout->attributeClass() == QLatin1String("QGridLayout")) { int row = node->attributeRow(); int col = node->attributeColumn(); int rowSpan = 1; if (node->hasAttributeRowSpan()) rowSpan = node->attributeRowSpan(); int colSpan = 1; if (node->hasAttributeColSpan()) colSpan = node->attributeColSpan(); opt = QString::fromLatin1(", %1, %2, %3, %4").arg(row).arg(col).arg(rowSpan).arg(colSpan); } QString method = QLatin1String("addItem"); switch (node->kind()) { case DomLayoutItem::Widget: method = QLatin1String("addWidget"); break; case DomLayoutItem::Layout: method = QLatin1String("addLayout"); break; case DomLayoutItem::Spacer: method = QLatin1String("addItem"); break; case DomLayoutItem::Unknown: Q_ASSERT( 0 ); break; } output << "\n" << option.indent << layoutName << "->" << method << "(" << varName << opt << ");\n\n";}void WriteInitialization::acceptActionGroup(DomActionGroup *node){ QString actionName = driver->findOrInsertActionGroup(node); QString varName = driver->findOrInsertWidget(m_widgetChain.top()); if (m_actionGroupChain.top()) varName = driver->findOrInsertActionGroup(m_actionGroupChain.top()); output << option.indent << actionName << " = new QActionGroup(" << varName << ");\n"; writeProperties(actionName, QLatin1String("QActionGroup"), node->elementProperty()); m_actionGroupChain.push(node); TreeWalker::acceptActionGroup(node); m_actionGroupChain.pop();}void WriteInitialization::acceptAction(DomAction *node){ if (node->hasAttributeMenu()) return; QString actionName = driver->findOrInsertAction(node); m_registeredActions.insert(actionName, node); QString varName = driver->findOrInsertWidget(m_widgetChain.top()); if (m_actionGroupChain.top()) varName = driver->findOrInsertActionGroup(m_actionGroupChain.top()); output << option.indent << actionName << " = new QAction(" << varName << ");\n"; writeProperties(actionName, QLatin1String("QAction"), node->elementProperty());}void WriteInitialization::acceptActionRef(DomActionRef *node){ QString actionName = node->attributeName(); bool isSeparator = actionName == QLatin1String("separator"); bool isMenu = false; QString varName = driver->findOrInsertWidget(m_widgetChain.top()); if (actionName.isEmpty() || !m_widgetChain.top()) { return; } else if (driver->actionGroupByName(actionName)) { return; } else if (DomWidget *w = driver->widgetByName(actionName)) { isMenu = uic->isMenu(w->attributeClass()); bool inQ3ToolBar = uic->customWidgetsInfo()->extends(m_widgetChain.top()->attributeClass(), QLatin1String("Q3ToolBar")); if (!isMenu && inQ3ToolBar) { actionOut << option.indent << actionName << "->setParent(0);\n"; actionOut << option.indent << actionName << "->setParent(" << varName << ");\n"; return; } } else if (!(driver->actionByName(actionName) || isSeparator)) { fprintf(stderr, "Warning: action `%s' not declared\n", actionName.toLatin1().data()); return; } if (m_widgetChain.top() && isSeparator) { // separator is always reserved! actionOut << option.indent << varName << "->addSeparator();\n"; return; } if (isMenu) actionName += QLatin1String("->menuAction()"); actionOut << option.indent << varName << "->addAction(" << actionName << ");\n";}void WriteInitialization::writeProperties(const QString &varName, const QString &className, const QList<DomProperty*> &lst){ bool isTopLevel = m_widgetChain.count() == 1; if (uic->customWidgetsInfo()->extends(className, QLatin1String("QAxWidget"))) { QHash<QString, DomProperty*> properties = propertyMap(lst); if (properties.contains(QLatin1String("control"))) { DomProperty *p = properties.value(QLatin1String("control")); output << option.indent << varName << "->setControl(QString::fromUtf8(" << fixString(toString(p->elementString()), option.indent) << "));\n"; } } DomWidget *buttonGroupWidget = findWidget(QLatin1String("Q3ButtonGroup")); output << option.indent << varName << "->setObjectName(QString::fromUtf8(" << fixString(varName, option.indent) << "));\n"; for (int i=0; i<lst.size(); ++i) { DomProperty *p = lst.at(i); QString propertyName = p->attributeName(); QString propertyValue; // special case for the property `geometry' if (isTopLevel && propertyName == QLatin1String("geometry") && p->elementRect()) { DomRect *r = p->elementRect(); int w = r->elementWidth(); int h = r->elementHeight(); output << option.indent << varName << "->resize(QSize(" << w << ", " << h << ").expandedTo(" << varName << "->minimumSizeHint()));\n"; continue; } else if (propertyName == QLatin1String("buttonGroupId") && buttonGroupWidget) { // Q3ButtonGroup support output << option.indent << driver->findOrInsertWidget(buttonGroupWidget) << "->insert(" << varName << ", " << p->elementNumber() << ");\n"; continue; } else if (propertyName == QLatin1String("currentRow") // QListWidget::currentRow && uic->customWidgetsInfo()->extends(className, QLatin1String("QListWidget"))) { delayedOut << option.indent << varName << "->setCurrentRow(" << p->elementNumber() << ");\n"; continue; } else if (propertyName == QLatin1String("currentIndex") // set currentIndex later && (uic->customWidgetsInfo()->extends(className, QLatin1String("QComboBox")) || uic->customWidgetsInfo()->extends(className, QLatin1String("QStackedWidget")) || uic->customWidgetsInfo()->extends(className, QLatin1String("QTabWidget")) || uic->customWidgetsInfo()->extends(className, QLatin1String("QToolBox")))) { delayedOut << option.indent << varName << "->setCurrentIndex(" << p->elementNumber() << ");\n"; continue; } else if (propertyName == QLatin1String("control") // ActiveQt support && uic->customWidgetsInfo()->extends(className, QLatin1String("QAxWidget"))) { // already done ;) continue; } else if (propertyName == QLatin1String("database") && p->elementStringList()) { // Sql support continue; } else if (propertyName == QLatin1String("frameworkCode") && p->kind() == DomProperty::Bool) { // Sql support continue; } else if (propertyName == QLatin1String("orientation") && uic->customWidgetsInfo()->extends(className, QLatin1String("Line"))) { // Line support QString shape = QLatin1String("QFrame::HLine"); if (p->elementEnum() == QLatin1String("Qt::Vertical")) shape = QLatin1String("QFrame::VLine"); output << option.indent << varName << "->setFrameShape(" << shape << ");\n"; continue; } bool stdset = m_stdsetdef; if (p->hasAttributeStdset()) stdset = p->attributeStdset(); QString setFunction; if (stdset) { setFunction = QLatin1String("->set") + propertyName.left(1).toUpper() + propertyName.mid(1) + QLatin1String("("); } else { setFunction = QLatin1String("->setProperty(\"") + propertyName + QLatin1String("\", QVariant("); } switch (p->kind()) { case DomProperty::Bool: { propertyValue = p->elementBool(); break; } case DomProperty::Color: { DomColor *c = p->elementColor(); propertyValue = QString::fromLatin1("QColor(%1, %2, %3)") .arg(c->elementRed()) .arg(c->elementGreen()) .arg(c->elementBlue()); } break; case DomProperty::Cstring: if (propertyName == QLatin1String("buddy") && uic->customWidgetsInfo()->extends(className, QLatin1String("QLabel"))) { m_buddies.append(Buddy(varName, p->elementCstring())); } else { if (stdset) propertyValue = fixString(p->elementCstring(), option.indent); else propertyValue = QLatin1String("QByteArray(") + fixString(p->elementCstring(), option.indent) + QLatin1String(")"); } break; case DomProperty::Cursor: propertyValue = QString::fromLatin1("QCursor(static_cast<Qt::CursorShape>(%1))") .arg(p->elementCursor()); break; case DomProperty::Enum: propertyValue = p->elementEnum(); if (!propertyValue.contains(QLatin1String("::"))) propertyValue.prepend(className + QLatin1String(QLatin1String("::"))); break; case DomProperty::Set: propertyValue = p->elementSet(); break; case DomProperty::Font: { DomFont *f = p->elementFont(); QString fontName = driver->unique(QLatin1String("font")); output << option.indent << "QFont " << fontName << ";\n"; if (!f->elementFamily().isEmpty()) { output << option.indent << fontName << ".setFamily(QString::fromUtf8(" << fixString(f->elementFamily(), option.indent) << "));\n"; } if (f->elementPointSize() > 0) { output << option.indent << fontName << ".setPointSize(" << f->elementPointSize() << ");\n"; } output << option.indent << fontName << ".setBold(" << (f->elementBold() ? "true" : "false") << ");\n"; output << option.indent << fontName << ".setItalic(" << (f->elementItalic() ? "true" : "false") << ");\n"; output << option.indent << fontName << ".setUnderline(" << (f->elementUnderline() ? "true" : "false") << ");\n"; if (f->elementWeight() > 0) { output << option.indent << fontName << ".setWeight(" << f->elementWeight() << ");" << endl; } output << option.indent << fontName << ".setStrikeOut(" << (f->elementStrikeOut() ? "true" : "false") << ");\n"; propertyValue = fontName; break; } case DomProperty::IconSet: propertyValue = pixCall(p); break; case DomProperty::Pixmap: propertyValue = pixCall(p); break; case DomProperty::Palette: { DomPalette *pal = p->elementPalette(); QString paletteName = driver->unique(QLatin1String("palette")); output << option.indent << "QPalette " << paletteName << ";\n"; writeColorGroup(pal->elementActive(), QLatin1String("QPalette::Active"), paletteName); writeColorGroup(pal->elementInactive(), QLatin1String("QPalette::Inactive"), paletteName); writeColorGroup(pal->elementDisabled(), QLatin1String("QPalette::Disabled"), paletteName); propertyValue = paletteName; break; } case DomProperty::Point: { DomPoint *po = p->elementPoint(); propertyValue = QString::fromLatin1("QPoint(%1, %2)") .arg(po->elementX()).arg(po->elementY()); break; } case DomProperty::Rect: { DomRect *r = p->elementRect(); propertyValue = QString::fromLatin1("QRect(%1, %2, %3, %4)") .arg(r->elementX()).arg(r->elementY()) .arg(r->elementWidth()).arg(r->elementHeight()); break; } case DomProperty::SizePolicy: { DomSizePolicy *sp = p->elementSizePolicy(); QString spName = driver->unique(QLatin1String("sizePolicy")); output << option.indent << "QSizePolicy " << spName << QString::fromLatin1( "(static_cast<QSizePolicy::Policy>(%1), static_cast<QSizePolicy::Policy>(%2));\n") .arg(sp->elementHSizeType()) .arg(sp->elementVSizeType()); output << option.indent << spName << ".setHorizontalStretch(" << sp->elementHorStretch() << ");\n"; output << option.indent << spName << ".setVerticalStretch(" << sp->elementVerStretch() << ");\n"; output << option.indent << spName << QString::fromLatin1( ".setHeightForWidth(%1->sizePolicy().hasHeightForWidth());\n") .arg(varName); propertyValue = spName; break; } case DomProperty::Size: { DomSize *s = p->elementSize(); propertyValue = QString::fromLatin1("QSize(%1, %2)") .arg(s->elementWidth()).arg(s->elementHeight()); break; } case DomProperty::String: { if (propertyName == QLatin1String("objectName")) { QString v = p->elementString()->text(); if (v == varName) break; // ### qWarning("Deprecated: the property `objectName' is different from the variable name"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -