Exemple #1
1
Font::Font(QString image_path, QString xml_path)
{
    QFile f(xml_path);
    QString errorStr("");
    int errorLine(0);
    int errorColumn(0);
    QDomDocument doc;
    QDomElement root;
    
    if (!f.open(QFile::ReadOnly | QFile::Text)) {
        qCritical("ERROR: Failed to open config file \"%s\": %s",
                  xml_path.toUtf8().constData(),
                  f.errorString().toUtf8().constData()
                  );
        return;
    }
    
    if (!doc.setContent(&f, false, &errorStr, &errorLine, &errorColumn)) {
        qCritical("ERROR: Failed to parse config file \"%s\" at line %d, column %d:\n%s",
                  xml_path.toUtf8().constData(),
                  errorLine,
                  errorColumn,
                  errorStr.toUtf8().constData()
                  );
        return;
    }
    
    root = doc.documentElement();
    if (root.tagName() != "Font") {
        qCritical("ERROR: Unexpected root element \"%s\" at line %d, column %d",
                  root.tagName().toUtf8().constData(),
                  root.lineNumber(),
                  root.columnNumber());
        return;
    }
    
    this->size = root.attribute("size").toInt();
    this->family = root.attribute("family");
    this->height = root.attribute("height").toInt();
    this->style = root.attribute("style");
    
//    qDebug("Font: %d, %s, %d, %s", this->size, this->family.toUtf8().constData(), this->height, this->style.toUtf8().constData());
    
    _minChar = 127;
    _maxChar = 0;
    QDomElement childElement = root.firstChildElement();
    while (!childElement.isNull()) {
        QString tagName = childElement.tagName();
        if (tagName == "Char") {
            Char *c = new Char(childElement);
            this->_chars[c->code] = c;
            if (c->code > _maxChar)
                _maxChar = c->code;
            if (c->code < _minChar)
                _minChar = c->code;
        }
        childElement = childElement.nextSiblingElement();
    }
    
    QImageReader image_reader(image_path);
    this->_image = image_reader.read();
}
Exemple #2
0
void domError(QDomElement e)
      {
      QString s = domElementPath(e);
      if (!docName.isEmpty())
            fprintf(stderr, "<%s>:", qPrintable(docName));
      int ln = e.lineNumber();
      if (ln != -1)
            fprintf(stderr, "line:%d ", ln);
      int col = e.columnNumber();
      if (col != -1)
            fprintf(stderr, "col:%d ", col);
      fprintf(stderr, "%s: Unknown Node <%s>, type %d\n",
         qPrintable(s), qPrintable(e.tagName()), e.nodeType());
      if (e.isText())
            fprintf(stderr, "  text node <%s>\n", qPrintable(e.toText().data()));
      }
void domError(const QDomElement& e)
      {
      QString m;
      QString s = domElementPath(e);
      if (!docName.isEmpty())
            m = QString("<%1>:").arg(docName);
      int ln = e.lineNumber();
      if (ln != -1)
            m += QString("line:%1 ").arg(ln);
      int col = e.columnNumber();
      if (col != -1)
            m += QString("col:%1 ").arg(col);
      m += QString("%1: Unknown Node <%2>, type %3").arg(s).arg(e.tagName()).arg(e.nodeType());
      if (e.isText())
            m += QString("  text node <%1>").arg(e.toText().data());
      qDebug("%s", qPrintable(m));
      }
