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

📄 converter.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            }        }        pn = pn.parentNode();    }}void Ui3Reader::createProperties(const QDomElement &n, QList<DomProperty*> *properties,                                 const QString &className){    QString objectName;    bool wordWrapFound = false;    for (QDomElement e=n.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) {        if (e.tagName().toLower() == QLatin1String("property")) {            QString name = e.attribute(QLatin1String("name"));            // changes in QPalette            if (name == QLatin1String("colorGroup")                || name == QLatin1String("paletteForegroundColor")                || name == QLatin1String("paletteBackgroundColor")                || name == QLatin1String("backgroundMode")                || name == QLatin1String("backgroundOrigin")                || name == QLatin1String("paletteBackgroundPixmap")                || name == QLatin1String("backgroundBrush")) {                errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber());                continue;            }            // changes in QFrame            if (name == QLatin1String("contentsRect")) {                errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber());                continue;            }            // changes in QWidget            if (name == QLatin1String("underMouse")                || name == QLatin1String("ownFont")) {                errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber());                continue;            }            if (name == QLatin1String("font")) {                QDomElement f = e.firstChild().toElement();                DomFont font;                findDerivedFontProperties(f, font);                e.removeChild(f);                QDomDocument doc = e.ownerDocument();                f = font.write(doc);                e.appendChild(f);            }            DomProperty *prop = readProperty(e);            if (!prop)                continue;            if (prop->kind() == DomProperty::String) {                QDomNodeList comments = e.elementsByTagName(QLatin1String("comment"));                if (comments.length()) {                    QString comment = comments.item(0).firstChild().toText().data();                    if (!comment.isEmpty())                        prop->elementString()->setAttributeComment(comment);                }            }            // objectName            if (name == QLatin1String("name")) {                objectName = prop->elementCstring();                continue;            }            if (className == QLatin1String("Line")                && prop->attributeName() == QLatin1String("orientation")) {                delete prop;                continue;            }            if (className.mid(1) == QLatin1String("LineEdit")) {                if (name == QLatin1String("hasMarkedText")) {                    prop->setAttributeName(QLatin1String("hasSelectedText"));                } else if (name == QLatin1String("edited")) {                    prop->setAttributeName(QLatin1String("modified"));                } else if (name == QLatin1String("markedText")) {                    prop->setAttributeName(QLatin1String("selectedText"));                }            }            if (className.endsWith(QLatin1String("ComboBox"))) {                CONVERT_PROPERTY(QLatin1String("currentItem"), QLatin1String("currentIndex"));                CONVERT_PROPERTY(QLatin1String("insertionPolicy"), QLatin1String("insertPolicy"));            }            if (className == QLatin1String("QToolBar")) {                if (name == QLatin1String("label")) {                    prop->setAttributeName(QLatin1String("windowTitle"));                }            }            CONVERT_PROPERTY(QLatin1String("customWhatsThis"), QLatin1String("whatsThis"));            CONVERT_PROPERTY(QLatin1String("icon"), QLatin1String("windowIcon"));            CONVERT_PROPERTY(QLatin1String("iconText"), QLatin1String("windowIconText"));            CONVERT_PROPERTY(QLatin1String("caption"), QLatin1String("windowTitle"));            if (name == QLatin1String("name")) {                continue; // skip the property name            }            if (name == QLatin1String("accel")) {                prop->setAttributeName(QLatin1String("shortcut"));            }            CONVERT_PROPERTY(QLatin1String("pixmap"), QLatin1String("icon"));            CONVERT_PROPERTY(QLatin1String("iconSet"), QLatin1String("icon"));            CONVERT_PROPERTY(QLatin1String("textLabel"), QLatin1String("text"));            CONVERT_PROPERTY(QLatin1String("toggleButton"), QLatin1String("checkable"));            CONVERT_PROPERTY(QLatin1String("isOn"), QLatin1String("checked"));            CONVERT_PROPERTY(QLatin1String("maxValue"), QLatin1String("maximum"));            CONVERT_PROPERTY(QLatin1String("minValue"), QLatin1String("minimum"));            CONVERT_PROPERTY(QLatin1String("lineStep"), QLatin1String("singleStep"));            name = prop->attributeName(); // sync the name            if (className == QLatin1String("QLabel") && name == QLatin1String("alignment")) {                QString v = prop->elementSet();                if (v.contains(QRegExp(QLatin1String("\\bWordBreak\\b"))))                    wordWrapFound = true;            }            // resolve the flags and enumerator            if (prop->kind() == DomProperty::Set) {                QStringList flags = prop->elementSet().split(QLatin1Char('|'));                QStringList v;                foreach (QString fl, flags) {                    QString e = WidgetInfo::resolveEnumerator(className, fl);                    if (e.isEmpty()) {                        e = m_porting->renameEnumerator(className + QLatin1String("::") + fl);                    }                    if (e.isEmpty()) {                        fprintf(stderr, "uic3: flag '%s' for widget '%s' is not supported\n", fl.latin1(), className.latin1());                        continue;                    }                    v.append(e);                }                if (v.isEmpty()) {                    delete prop;                    continue;                }                prop->setElementSet(v.join(QLatin1String("|")));            } else if (prop->kind() == DomProperty::Enum) {                QString e = WidgetInfo::resolveEnumerator(className, prop->elementEnum());                if (e.isEmpty()) {                    e = m_porting->renameEnumerator(className + QLatin1String("::") + prop->elementEnum());                }                if (e.isEmpty()) {                    fprintf(stderr, "uic3: enumerator '%s' for widget '%s' is not supported\n",                            prop->elementEnum().latin1(), className.latin1());                    delete prop;                    continue;                }                prop->setElementEnum(e);            }            if (className.size()                && !(className == QLatin1String("QLabel") && name == QLatin1String("buddy"))                && !(name == QLatin1String("buttonGroupId"))                && !(name == QLatin1String("frameworkCode"))                && !(name == QLatin1String("database"))) {                if (!WidgetInfo::isValidProperty(className, name)) {                    errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber());                    delete prop;                } else {                    properties->append(prop);                }            } else {                properties->append(prop);            }        }    }    if (className == QLatin1String("QLabel")) {        DomProperty *wordWrap = new DomProperty();        wordWrap->setAttributeName(QLatin1String("wordWrap"));        if (wordWrapFound)            wordWrap->setElementBool(QLatin1String("true"));        else            wordWrap->setElementBool(QLatin1String("false"));        properties->append(wordWrap);    }}DomProperty *Ui3Reader::readProperty(const QDomElement &e){    QString name = e.firstChild().toElement().tagName().toLower();    if (name == QLatin1String("class")) // skip class        name = e.firstChild().nextSibling().toElement().tagName().toLower();    DomProperty *p = new DomProperty;    p->read(e);    if (p->kind() == DomProperty::Number) {        QString value = e.firstChild().toElement().firstChild().nodeValue();        if (value.contains(QLatin1Char('.'))) {            p->setElementDouble(value.toDouble());        }    } else if (p->kind() == DomProperty::Pixmap) {        DomResourcePixmap *domPix = p->elementPixmap();        if (m_extractImages) {            QString imageFile = domPix->text() + QLatin1String(".xpm");            if (m_imageMap.contains(domPix->text()))                imageFile = m_imageMap.value(domPix->text());            domPix->setAttributeResource(m_qrcOutputFile);            domPix->setText(QLatin1String(":/") + nameOfClass + QLatin1String("/images/") + imageFile);        }    } else if (p->kind() == DomProperty::Unknown) {        delete p;        p = 0;    }    return p;}void Ui3Reader::createAttributes(const QDomElement &n, QList<DomProperty*> *properties,                                 const QString &className){    Q_UNUSED(className);    for (QDomElement e=n.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) {        if (e.tagName().toLower() == QLatin1String("attribute")) {            QString name = e.attribute(QLatin1String("name"));            DomProperty *prop = readProperty(e);            if (!prop)                continue;            properties->append(prop);        }    }}QString Ui3Reader::fixDeclaration(const QString &d) const{    QString text;    int i = 0;    while (i < d.size()) {        QChar ch = d.at(i);        if (ch.isLetter() || ch == QLatin1Char('_')) {            int start = i;            while (i < d.size() && (d.at(i).isLetterOrNumber() || d.at(i) == QLatin1Char('_')))                ++i;            text += fixClassName(d.mid(start, i-start));        } else {            text += ch;            ++i;        }    }    return text;}/*    fixes a (possible composite) type name*/QString Ui3Reader::fixType(const QString &t) const{    QString newText = t;    //split type name on <>*& and whitespace    QStringList typeNames = t.split(QRegExp(QLatin1String("<|>|\\*|&| ")), QString::SkipEmptyParts);    foreach(QString typeName , typeNames) {        QString newName = fixClassName(typeName);        if( newName != typeName ) {            newText.replace(typeName, newName);        }    }    return newText;}QString Ui3Reader::fixMethod(const QString &method) const{    const QByteArray normalized = QMetaObject::normalizedSignature(method.toLatin1());    QByteArray result;    int index = normalized.indexOf('(');    if (index == -1)        return QLatin1String(normalized);    result.append(normalized.left(++index));    int limit = normalized.length()-1;    while (index < limit) {        QByteArray type;        while ((index < limit) && (normalized.at(index) != ','))            type.append(normalized.at(index++));        result.append(fixType(QLatin1String(type)).toLatin1());        if ((index < limit) && (normalized.at(index) == ','))            result.append(normalized.at(index++));    }    result.append(normalized.mid(index));    return QLatin1String(result);}

⌨️ 快捷键说明

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