Ejemplo n.º 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();
}
Ejemplo n.º 2
0
/**
 * @brief VExceptionWrongId exception wrong parameter id
 * @param what string with error
 * @param domElement som element
 */
VExceptionWrongId::VExceptionWrongId(const QString &what, const QDomElement &domElement)
    :VException(what), tagText(QString()), tagName(QString()), lineNumber(-1)
{
    Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
    QTextStream stream(&tagText);
    domElement.save(stream, 4);
    tagName = domElement.tagName();
    lineNumber = domElement.lineNumber();
}
Ejemplo n.º 3
0
void VERBOSE_XML(
    unsigned int verbose_type,
    const QString &filename, const QDomElement &element, QString msg)
{
    VERBOSE(verbose_type,
            QString("%1\n\t\t\t"
                    "Location: %2 @ %3\n\t\t\t"
                    "Name: '%4'\tType: '%5'")
            .arg(msg).arg(filename).arg(element.lineNumber())
            .arg(element.attribute("name", "")).arg(element.tagName()));
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
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()));
      }
Ejemplo n.º 6
0
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));
      }
Ejemplo n.º 7
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()
            );
        }

    }
}
Ejemplo n.º 8
0
QString SkinContext::variableNodeToText(const QDomElement& variableNode) const {
    if (variableNode.hasAttribute("expression")) {
        QScriptValue result = m_pScriptEngine->evaluate(
            variableNode.attribute("expression"), m_xmlPath,
            variableNode.lineNumber());
        return result.toString();
    } else if (variableNode.hasAttribute("name")) {
        QString variableName = variableNode.attribute("name");
        if (variableNode.hasAttribute("format")) {
            QString formatString = variableNode.attribute("format");
            return formatString.arg(variable(variableName));
        } else if (variableNode.nodeName() == "SetVariable") {
            // If we are setting the variable name and we didn't get a format
            // string then return the node text. Use nodeToString to translate
            // embedded variable references.
            return nodeToString(variableNode);
        } else {
            return variable(variableName);
        }
    }
    return nodeToString(variableNode);
}
Ejemplo n.º 9
0
void updateMonsterXml(const QString &file)
{
    QDomDocument domDocument;
    //open and quick check the file
    QFile xmlFile(file);
    QByteArray xmlContent;
    if(!xmlFile.open(QIODevice::ReadOnly))
    {
        qDebug() << (QStringLiteral("Unable to open the xml monster file: %1, error: %2").arg(file).arg(xmlFile.errorString()));
        return;
    }
    xmlContent=xmlFile.readAll();
    xmlFile.close();
    QString errorStr;
    int errorLine,errorColumn;
    if (!domDocument.setContent(xmlContent, false, &errorStr,&errorLine,&errorColumn))
    {
        qDebug() << (QStringLiteral("Unable to open the xml file: %1, Parse error at line %2, column %3: %4").arg(file).arg(errorLine).arg(errorColumn).arg(errorStr));
        return;
    }
    QDomElement root = domDocument.documentElement();
    if(root.tagName()!="monsters")
    {
        qDebug() << (QStringLiteral("Unable to open the xml file: %1, \"list\" root balise not found for the xml file").arg(file));
        return;
    }

    //load the content
    bool ok;
    QDomElement item = root.firstChildElement(text_monster);
    while(!item.isNull())
    {
        if(item.isElement())
        {
            bool attributeIsOk=true;
            if(!item.hasAttribute(text_id))
            {
                qDebug() << (QStringLiteral("Unable to open the xml file: %1, have not the monster attribute \"id\": child.tagName(): %2 (at line: %3)").arg(file).arg(item.tagName()).arg(item.lineNumber()));
                attributeIsOk=false;
            }
            if(attributeIsOk)
            {
                QSet<quint32> byitemAlreadySet;
                QSet<quint32> skillAlreadySet;
                quint32 id=item.attribute(text_id).toUInt(&ok);
                if(!ok)
                    qDebug() << (QStringLiteral("Unable to open the xml file: %1, id not a number: child.tagName(): %2 (at line: %3)").arg(file).arg(item.tagName()).arg(item.lineNumber()));
                else
                {
                    #ifdef DEBUG_MESSAGE_MONSTER_LOAD
                    qDebug() << (QStringLiteral("monster loading: %1").arg(id));
                    #endif
                    if(ok)
                    {
                        {
                            QDomElement attack_list = item.firstChildElement(text_attack_list);
                            if(!attack_list.isNull())
                            {
                                if(attack_list.isElement())
                                {
                                    //QSet<quint32> learnByItem;
                                    QDomElement attack = attack_list.firstChildElement(text_attack);
                                    while(!attack.isNull())
                                    {
                                        if(attack.isElement())
                                        {
                                            if(attack.hasAttribute(text_skill) || attack.hasAttribute(text_id))
                                            {
                                                if(attack.hasAttribute(text_byitem))
                                                {
                                                    attack.parentNode().removeChild(attack);
                                                    /*quint32 itemId;
                                                    if(ok)
                                                    {
                                                        itemId=attack.attribute(text_byitem).toUShort(&ok);
                                                        if(!ok)
                                                            qDebug() << (QStringLiteral("Unable to open the xml file: %1, item to learn is not a number %4: child.tagName(): %2 (at line: %3)").arg(file).arg(attack.tagName()).arg(attack.lineNumber()).arg(attack.attribute(text_byitem)));
                                                    }
                                                    if(ok)
                                                    {
                                                        if(learnByItem.contains(itemId))
                                                        {
                                                            qDebug() << (QStringLiteral("Unable to open the xml file: %1, item to learn is already used %4: child.tagName(): %2 (at line: %3)").arg(file).arg(attack.tagName()).arg(attack.lineNumber()).arg(itemId));
                                                            ok=false;
                                                        }
                                                    }
                                                    if(ok)
                                                        learnByItem << itemId;*/
                                                }
                                            }
                                            else
                                                qDebug() << (QStringLiteral("Unable to open the xml file: %1, missing arguements (level or skill): child.tagName(): %2 (at line: %3)").arg(file).arg(attack.tagName()).arg(attack.lineNumber()));
                                        }
                                        else
                                            qDebug() << (QStringLiteral("Unable to open the xml file: %1, attack_list balise is not an element: child.tagName(): %2 (at line: %3)").arg(file).arg(attack.tagName()).arg(attack.lineNumber()));
                                        attack = attack.nextSiblingElement(text_attack);
                                    }
                                    //add the missing skill
                                    if(monsterIdToName.contains(id))
                                        if(monsterToLink.contains(monsterIdToName.value(id)))
                                        {
                                            const QList<Link> &link_list=monsterToLink.value(monsterIdToName.value(id));
                                            int index=0;
                                            while(index<link_list.size())
                                            {
                                                const Link &link=link_list.at(index);
                                                if(itemNameToId.contains(link.skill))
                                                    if(skillNameToId.contains(link.skill))
                                                    {
                                                        quint32 byitem=itemNameToId.value(link.skill);
                                                        quint32 skill=skillNameToId.value(link.skill);
                                                        if(!byitemAlreadySet.contains(byitem) && !skillAlreadySet.contains(skill))
                                                        {
                                                            byitemAlreadySet << byitem;
                                                            skillAlreadySet << skill;
                                                            QDomElement newElement=attack_list.ownerDocument().createElement("attack");
                                                            newElement.setAttribute("byitem",byitem);
                                                            newElement.setAttribute("id",skill);
                                                            if(!newElement.isNull())
                                                                attack_list.appendChild(newElement);
                                                        }
                                                    }
                                                index++;
                                            }
                                        }
                                }
                                else
                                    qDebug() << (QStringLiteral("Unable to open the xml file: %1, attack_list balise is not an element: child.tagName(): %2 (at line: %3)").arg(file).arg(item.tagName()).arg(item.lineNumber()));
                            }
                            else
                                qDebug() << (QStringLiteral("Unable to open the xml file: %1, have not attack_list: child.tagName(): %2 (at line: %3)").arg(file).arg(item.tagName()).arg(item.lineNumber()));
                        }
                    }
                    else
                        qDebug() << (QStringLiteral("Unable to open the xml file: %1, one of the attribute is wrong or is not a number: child.tagName(): %2 (at line: %3)").arg(file).arg(item.tagName()).arg(item.lineNumber()));
                }
            }
            else
                qDebug() << (QStringLiteral("Unable to open the xml file: %1, have not the monster id: child.tagName(): %2 (at line: %3)").arg(file).arg(item.tagName()).arg(item.lineNumber()));
        }
        else
            qDebug() << (QStringLiteral("Unable to open the xml file: %1, is not an element: child.tagName(): %2 (at line: %3)").arg(file).arg(item.tagName()).arg(item.lineNumber()));
        item = item.nextSiblingElement(text_monster);
    }
    {
        if(!xmlFile.open(QIODevice::WriteOnly))
        {
            qDebug() << QString("Unable to open the file %1:\n%2").arg(xmlFile.fileName()).arg(xmlFile.errorString());
            return;
        }
        xmlFile.write(domDocument.toByteArray(4));
        xmlFile.close();
    }
}
Ejemplo n.º 10
0
void parseMonstersExtra()
{
    QString STATIC_DATAPACK_BASE_PATH_MONSTERS=QLatin1Literal(DATAPACK_BASE_PATH_MONSTERS);
    const QString &file=datapackPath+STATIC_DATAPACK_BASE_PATH_MONSTERS+QStringLiteral("monster.xml");
    QDomDocument domDocument;
    //open and quick check the file
    QFile xmlFile(file);
    QByteArray xmlContent;
    if(!xmlFile.open(QIODevice::ReadOnly))
    {
        qDebug() << (QStringLiteral("Unable to open the xml monster extra file: %1, error: %2").arg(file).arg(xmlFile.errorString()));
        return;
    }
    xmlContent=xmlFile.readAll();
    xmlFile.close();
    QString errorStr;
    int errorLine,errorColumn;
    if (!domDocument.setContent(xmlContent, false, &errorStr,&errorLine,&errorColumn))
    {
        qDebug() << (QStringLiteral("Unable to open the xml file: %1, Parse error at line %2, column %3: %4").arg(file).arg(errorLine).arg(errorColumn).arg(errorStr));
        return;
    }
    QDomElement root = domDocument.documentElement();
    if(root.tagName()!="monsters")
    {
        qDebug() << (QStringLiteral("Unable to open the xml file: %1, \"list\" root balise not found for the xml file").arg(file));
        return;
    }

    const QString &language="en";
    //load the content
    bool ok;
    QDomElement item = root.firstChildElement(text_monster);
    while(!item.isNull())
    {
        if(item.isElement())
        {
            if(item.hasAttribute(text_id))
            {
                quint32 id=item.attribute(text_id).toUInt(&ok);
                if(!ok)
                    qDebug() << (QStringLiteral("Unable to open the xml file: %1, id not a number: child.tagName(): %2 (at line: %3)").arg(file).arg(item.tagName()).arg(item.lineNumber()));
                else
                {
                    QString nameText;
                    #ifdef DEBUG_MESSAGE_MONSTER_LOAD
                    qDebug() << (QStringLiteral("monster extra loading: %1").arg(id));
                    #endif
                    {
                        bool found=false;
                        QDomElement name = item.firstChildElement(text_name);
                        if(!language.isEmpty() && language!=text_en)
                            while(!name.isNull())
                            {
                                if(name.isElement())
                                {
                                    if(name.hasAttribute(text_lang) && name.attribute(text_lang)==language)
                                    {
                                        nameText=name.text();
                                        found=true;
                                        break;
                                    }
                                }
                                else
                                    qDebug() << (QStringLiteral("Unable to open the xml file: %1, name balise is not an element: child.tagName(): %2 (at line: %3)").arg(file).arg(item.tagName()).arg(item.lineNumber()));
                                name = name.nextSiblingElement(text_name);
                            }
                        if(!found)
                        {
                            name = item.firstChildElement(text_name);
                            while(!name.isNull())
                            {
                                if(name.isElement())
                                {
                                    if(!name.hasAttribute(text_lang) || name.attribute(text_lang)==text_en)
                                    {
                                        nameText=name.text();
                                        break;
                                    }
                                }
                                else
                                    qDebug() << (QStringLiteral("Unable to open the xml file: %1, name balise is not an element: child.tagName(): %2 (at line: %3)").arg(file).arg(item.tagName()).arg(item.lineNumber()));
                                name = name.nextSiblingElement(text_name);
                            }
                        }
                    }
                    if(!nameText.isEmpty())
                    {
                        monsterNameToId[nameText]=id;
                        monsterIdToName[id]=nameText;
                    }
                }
            }
            else
                qDebug() << (QStringLiteral("Unable to open the xml file: %1, have not the monster id at monster extra: child.tagName(): %2 (at line: %3)").arg(file).arg(item.tagName()).arg(item.lineNumber()));
        }
        else
            qDebug() << (QStringLiteral("Unable to open the xml file: %1, is not an element: child.tagName(): %2 (at line: %3)").arg(file).arg(item.tagName()).arg(item.lineNumber()));
        item = item.nextSiblingElement(text_monster);
    }

    qDebug() << QStringLiteral("%1 monster(s) extra loaded").arg(monsterNameToId.size());
}
Ejemplo n.º 11
0
void parseItemsExtra()
{
    //open and quick check the file
    QFile itemsFile(datapackPath+"items/items.xml");
    QByteArray xmlContent;
    if(!itemsFile.open(QIODevice::ReadOnly))
    {
        qDebug() << QStringLiteral("Unable to open the file: %1, error: %2").arg(itemsFile.fileName()).arg(itemsFile.errorString());
        return;
    }
    xmlContent=itemsFile.readAll();
    itemsFile.close();
    QDomDocument domDocument;
    QString errorStr;
    int errorLine,errorColumn;
    if (!domDocument.setContent(xmlContent, false, &errorStr,&errorLine,&errorColumn))
    {
        qDebug() << QStringLiteral("Unable to open the file: %1, Parse error at line %2, column %3: %4").arg(itemsFile.fileName()).arg(errorLine).arg(errorColumn).arg(errorStr);
        return;
    }
    QDomElement root = domDocument.documentElement();
    if(root.tagName()!="items")
    {
        qDebug() << QStringLiteral("Unable to open the file: %1, \"items\" root balise not found for the xml file").arg(itemsFile.fileName());
        return;
    }

    //load the content
    bool ok;
    QDomElement item = root.firstChildElement("item");
    while(!item.isNull())
    {
        if(item.isElement())
        {
            if(item.hasAttribute("id"))
            {
                item.attribute("id").toULongLong(&ok);
                if(ok)
                {
                    //load the name
                    {
                        QDomElement name = item.firstChildElement("name");
                        while(!name.isNull())
                        {
                            if(name.isElement())
                            {
                                if(!name.hasAttribute("lang") || name.attribute("lang")=="en")
                                {
                                    QString tempName=name.text();
                                    tempName.remove(QRegularExpression("[\r\n\t]+"));
                                    if(tempName.contains("TM") || tempName.contains("HM"))
                                        if(tempName.contains(QRegularExpression("^.*((TM|HM)[0-9]{2}) (.*)$",QRegularExpression::MultilineOption|QRegularExpression::DotMatchesEverythingOption)))
                                        {
                                            tempName.replace(QRegularExpression("^.*((TM|HM)[0-9]{2}) (.*)$",QRegularExpression::MultilineOption|QRegularExpression::DotMatchesEverythingOption),"\\3");
                                            //tempName=tempName.toLower();
                                            itemNameToId[tempName]=item.attribute("id").toUInt();
                                        }
                                    break;
                                }
                            }
                            name = name.nextSiblingElement("name");
                        }
                    }
                }
                else
                    qDebug() << QStringLiteral("Unable to open the file: %1, id is not a number: child.tagName(): %2 (at line: %3)").arg(itemsFile.fileName()).arg(item.tagName()).arg(item.lineNumber());
            }
            else
                qDebug() << QStringLiteral("Unable to open the file: %1, have not the item id: child.tagName(): %2 (at line: %3)").arg(itemsFile.fileName()).arg(item.tagName()).arg(item.lineNumber());
        }
        else
            qDebug() << QStringLiteral("Unable to open the file: %1, is not an element: child.tagName(): %2 (at line: %3)").arg(itemsFile.fileName()).arg(item.tagName()).arg(item.lineNumber());
        item = item.nextSiblingElement("item");
    }

    qDebug() << QStringLiteral("%1 item(s) extra loaded").arg(itemNameToId.size());
}
Ejemplo n.º 12
0
void MainWindow::on_itemListDelete_clicked()
{
    QList<QListWidgetItem *> selectedItems=ui->itemList->selectedItems();
    if(selectedItems.size()!=1)
    {
        QMessageBox::warning(this,tr("Error"),tr("Select a bot into the bot list"));
        return;
    }
    quint32 id=selectedItems.first()->data(99).toUInt();
    if(!items.contains(id))
    {
        QMessageBox::warning(this,tr("Error"),tr("Unable remove the bot, because the returned id is not into the list"));
        return;
    }
    bool ok;
    //load the bots
    QDomElement child = domDocument.documentElement().firstChildElement("item");
    while(!child.isNull())
    {
        if(!child.hasAttribute("id"))
            qDebug() << QStringLiteral("Has not attribute \"id\": child.tagName(): %1 (at line: %2)").arg(child.tagName()).arg(child.lineNumber());
        else if(!child.isElement())
            qDebug() << QStringLiteral("Is not an element: child.tagName(): %1, name: %2 (at line: %3)").arg(child.tagName().arg(child.attribute("name")).arg(child.lineNumber()));
        else
        {
            quint8 tempId=child.attribute("id").toUShort(&ok);
            if(ok)
            {
                if(tempId==id)
                {
                    child.parentNode().removeChild(child);
                    break;
                }
            }
            else
                qDebug() << QStringLiteral("Attribute \"id\" is not a number: bot.tagName(): %1 (at line: %2)").arg(child.tagName()).arg(child.lineNumber());
        }
        child = child.nextSiblingElement("item");
    }
    items.remove(id);
    updateItemList();
}
Ejemplo n.º 13
0
//Function executed at each frame
bool FakeTrackingModule::run() {

    QDomElement e;
    Blob b;
    Object o;
    int X1,Y1,X2,Y2,id;
    double X,Y,x,y,Vx,Vy;
    ObjectType type;
    std::map<int,Object>::iterator it, end_it;

    //VideoAnalysis::appendToLog("Tracking: Se puede!! :D");
    if(!currentNode.isNull()) {
        do {
            e = currentNode.toElement();
            if( !e.isNull() ) {
                if( e.tagName() == "Image" ) {
                    currentFrame = e.attribute( "IDimage", "" ).toInt();
                } else {
                    QMessageBox::warning(0, "Error reading ground-truth.", "The ground-truth file '" + m_fileName + "', at line" + e.lineNumber() + ", contains an element different than Image, inside VideoAnalysis. Execution will be aborted.");
                    return false;
                }
            } else {
                    QMessageBox::warning(0, "Error reading ground-truth.", "Error in the ground-truth file '" + m_fileName + "' at line" + e.lineNumber() + ". Execution will be aborted.");
                    return false;
            }
            if(currentFrame < m_data->frameNumber)
                currentNode = currentNode.nextSibling();
            //std::cout << "frameNumber: " << m_data->frameNumber << std::endl;
            //std::cout << "currentFrame: " << currentFrame << std::endl;
        } while(currentFrame < m_data->frameNumber && !currentNode.isNull());

        //If frame is found, extract blobs:
        if(!currentNode.isNull() && currentFrame == m_data->frameNumber) {
            QDomNode n = currentNode.firstChild();
            end_it = m_data->fake_objects.end();
            while(!n.isNull()) {
                e = n.toElement();
                if( !e.isNull() ) {
                    if( e.tagName() == "Object" ) {
                        //These coordinates are X horizontal, Y vertical...
                        X1 = e.attribute( "beginX", "" ).toInt() - 4;
                        Y1 = e.attribute( "beginY", "" ).toInt() - 2;
                        X2 = e.attribute( "endX", "" ).toInt() - 4;
                        Y2 = e.attribute( "endY", "" ).toInt() - 2;
                        id = e.attribute( "IDobject", "" ).toInt();
                        type = Object::extractType( e.attribute( "Nameobject", ""));
                        //Vertical
                        if(Y1 < Y2) {
                            BLOB_YTOP(&b) = Y1;
                            BLOB_YBOTTOM(&b) = Y2;
                            BLOB_HEIGHT(&b) = Y2 - Y1 + 1;
                        } else {
                            BLOB_YTOP(&b) = Y2;
                            BLOB_YBOTTOM(&b) = Y1;
                            BLOB_HEIGHT(&b) = Y1 - Y2 + 1;
                        }
                        //Horizontal
                        if(X1 < X2) {
                            BLOB_XLEFT(&b) = X1;
                            BLOB_XRIGHT(&b) = X2;
                            BLOB_WIDTH(&b) = X2 - X1 + 1;
                        } else {
                            BLOB_XLEFT(&b) = X2;
                            BLOB_XRIGHT(&b) = X1;
                            BLOB_WIDTH(&b) = X1 - X2 + 1;
                        }

                        SceneModel::getXY(m_pos,X,Y,b);
                        SceneModel::imgToWorldCoordsGivenHeight(m_data->sceneModel->p_matrix, X, Y, 0.0, &x, &y);
                        if( (it = m_data->fake_objects.find(id)) != end_it) { //Existing object
                            (*it).second.info2D = b;
                            Vx = x - ((*it).second.trajectory.back()).x;
                            Vy = y - ((*it).second.trajectory.back()).y;
                            Info3D i;
                            i.x = x; i.y = y; i.Vx = Vx; i.Vy = Vy;
                            (*it).second.trajectory.push_back(i);
                        } else { //new object
                            o.info2D = b;
                            o.label = id;
                            o.type = type;
                            Info3D i;
                            i.x = x; i.y = y; i.Vx = 0.0; i.Vy = 0.0;
                            o.trajectory.push_back(i);
                            m_data->fake_objects[id] = o;
                        }
                    } else {
                        QMessageBox::warning(0, "Error reading ground-truth.", "The ground-truth file '" + m_fileName + "', at line" + e.lineNumber() + ", contains an element different than Object, inside Image. Execution will be aborted.");
                        return false;
                    }
                } else {
                    QMessageBox::warning(0, "Error reading ground-truth.", "Error in the ground-truth file '" + m_fileName + "' at line" + e.lineNumber() + ". Execution will be aborted.");
                    return false;
                }
                n = n.nextSibling();
            }
            currentNode = currentNode.nextSibling();
        }
    }

    return true;
}
Ejemplo n.º 14
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);
    }
}
Ejemplo n.º 15
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() ) );
  }
}
Ejemplo n.º 16
0
bool accounts::parse_account_node(QDomElement node) {
	QString proto_name = node.attribute("protocol-name");
	ProtocolI *proto = get_proto_interface(proto_name);
	if(!proto) {
		qDebug() << "Accounts: skipping account data for unknown protocol -" << proto_name << "- on line" << node.lineNumber();
		return false;
	}
	
	QString account_id = node.attribute("id");
	if(account_ids(proto_name).contains(account_id)) {
		qDebug() << "Accounts: skipping already defined account id -" << account_id << "- on line" << node.lineNumber();
		return false;
	}

	Account *acc = new Account();
	acc->proto = proto;
	acc->enabled = node.attribute("enabled", "true") != "false";
	acc->host = node.attribute("host", proto->defaultHost());
	acc->nick = node.attribute("nickname", QDir::home().dirName());
	acc->username = node.attribute("username", QDir::home().dirName());
	acc->password = core_i->decrypt(node.attribute("password"), acc->username + acc->host);
	acc->port = node.attribute("port").toInt();
	acc->account_id = account_id;
	acc->account_name = node.attribute("account-name", account_id);
	acc->status = acc->desiredStatus = ST_OFFLINE;

	account_list[acc->proto][acc->account_id] = acc;
	icons_i->setup_account_status_icons(acc);			

	AccountChanged ac(acc, this);
	events_i->fire_event(ac);
	proto->parse_extra_data(node, acc);

	return true;
}
Ejemplo n.º 17
0
void MainWindow::on_openItemFile_clicked()
{
    if(ui->lineEditItemFile->text().isEmpty())
    {
        QMessageBox::warning(this,tr("Error"),tr("You need select a Item file"));
        return;
    }
    if(!ui->lineEditItemFile->text().contains(QRegExp("\\.xml$")))
    {
        QMessageBox::warning(this,tr("Error"),tr("The Item file is a xml file"));
        return;
    }
    QFile xmlFile(ui->lineEditItemFile->text());
    if(!xmlFile.open(QIODevice::ReadOnly))
    {
        QMessageBox::warning(this,tr("Error"),tr("Unable to open the file %1:\n%2").arg(xmlFile.fileName()).arg(xmlFile.errorString()));
        return;
    }
    settings.setValue("file",ui->lineEditItemFile->text());
    QByteArray xmlContent=xmlFile.readAll();
    xmlFile.close();
    QString errorStr;
    int errorLine,errorColumn;
    if (!domDocument.setContent(xmlContent, false, &errorStr,&errorLine,&errorColumn))
    {
        QMessageBox::warning(this,tr("Error"),tr("Unable to open the file %1:\nParse error at line %2, column %3: %4").arg(xmlFile.fileName()).arg(errorLine).arg(errorColumn).arg(errorStr));
        return;
    }
    bool ok;
    QDomElement root = domDocument.documentElement();
    if(root.tagName()!="items")
    {
        QMessageBox::warning(this,tr("Error"),tr("Unable to open the file %1:\nThe root balise is not Items").arg(xmlFile.fileName()));
        return;
    }
    bool error=false;
    //load the Items
    QDomElement child = root.firstChildElement("item");
    while(!child.isNull())
    {
        if(!child.hasAttribute("id") || !child.hasAttribute("price"))
        {
            qDebug() << QStringLiteral("Has not attribute \"id\" or \"price\": child.tagName(): %1 (at line: %2)").arg(child.tagName()).arg(child.lineNumber());
            error=true;
        }
        else if(!child.isElement())
        {
            qDebug() << QStringLiteral("Is not an element: child.tagName(): %1, name: %2 (at line: %3)").arg(child.tagName().arg(child.attribute("name")).arg(child.lineNumber()));
            error=true;
        }
        else
        {
            quint32 id=child.attribute("id").toUInt(&ok);
            if(ok)
                items[id]=child;
            else
            {
                qDebug() << QStringLiteral("Attribute \"id\" is not a number: Item.tagName(): %1 (at line: %2)").arg(child.tagName()).arg(child.lineNumber());
                error=true;
            }
        }
        child = child.nextSiblingElement("item");
    }
    if(error)
        QMessageBox::warning(this,tr("Error"),tr("Some error have been found into the file").arg(xmlFile.fileName()));
    ui->stackedWidget->setCurrentWidget(ui->page_list);
    updateItemList();
}
Ejemplo n.º 18
0
XmlParseException::XmlParseException(const QString& desc, const QDomElement& ele)
{
    m_description = desc;
    m_line = ele.lineNumber();
    m_elementName = ele.nodeName();
}
Ejemplo n.º 19
0
QHash<quint32,MonsterDrops> BaseServerFight::loadMonsterDrop(const QString &file, QHash<quint32,Item> items,const QHash<quint32,Monster> &monsters)
{
    QMultiHash<quint32,MonsterDrops> monsterDrops;
    //open and quick check the file
    QFile xmlFile(file);
    QByteArray xmlContent;
    if(!xmlFile.open(QIODevice::ReadOnly))
    {
        DebugClass::debugConsole(QString("Unable to open the xml file: %1, error: %2").arg(xmlFile.fileName()).arg(xmlFile.errorString()));
        return monsterDrops;
    }
    xmlContent=xmlFile.readAll();
    xmlFile.close();
    QDomDocument domDocument;
    QString errorStr;
    int errorLine,errorColumn;
    if (!domDocument.setContent(xmlContent, false, &errorStr,&errorLine,&errorColumn))
    {
        DebugClass::debugConsole(QString("Unable to open the xml file: %1, Parse error at line %2, column %3: %4").arg(xmlFile.fileName()).arg(errorLine).arg(errorColumn).arg(errorStr));
        return monsterDrops;
    }
    QDomElement root = domDocument.documentElement();
    if(root.tagName()!="list")
    {
        DebugClass::debugConsole(QString("Unable to open the xml file: %1, \"plants\" root balise not found for the xml file").arg(xmlFile.fileName()));
        return monsterDrops;
    }

    //load the content
    bool ok;
    QDomElement item = root.firstChildElement("monster");
    while(!item.isNull())
    {
        if(item.isElement())
        {
            if(item.hasAttribute("id"))
            {
                quint32 id=item.attribute("id").toUInt(&ok);
                if(!ok)
                    DebugClass::debugConsole(QString("Unable to open the xml file: %1, id not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                else if(!monsters.contains(id))
                    DebugClass::debugConsole(QString("Unable to open the xml file: %1, id into the monster list, skip: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                else
                {
                    QDomElement drops = item.firstChildElement("drops");
                    if(!drops.isNull())
                    {
                        if(drops.isElement())
                        {
                            QDomElement drop = drops.firstChildElement("drop");
                            while(!drop.isNull())
                            {
                                if(drop.isElement())
                                {
                                    if(drop.hasAttribute("item"))
                                    {
                                        MonsterDrops dropVar;
                                        if(drop.hasAttribute("quantity_min"))
                                        {
                                            dropVar.quantity_min=drop.attribute("quantity_min").toUInt(&ok);
                                            if(!ok)
                                                DebugClass::debugConsole(QString("Unable to open the xml file: %1, quantity_min is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                                        }
                                        else
                                            dropVar.quantity_min=1;
                                        if(ok)
                                        {
                                            if(drop.hasAttribute("quantity_max"))
                                            {
                                                dropVar.quantity_max=drop.attribute("quantity_max").toUInt(&ok);
                                                if(!ok)
                                                    DebugClass::debugConsole(QString("Unable to open the xml file: %1, quantity_max is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                                            }
                                            else
                                                dropVar.quantity_max=1;
                                        }
                                        if(ok)
                                        {
                                            if(dropVar.quantity_min<=0)
                                            {
                                                ok=false;
                                                DebugClass::debugConsole(QString("Unable to open the xml file: %1, dropVar.quantity_min is 0: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                                            }
                                        }
                                        if(ok)
                                        {
                                            if(dropVar.quantity_max<=0)
                                            {
                                                ok=false;
                                                DebugClass::debugConsole(QString("Unable to open the xml file: %1, dropVar.quantity_max is 0: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                                            }
                                        }
                                        if(ok)
                                        {
                                            if(dropVar.quantity_max<dropVar.quantity_min)
                                            {
                                                ok=false;
                                                DebugClass::debugConsole(QString("Unable to open the xml file: %1, dropVar.quantity_max<dropVar.quantity_min: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                                            }
                                        }
                                        if(ok)
                                        {
                                            if(drop.hasAttribute("luck"))
                                            {
                                                QString luck=drop.attribute("luck");
                                                luck.remove("%");
                                                dropVar.luck=luck.toUShort(&ok);
                                                if(!ok)
                                                    DebugClass::debugConsole(QString("Unable to open the xml file: %1, luck is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                                            }
                                            else
                                                dropVar.luck=100;
                                        }
                                        if(ok)
                                        {
                                            if(dropVar.luck<=0)
                                            {
                                                ok=false;
                                                DebugClass::debugConsole(QString("Unable to open the xml file: %1, luck is 0!: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                                            }
                                            if(dropVar.luck>100)
                                            {
                                                ok=false;
                                                DebugClass::debugConsole(QString("Unable to open the xml file: %1, luck is greater than 100: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                                            }
                                        }
                                        if(ok)
                                        {
                                            if(drop.hasAttribute("item"))
                                            {
                                                dropVar.item=drop.attribute("item").toUInt(&ok);
                                                if(!ok)
                                                    DebugClass::debugConsole(QString("Unable to open the xml file: %1, item is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                                            }
                                            else
                                                dropVar.luck=100;
                                        }
                                        if(ok)
                                        {
                                            if(!items.contains(dropVar.item))
                                            {
                                                ok=false;
                                                DebugClass::debugConsole(QString("Unable to open the xml file: %1, the item is not into the item list: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                                            }
                                        }
                                        if(ok)
                                            monsterDrops.insert(id,dropVar);
                                    }
                                    else
                                        DebugClass::debugConsole(QString("Unable to open the xml file: %1, as not item attribute: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                                }
                                else
                                    DebugClass::debugConsole(QString("Unable to open the xml file: %1, effect balise is not an element: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                                drop = drop.nextSiblingElement("drop");
                            }
                        }
                        else
                            DebugClass::debugConsole(QString("Unable to open the xml file: %1, drops balise is not an element: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
                    }
                }
            }
            else
                DebugClass::debugConsole(QString("Unable to open the xml file: %1, have not the monster id: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
        }
        else
            DebugClass::debugConsole(QString("Unable to open the xml file: %1, is not an element: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(item.tagName()).arg(item.lineNumber()));
        item = item.nextSiblingElement("monster");
    }
    return monsterDrops;
}
GraphicsMidiInputItem::GraphicsMidiInputItem(QDomElement controlNode, const PixmapMap& pixmapMap)
{
	// map a midi message to a
	m_inputMidiMessages.append(MidiMessage(controlNode));

	m_name = controlNode.attribute(CONTROL_NAME, "");
	m_groupName = controlNode.attribute(CONTROL_GROUP, "");
	QString debugColor = controlNode.attribute("debug");

	GraphicsMidiArea area = parseAreaElement(controlNode);
	if (area.isNull())
		return;

	QString mask = parsePixmapMask(controlNode);

	setSceneRect(area.rect);
	bool hasRanged = false;

	// get states
	QDomElement stateNode = controlNode.firstChildElement("state");
	int rangeMarker;
	QPixmap backgroundPixmap = pixmapFromMap(GuiUtils::background, m_sceneRect, pixmapMap, mask);
	ushort minRangeId, maxRangeId;
	while (!stateNode.isNull())
	{
		QString state = stateNode.text();
		QString stateValue = stateNode.attribute("value").trimmed();

		// map range to m_state2Pixmap
		rangeMarker = stateValue.indexOf(INPUT_STATE_RANGEMARKER);
		if (rangeMarker > 0)
		{
			hasRanged = true;
			bool ok = false;
			//qDebug() << state << stateValue  << rangeMarker << stateValue.left(rangeMarker) << stateValue.mid(rangeMarker + 1);
			minRangeId = stateValue.left(rangeMarker).toUShort(&ok, 0);
			if (ok)
				maxRangeId = stateValue.mid(rangeMarker + 1).toUShort(&ok, 0);
			if (!ok)
			{
				qCritical() << "error parsing:" << stateValue << "; line:" << stateNode.lineNumber();
				return;
			}

			QPixmap pixmap = pixmapFromState(stateNode, backgroundPixmap, m_sceneRect, pixmapMap, mask);
			if (!pixmap.isNull())
			{
				checkDebug(debugColor, pixmap, area);
				// map range to m_state2Pixmap
				m_state2Pixmap.insert(maxRangeId, pixmap);
				m_range2State.insert(minRangeId, maxRangeId); // add ranged value
			}
		}
		else
		{
			bool ok = false;
			ushort stateId = stateValue.toUShort(&ok, 0);
			if (pixmapMap.contains(state) && ok)
			{
//				QPixmap pixmap = pixmapMap.value(state).copy(rect);
				QPixmap pixmap = pixmapFromState(stateNode, backgroundPixmap, m_sceneRect, pixmapMap, mask);
				checkDebug(debugColor, pixmap, area);

				m_state2Pixmap.insert(stateId, pixmap);
				m_range2State.insert(stateId, stateId); // support for ranged values
				if (GuiUtils::isBackground(state))
				{
					m_offState = stateId;
					setPixmap(pixmap);
				}
			}
		}
		stateNode = stateNode.nextSiblingElement("state");
	}

	if (!hasRanged)
		m_range2State.clear(); // no ranged values after all...

/*	QPixmap pixmap = pixmapMap[GuiUtils::background];

if (0) {
	setPixmap(pixmap.copy(rect));
} else {
QPixmap tmp = pixmap.copy(rect);
QPainter dc(&tmp);
dc.setPen(Qt::green);
dc.drawRect(0,0,rect.width()-1, rect.height()-1);
setPixmap(tmp);
}
*/
	setPos(m_sceneRect.topLeft());
	setZValue(2);

	m_hasInput = true;
}
Ejemplo n.º 21
0
TaskInfo XmlTaskLoader::read()
{
    if (!m_document)
    {
        throw StopIterException();
    }

    int curLevel = m_level;
    while (!m_curElement.isNull())
    {
        QDomElement taskElement = m_curElement;

        QDomElement childElement;
        bool hasChildNodes = m_curElement.hasChildNodes();
        QDomElement element = m_curElement.firstChildElement("TASK");
        bool isNull = element.isNull();

        if (m_curElement.hasChildNodes() &&
            !(childElement = m_curElement.firstChildElement("TASK")).isNull())
        {
            m_curElement = childElement;
            m_level++;
        }
        else
        {
            QDomElement nextElement = m_curElement.nextSiblingElement("TASK");
            if (nextElement.isNull())
            {
                while (m_level > 0)
                {
                    m_curElement = m_curElement.parentNode().toElement();
                    m_level--;
                    nextElement = m_curElement.nextSiblingElement("TASK");
                    if (!nextElement.isNull())
                    {
                        m_curElement = nextElement;
                        break;
                    }
                }
                if (m_level == 0)
                {
                    m_curElement = nextElement;
                }
            }
            else
            {
                m_curElement = nextElement;
            }
        }

        TaskInfo taskInfo;

        // Required arguments
        bool parsedOk = false;
        taskInfo.id = taskElement.attribute("ID").toInt(&parsedOk);
        if (!parsedOk)
            throw LoadTasksException(QString("Can't parse task ID at line %1.").arg(taskElement.lineNumber()));
        taskInfo.title = taskElement.attribute("TITLE");

        // Optional arguments
        taskInfo.percentDone = taskElement.attribute("PERCENTDONE", "0").toUShort();
        taskInfo.iconIndex = taskElement.attribute("ICONINDEX", "-1").toInt();
        taskInfo.pos = taskElement.attribute("POS", "1").toInt();
        taskInfo.priority = taskElement.attribute("PRIORITY", "5").toInt();
        taskInfo.risk = taskElement.attribute("RISK", "0").toInt();
        taskInfo.cost = taskElement.attribute("COST", "0.0").toDouble();
        taskInfo.startDate = taskElement.attribute("STARTDATE", "0.0").toDouble();
        taskInfo.creationDate = taskElement.attribute("CREATIONDATE", "0.0").toDouble();
        taskInfo.doneDate = taskElement.attribute("DONEDATE", "0.0").toDouble();
        taskInfo.priorityColor = taskElement.attribute("PRIORITYCOLOR");
        taskInfo.textColor = taskElement.attribute("TEXTCOLOR");
        taskInfo.comments = taskElement.attribute("COMMENTS");
        taskInfo.commentsType = taskElement.attribute("COMMENTSTYPE");
        taskInfo.lastMod = taskElement.attribute("LASTMOD", "0.0").toDouble();

        int parentId = curLevel > 0 ? taskElement.
                                        parentNode().
                                        toElement().
                                        attribute("ID").
                                        toInt() :
                                     -1;

        taskInfo.parentId = parentId;

        return taskInfo;
    }
    throw StopIterException();
}
Ejemplo n.º 22
0
NewProfile::NewProfile(const QString &datapackPath, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::NewProfile)
{
    ui->setupUi(this);
    DatapackClientLoader::datapackLoader.resetAll();
    this->datapackPath=datapackPath;
    this->ok=false;
    ui->description->setText(tr("Profile loading..."));

    //open and quick check the file
    QFile xmlFile(datapackPath+DATAPACK_BASE_PATH_PLAYER+"start.xml");
    QByteArray xmlContent;
    if(!xmlFile.open(QIODevice::ReadOnly))
    {
        CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file to have new profile: %1, error: %2").arg(xmlFile.fileName()).arg(xmlFile.errorString()));
        return;
    }
    xmlContent=xmlFile.readAll();
    xmlFile.close();
    QDomDocument domDocument;
    QString errorStr;
    int errorLine,errorColumn;
    if (!domDocument.setContent(xmlContent, false, &errorStr,&errorLine,&errorColumn))
    {
        CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, Parse error at line %2, column %3: %4").arg(xmlFile.fileName()).arg(errorLine).arg(errorColumn).arg(errorStr));
        return;
    }
    QDomElement root = domDocument.documentElement();
    if(root.tagName()!="list")
    {
        CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, \"list\" root balise not found for the xml file").arg(xmlFile.fileName()));
        return;
    }

    //load the content
    bool ok;
    QDomElement startItem = root.firstChildElement("start");
    while(!startItem.isNull())
    {
        if(startItem.isElement())
        {
            Profile profile;
            const QString &language=LanguagesSelect::languagesSelect->getCurrentLanguages();
            bool found=false;
            QDomElement name = startItem.firstChildElement("name");
            if(!language.isEmpty() && language!="en")
                while(!name.isNull())
                {
                    if(name.isElement())
                    {
                        if(name.hasAttribute("lang") && name.attribute("lang")==language)
                        {
                            profile.name=name.text();
                            found=true;
                            break;
                        }
                    }
                    name = name.nextSiblingElement("name");
                }
            if(!found)
            {
                name = startItem.firstChildElement("name");
                while(!name.isNull())
                {
                    if(name.isElement())
                    {
                        if(!name.hasAttribute("lang") || name.attribute("lang")=="en")
                        {
                            profile.name=name.text();
                            break;
                        }
                    }
                    name = name.nextSiblingElement("name");
                }
            }
            if(profile.name.isEmpty())
            {
                CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, name empty or not found: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                startItem = startItem.nextSiblingElement("start");
                continue;
            }
            found=false;
            QDomElement description = startItem.firstChildElement("description");
            if(!language.isEmpty() && language!="en")
                while(!description.isNull())
                {
                    if(description.isElement())
                    {
                        if(description.hasAttribute("lang") && description.attribute("lang")==language)
                        {
                            profile.description=description.text();
                            found=true;
                            break;
                        }
                    }
                    description = description.nextSiblingElement("description");
                }
            if(!found)
            {
                description = startItem.firstChildElement("description");
                while(!description.isNull())
                {
                    if(description.isElement())
                    {
                        if(!description.hasAttribute("lang") || description.attribute("lang")=="en")
                        {
                            profile.description=description.text();
                            break;
                        }
                    }
                    description = description.nextSiblingElement("description");
                }
            }
            if(profile.description.isEmpty())
            {
                CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, description empty or not found: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                startItem = startItem.nextSiblingElement("start");
                continue;
            }
            QDomElement map = startItem.firstChildElement("map");
            if(!map.isNull() && map.isElement() && map.hasAttribute("file") && map.hasAttribute("x") && map.hasAttribute("y"))
            {
                profile.map=map.attribute("file");
                if(!QFile::exists(datapackPath+DATAPACK_BASE_PATH_MAP+profile.map))
                {
                    CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, map don't exists %2: child.tagName(): %3 (at line: %4)").arg(xmlFile.fileName()).arg(profile.map).arg(startItem.tagName()).arg(startItem.lineNumber()));
                    startItem = startItem.nextSiblingElement("start");
                    continue;
                }
                profile.x=map.attribute("x").toUShort(&ok);
                if(!ok)
                {
                    CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, map x is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                    startItem = startItem.nextSiblingElement("start");
                    continue;
                }
                profile.y=map.attribute("y").toUShort(&ok);
                if(!ok)
                {
                    CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, map y is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                    startItem = startItem.nextSiblingElement("start");
                    continue;
                }
            }
            else
            {
                CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, no correct map configuration: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                startItem = startItem.nextSiblingElement("start");
                continue;
            }
            QDomElement forcedskin = startItem.firstChildElement("forcedskin");
            if(!forcedskin.isNull() && forcedskin.isElement() && forcedskin.hasAttribute("value"))
            {
                profile.forcedskin=forcedskin.attribute("value").split(";");
                int index=0;
                while(index<profile.forcedskin.size())
                {
                    if(!QFile::exists(datapackPath+DATAPACK_BASE_PATH_SKIN+profile.forcedskin.at(index)))
                    {
                        CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, skin %4 don't exists: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()).arg(profile.forcedskin.at(index)));
                        profile.forcedskin.removeAt(index);
                    }
                    else
                        index++;
                }
            }
            profile.cash=0;
            QDomElement cash = startItem.firstChildElement("cash");
            if(!cash.isNull() && cash.isElement() && cash.hasAttribute("value"))
            {
                profile.cash=cash.attribute("value").toULongLong(&ok);
                if(!ok)
                {
                    CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, cash is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                    profile.cash=0;
                }
            }
            QDomElement monstersElement = startItem.firstChildElement("monster");
            while(!monstersElement.isNull())
            {
                Profile::Monster monster;
                if(monstersElement.isElement() && monstersElement.hasAttribute("id") && monstersElement.hasAttribute("level") && monstersElement.hasAttribute("captured_with"))
                {
                    monster.id=monstersElement.attribute("id").toUInt(&ok);
                    if(!ok)
                    {
                        CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, monster id is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                        monstersElement = monstersElement.nextSiblingElement("monster");
                        continue;
                    }
                    monster.level=monstersElement.attribute("level").toUShort(&ok);
                    if(!ok)
                    {
                        CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, monster level is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                        monstersElement = monstersElement.nextSiblingElement("monster");
                        continue;
                    }
                    if(monster.level==0 || monster.level>CATCHCHALLENGER_MONSTER_LEVEL_MAX)
                    {
                        CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, monster level is not into the range: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                        monstersElement = monstersElement.nextSiblingElement("monster");
                        continue;
                    }
                    monster.captured_with=monstersElement.attribute("captured_with").toUInt(&ok);
                    if(!ok)
                    {
                        CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, captured_with is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                        monstersElement = monstersElement.nextSiblingElement("monster");
                        continue;
                    }
                    profile.monsters << monster;
                }
                monstersElement = monstersElement.nextSiblingElement("monster");
            }
            if(profile.monsters.empty())
            {
                CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, not monster to load: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                startItem = startItem.nextSiblingElement("start");
                continue;
            }
            QDomElement reputationElement = startItem.firstChildElement("reputation");
            while(!reputationElement.isNull())
            {
                Profile::Reputation reputationTemp;
                if(reputationElement.isElement() && reputationElement.hasAttribute("type") && reputationElement.hasAttribute("level"))
                {
                    reputationTemp.type=reputationElement.attribute("type");
                    reputationTemp.level=reputationElement.attribute("level").toShort(&ok);
                    if(!ok)
                    {
                        CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, reputation level is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                        reputationElement = reputationElement.nextSiblingElement("reputation");
                        continue;
                    }
                    reputationTemp.point=0;
                    if(reputationElement.hasAttribute("point"))
                    {
                        reputationTemp.point=reputationElement.attribute("point").toInt(&ok);
                        if(!ok)
                        {
                            CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, reputation point is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                            reputationElement = reputationElement.nextSiblingElement("reputation");
                            continue;
                        }
                        if((reputationTemp.point>0 && reputationTemp.level<0) || (reputationTemp.point<0 && reputationTemp.level>=0))
                        {
                            CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, reputation point is not negative/positive like the level: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                            reputationElement = reputationElement.nextSiblingElement("reputation");
                            continue;
                        }
                    }
                    profile.reputation << reputationTemp;
                }
                reputationElement = reputationElement.nextSiblingElement("reputation");
            }
            QDomElement itemElement = startItem.firstChildElement("item");
            while(!itemElement.isNull())
            {
                Profile::Item itemTemp;
                if(itemElement.isElement() && itemElement.hasAttribute("id"))
                {
                    itemTemp.id=itemElement.attribute("id").toUInt(&ok);
                    if(!ok)
                    {
                        CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, item id is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                        itemElement = itemElement.nextSiblingElement("item");
                        continue;
                    }
                    itemTemp.quantity=0;
                    if(itemElement.hasAttribute("quantity"))
                    {
                        itemTemp.quantity=itemElement.attribute("quantity").toUInt(&ok);
                        if(!ok)
                        {
                            CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, item quantity is not a number: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                            itemElement = itemElement.nextSiblingElement("item");
                            continue;
                        }
                        if(itemTemp.quantity==0)
                        {
                            CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, item quantity is null: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
                            itemElement = itemElement.nextSiblingElement("item");
                            continue;
                        }
                    }
                    profile.items << itemTemp;
                }
                itemElement = itemElement.nextSiblingElement("item");
            }
            profileList << profile;
        }
        else
            CatchChallenger::DebugClass::debugConsole(QString("Unable to open the xml file: %1, is not an element: child.tagName(): %2 (at line: %3)").arg(xmlFile.fileName()).arg(startItem.tagName()).arg(startItem.lineNumber()));
        startItem = startItem.nextSiblingElement("start");
    }
    if(profileList.size()==0)
    {
        QMessageBox::critical(this,tr("Error"),tr("No profile selected to start a new game"));
        close();
        return;
    }
    ui->comboBox->clear();
    int index=0;
    while(index<profileList.size())
    {
        ui->comboBox->addItem(profileList.at(index).name);
        index++;
    }
    if(ui->comboBox->count()>0)
        ui->description->setText(profileList.at(ui->comboBox->currentIndex()).description);

    connect(this,&NewProfile::parseDatapack,&DatapackClientLoader::datapackLoader,&DatapackClientLoader::parseDatapack,Qt::QueuedConnection);
    connect(&DatapackClientLoader::datapackLoader,&DatapackClientLoader::datapackParsed,this,&NewProfile::datapackParsed,Qt::QueuedConnection);
    isParsingDatapack=DatapackClientLoader::datapackLoader.isParsingDatapack();
    if(!isParsingDatapack)
        emit parseDatapack(datapackPath);
}