ViewItem* ArrowItemFactory::generateGraphics(QXmlStreamReader& xml, ObjectStore *store, View *view, ViewItem *parent) {
  ArrowItem *rc = 0;
  while (!xml.atEnd()) {
    bool validTag = true;
    if (xml.isStartElement()) {
      if (!rc && xml.name().toString() == "arrow") {
        Q_ASSERT(!rc);
        rc = new ArrowItem(view);
        if (parent) {
          rc->setParentViewItem(parent);
        }
        QXmlStreamAttributes attrs = xml.attributes();
        QStringRef av;
        av = attrs.value("startarrowhead");
        if (!av.isNull()) {
          rc->setStartArrowHead(QVariant(av.toString()).toBool());
        }
        av = attrs.value("endarrowhead");
        if (!av.isNull()) {
          rc->setEndArrowHead(QVariant(av.toString()).toBool());
        }
        av = attrs.value("startarrowheadscale");
        if (!av.isNull()) {
          rc->setStartArrowScale(QVariant(av.toString()).toDouble());
        }
        av = attrs.value("endarrowheadscale");
        if (!av.isNull()) {
          rc->setEndArrowScale(QVariant(av.toString()).toDouble());
        }
        // Add any new specialized ArrowItem Properties here.
      } else {
        Q_ASSERT(rc);
        if (!rc->parse(xml, validTag) && validTag) {
          ViewItem *i = GraphicsFactory::parse(xml, store, view, rc);
          if (!i) {
          }
        }
      }
    } else if (xml.isEndElement()) {
      if (xml.name().toString() == "arrow") {
        break;
      } else {
        validTag = false;
      }
    }
    if (!validTag) {
      qDebug("invalid Tag\n");
      Debug::self()->log(QObject::tr("Error creating arrow object from Kst file."), Debug::Warning);
      delete rc;
      return 0;
    }
    xml.readNext();
  }

  return rc;
}
QPoint DrawingAnchor::loadXmlPos(QXmlStreamReader &reader)
{
    Q_ASSERT(reader.name() == QLatin1String("pos"));

    QPoint pos;
    QXmlStreamAttributes attrs = reader.attributes();
    pos.setX(attrs.value(QLatin1String("x")).toString().toInt());
    pos.setY(attrs.value(QLatin1String("y")).toString().toInt());
    return pos;
}
Exemple #3
0
bool optional_assign(const QXmlStreamAttributes &attr, const char *key, T &v, const QXmlStreamReader &reader) {
	if ( attr.hasAttribute(XmlUtil::XML_NS, key) ) {
		v = checked_convert<T>(attr.value(XmlUtil::XML_NS, key).toString(), key, reader);
		return true;
	} else if ( attr.hasAttribute("", key) ) {
		v = checked_convert<T>(attr.value("", key).toString(), key, reader);
		return true;
	}
	return false;
}
QSize DrawingAnchor::loadXmlExt(QXmlStreamReader &reader)
{
    Q_ASSERT(reader.name() == QLatin1String("ext"));

    QSize size;
    QXmlStreamAttributes attrs = reader.attributes();
    size.setWidth(attrs.value(QLatin1String("cx")).toString().toInt());
    size.setHeight(attrs.value(QLatin1String("cy")).toString().toInt());
    return size;
}
Exemple #5
0
/*!
  Loads from XML.
*/
bool BinaryFilter::load(XmlStreamReader* reader) {
	if(!reader->isStartElement() || reader->name() != "binaryFilter"){
		reader->raiseError(i18n("no binary filter element found"));
		return false;
	}

	QString attributeWarning = i18n("Attribute '%1' missing or empty, default value is used");
	QXmlStreamAttributes attribs = reader->attributes();

	// read attributes
	QString str = attribs.value("vectors").toString();
	if(str.isEmpty())
		reader->raiseWarning(attributeWarning.arg("'vectors'"));
	else
		d->vectors = str.toInt();

	str = attribs.value("dataType").toString();
	if(str.isEmpty())
		reader->raiseWarning(attributeWarning.arg("'dataType'"));
	else
		d->dataType = (BinaryFilter::DataType) str.toInt();

	str = attribs.value("byteOrder").toString();
	if(str.isEmpty())
		reader->raiseWarning(attributeWarning.arg("'byteOrder'"));
	else
		d->byteOrder = (BinaryFilter::ByteOrder) str.toInt();

	str = attribs.value("autoMode").toString();
	if(str.isEmpty())
		reader->raiseWarning(attributeWarning.arg("'autoMode'"));
	else
		d->autoModeEnabled = str.toInt();

	str = attribs.value("startRow").toString();
	if(str.isEmpty())
		reader->raiseWarning(attributeWarning.arg("'startRow'"));
	else
		d->startRow = str.toInt();

	str = attribs.value("endRow").toString();
	if(str.isEmpty())
		reader->raiseWarning(attributeWarning.arg("'endRow'"));
	else
		d->endRow = str.toInt();

	str = attribs.value("skipStartBytes").toString();
	if(str.isEmpty())
		reader->raiseWarning(attributeWarning.arg("'skipStartBytes'"));
	else
		d->skipStartBytes = str.toInt();

	str = attribs.value("skipBytes").toString();
	if(str.isEmpty())
		reader->raiseWarning(attributeWarning.arg("'skipBytes'"));
	else
		d->skipBytes = str.toInt();

	return true;
}
void DocumentModelPointMatch::loadXml(QXmlStreamReader &reader)
{
  LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelPointMatch::loadXml";

  bool success = true;

  QXmlStreamAttributes attributes = reader.attributes();

  if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_POINT_SIZE) &&
      attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_ACCEPTED) &&
      attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_CANDIDATE) &&
      attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_REJECTED)) {

    setMaxPointSize (attributes.value(DOCUMENT_SERIALIZE_POINT_MATCH_POINT_SIZE).toDouble());
    setPaletteColorAccepted ((ColorPalette) attributes.value(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_ACCEPTED).toInt());
    setPaletteColorCandidate ((ColorPalette) attributes.value(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_CANDIDATE).toInt());
    setPaletteColorRejected ((ColorPalette) attributes.value(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_REJECTED).toInt());

    // Read until end of this subtree
    while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
    (reader.name() != DOCUMENT_SERIALIZE_POINT_MATCH)){
      loadNextFromReader(reader);
      if (reader.atEnd()) {
        success = false;
        break;
      }
    }
  }

  if (!success) {
    reader.raiseError (QObject::tr ("Cannot read point match data"));
  }
}
void GeneratorBMRC::Generate()
{

    writer->setAutoFormatting(true);
    writer->writeStartDocument("1.0");



    writer->writeStartElement("Station");
    writer->writeAttribute("STEP_GRID", QString::number(MainElement::GetStepGrid()));
    writer->writeAttribute("RadContact", QString::number(MainElement::getRad()));
    writer->writeAttribute("widthLinesElements", QString::number(MainElement::getWidthLinesElements()));
    writer->writeAttribute("widthLinesContacts", QString::number(MainElement::getWidthLinesContacts()));

     QVector<int> posx, posy;

    while(!reader->atEnd() && !reader->hasError())
    {
        QXmlStreamReader::TokenType token = reader->readNext();


        if(token == QXmlStreamReader::StartElement)
        {
            if(reader->name() == "Chain")
            {
                QXmlStreamAttributes attrib = reader->attributes();
                int idChain;

                if(attrib.hasAttribute("id"))
                    idChain = attrib.value("id").toInt();


              ReadOneChain(reader, posx, posy);

            }

        }


    }




    for(int i=0;i<element.size();i++)
    {
        element[i]->SaveToXml(*writer);
    }


    writer->writeEndElement();//Station
    writer->writeEndDocument();

    reader->clear();
}
CmdAddPointGraph::CmdAddPointGraph (MainWindow &mainWindow,
                                    Document &document,
                                    const QString &cmdDescription,
                                    QXmlStreamReader &reader) :
  CmdPointChangeBase (mainWindow,
                      document,
                      cmdDescription)
{
  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointGraph::CmdAddPointGraph";

  QXmlStreamAttributes attributes = reader.attributes();

  if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_X) ||
      !attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_Y) ||
      !attributes.hasAttribute(DOCUMENT_SERIALIZE_CURVE_NAME) ||
      !attributes.hasAttribute(DOCUMENT_SERIALIZE_ORDINAL) ||
      !attributes.hasAttribute(DOCUMENT_SERIALIZE_IDENTIFIER)) {
    xmlExitWithError (reader,
                      QString ("Missing attribute(s) %1, %2, %3, %4 and/or %5")
                      .arg (DOCUMENT_SERIALIZE_SCREEN_X)
                      .arg (DOCUMENT_SERIALIZE_SCREEN_Y)
                      .arg (DOCUMENT_SERIALIZE_CURVE_NAME)
                      .arg (DOCUMENT_SERIALIZE_ORDINAL)
                      .arg (DOCUMENT_SERIALIZE_IDENTIFIER));
  }

  m_posScreen.setX(attributes.value(DOCUMENT_SERIALIZE_SCREEN_X).toDouble());
  m_posScreen.setY(attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y).toDouble());
  m_curveName = attributes.value(DOCUMENT_SERIALIZE_CURVE_NAME).toString();
  m_identifierAdded = attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
  m_ordinal = attributes.value(DOCUMENT_SERIALIZE_ORDINAL).toDouble();
}
Exemple #9
0
/**
 * Called when the webview finished loading a new page
 */
