📄 ui3reader.cpp
字号:
void Ui3Reader::setOutputFileName(const QString &fileName){ outputFileName = fileName;}/*! Extracts a pixmap loader function from \a e */QString Ui3Reader::getPixmapLoaderFunction(const QDomElement& e){ QDomElement n; for (n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement()) { if (n.tagName() == QLatin1String("pixmapfunction")) return n.firstChild().toText().data(); } return QString();}/*! Extracts the forms class name from \a e */QString Ui3Reader::getFormClassName(const QDomElement& e){ QDomElement n; QString cn; for (n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement()) { if (n.tagName() == QLatin1String("class")) { QString s = n.firstChild().toText().data(); int i; while ((i = s.indexOf(QLatin1Char(' '))) != -1) s[i] = QLatin1Char('_'); cn = s; } } return cn;}/*! Extracts a class name from \a e. */QString Ui3Reader::getClassName(const QDomElement& e){ QString s = e.attribute(QLatin1String("class")); if (s.isEmpty() && e.tagName() == QLatin1String("toolbar")) s = QLatin1String(QLatin1String("QToolBar")); else if (s.isEmpty() && e.tagName() == QLatin1String("menubar")) s = QLatin1String("QMenuBar"); return fixClassName(s);}/*! Returns true if database framework code is generated, else false.*/bool Ui3Reader::isFrameworkCodeGenerated(const QDomElement& e){ QDomElement n = getObjectProperty(e, QLatin1String("frameworkCode")); if (n.attribute(QLatin1String("name")) == QLatin1String("frameworkCode") && !DomTool::elementToVariant(n.firstChild().toElement(), QVariant(true)).toBool()) return false; return true;}/*! Extracts an object name from \a e. It's stored in the 'name' property. */QString Ui3Reader::getObjectName(const QDomElement& e){ QDomElement n = getObjectProperty(e, QLatin1String("name")); if (n.firstChild().toElement().tagName() == QLatin1String("cstring")) return n.firstChild().toElement().firstChild().toText().data(); return QString();}/*! Extracts an layout name from \a e. It's stored in the 'name' property of the preceding sibling (the first child of a QLayoutWidget). */QString Ui3Reader::getLayoutName(const QDomElement& e){ QDomElement p = e.parentNode().toElement(); QString name; if (getClassName(p) != QLatin1String("QLayoutWidget")) name = QLatin1String("Layout"); QDomElement n = getObjectProperty(p, QLatin1String("name")); if (n.firstChild().toElement().tagName() == QLatin1String("cstring")) { name.prepend(n.firstChild().toElement().firstChild().toText().data()); return name.split(QLatin1String("::")).last(); } return e.tagName();}QString Ui3Reader::getDatabaseInfo(const QDomElement& e, const QString& tag){ QDomElement n; QDomElement n1; int child = 0; // database info is a stringlist stored in this order if (tag == QLatin1String("connection")) child = 0; else if (tag == QLatin1String("table")) child = 1; else if (tag == QLatin1String("field")) child = 2; else return QString(); n = getObjectProperty(e, QLatin1String("database")); if (n.firstChild().toElement().tagName() == QLatin1String("stringlist")) { // find correct stringlist entry QDomElement n1 = n.firstChild().firstChild().toElement(); for (int i = 0; i < child && !n1.isNull(); ++i) n1 = n1.nextSibling().toElement(); if (n1.isNull()) return QString(); return n1.firstChild().toText().data(); } return QString();}static const char* const ColorRole[] = { "Foreground", "Button", "Light", "Midlight", "Dark", "Mid", "Text", "BrightText", "ButtonText", "Base", "Background", "Shadow", "Highlight", "HighlightedText", "Link", "LinkVisited", 0};/*! Creates a colorgroup with name \a name from the color group \a cg */void Ui3Reader::createColorGroupImpl(const QString& name, const QDomElement& e){ int r = -1; QDomElement n = e.firstChild().toElement(); QString color; Color white; white.init(255, 255, 255); Color black; black.init(0, 0, 0); while (!n.isNull()) { if (n.tagName() == QLatin1String("color")) { r++; Color col = DomTool::readColor(n); color = QLatin1String("QColor(%1, %2, %3)"); color = color.arg(col.red).arg(col.green).arg(col.blue); if (col == white) color = QLatin1String("white"); else if (col == black) color = QLatin1String("black"); if (n.nextSibling().toElement().tagName() != QLatin1String("pixmap")) { out << indent << name << ".setColor(QColorGroup::" << ColorRole[r] << ", " << color << ");" << endl; } } else if (n.tagName() == QLatin1String("pixmap")) { QString pixmap = n.firstChild().toText().data(); if (!pixmapLoaderFunction.isEmpty()) { pixmap.prepend(pixmapLoaderFunction + QLatin1String("(") + QLatin1String(externPixmaps ? "\"" : "")); pixmap.append(QLatin1String(externPixmaps ? "\"" : "") + QLatin1String(")")); } out << indent << name << ".setBrush(QColorGroup::" << ColorRole[r] << ", QBrush(" << color << ", " << pixmap << "));" << endl; } n = n.nextSibling().toElement(); }}/*! Auxiliary function to load a color group. The colorgroup must not contain pixmaps. */ColorGroup Ui3Reader::loadColorGroup(const QDomElement &e){ ColorGroup cg; int r = -1; QDomElement n = e.firstChild().toElement(); Color col; while (!n.isNull()) { if (n.tagName() == QLatin1String("color")) { r++; col = DomTool::readColor(n); cg.append(qMakePair(r, col)); } n = n.nextSibling().toElement(); } return cg;}/*! Returns true if the widget properties specify that it belongs to the database \a connection and \a table.*/bool Ui3Reader::isWidgetInTable(const QDomElement& e, const QString& connection, const QString& table){ QString conn = getDatabaseInfo(e, QLatin1String("connection")); QString tab = getDatabaseInfo(e, QLatin1String("table")); if (conn == connection && tab == table) return true; return false;}/*! Registers all database connections, cursors and forms.*/void Ui3Reader::registerDatabases(const QDomElement& e){ QDomElement n; QDomNodeList nl; int i; nl = e.parentNode().toElement().elementsByTagName(QLatin1String("widget")); for (i = 0; i < (int) nl.length(); ++i) { n = nl.item(i).toElement(); QString conn = getDatabaseInfo(n, QLatin1String("connection")); QString tab = getDatabaseInfo(n, QLatin1String("table")); QString fld = getDatabaseInfo(n, QLatin1String("field")); if (!conn.isNull()) { dbConnections += conn; if (!tab.isNull()) { dbCursors[conn] += tab; if (!fld.isNull()) dbForms[conn] += tab; } } }}/*! Registers an object with name \a name. The returned name is a valid variable identifier, as similar to \a name as possible and guaranteed to be unique within the form. \sa registeredName(), isObjectRegistered() */QString Ui3Reader::registerObject(const QString& name){ if (objectNames.isEmpty()) { // some temporary variables we need objectNames += QLatin1String("img"); objectNames += QLatin1String("item"); objectNames += QLatin1String("cg"); objectNames += QLatin1String("pal"); } QString result = name; int i; while ((i = result.indexOf(QLatin1Char(' '))) != -1 ) { result[i] = QLatin1Char('_'); } if (objectNames.contains(result)) { int i = 2; while (objectNames.contains(result + QLatin1String("_") + QString::number(i))) i++; result += QLatin1String("_"); result += QString::number(i); } objectNames += result; objectMapper.insert(name, result); return result;}/*! Returns the registered name for the original name \a name or \a name if \a name wasn't registered. \sa registerObject(), isObjectRegistered() */QString Ui3Reader::registeredName(const QString& name){ if (!objectMapper.contains(name)) return name; return objectMapper[name];}/*! Returns whether the object \a name was registered yet or not. */bool Ui3Reader::isObjectRegistered(const QString& name){ return objectMapper.contains(name);}/*! Unifies the entries in stringlist \a list. Should really be a QStringList feature. */QStringList Ui3Reader::unique(const QStringList& list){ if (list.isEmpty()) return list; QStringList result; for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) { if (!result.contains(*it)) result += *it; } return result;}bool Ui3Reader::isLayout(const QString& name) const{ return layoutObjects.contains(name);}void Ui3Reader::setExtractImages(bool extract, const QString &qrcOutputFile){ m_extractImages = extract; m_qrcOutputFile = qrcOutputFile;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -