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

📄 domtool.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        v = QVariant(QTime(h, m, s));    } else if (e.tagName() == QLatin1String("datetime")) {        QDomElement n3 = e.firstChild().toElement();        int h, mi, s, y, mo, d ;        h = mi = s = y = mo = d = 0;        while (!n3.isNull()) {            if (n3.tagName() == QLatin1String("hour"))                h = n3.firstChild().toText().data().toInt();            else if (n3.tagName() == QLatin1String("minute"))                mi = n3.firstChild().toText().data().toInt();            else if (n3.tagName() == QLatin1String("second"))                s = n3.firstChild().toText().data().toInt();            else if (n3.tagName() == QLatin1String("year"))                y = n3.firstChild().toText().data().toInt();            else if (n3.tagName() == QLatin1String("month"))                mo = n3.firstChild().toText().data().toInt();            else if (n3.tagName() == QLatin1String("day"))                d = n3.firstChild().toText().data().toInt();            n3 = n3.nextSibling().toElement();        }        v = QVariant(QDateTime(QDate(y, mo, d), QTime(h, mi, s)));    }    return v;}/*  Returns the color which is returned in the dom element \a e. */Color DomTool::readColor(const QDomElement &e){    QDomElement n = e.firstChild().toElement();    int r= 0, g = 0, b = 0;    while (!n.isNull()) {        if (n.tagName() == QLatin1String("red"))            r = n.firstChild().toText().data().toInt();        else if (n.tagName() == QLatin1String("green"))            g = n.firstChild().toText().data().toInt();        else if (n.tagName() == QLatin1String("blue"))            b = n.firstChild().toText().data().toInt();        n = n.nextSibling().toElement();    }    Color c;    c.init(r, g, b);    return c;}/*  Returns the contents of attribute \a name of object \a e as  a variant or the variant passed as \a defValue if the attribute does  not exist. The \a comment is passed to the elementToVariant()  function.  \sa hasAttribute() */QVariant DomTool::readAttribute(const QDomElement& e, const QString& name, const QVariant& defValue, QString& comment){    QDomElement n;    for (n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement()) {        if (n.tagName() == QLatin1String("attribute")) {            if (n.attribute(QLatin1String("name")) != name)                continue;            return elementToVariant(n.firstChild().toElement(), defValue, comment);        }    }    return defValue;}/*  \overload*/QVariant DomTool::readAttribute(const QDomElement& e, const QString& name, const QVariant& defValue){    QString comment;    return readAttribute(e, name, defValue, comment);}/*  Returns whether object \a e defines attribute \a name or not.  \sa readAttribute() */bool DomTool::hasAttribute(const QDomElement& e, const QString& name){    QDomElement n;    for (n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement()) {        if (n.tagName() == QLatin1String("attribute")) {            if (n.attribute(QLatin1String("name")) != name)                continue;            return true;        }    }    return false;}static bool toBool(const QString& s){    return s == QLatin1String("true") || s.toInt() != 0;}static double versionToDouble(QString version){    version = version.trimmed();    if (version.isEmpty())        return 0.0;    bool decpt = false;    QString num_str;    for (int i = 0; i < version.size(); ++i) {        char c = version.at(i).toAscii();        if ((c < '0' || c > '9') && c != '.')            break;        if (c == '.') {            if (decpt)                break;            decpt = true;        }        num_str.append(QLatin1Char(c));    }    return num_str.toDouble();}/*    \internal    Convert Qt 2.x format to Qt 3.x format if necessary.*/void DomTool::fixDocument(QDomDocument& doc){    QDomElement e;    QDomNode n;    QDomNodeList nl;    int i = 0;    e = doc.firstChild().toElement();    if (e.tagName() != QLatin1String("UI"))        return;    // rename classes and properties    double version = versionToDouble(e.attribute(QLatin1String("version")));    nl = e.childNodes();    fixAttributes(nl, version);    // 3.x don't do anything more    if (version >= 3.0)        return;    // in versions smaller than 3.0 we need to change more    e.setAttribute(QLatin1String("version"), 3.0);    e.setAttribute(QLatin1String("stdsetdef"), 1);    nl = e.elementsByTagName(QLatin1String("property"));    for (i = 0; i <  (int) nl.length(); i++) {        e = nl.item(i).toElement();        QString name;        QDomElement n2 = e.firstChild().toElement();        if (n2.tagName() == QLatin1String("name")) {            name = n2.firstChild().toText().data();            if (name == QLatin1String("resizeable"))                e.setAttribute(QLatin1String("name"), QLatin1String("resizable"));            else                e.setAttribute(QLatin1String("name"), name);            e.removeChild(n2);        }        bool stdset = toBool(e.attribute(QLatin1String("stdset")));        if (stdset || name == QLatin1String("toolTip") || name == QLatin1String("whatsThis") ||             name == QLatin1String("buddy") ||             e.parentNode().toElement().tagName() == QLatin1String("item") ||             e.parentNode().toElement().tagName() == QLatin1String("spacer") ||             e.parentNode().toElement().tagName() == QLatin1String("column")            )            e.removeAttribute(QLatin1String("stdset"));        else            e.setAttribute(QLatin1String("stdset"), 0);    }    nl = doc.elementsByTagName(QLatin1String("attribute"));    for (i = 0; i <  (int) nl.length(); i++) {        e = nl.item(i).toElement();        QString name;        QDomElement n2 = e.firstChild().toElement();        if (n2.tagName() == QLatin1String("name")) {            name = n2.firstChild().toText().data();            e.setAttribute(QLatin1String("name"), name);            e.removeChild(n2);        }    }    nl = doc.elementsByTagName(QLatin1String("image"));    for (i = 0; i <  (int) nl.length(); i++) {        e = nl.item(i).toElement();        QString name;        QDomElement n2 = e.firstChild().toElement();        if (n2.tagName() == QLatin1String("name")) {            name = n2.firstChild().toText().data();            e.setAttribute(QLatin1String("name"), name);            e.removeChild(n2);        }    }    nl = doc.elementsByTagName(QLatin1String("widget"));    for (i = 0; i <  (int) nl.length(); i++) {        e = nl.item(i).toElement();        QString name;        QDomElement n2 = e.firstChild().toElement();        if (n2.tagName() == QLatin1String("class")) {            name = n2.firstChild().toText().data();            e.setAttribute(QLatin1String("class"), name);            e.removeChild(n2);        }    }}struct widgetName {    widgetName(double v, QString b, QString a)        : version(v), before(b), after(a) {}    double version;    QString before;    QString after;};struct propertyName : public widgetName {    propertyName(double v, QString b, QString a, QString c = QString())        : widgetName(v, b, a), clss(c) {}    QString clss;};const int widgs = 1;widgetName widgetTable[1] = {    widgetName(3.3, QLatin1String("before"), QLatin1String("after")),};const int props = 1;propertyName propertyTable[1] = {    propertyName(3.0, QLatin1String("resizeable"), QLatin1String("resizable")), // we need to fix a spelling error in 3.0};/*    \internal*/void DomTool::fixAttributes(QDomNodeList &nodes, double version){    QDomNode n;    QDomNodeList nl;    for (int i = 0; i < (int) nodes.count(); ++i) {        n = nodes.item(i);        fixAttribute(n, version);        nl = n.childNodes();        fixAttributes(nl, version);    }}/*    \internal*/void DomTool::fixAttribute(QDomNode &node, double version){    QString tagName =  node.toElement().tagName();    if (tagName == QLatin1String("widget")) {        QString clss = node.toElement().attribute(QLatin1String("class"));        for (int i = 0; i < widgs; ++i)            if ((version < widgetTable[i].version)                 && (clss == widgetTable[i].before)) {                node.toElement().setAttribute(QLatin1String("class"), propertyTable[i].after);                return;            }        return;    }    if (tagName == QLatin1String("property")) {        QDomElement e = node.parentNode().toElement();        QString clss = e.attribute(QLatin1String("class"));        QString name = node.toElement().attribute(QLatin1String("name"), QLatin1String(""));        for (int i = 0; i < props; ++i)            if ((version < propertyTable[i].version)                 && (clss == propertyTable[i].clss)                 && (propertyTable[i].before.isNull()                      || name == propertyTable[i].before)) {                node.toElement().setAttribute(QLatin1String("name"), propertyTable[i].after);                return;            }    }}

⌨️ 快捷键说明

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