void PhoneGap::loadFinished( bool ok ) {
    Q_UNUSED(ok)

    // Change into the xml-directory
    QDir xmlDir( m_workingDir );
    xmlDir.cd( "xml" );

    // Try to open the plugins configuration
    QFile pluginsXml( xmlDir.filePath("plugins.xml") );
    if( !pluginsXml.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
        qDebug() << "Error loading plugins config!";
        return;
    }

    // Start reading the file as a stream
    QXmlStreamReader plugins;
    plugins.setDevice( &pluginsXml );

    // Get a reference to the current main-frame
    QWebFrame *webFrame = m_webView->page()->mainFrame();

    // Iterate over plugins-configuration and load all according plugins
    while(!plugins.atEnd()) {
        if( plugins.readNext() == QXmlStreamReader::StartElement ) {
            // Check if we have a plugin element
            if( plugins.name() == "plugin" ) {
                QXmlStreamAttributes attribs = plugins.attributes();
                // Check for name & value attributes
                if( attribs.hasAttribute("name") && attribs.hasAttribute("value") ) {
                    // Construct object & attribute names
                    QString attribName = attribs.value( "name" ).toString();
                    QString attribValue = attribs.value( "value" ).toString();
                    QString objectName = attribName + "_native";

                    qDebug() << "Adding Plugin " << attribName << " with " << attribValue;
                    // Check for such a plugin
                    PGPlugin *currPlugin = PluginRegistry::getRegistry()->getPlugin( attribValue );
                    if( currPlugin != NULL ) {
                        currPlugin->setWebFrame( webFrame );
                        webFrame->addToJavaScriptWindowObject( objectName, currPlugin );

                        webFrame->evaluateJavaScript( "PhoneGap.Qt.registerObject( '" + attribValue + "', " + objectName + " )" );
                        webFrame->evaluateJavaScript( "PhoneGap.enablePlugin( '" + attribValue + "' )" );
                    }
                    else {
                        qDebug() << "Unknown Plugin " << attribName;
                    }
                }
            }
        }
    }

    // Device is now ready to rumble
    webFrame->evaluateJavaScript( "PhoneGap.deviceready();" );
}
Exemple #10
0
bool CeSdkHandler::parse()
{
    // look at the file at %VCInstallDir%/vcpackages/WCE.VCPlatform.config
    // and scan through all installed sdks...    
    m_list.clear();
    VCInstallDir = QString::fromLatin1(qgetenv("VCInstallDir"));
    VCInstallDir += QLatin1String("\\");
    VSInstallDir = QString::fromLatin1(qgetenv("VSInstallDir"));
    VSInstallDir += QLatin1String("\\");
    if (VCInstallDir.isEmpty() || VSInstallDir.isEmpty())
        return false;

    QDir vStudioDir(VCInstallDir);
    if (!vStudioDir.cd(QLatin1String("vcpackages")))
        return false;

    QFile configFile(vStudioDir.absoluteFilePath(QLatin1String("WCE.VCPlatform.config")));
    if (!configFile.exists() || !configFile.open(QIODevice::ReadOnly))
        return false;
    
    QString currentElement;
    CeSdkInfo currentItem;
    QXmlStreamReader xml(&configFile);
    while (!xml.atEnd()) {
        xml.readNext();
        if (xml.isStartElement()) {
            currentElement = xml.name().toString();
            if (currentElement == QLatin1String("Platform"))
                currentItem = CeSdkInfo();
            else if (currentElement == QLatin1String("Directories")) {
                QXmlStreamAttributes attr = xml.attributes();
                currentItem.m_include = fixPaths(attr.value(QLatin1String("Include")).toString());
                currentItem.m_lib = fixPaths(attr.value(QLatin1String("Library")).toString());
                currentItem.m_bin = fixPaths(attr.value(QLatin1String("Path")).toString());
            }
        } else if (xml.isEndElement()) {
            if (xml.name().toString() == QLatin1String("Platform"))
                m_list.append(currentItem);
        } else if (xml.isCharacters() && !xml.isWhitespace()) {
            if (currentElement == QLatin1String("PlatformName"))
                currentItem.m_name = xml.text().toString();
            else if (currentElement == QLatin1String("OSMajorVersion"))
                currentItem.m_major = xml.text().toString().toInt();
            else if (currentElement == QLatin1String("OSMinorVersion"))
                currentItem.m_minor = xml.text().toString().toInt();
        }
    }

    if (xml.error() && xml.error() != QXmlStreamReader::PrematureEndOfDocumentError) {
        qWarning() << "XML ERROR:" << xml.lineNumber() << ": " << xml.errorString();
        return false;
    }

    return m_list.size() > 0 ? true : false;
}
Exemple #11
0
// Constructor for parser function
Message::Message(XmlStreamReader& xml)
 :  QObject(),
    m_timeStamp(),
    m_timeStampPresent( false ),
    m_code( 0 ),
    m_codePresent( false ),
    m_version( "1.0.0" ), // initialize fixed value
    m_versionPresent( true ),
    m_changed(true)
{
    QXmlStreamAttributes attr = xml.attributes();
    if ( attr.hasAttribute( "TimeStamp" ) )
    {
        if ( !setTimeStamp( QDateTime::fromString(attr.value( "TimeStamp" ).toString(), Qt::ISODate)) )
            xml.validationError( "error set TimeStamp = " + attr.value( "TimeStamp" ).toString() );
    }
    if ( attr.hasAttribute( "Code" ) )
    {
        if ( !setCode( attr.value( "Code" ).toString().toInt() ) )
            xml.validationError( "error set Code = " + attr.value( "Code" ).toString() );
    }
    if ( attr.hasAttribute( "Version" ) )
    {
        if ( !setVersion( attr.value( "Version" ).toString() ) )
            xml.validationError( "error set Version = " + attr.value( "Version" ).toString() );
    }
    bool stop(false);
    while(!xml.atEnd() && !stop)
    {
        QXmlStreamReader::TokenType token = xml.readNext();
        switch ( token )
        {
        case QXmlStreamReader::EndElement:
            if (  xml.name() == "Message" )
                stop = true;
            break;
        case QXmlStreamReader::StartElement:
            if ( xml.name() == "Argument" )
            {
                QString val = xml.readElementText();
                if ( xml.name() != "Argument" )
                    xml.raiseError( "tag mismatch Argument" );
                else if ( !addArgument( val ) )
                    xml.validationError( "error add Argument"  );
            }
            else
            {
                xml.validationError( "unexpected element " + xml.name().toString() );
            }
            break;
        default:
            break;
        }
    }
}
    bool handleStanza(const QXmlStreamAttributes &attributes)
    {
        if (!attributes.hasAttribute("branch"))
            return false;
        if (!attributes.hasAttribute("tip"))
            return false;

        data->branch = attributes.value("branch").toString();
        data->tip = attributes.value("tip").toString();
        return true;
    }