Exemple #4
0
void ConfigLoader::loadIncludes(QDomDocument const &config, QFileInfo const &currentFile)
{
    QDomNodeList includes = config.elementsByTagName("include");
    for (unsigned i = 0; i < includes.length(); i++) {
        QDomElement includeElement = includes.at(i).toElement();
        QString includeName = includeElement.attribute("name");
        QFileInfo included = QFileInfo(currentFile.dir(), includeName);
        if (included.exists()) {
            load(included.canonicalFilePath());
        } else {
            fprintf(stderr, "Error 13 (%s:%d,%d) : Include '%s' is unknown.\n",
                    currentFile.fileName().toLatin1().constData(),
                    includeElement.lineNumber(),
                    includeElement.columnNumber(),
                    includeName.toLatin1().constData()
            );
        }

    }
}
Exemple #5
0
void ConfigLoader::loadClasses(QDomDocument const &config)
{
    QDomNodeList classes = config.elementsByTagName("class");
    for (unsigned i = 0; i < classes.length(); i++)
    {
        QDomElement classElement = classes.at(i).toElement();
        ReflectionGen *result = new ReflectionGen();
        result->name = getNamingFromXML(classElement);
        QString uibase = classElement.attribute("uibase");
        result->uiBaseClass = toCString(uibase);

        qDebug() << "Class" << result->name.name << " (" << i << "/" << classes.length() << ")";

        QDomNodeList fields = classElement.elementsByTagName("field");
        for (unsigned j = 0; j < fields.length(); j++)
        {
            QDomElement fieldElement = fields.at(j).toElement();
            ReflectionNaming fieldNameing = getNamingFromXML(fieldElement);

            QDomAttr typeAttribute = fieldElement.attributeNode("type");
            QString type = typeAttribute.value();

            qDebug() << "  Field" << fieldNameing.name << " type " << type;

            QString defaultValue = fieldElement.attribute("defaultValue");
            QString minValue     = fieldElement.attribute("min");
            QString maxValue     = fieldElement.attribute("max");
            QString stepValue    = fieldElement.attribute("step");
            bool hasAdditionalParameters = (!minValue.isEmpty()) || (!maxValue.isEmpty()) || (!stepValue.isEmpty());

            BaseField *field = NULL;

            if (type == "int")
            {
                field = new IntFieldGen(
                          defaultValue.toInt()
                        , fieldNameing
                        , hasAdditionalParameters
                        , minValue.toInt()
                        , maxValue.toInt()
                        , stepValue.isEmpty() ? 1 : stepValue.toInt());
            }
            else if (type == "double")
            {
                DoubleWidgetType widgetType = fieldElement.attribute("widget") == "ExponentialSlider" ?
                                           exponentialSlider :
                                           doubleSpinBox;
                field = new DoubleFieldGen(
                          defaultValue.toDouble()
                        , widgetType
                        , fieldNameing
                        , hasAdditionalParameters
                        , minValue.toDouble()
                        , maxValue.toDouble()
                        , stepValue.isEmpty() ? 1.0 : stepValue.toDouble());
            }
            else if (type == "bool")
            {
                BoolWidgetType widgetType = fieldElement.attribute("widget") == "RadioButton" ?
                                            radioButton :
                                            checkBox;

                field = new BoolFieldGen(defaultValue == "true", widgetType, fieldNameing);
            }
            else if (type == "string")
            {
                const char *dValue = toCString(defaultValue);
                field = new StringFieldGen(dValue, fieldNameing);
            }
            else if (type == "Vector2dd" || type == "Vector3dd")
            {
                // not supported yet (and most probably won't be supported)
            }
            /* TODO: Use "Type *" syntax instead */
            else if (type == "pointer")
            {
                QString targetType = fieldElement.attribute("target");
                field = new PointerFieldGen(fieldNameing, toCString(targetType));

            }
            else // composite field or enum
            {
                Reflection *reflection = mReflections.value(type);
                EnumReflection *enumRef = mEnums.value(type);

                if (reflection) // is it a field with the type of some other class?
                {
                    QDomAttr typeAttribute = fieldElement.attributeNode("size");
                    int size = typeAttribute.value().toInt();

                    if (size <= 0) {
                        field = new CompositeFieldGen(fieldNameing, toCString(type), reflection);
                    } else {
                        field = new CompositeArrayFieldGen(fieldNameing, toCString(type), size, reflection);
                    }
                }
                else if (enumRef) // then it should be a enum
                {
                    EnumWidgetType widgetType = fieldElement.attribute("widget") == "TabWidget" ?
                                                tabWidget :
                                                comboBox;

                    field = new EnumFieldGen(defaultValue.toInt(), widgetType, fieldNameing, enumRef);
                } else {
                    fprintf(stderr, "Error 12 (%s:%d,%d) : Type '%s' is unknown. Is neither enum, nor known type.\n",
                            result->name.name,
                            fieldElement.lineNumber(),
                            fieldElement.columnNumber(),
                            type.toLatin1().constData()
                    );
                }
            }

            if (field)
            {
                bool isAdavnced = fieldElement.hasAttribute("adv") | fieldElement.hasAttribute("advanced");
                field->isAdvanced = isAdavnced;
                result->fields.push_back(field);
            }
        }

        QDomNodeList embeds = classElement.elementsByTagName("embed");
        for (unsigned j = 0; j < embeds.length(); j++)
        {
            // qDebug() << "processing tag embed N" << j << " of (" << embeds.length() << ")";
            QDomElement embeddedElement = embeds.at(j).toElement();
            QString type = embeddedElement.attribute("type");

            ReflectionNaming embedNameing = getNamingFromXML(embeddedElement);

            Reflection *reflection = mReflections.value(type);
            if (!reflection) {
                fprintf(stderr, "Error 12 (%s:%d,%d) : Type '%s' is unknown.\n",
                        result->name.name,
                        embeddedElement.lineNumber(),
                        embeddedElement.columnNumber(),
                        type.toLatin1().constData()
                );
                continue;
            }

            EmbedSubclass *subclass = new EmbedSubclass();
            subclass->name = embedNameing;
            subclass->subclass = reflection;

            QDomNodeList prefix = embeddedElement.elementsByTagName("prefix");
            if (prefix.isEmpty())
            {
                // TODO: Partial renames
                QDomNodeList renames = embeddedElement.elementsByTagName("rename");
                for (unsigned j = 0; j < renames.length(); j++)
                {
                    QDomElement renaming = renames.at(j).toElement();
                    QString from = renaming.attribute("from");
                    QString to   = renaming.attribute("to");
//                    printf("  rename: %s -> %s\n", from.toLatin1().constData(), to.toLatin1().constData());
                    EmbedSubclass::EmbedMap map;
                    map.embeddedName = toCString(to);
                    map.originalName = toCString(from);
                    subclass->renameing.push_back(map);
                }
            } else
            {
                QString prefixString = prefix.at(0).toElement().attribute("name");
                vector<const BaseField *>::iterator it;
                for (it = reflection->fields.begin(); it != reflection->fields.end(); ++it)
                {
                    const BaseField *orignalField = (*it);
                    QString from = orignalField->getSimpleName();
                    QString to   = prefixString + from;
//                    printf("  rename: %s -> %s\n", from.toLatin1().constData(), to.toLatin1().constData());
                    EmbedSubclass::EmbedMap map;
                    map.embeddedName = toCString(to);
                    map.originalName = toCString(from);
                    subclass->renameing.push_back(map);
                }

            }

            result->embeds.push_back(subclass);
            // qDebug() << "Adding embed" << subclass->name.name;

            /* Now add fields */
            vector<const BaseField *>::iterator it;
            for (it = reflection->fields.begin(); it != reflection->fields.end(); ++it)
            {
                const BaseField *orignalField = (*it);
                const char *embeddedName = subclass->getEmbeddedName(orignalField->getSimpleName());
                BaseField *embeddedField = orignalField->clone();
                embeddedField->name.name = embeddedName;
                result->fields.push_back(embeddedField);
            }
        }

        mReflections.insert(result->name.name, result);
    }
}
Exemple #6
0
void Parser::parseInclude( ParserContext *context, const QDomElement &element )
{
  QString location = element.attribute( QLatin1String("schemaLocation") );

  if( !location.isEmpty() ) {
    // don't include a schema twice
    if ( d->mIncludedSchemas.contains( location ) )
      return;
    else
      d->mIncludedSchemas.append( location );

    includeSchema( context, location );
  }
  else {
    context->messageHandler()->warning( QString::fromLatin1("include tag found at (%1, %2) contains no schemaLocation tag.").arg( element.lineNumber(), element.columnNumber() ) );
  }
}
Exemple #7
0
QString TBase::parseID(QDomElement element)
{
    QString ret = "";
    if (element.hasAttribute("id"))
        ret = element.attribute("id");
    if (element.hasAttribute("xml:id")) // In SMIL 3.0 superset old SMIL 2.0 id.
        ret = element.attribute("xml:id");
    if (ret == "") // get line and column number as alternative when no
    {

        ret = element.tagName()+"_"+QString::number(element.lineNumber()) + "_" + QString::number(element.columnNumber());
    }
    return ret;
}