Exemple #13
0
DriOptionInfo::DriOptionInfo(QXmlStreamReader *xml)
{
    QXmlStreamAttributes attributes = xml->attributes();

    if (attributes.hasAttribute("name"))
        name = attributes.value("name").toString();
    else
        throw "Missing name element to option info";

    if (attributes.hasAttribute("type")) {
        QString type_string = attributes.value("type").toString();
        if (type_string == "bool")
            type = OptionBool;
        else if (type_string == "int")
            type = OptionInt;
        else if (type_string == "enum")
            type = OptionEnum;
        else if (type_string == "string")
            type = OptionString;
        else
            throw "Unknown type element to option info";
    } else
        throw "Missing type element to option info";

    if (attributes.hasAttribute("default"))
        default_value = attributes.value("default").toString();
    else
        default_value.clear();

    if (type == OptionEnum) {
        if (!attributes.hasAttribute("valid"))
            throw "Missing valid element to option info with enum";

        QString valid_string = attributes.value("valid").toString();
        QStringList valid_string_list = valid_string.split(':');
        bool ok = 0;

        if (!valid_string_list.count() == 2)
            throw "Invalid valid element to option info with enum";

        min_valid = valid_string_list[0].toInt(&ok);
        if (!ok)
            throw "Invalid valid element to option info with enum";
        max_valid = valid_string_list[1].toInt(&ok);
        if (!ok || min_valid > max_valid)
            throw "Invalid valid element to option info with enum";
    }

    descriptions.clear();
    if (!xml->readNextStartElement()) {
        return;
    }
    do {
        if (xml->name() == "description")
            descriptions.append(new DescriptionLangInfo(xml));
        else
            xml->skipCurrentElement();
    } while (xml->readNextStartElement());
}
void CStateMachine::parseStateChangedArgs(QXmlStreamReader* reader)
{
	m_state = e_state_changed;

	QXmlStreamAttributes att = reader->attributes();
    QStringRef stateStrRef = att.value(QString(), QString("state"));

    bool ok;
    m_sessionState = stateStrRef.toString().toInt(&ok);
    if(!ok) m_sessionState = e_stopped;
}
Exemple #15
0
//------------------------------------------------------------------------------
void getListWordFromDict(const QString f_path, QMap<QString, QString>* f_map)
{
    f_map->clear();

    QFile* xmlFile = new QFile(f_path);
    if (!xmlFile->open(QIODevice::ReadOnly | QIODevice::Text))
    {
        return;
    }
    QXmlStreamReader* xmlReader = new QXmlStreamReader(xmlFile);


    //Parse the XML until we reach end of it
    while(!xmlReader->atEnd() && !xmlReader->hasError())
    {
        // Read next element
        QXmlStreamReader::TokenType token = xmlReader->readNext();
        //If token is just StartDocument - go to next
        if(token == QXmlStreamReader::StartDocument)
        {
            continue;
        }
        //If token is StartElement - read it
        if(token == QXmlStreamReader::StartElement)
        {

            if(xmlReader->name() == "word")
            {
                QXmlStreamAttributes attrs = xmlReader->attributes();

                QStringList t_list;
                QString t_text;
                t_list << xmlReader->readElementText().split("\n");
                removeEmptyQStringFromQStringList(&t_list);

                for (int i = 0; i < t_list.size(); i++)
                {
                    t_text.append(QString(t_list.at(i)).replace("    ", "") + "\n");
                }

                f_map->insert(attrs.value("name").toString(), t_text);
            }
        }
    }

    if(xmlReader->hasError())
    {
        return;
    }

    //close reader and flush file
    xmlReader->clear();
    xmlFile->close();
}
void OsmDataManager::addNode(QXmlStreamReader& xml){
    QXmlStreamAttributes attr = xml.attributes();
    QString id = attr.value("id").toString();
    float lat = attr.value("lat").toString().toFloat();
    float lon = attr.value("lon").toString().toFloat();
    QList<float> nodes;
    nodes.append(lat);
    nodes.append(lon);
    m_nodes[id] = nodes;
    xml.skipCurrentElement();
}
void PrivacyQueryFactory::handleStartElement(const QStringRef &name, const QStringRef &uri,
											 const QXmlStreamAttributes &attributes)
{
	Q_UNUSED(uri);
	m_depth++;
	if (m_depth == 1) {
		m_query.reset(new PrivacyQuery);
	} if (m_depth == 2) {
		QStringRef listName = attributes.value(QLatin1String("name"));
		if (name == QLatin1String("list")) {
			m_state = AtList;
			m_name = listName.toString();
			
		} else if (name == QLatin1String("active")) {
			m_query->activeList = listName.toString();
		} else if (name == QLatin1String("default")) {
			m_query->defaultList = listName.toString();
		}
	} else if (m_depth == 3 && m_state == AtList && name == QLatin1String("item")) {
		// We should provide fallback as said in rfc-3920
		m_items.append(m_items.isEmpty() ? PrivacyItem() : m_items.last());
		PrivacyItem &item = m_items.last();
		m_state = AtItem;
		QStringRef data = attributes.value(QLatin1String("value"));
		int type = strToEnum(attributes.value(QLatin1String("type")), privacy_types);
		if (type == -1 && !data.isEmpty())
			type = item.type();
		switch (type) {
		case PrivacyItem::ByJID:
			item.setJID(data.toString());
			break;
		case PrivacyItem::ByGroup:
			item.setGroup(data.toString());
			break;
		case PrivacyItem::BySubscription:
			item.setSubscription(strToEnum<PrivacyItem::SubscriptionType>(data, subscription_types));
			break;
		default:
			item = PrivacyItem();
			break;
		}
		data = attributes.value(QLatin1String("action"));
		item.setAction(strToEnum<PrivacyItem::Action>(data, privacy_actions));
		item.setOrder(attributes.value(QLatin1String("order")).toString().toInt());
		item.setStanzaTypes(0);
	} else if (m_depth == 4 && m_state == AtItem) {
		int data = strToEnum(name, privacy_stanzas);
		if (data == -1)
			return;
		PrivacyItem &item = m_items.last();
		item.setStanzaTypes(item.stanzaTypes() | static_cast<PrivacyItem::StanzaType>(1 << data));
	}
}
QString ComplexShapeHandler::handle_gd(QXmlStreamReader* reader)
{
    QXmlStreamAttributes attrs = reader->attributes();

    QString name = attrs.value("name").toString();
    QString function = attrs.value("fmla").toString();

    QString returnString = QString("<draw:equation draw:name=\"%1\" draw:formula=\"%2\"/>").arg(name).arg(createEquation(function));

    reader->readNext();
    return returnString;
}
Exemple #19
0
bool DateTime2StringFilter::load(XmlStreamReader * reader)
{
	QXmlStreamAttributes attribs = reader->attributes();
	QString str = attribs.value(reader->namespaceUri().toString(), "format").toString();

	if (AbstractSimpleFilter::load(reader))
		setFormat(str);
	else
		return false;

	return !reader->hasError();
}
Exemple #20
0
void Groups::finishedFetchingGroups()
{
    QNetworkReply *reply = static_cast<QNetworkReply *>(sender());

    if (reply->hasRawHeader("Backoff"))
        d->api->startBackoff(QString::fromLatin1(reply->rawHeader("Backoff").constData()).toInt());
    else if (reply->hasRawHeader("Retry-After"))
        d->api->startBackoff(QString::fromLatin1(reply->rawHeader("Retry-After").constData()).toInt());

    if (reply->error() == QNetworkReply::NoError) {
        QString nextPage;
        QXmlStreamReader xmlReader(reply);
        while (!xmlReader.atEnd() && !xmlReader.hasError()) {
            const QXmlStreamReader::TokenType tt = xmlReader.readNext();
            if (tt == QXmlStreamReader::StartElement && xmlReader.name() == QStringLiteral("entry")) {
                QString label;
                int groupId = -1;
                while (!xmlReader.atEnd() && !xmlReader.hasError()) {
                    const QXmlStreamReader::TokenType tt = xmlReader.readNext();
                    if (tt == QXmlStreamReader::StartElement && xmlReader.name() == QStringLiteral("title"))
                        label = xmlReader.readElementText(QXmlStreamReader::IncludeChildElements);
                    else if (tt == QXmlStreamReader::StartElement && xmlReader.name() == QStringLiteral("groupID")) {
                        bool ok = false;
                        groupId = xmlReader.readElementText(QXmlStreamReader::IncludeChildElements).toInt(&ok);
                        if (groupId < 1) groupId = -1;
                    } else if (tt == QXmlStreamReader::EndElement && xmlReader.name() == QStringLiteral("entry"))
                        break;
                }

                if (!label.isEmpty() && groupId > 0)
                    d->groups.insert(groupId, label);
            } else if (tt == QXmlStreamReader::StartElement && xmlReader.name() == QStringLiteral("link")) {
                const QXmlStreamAttributes attrs = xmlReader.attributes();
                if (attrs.hasAttribute(QStringLiteral("rel")) && attrs.hasAttribute(QStringLiteral("href")) && attrs.value(QStringLiteral("rel")) == QStringLiteral("next"))
                    nextPage = attrs.value(QStringLiteral("href")).toString();
            } else if (tt == QXmlStreamReader::EndElement && xmlReader.name() == QStringLiteral("feed"))
                break;
        }

        if (!nextPage.isEmpty())
            d->requestZoteroUrl(nextPage);
        else {
            d->busy = false;
            d->initialized = true;
            emit finishedLoading();
        }
    } else {
        qCWarning(LOG_KBIBTEX_NETWORKING) << reply->errorString(); ///< something went wrong
        d->busy = false;
        d->initialized = false;
        emit finishedLoading();
    }
}
Exemple #21
0
void BillItemMeasure::loadFromXml10(const QXmlStreamAttributes &attrs) {
    if( attrs.hasAttribute( "comment" ) ){
        setComment(  attrs.value( "comment").toString() );
    }
    if( attrs.hasAttribute( "formula" ) ){
        QString f = attrs.value( "formula").toString();
        if( m_d->parser->decimalSeparator() != "." ){
            f.replace( ".", m_d->parser->decimalSeparator());
        }
        setFormula( f );
    }
}
Exemple #22
0
void PriceList::loadFromXml10(const QXmlStreamAttributes &attrs ) {
    for( QXmlStreamAttributes::const_iterator attrIter = attrs.begin(); attrIter != attrs.end(); ++attrIter ){
        QString nameUp = attrIter->name().toString().toUpper();
        if( nameUp == "ID" ){
            m_d->id = attrIter->value().toString().toUInt();
        } else if( nameUp == "NAME" ){
            setName( attrIter->value().toString() );
        } else if( nameUp == "DESCRIPTION" ){
            setDescription( attrIter->value().toString() );
        }
    }
}
Exemple #23
0
void LayoutParser::parseImportChild(QStringList *target_list)
{
    const QXmlStreamAttributes attributes(m_xml.attributes());
    const QString src(attributes.value(QLatin1String("src")).toString());

    if (src.isEmpty()) {
        error(QString::fromLatin1("Expected non-empty 'src' attribute in '<%1>'.").arg(m_xml.name().toString()));
    } else if (target_list) {
        target_list->append(src);
    }

    m_xml.skipCurrentElement();
}
Exemple #24
0
void LayoutParser::parseImport()
{
    const QXmlStreamAttributes attributes(m_xml.attributes());
    const QString file(attributes.value(QLatin1String("file")).toString());

    if (file.isEmpty()) {
        parseNewStyleImport();
    } else {
        if (validateOldStyleImport()) {
            m_imports.append(file);
        }
    }
}
QStringList Manager::assignMoves(const QStringList &stringList) {

    QTextStream cout(stdout); // set cout for console debug

    cout << QDir::setCurrent("/usr/share/harbour-pocketmonsters/qml/pages/xmls/") << endl;

    QFile movedex( "movedex.xml");

    QStringList array;
    QStringList list = stringList;

    for ( int i = 0; i < 4; i++) {
        if (movedex.isOpen()) {
            movedex.close();
            movedex.open(QIODevice::ReadOnly);
        } else
            movedex.open(QIODevice::ReadOnly);
        QXmlStreamReader xml(&movedex);
        QString id = list[i];
        array.append(id);
        bool found = false;
        while (!xml.atEnd() && !xml.hasError()) {
            xml.readNext();
            QXmlStreamAttributes attributes = xml.attributes();
            QString name = xml.name().toString();
            if ( !found && xml.isStartElement() && name == "index" && attributes.value("id") == id)
                found = true;
            if ( found && xml.isEndElement() && name == "index")
                found = false;
            if ( found && xml.isStartElement() && name != "index")
                array.append(xml.readElementText());
        }

        if (xml.hasError()) {
            cout << "XML error: " << xml.errorString() << " - line:column - " << xml.lineNumber() << ":" << xml.columnNumber() << endl;
        } else if (xml.atEnd()) {
            cout << "Reached end, done" << endl;
        }
    }

    for ( int i = 1; i < 5; i++) {
        cout << array[9*i-1] << endl;
        cout << stringList[3+i] << endl;
    }

    for ( int i = 0; i < array.length(); i++)
        cout << array[i] << ":";

    cout << endl;
    return array;
}
// Read all current Ranges controls from an XML stream
bool US_RunProtocol::RunProtoRanges::fromXml( QXmlStreamReader& xmli )
{
   nranges              = 0;
   chrngs.clear();
   Ranges rng;

   while( ! xmli.atEnd() )
   {
      QString ename   = xmli.name().toString();

      if ( xmli.isStartElement() )
      {
         if ( ename == "range"  ||  ename == "spectrum" )
         {
            QXmlStreamAttributes attr = xmli.attributes();
            rng.channel          = attr.value( "channel" )     .toString();
            QString slorad       = attr.value( "start_radius" ).toString();
            QString shirad       = attr.value( "end_radius" )  .toString();
            rng.lo_rad           = slorad.isEmpty() ? rng.lo_rad : slorad.toDouble();
            rng.hi_rad           = shirad.isEmpty() ? rng.hi_rad : shirad.toDouble();

            rng.wvlens.clear();
         }

         else if ( ename == "wavelength"  ||  ename == "point" )
         {
            QXmlStreamAttributes attr = xmli.attributes();
            rng.wvlens << attr.value( "lambda" ).toString().toDouble();
         }
      }

      else if ( xmli.isEndElement()  &&
               ( ename == "range"  ||  ename == "spectrum" ) )
      {
         chrngs << rng;
         nranges++;
      }

      bool was_end    = xmli.isEndElement();  // Just read was End of element?
      xmli.readNext();                        // Read the next element

      if ( was_end )
      {
         if ( ename == "ranges"  ||          // Break after "</ranges>"
              ename == "spectra" )           // Break after "</spectra>"
           break;
      }
   }

   return ( ! xmli.hasError() );
}
void CompositorSettings::load(QXmlStreamReader *xml)
{
    while (!xml->atEnd()) {
        xml->readNext();
        if (xml->isStartElement()) {
            if (xml->name() == "option") {
                QXmlStreamAttributes attribs = xml->attributes();
                QString name = attribs.value("name").toString();
                QString value = attribs.value("value").toString();
                set(name, value);
            }
        }
    }
}
Exemple #28
0
void PointStyle::loadXml(QXmlStreamReader &reader)
{
  LOG4CPP_INFO_S ((*mainCat)) << "PointStyle::loadXml";

  QXmlStreamAttributes attributes = reader.attributes();

  if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS) &&
      attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH) &&
      attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_COLOR) &&
      attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE)) {

    setRadius (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS).toInt());
    setLineWidth (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH).toInt());
    setPaletteColor ((ColorPalette) attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_COLOR).toInt());
    setShape ((PointShape) attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE).toInt());

    // Read until end of this subtree
    while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
    (reader.name() != DOCUMENT_SERIALIZE_POINT_STYLE)){
      loadNextFromReader(reader);
    }
  } else {
    reader.raiseError ("Cannot read point style data");
  }
}
Exemple #29
0
DriOptionValue::DriOptionValue(QXmlStreamReader *xml)
{
    QXmlStreamAttributes attributes = xml->attributes();

    if (attributes.hasAttribute("name"))
        name = attributes.value("name").toString();
    else
        throw "Missing name element to option";
    if (attributes.hasAttribute("value"))
        value = attributes.value("value").toString(); // We'll have to check after the type
    else
        throw "Missing value element to option";
    xml->skipCurrentElement();
}
	std::tuple<bool, const char*> loadWordStatisticsXml(const std::wstring& filePath, WordsUsageInfo& wordsStat, std::vector<const WordSeqUsage*>& wordSeqOrder)
	{
		QFile file(QString::fromStdWString(filePath));
		if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
			return std::make_tuple(false, "Can't open file");

		QXmlStreamReader xml;
		xml.setDevice(&file);

		// got to document root

		xml.readNextStartElement(); // document root

		//
		while (!xml.atEnd())
		{
			xml.readNext();
			if (xml.isStartElement() && xml.name() == "word")
			{
				QXmlStreamAttributes attrs = xml.attributes();
				QStringRef idRef = attrs.value("id");
				bool parseNum;
				int usedCount = attrs.value("usedCount").toInt(&parseNum);
				if (!parseNum)
					return std::make_tuple(false, "usedCount must be integer");

				QString wordQ = QString::fromRawData(idRef.constData(), idRef.size());
				std::wstring wordW((const wchar_t*)wordQ.utf16(), wordQ.size());

				bool wasAdded = false;
				const WordPart* wordPart = wordsStat.getOrAddWordPart(wordW, WordPartSide::WholeWord, &wasAdded);
				if (!wasAdded)
					return std::make_tuple(false, "Error: duplicate words in words statistic");
				
				WordSeqKey wordIds({ wordPart->id() });

				WordSeqUsage* wordUsage = wordsStat.getOrAddWordSequence(wordIds, &wasAdded);
				if (!wasAdded)
					return std::make_tuple(false, "Error: duplicate words in words statistic");

				wordUsage->UsedCount = usedCount;

				wordSeqOrder.push_back(wordUsage);
			}
		}
		if (xml.hasError())
			return std::make_tuple(false, "Error in XML parsing");

		return std::make_tuple(true, nullptr);
	}