Пример #1
0
static QString dump_element(const QDomElement &el)
{
	QString ret;
	QTextStream s(&ret);
	el.save(s, QDomNode::EncodingFromDocument);
	return ret;
}
Пример #2
0
bool QgsStyleV2::saveColorRamp( QString name, QgsVectorColorRampV2* ramp, int groupid, QStringList tags )
{
  // TODO add support for groups and tags
  Q_UNUSED( tags );

  // insert it into the database
  QDomDocument doc( "dummy" );
  QDomElement rampEl = QgsSymbolLayerV2Utils::saveColorRamp( name, ramp, doc );
  if ( rampEl.isNull() )
  {
    QgsDebugMsg( "Couldn't convert color ramp to valid XML!" );
    return false;
  }

  QByteArray xmlArray;
  QTextStream stream( &xmlArray );
  rampEl.save( stream, 4 );
  char *query = sqlite3_mprintf( "INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
                                 name.toUtf8().constData(), xmlArray.constData(), groupid );

  if ( !runEmptyQuery( query ) )
  {
    QgsDebugMsg( "Couldn't insert colorramp into the database!" );
    return false;
  }

  return true;
}
Пример #3
0
bool QgsStyle::saveSymbol( const QString& name, QgsSymbol* symbol, int groupid, const QStringList& tags )
{
  // TODO add support for groups
  QDomDocument doc( "dummy" );
  QDomElement symEl = QgsSymbolLayerUtils::saveSymbol( name, symbol, doc );
  if ( symEl.isNull() )
  {
    QgsDebugMsg( "Couldn't convert symbol to valid XML!" );
    return false;
  }

  QByteArray xmlArray;
  QTextStream stream( &xmlArray );
  stream.setCodec( "UTF-8" );
  symEl.save( stream, 4 );
  char *query = sqlite3_mprintf( "INSERT INTO symbol VALUES (NULL, '%q', '%q', %d);",
                                 name.toUtf8().constData(), xmlArray.constData(), groupid );

  if ( !runEmptyQuery( query ) )
  {
    QgsDebugMsg( "Couldn't insert symbol into the database!" );
    return false;
  }

  tagSymbol( SymbolEntity, name, tags );

  emit symbolSaved( name, symbol );

  return true;
}
Пример #4
0
// createRootXmlTags
//
// This function creates three QStrings, one being an <?xml .. ?> processing
// instruction, and the others being the opening and closing tags of an
// element, <foo> and </foo>.  This basically allows us to get the raw XML
// text needed to open/close an XML stream, without resorting to generating
// the XML ourselves.  This function uses QDom to do the generation, which
// ensures proper encoding and entity output.
static void createRootXmlTags(const QDomElement &root, QString *xmlHeader, QString *tagOpen, QString *tagClose)
{
	QDomElement e = root.cloneNode(false).toElement();

	// insert a dummy element to ensure open and closing tags are generated
	QDomElement dummy = e.ownerDocument().createElement("dummy");
	e.appendChild(dummy);

	// convert to xml->text
	QString str;
	{
		QTextStream ts(&str, QIODevice::WriteOnly);
		e.save(ts, 0);
	}

	// parse the tags out
	int n = str.indexOf('<');
	int n2 = str.indexOf('>', n);
	++n2;
	*tagOpen = str.mid(n, n2-n);
	n2 = str.lastIndexOf('>');
	n = str.lastIndexOf('<');
	++n2;
	*tagClose = str.mid(n, n2-n);

	// generate a nice xml processing header
	*xmlHeader = "<?xml version=\"1.0\"?>";
}
Пример #5
0
bool QgsStyle::saveColorRamp( const QString& name, QgsColorRamp* ramp, int groupid, const QStringList& tags )
{
  // insert it into the database
  QDomDocument doc( "dummy" );
  QDomElement rampEl = QgsSymbolLayerUtils::saveColorRamp( name, ramp, doc );
  if ( rampEl.isNull() )
  {
    QgsDebugMsg( "Couldn't convert color ramp to valid XML!" );
    return false;
  }

  QByteArray xmlArray;
  QTextStream stream( &xmlArray );
  stream.setCodec( "UTF-8" );
  rampEl.save( stream, 4 );
  char *query = sqlite3_mprintf( "INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
                                 name.toUtf8().constData(), xmlArray.constData(), groupid );

  if ( !runEmptyQuery( query ) )
  {
    QgsDebugMsg( "Couldn't insert colorramp into the database!" );
    return false;
  }

  tagSymbol( ColorrampEntity, name, tags );

  return true;
}
Пример #6
0
void QgsServerProjectParser::addGetFeatureLayers( const QDomElement& layerElem ) const
{
  QString str;
  QTextStream stream( &str );
  layerElem.save( stream, 2 );

  QRegExp rx( "getFeature\\('([^']*)'" );
  int idx = 0;
  while (( idx = rx.indexIn( str, idx ) ) != -1 )
  {
    QString name = rx.cap( 1 );
    QgsMapLayer* ml = nullptr;
    QHash< QString, QDomElement >::const_iterator layerElemIt = mProjectLayerElementsById.find( name );
    if ( layerElemIt != mProjectLayerElementsById.constEnd() )
    {
      ml = createLayerFromElement( layerElemIt.value() );
    }
    else
    {
      layerElemIt = mProjectLayerElementsByName.find( name );
      if ( layerElemIt != mProjectLayerElementsByName.constEnd() )
      {
        ml = createLayerFromElement( layerElemIt.value() );
      }
    }

    if ( ml )
    {
      QgsMapLayerRegistry::instance()->addMapLayer( ml, false, false );
    }
    idx += rx.matchedLength();
  }
}
Пример #7
0
QComponentNode::QComponentNode(const QDomElement& xmlNode, int row, QXmlTreeModel* model, QXmlTreeNode* parent ) : QXmlTreeNode(xmlNode, row, model, parent)
{
	QString data;
	QTextStream stream(&data);
	xmlNode.save(stream, 4);
	unsigned int entityID = GameEngine::entityWorldID( qPrintable(parent->property("Name").toString()) );
	m_valid = GameEngine::setComponentData(entityID, qPrintable( xmlNode.tagName() ), qPrintable(data));
}
Пример #8
0
static QString domToString(const QDomElement &elt)
{
    QString result;
    QTextStream stream(&result, QIODevice::WriteOnly);
    elt.save(stream, 2);
    stream.flush();
    return result;
}
Пример #9
0
QString HtmlTidy::output()
{
    QDomDocument document;
    QDomElement body = output(document);
    QString s;
    QTextStream ts(&s) ;
    body.save(ts, 0);
    return s;
}
Пример #10
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();
}
Пример #11
0
QString BinController::xmlFromId(const QString & id)
{
    ClipController *controller = m_clipList.value(id);
    if (!controller) return NULL;
    Mlt::Producer original = controller->originalProducer();
    QString xml = getProducerXML(original);
    QDomDocument mltData;
    mltData.setContent(xml);
    QDomElement producer = mltData.documentElement().firstChildElement(QStringLiteral("producer"));
    QString str;
    QTextStream stream(&str);
    producer.save(stream, 4);
    return str;
}
Пример #12
0
QSharedDataPointer<QDBusIntrospection::ObjectTree>
QDBusXmlParser::objectTree() const
{
    QSharedDataPointer<QDBusIntrospection::ObjectTree> retval;

    if (m_node.isNull())
        return retval;

    retval = new QDBusIntrospection::ObjectTree;

    retval->service = m_service;
    retval->path = m_path;

    QTextStream ts(&retval->introspection);
    m_node.save(ts,2);

    // interfaces are easy:
    retval->interfaceData = interfaces();
    retval->interfaces = retval->interfaceData.keys();

    // sub-objects are slightly more difficult:
    QDomNodeList objects = m_node.elementsByTagName(QLatin1String("node"));
    for (int i = 0; i < objects.count(); ++i) {
        QDomElement obj = objects.item(i).toElement();
        QString objName = obj.attribute(QLatin1String("name"));
        if (obj.isNull() || objName.isEmpty())
            continue;           // for whatever reason

        // check if we have anything to process
        if (!obj.firstChild().isNull()) {
            // yes, introspect this object
            QString xml;
            QTextStream ts2(&xml);
            obj.save(ts2,0);

            // parse it
            QString objAbsName = m_path;
            if (!objAbsName.endsWith(QLatin1Char('/')))
                objAbsName.append(QLatin1Char('/'));
            objAbsName += objName;

            QDBusXmlParser parser(m_service, objAbsName, obj);
            retval->childObjectData.insert(objName, parser.objectTree());
        }

        retval->childObjects << objName;
    }

    return QSharedDataPointer<QDBusIntrospection::ObjectTree>( retval );
}
Пример #13
0
StyleItem::StyleItem( QDomElement el, QString colors[], QDomElement defs )
{
    QDomElement name = el.firstChildElement("name");
    this->name = name.text();
    QDomElement svg = el.firstChildElement("svg");
    if ( svg.isNull() ) {
        this->renderer = NULL;
    } else {
        if ( !defs.isNull() ) svg.insertBefore( defs, QDomNode() );
        QDomDocument doc;
        doc.setContent( css );
        svg.insertBefore( doc, QDomNode() );
        QTextStream stream(&(this->svg));
        svg.save(stream, 0);
        this->renderer = new QSvgRenderer( this->makeSvg( colors, STYLE_KEY_COLOR ).toAscii() );
    }
}
Пример #14
0
void Shape::init(const QString &shape)
{
	if (shape.isEmpty())
		return;

	QString error = "";
	int errorLine = 0;
	int errorCol = 0;
	QDomDocument doc;
	if (!doc.setContent(shape, false, &error, &errorLine, &errorCol))
		return;

	QDomElement graphics = doc.firstChildElement("graphics");

	QDomElement picture = graphics.firstChildElement("picture");
	QTextStream out(&mPicture);
	picture.save(out, 4);

	mWidth = graphics.firstChildElement("picture").attribute("sizex", "88").toInt();
	mHeight = graphics.firstChildElement("picture").attribute("sizey", "88").toInt();

	initLabels(graphics);
	initPorts(graphics);
}
Пример #15
0
QPositionNode::QPositionNode(const QDomElement& xmlNode, int row, QXmlTreeModel* model, QXmlTreeNode* parent) : QXmlTreeNode(xmlNode, row, model, parent),
m_dynamicProperty(false)
{
	QString data;
	QTextStream stream(&data);
	xmlNode.save(stream, 4);
	m_entityID = GameEngine::entityWorldID( qPrintable(parent->property("Name").toString()) );
	GameEngine::setComponentData(m_entityID, qPrintable( xmlNode.tagName() ), qPrintable(data));
	QXmlTreeNode* root = static_cast<AttachmentTreeModel*>(model)->sceneNodeParent();
	// If the entity has no position we have to create one for the crowd particle
	if( !root->property("Position").isValid() )
	{
		QVec3f pos( m_xmlNode.attribute("x").toFloat(), m_xmlNode.attribute("y").toFloat(), m_xmlNode.attribute("z").toFloat() );
		// Since the parent doesn't have a position yet we create one dynamically (not necessary if the particle is a child of 
		// an entity created by an attachment of a Horde3D scene graph node )
		m_dynamicProperty = true;
		root->setProperty( "Position", QVariant::fromValue(pos) );
		// We have to add scale too, otherwise the transformation changes in the editor are not possible
		root->setProperty( "Scale", QVariant::fromValue( QVec3f(1, 1, 1) ) );
		root->installEventFilter(this);
		QVariant transProp = root->property("__AbsoluteTransformation");
		if( !transProp.isValid() )
		{
			root->setProperty("__AbsoluteTransformation", 
				QVariant::fromValue(QMatrix4f::TransMat( pos.X, pos.Y, pos.Z) ) );
			root->setProperty("__RelativeTransformation", 
				QVariant::fromValue(QMatrix4f::TransMat( pos.X, pos.Y, pos.Z) ) );
		}
	}
	else // Remove any position attribute, since the position should be used from the scene node
	{
		m_xmlNode.removeAttribute("x");
		m_xmlNode.removeAttribute("y");
		m_xmlNode.removeAttribute("z");
	}
}
Пример #16
0
bool Deck::importFromXml(QString fileName)
{
    QDomDocument domDocument;
    QString errorStr;
    int errorLine;
    int errorColumn;
    QFile file(fileName);

    file.open(QIODevice::ReadOnly | QIODevice::Text);

    if(!file.isOpen())
        return false;

    if (!domDocument.setContent(&file, true, &errorStr, &errorLine,
                                &errorColumn)) {
        qDebug() << QString("Parse error at line %1, column %2:\n%3")
                                 .arg(errorLine)
                                 .arg(errorColumn)
                                 .arg(errorStr);
        return false;
    }

    QDomElement root = domDocument.documentElement();
    if (root.tagName().toLower() != XML_TAG_ROOT) {
        qDebug() << "root node is mismatched.";

        return false;
    }

    QDomElement nodeDeck;
    QDomElement nodeCards;
    QDomElement elnode;

    nodeDeck = root.firstChildElement(XML_TAG_DECK);
    if(nodeDeck.isNull()) {
        qDebug() << "deck node is mismatched.";

        return false;
    }

    elnode = nodeDeck.firstChildElement(XML_TAG_NAME);
    if(!elnode.isNull()) {
        name=elnode.text();
    }

    elnode = nodeDeck.firstChildElement(XML_TAG_DESC);
    if(!elnode.isNull()) {
        desc=elnode.text();
    }

    elnode = nodeDeck.firstChildElement(XML_TAG_ICON);
    if(!elnode.isNull()) {
        
    }

    elnode = nodeDeck.firstChildElement(XML_TAG_GUID);
    if(!elnode.isNull()) {
        guid=QUuid(elnode.text());
    }

    elnode = nodeDeck.firstChildElement(XML_TAG_CREATED);
    if(!elnode.isNull()) {
        createdTime=QDateTime::fromString(elnode.text());
    }

    elnode = nodeDeck.firstChildElement(XML_TAG_UPDATED);
    if(!elnode.isNull()) {
        updatedTime=QDateTime::fromString(elnode.text());
    }

    elnode = nodeDeck.firstChildElement(XML_TAG_AUTHOR);
    if(!elnode.isNull()) {
        author=elnode.text();
    }

    elnode = nodeDeck.firstChildElement(XML_TAG_TAGS);
    if(!elnode.isNull()) {
        tags=elnode.text();
    }

    elnode = nodeDeck.firstChildElement(XML_TAG_FLAGS);
    if(!elnode.isNull()) {
        flags=elnode.text().toUInt();
    }

    elnode = nodeDeck.firstChildElement(XML_TAG_INHAND);
    if(!elnode.isNull()) {
        inhand=elnode.text().toInt();
    }

    elnode = nodeDeck.firstChildElement(XML_TAG_FORMAT);
    if(!elnode.isNull()) {
        //// Converting QDomElement to QString
        //// http://qt-project.org/doc/qt-5/qdomnode.html#save
        QString str;
        QTextStream stream(&str);
        elnode.save(stream, 4);
        format.fromString(str);
    }

    nodeCards = nodeDeck.firstChildElement(XML_TAG_CARDS);
    if(!elnode.isNull()) {
        QDomNodeList nodes = root.elementsByTagName(XML_TAG_CARD);
        QDomNode nodeCard;
        QString front, back;
        int flags = 0;

        int count = nodes.count();
        for(int no = 0; no < count; no++) {
            nodeCard = nodes.at(no);
            flags = 0;
            front.clear();
            back.clear();

            elnode = nodeCard.firstChildElement(XML_TAG_FRONT);
            if(!elnode.isNull()) {
                front = elnode.text();
            }

            elnode = nodeCard.firstChildElement(XML_TAG_BACK);            
            if(!elnode.isNull()) {
                back = elnode.text();
            }

            elnode = nodeCard.firstChildElement(XML_TAG_FLAGS);            
            if(!elnode.isNull()) {
                flags = elnode.text().toInt();
            }

            if(!front.isEmpty()) {
                Card *card = new Card;

                card->updateFront(front);
                card->updateBack(back);
                card->setFlags(flags);

                addCard(card);
            }
        }
    }
        
    file.close();

    return true;
}
Пример #17
0
QDBusIntrospection::Interfaces
QDBusXmlParser::interfaces() const
{
    QDBusIntrospection::Interfaces retval;

    if (m_node.isNull())
        return retval;

    QDomNodeList interfaceList = m_node.elementsByTagName(QLatin1String("interface"));
    for (int i = 0; i < interfaceList.count(); ++i)
    {
        QDomElement iface = interfaceList.item(i).toElement();
        QString ifaceName = iface.attribute(QLatin1String("name"));
        if (iface.isNull())
            continue;           // for whatever reason
        if (!QDBusUtil::isValidInterfaceName(ifaceName)) {
            qWarning("Invalid D-BUS interface name '%s' found while parsing introspection",
                     qPrintable(ifaceName));
            continue;
        }

        QDBusIntrospection::Interface *ifaceData = new QDBusIntrospection::Interface;
        ifaceData->name = ifaceName;
        {
            // save the data
            QTextStream ts(&ifaceData->introspection);
            iface.save(ts,2);
        }

        // parse annotations
        ifaceData->annotations = parseAnnotations(iface);

        // parse methods
        QDomNodeList list = iface.elementsByTagName(QLatin1String("method"));
        for (int j = 0; j < list.count(); ++j)
        {
            QDomElement method = list.item(j).toElement();
            QString methodName = method.attribute(QLatin1String("name"));
            if (method.isNull())
                continue;
            if (!QDBusUtil::isValidMemberName(methodName)) {
                qWarning("Invalid D-BUS member name '%s' found in interface '%s' while parsing introspection",
                         qPrintable(methodName), qPrintable(ifaceName));
                continue;
            }

            QDBusIntrospection::Method methodData;
            methodData.name = methodName;

            // parse arguments
            methodData.inputArgs = parseArgs(method, QLatin1String("in"), true);
            methodData.outputArgs = parseArgs(method, QLatin1String("out"), false);
            methodData.annotations = parseAnnotations(method);

            // add it
            ifaceData->methods.insert(methodName, methodData);
        }

        // parse signals
        list = iface.elementsByTagName(QLatin1String("signal"));
        for (int j = 0; j < list.count(); ++j)
        {
            QDomElement signal = list.item(j).toElement();
            QString signalName = signal.attribute(QLatin1String("name"));
            if (signal.isNull())
                continue;
            if (!QDBusUtil::isValidMemberName(signalName)) {
                qWarning("Invalid D-BUS member name '%s' found in interface '%s' while parsing introspection",
                         qPrintable(signalName), qPrintable(ifaceName));
                continue;
            }

            QDBusIntrospection::Signal signalData;
            signalData.name = signalName;

            // parse data
            signalData.outputArgs = parseArgs(signal, QLatin1String("out"), true);
            signalData.annotations = parseAnnotations(signal);

            // add it
            ifaceData->signals_.insert(signalName, signalData);
        }

        // parse properties
        list = iface.elementsByTagName(QLatin1String("property"));
        for (int j = 0; j < list.count(); ++j)
        {
            QDomElement property = list.item(j).toElement();
            QString propertyName = property.attribute(QLatin1String("name"));
            if (property.isNull())
                continue;
            if (!QDBusUtil::isValidMemberName(propertyName)) {
                qWarning("Invalid D-BUS member name '%s' found in interface '%s' while parsing introspection",
                         qPrintable(propertyName), qPrintable(ifaceName));
                continue;
            }

            QDBusIntrospection::Property propertyData;

            // parse data
            propertyData.name = propertyName;
            propertyData.type = property.attribute(QLatin1String("type"));
            propertyData.annotations = parseAnnotations(property);

            if (!QDBusUtil::isValidSingleSignature(propertyData.type)) {
                // cannot be!
                qWarning("Invalid D-BUS type signature '%s' found in property '%s.%s' while parsing introspection",
                         qPrintable(propertyData.type), qPrintable(ifaceName),
                         qPrintable(propertyName));
                continue;
            }

            QString access = property.attribute(QLatin1String("access"));
            if (access == QLatin1String("read"))
                propertyData.access = QDBusIntrospection::Property::Read;
            else if (access == QLatin1String("write"))
                propertyData.access = QDBusIntrospection::Property::Write;
            else if (access == QLatin1String("readwrite"))
                propertyData.access = QDBusIntrospection::Property::ReadWrite;
            else {
                qWarning("Invalid D-BUS property access '%s' found in property '%s.%s' while parsing introspection",
                         qPrintable(access), qPrintable(ifaceName),
                         qPrintable(propertyName));
                continue;       // invalid one!
            }

            // add it
            ifaceData->properties.insert(propertyName, propertyData);
        }

        // add it
        retval.insert(ifaceName, QSharedDataPointer<QDBusIntrospection::Interface>(ifaceData));
    }

    return retval;
}
Пример #18
0
/*
    <name>Lines</name>
    <description>Lines from top to bottom</description>
    <author>Marco Gittler</author>
    <properties tag="lines" id="lines" />
    <parameter default="5" type="constant" value="5" min="0" name="num" max="255" >
      <name>Num</name>
    </parameter>
    <parameter default="4" type="constant" value="4" min="0" name="width" max="255" >
      <name>Width</name>
    </parameter>
  </effect>

*/
void ParameterPlotter::setPointLists(const QDomElement& d, const QString& paramName, int startframe, int endframe)
{

    //QListIterator <QPair <QString, QMap< int , QVariant > > > nameit(params);
    m_paramName = paramName;
    m_itemParameter = d;
    QDomNodeList namenode = d.elementsByTagName("parameter");

    m_max_y = 0;
    m_min_y = 0;
    removeAllPlotObjects();
    m_stretchFactors.clear();
    m_parameterNameList.clear();
    m_plotobjects.clear();

    QString dat;
    QTextStream stre(&dat);
    d.save(stre, 2);
    //qDebug() << dat;
    int i = 0;
    while (!namenode.item(i).isNull() && namenode.item(i).toElement().attribute("name") != m_paramName)
        ++i;

    if (namenode.count()) {
        QDomElement pa = namenode.item(i).toElement();
        //QDomNode na = pa.firstChildElement("name");

        m_parameterNameList << pa.attribute("namedesc").split(';');
        emit parameterList(m_parameterNameList);

        //max_y=pa.attributes().namedItem("max").nodeValue().toInt();
        //int val=pa.attributes().namedItem("value").nodeValue().toInt();
        QStringList defaults;
        if (pa.attribute("start").contains(';'))
            defaults = pa.attribute("start").split(';');
        else if (pa.attribute("value").contains(';'))
            defaults = pa.attribute("value").split(';');
        else if (pa.attribute("default").contains(';'))
            defaults = pa.attribute("default").split(';');
        QStringList maxv = pa.attribute("max").split(';');
        QStringList minv = pa.attribute("min").split(';');
        for (int i = 0; i < maxv.size() && i < minv.size(); ++i) {
            if (m_max_y < maxv[i].toInt()) m_max_y = maxv[i].toInt();
            if (m_min_y > minv[i].toInt()) m_min_y = minv[i].toInt();
        }
        for (int i = 0; i < m_parameterNameList.count(); ++i) {
            KPlotObject *plot = new KPlotObject(m_colors[m_plotobjects.size()%m_colors.size()]);
            plot->setShowLines(true);
            if (!m_stretchFactors.contains(i) && i < maxv.size()) {
                if (maxv[i].toInt() != 0)
                    m_stretchFactors[i] = m_max_y / maxv[i].toInt();
                else
                    m_stretchFactors[i] = 1.0;
            }
            if (i < defaults.size() && defaults[i].toDouble() > m_max_y)
                defaults[i] = m_max_y;
            int def = 0;
            if (i < defaults.size())
                def = (int)(defaults[i].toInt() * m_stretchFactors[i]);
            QString name = "";
            if (i < m_parameterNameList.size())
                name = m_parameterNameList[i];
            plot->addPoint(startframe, def, name);
            //add keyframes here
            plot->addPoint(endframe, def);

            m_plotobjects.append(plot);
        }

        /*TODO keyframes
        while (pointit.hasNext()){
         pointit.next();
         plot->addPoint(QPointF(pointit.key(),pointit.value().toDouble()),item.first,1);
         if (pointit.value().toInt() >maxy)
          max_y=pointit.value().toInt();
        }*/

    }
    setLimits(-1, endframe + 1, m_min_y - 10, m_max_y + 10);

    addPlotObjects(m_plotobjects);

}
Пример #19
0
/// \cond
void QXmppMessage::parse(const QDomElement &element)
{
    QXmppStanza::parse(element);

    const QString type = element.attribute("type");
    d->type = Normal;
    for (int i = Error; i <= Headline; i++) {
        if (type == message_types[i]) {
            d->type = static_cast<Type>(i);
            break;
        }
    }

    d->body = element.firstChildElement("body").text();
    d->subject = element.firstChildElement("subject").text();
    d->thread = element.firstChildElement("thread").text();

    // chat states
    for (int i = Active; i <= Paused; i++)
    {
        QDomElement stateElement = element.firstChildElement(chat_states[i]);
        if (!stateElement.isNull() &&
            stateElement.namespaceURI() == ns_chat_states)
        {
            d->state = static_cast<QXmppMessage::State>(i);
            break;
        }
    }

    // XEP-0071: XHTML-IM
    QDomElement htmlElement = element.firstChildElement("html");
    if (!htmlElement.isNull() && htmlElement.namespaceURI() == ns_xhtml_im) {
        QDomElement bodyElement = htmlElement.firstChildElement("body");
        if (!bodyElement.isNull() && bodyElement.namespaceURI() == ns_xhtml) {
            QTextStream stream(&d->xhtml, QIODevice::WriteOnly);
            bodyElement.save(stream, 0);

            d->xhtml = d->xhtml.mid(d->xhtml.indexOf('>') + 1);
            d->xhtml.replace(" xmlns=\"http://www.w3.org/1999/xhtml\"", "");
            d->xhtml.replace("</body>", "");
            d->xhtml = d->xhtml.trimmed();
        }
    }

    // XEP-0184: Message Delivery Receipts
    QDomElement receivedElement = element.firstChildElement("received");
    if (!receivedElement.isNull() && receivedElement.namespaceURI() == ns_message_receipts) {
        d->receiptId = receivedElement.attribute("id");

        // compatibility with old-style XEP
        if (d->receiptId.isEmpty())
            d->receiptId = id();
    } else {
        d->receiptId = QString();
    }
    d->receiptRequested = element.firstChildElement("request").namespaceURI() == ns_message_receipts;

    // XEP-0203: Delayed Delivery
    QDomElement delayElement = element.firstChildElement("delay");
    if (!delayElement.isNull() && delayElement.namespaceURI() == ns_delayed_delivery)
    {
        const QString str = delayElement.attribute("stamp");
        d->stamp = QXmppUtils::datetimeFromString(str);
        d->stampType = DelayedDelivery;
    }

    // XEP-0224: Attention
    d->attentionRequested = element.firstChildElement("attention").namespaceURI() == ns_attention;

    const QList<QPair<QString, QString> > &knownElems = knownMessageSubelems();

    QXmppElementList extensions;
    QDomElement xElement = element.firstChildElement();
    while (!xElement.isNull())
    {
        if (xElement.tagName() == "x")
        {
            if (xElement.namespaceURI() == ns_legacy_delayed_delivery)
            {
                // XEP-0091: Legacy Delayed Delivery
                const QString str = xElement.attribute("stamp");
                d->stamp = QDateTime::fromString(str, "yyyyMMddThh:mm:ss");
                d->stamp.setTimeSpec(Qt::UTC);
                d->stampType = LegacyDelayedDelivery;
            } else if (xElement.namespaceURI() == ns_conference) {
                // XEP-0249: Direct MUC Invitations
                d->mucInvitationJid = xElement.attribute("jid");
                d->mucInvitationPassword = xElement.attribute("password");
                d->mucInvitationReason = xElement.attribute("reason");
            }
            else {
                extensions << QXmppElement(xElement);
            }
        } else if (!knownElems.contains(qMakePair(xElement.tagName(), xElement.namespaceURI())) &&
                   !knownElems.contains(qMakePair(xElement.tagName(), QString()))) {
            // other extensions
            extensions << QXmppElement(xElement);
        }
        xElement = xElement.nextSiblingElement();
    }
    setExtensions(extensions);
}
/// \cond
void QXmppMessage::parse(const QDomElement &element)
{
    QXmppStanza::parse(element);

    const QString type = element.attribute("type");
    d->type = Normal;
    for (int i = Error; i <= Headline; i++) {
        if (type == message_types[i]) {
            d->type = static_cast<Type>(i);
            break;
        }
    }

    d->body = element.firstChildElement("body").text();
    d->subject = element.firstChildElement("subject").text();
    d->thread = element.firstChildElement("thread").text();

    // chat states
    for (int i = Active; i <= Paused; i++)
    {
        QDomElement stateElement = element.firstChildElement(chat_states[i]);
        if (!stateElement.isNull() &&
            stateElement.namespaceURI() == ns_chat_states)
        {
            d->state = static_cast<QXmppMessage::State>(i);
            break;
        }
    }

    // XEP-0071: XHTML-IM
    QDomElement htmlElement = element.firstChildElement("html");
    if (!htmlElement.isNull() && htmlElement.namespaceURI() == ns_xhtml_im) {
        QDomElement bodyElement = htmlElement.firstChildElement("body");
        if (!bodyElement.isNull() && bodyElement.namespaceURI() == ns_xhtml) {
            QTextStream stream(&d->xhtml, QIODevice::WriteOnly);
            bodyElement.save(stream, 0);

            d->xhtml = d->xhtml.mid(d->xhtml.indexOf('>') + 1);
            d->xhtml.replace(" xmlns=\"http://www.w3.org/1999/xhtml\"", "");
            d->xhtml.replace("</body>", "");
            d->xhtml = d->xhtml.trimmed();
        }
    }

    // XEP-0184: Message Delivery Receipts
    QDomElement receivedElement = element.firstChildElement("received");
    if (!receivedElement.isNull() && receivedElement.namespaceURI() == ns_message_receipts) {
        d->receiptId = receivedElement.attribute("id");

        // compatibility with old-style XEP
        if (d->receiptId.isEmpty())
            d->receiptId = id();
    } else {
        d->receiptId = QString();
    }
    d->receiptRequested = element.firstChildElement("request").namespaceURI() == ns_message_receipts;

    // XEP-0203: Delayed Delivery
    QDomElement delayElement = element.firstChildElement("delay");
    if (!delayElement.isNull() && delayElement.namespaceURI() == ns_delayed_delivery)
    {
        const QString str = delayElement.attribute("stamp");
        d->stamp = QXmppUtils::datetimeFromString(str);
        d->stampType = DelayedDelivery;
    }

    // XEP-0313: Extract forwarded message from mam packet
    QDomElement mamElement = element.firstChildElement("result");
    if (!mamElement.isNull() && mamElement.namespaceURI() == ns_simple_archive)
    {
        QDomElement forwardedElement = mamElement.firstChildElement("forwarded");
        if (!forwardedElement.isNull() && forwardedElement.namespaceURI() == ns_stanza_forwarding)
        {
            setMaMMessage(parseForward(forwardedElement));
        }
    }

    // XEP-0280: message carbons
    QDomElement carbonElement = element.firstChildElement("sent");
    if (!carbonElement.isNull() && carbonElement.namespaceURI() == ns_message_carbons)
    {
        QDomElement forwardedElement = carbonElement.firstChildElement("forwarded");
        if (!forwardedElement.isNull() && forwardedElement.namespaceURI() == ns_stanza_forwarding)
        {
            setMessagecarbon(parseForward(forwardedElement));
        }
    }

    // XEP-0297: Forwarding
    QDomElement forwardedElement = element.firstChildElement("forwarded");
    if (!forwardedElement.isNull() && forwardedElement.namespaceURI() == ns_stanza_forwarding)
    {
        setForwarded(parseForward(forwardedElement));
    }

    // XEP-0224: Attention
    d->attentionRequested = element.firstChildElement("attention").namespaceURI() == ns_attention;

    // XEP-0334: Message Processing Hints
    // check for all the marker types
    QDomElement hintElement;
    for (int i = NoPermanentStorage; i <= AllowPermantStorage; i++)
    {
        hintElement = element.firstChildElement(hint_types[i]);
        if (!hintElement.isNull() &&
            hintElement.namespaceURI() == ns_message_processing_hints)
        {
            d->hints.append(static_cast<QXmppMessage::Hint>(i));
        }
    }

    // XEP-0333: Chat Markers
    QDomElement markableElement = element.firstChildElement("markable");
    if (!markableElement.isNull())
    {
        d->markable = true;
    }
    // check for all the marker types
    QDomElement chatStateElement;
    QXmppMessage::Marker marker = QXmppMessage::NoMarker;
    for (int i = Received; i <= Acknowledged; i++)
    {
        chatStateElement = element.firstChildElement(marker_types[i]);
        if (!chatStateElement.isNull() &&
            chatStateElement.namespaceURI() == ns_chat_markers)
        {
            marker = static_cast<QXmppMessage::Marker>(i);
            break;
        }
    }
    // if marker is present, check it's the right ns
    if (!chatStateElement.isNull())
    {
        if (chatStateElement.namespaceURI() == ns_chat_markers)
        {
            d->marker = marker;
            d->markedId = chatStateElement.attribute("id", QString());
            d->markedThread = chatStateElement.attribute("thread", QString());
        }
    }

    // XEP-0308: Last Message Correction
    QDomElement replaceElement = element.firstChildElement("replace");
    if(!replaceElement.isNull())
    {
        if(replaceElement.namespaceURI() == ns_replace_message)
        {
            d->replace = true;
            d->replaceId = replaceElement.attribute("id", QString());
        }
    }

    QXmppElementList extensions;
    QDomElement xElement = element.firstChildElement("x");
    while (!xElement.isNull())
    {
        if (xElement.namespaceURI() == ns_legacy_delayed_delivery)
        {
            // XEP-0091: Legacy Delayed Delivery
            const QString str = xElement.attribute("stamp");
            d->stamp = QDateTime::fromString(str, "yyyyMMddThh:mm:ss");
            d->stamp.setTimeSpec(Qt::UTC);
            d->stampType = LegacyDelayedDelivery;
        } else if (xElement.namespaceURI() == ns_conference) {
            // XEP-0249: Direct MUC Invitations
            d->mucInvitationJid = xElement.attribute("jid");
            d->mucInvitationPassword = xElement.attribute("password");
            d->mucInvitationReason = xElement.attribute("reason");
        } else {
            // other extensions
            extensions << QXmppElement(xElement);
        }
        xElement = xElement.nextSiblingElement("x");
    }
    setExtensions(extensions);
}
Пример #21
0
/// \cond
void QXmppMessage::parse(const QDomElement &element)
{
    QXmppStanza::parse(element);

    const QString type = element.attribute("type");
    d->type = Normal;
    for (int i = Error; i <= Headline; i++) {
        if (type == message_types[i]) {
            d->type = static_cast<Type>(i);
            break;
        }
    }

    d->body = element.firstChildElement("body").text();
    d->subject = element.firstChildElement("subject").text();
    d->thread = element.firstChildElement("thread").text();

    // chat states
    for (int i = Active; i <= Paused; i++)
    {
        QDomElement stateElement = element.firstChildElement(chat_states[i]);
        if (!stateElement.isNull() &&
            stateElement.namespaceURI() == ns_chat_states)
        {
            d->state = static_cast<QXmppMessage::State>(i);
            break;
        }
    }

    // XEP-0071: XHTML-IM
    QDomElement htmlElement = element.firstChildElement("html");
    if (!htmlElement.isNull() && htmlElement.namespaceURI() == ns_xhtml_im) {
        QDomElement bodyElement = htmlElement.firstChildElement("body");
        if (!bodyElement.isNull() && bodyElement.namespaceURI() == ns_xhtml) {
            QTextStream stream(&d->xhtml, QIODevice::WriteOnly);
            bodyElement.save(stream, 0);

            d->xhtml = d->xhtml.mid(d->xhtml.indexOf('>') + 1);
            d->xhtml.replace(" xmlns=\"http://www.w3.org/1999/xhtml\"", "");
            d->xhtml.replace("</body>", "");
            d->xhtml = d->xhtml.trimmed();
        }
    }

    // XEP-0184: Message Delivery Receipts
    QDomElement receivedElement = element.firstChildElement("received");
    if (!receivedElement.isNull() && receivedElement.namespaceURI() == ns_message_receipts) {
        d->receiptId = receivedElement.attribute("id");

        // compatibility with old-style XEP
        if (d->receiptId.isEmpty())
            d->receiptId = id();
    } else {
        d->receiptId = QString();
    }
    d->receiptRequested = element.firstChildElement("request").namespaceURI() == ns_message_receipts;

    // XEP-0203: Delayed Delivery
    QDomElement delayElement = element.firstChildElement("delay");
    if (!delayElement.isNull() && delayElement.namespaceURI() == ns_delayed_delivery)
    {
        const QString str = delayElement.attribute("stamp");
        d->stamp = QXmppUtils::datetimeFromString(str);
        d->stampType = DelayedDelivery;
    }

    // XEP-0224: Attention
    d->attentionRequested = element.firstChildElement("attention").namespaceURI() == ns_attention;

    // XEP-0333: Chat Markers
    QDomElement markableElement = element.firstChildElement("markable");
    if (!markableElement.isNull())
    {
        d->markable = true;
    }
    // check for all the marker types
    QDomElement chatStateElement;
    QXmppMessage::Marker marker = QXmppMessage::NoMarker;
    for (int i = Received; i <= Acknowledged; i++)
    {
        chatStateElement = element.firstChildElement(marker_types[i]);
        if (!chatStateElement.isNull() &&
            chatStateElement.namespaceURI() == ns_chat_markers)
        {
            marker = static_cast<QXmppMessage::Marker>(i);
            break;
        }
    }
    // if marker is present, check it's the right ns
    if (!chatStateElement.isNull())
    {
        if (chatStateElement.namespaceURI() == ns_chat_markers)
        {
            d->marker = marker;
            d->markedId = chatStateElement.attribute("id", QString());
            d->markedThread = chatStateElement.attribute("thread", QString());
        }
    }

    // XEP-0280: Message Carbons
    QDomElement privateElement = element.firstChildElement("private");
    if (!privateElement.isNull())
        d->privatemsg = true;

    // XEP-0308: Last Message Correction
    QDomElement replaceElement = element.firstChildElement("replace");
    if (!replaceElement.isNull() && replaceElement.namespaceURI() == ns_message_correct)
        d->replaceId = replaceElement.attribute("id");

    const QList<QPair<QString, QString> > &knownElems = knownMessageSubelems();

    QXmppElementList extensions;
    QDomElement xElement = element.firstChildElement();
    while (!xElement.isNull())
    {
        if (xElement.tagName() == "x")
        {
            if (xElement.namespaceURI() == ns_legacy_delayed_delivery)
            {
                // if XEP-0203 exists, XEP-0091 has no need to parse because XEP-0091 is no more standard protocol)
                if (d->stamp.isNull())
                {
                    // XEP-0091: Legacy Delayed Delivery
                    const QString str = xElement.attribute("stamp");
                    d->stamp = QDateTime::fromString(str, "yyyyMMddThh:mm:ss");
                    d->stamp.setTimeSpec(Qt::UTC);
                    d->stampType = LegacyDelayedDelivery;
                }
            } else if (xElement.namespaceURI() == ns_conference) {
                // XEP-0249: Direct MUC Invitations
                d->mucInvitationJid = xElement.attribute("jid");
                d->mucInvitationPassword = xElement.attribute("password");
                d->mucInvitationReason = xElement.attribute("reason");
            } else if (xElement.namespaceURI() == ns_oob) {
                // XEP-0066: Out of Band Data
                d->outOfBandUrl = xElement.firstChildElement("url").text();
            }
            else {
                extensions << QXmppElement(xElement);
            }
        // XEP-0369: Mediated Information eXchange (MIX)
        } else if (xElement.tagName() == "mix" && xElement.namespaceURI() == ns_mix) {
            d->mixUserJid = xElement.firstChildElement("jid").text();
            d->mixUserNick = xElement.firstChildElement("nick").text();
        // XEP-0382: Spoiler messages
        } else if (xElement.tagName() == "spoiler" && xElement.namespaceURI() == ns_spoiler) {
            d->isSpoiler = true;
            d->spoilerHint = xElement.text();
        } else if (!knownElems.contains(qMakePair(xElement.tagName(), xElement.namespaceURI())) &&
                   !knownElems.contains(qMakePair(xElement.tagName(), QString()))) {
            // other extensions
            extensions << QXmppElement(xElement);
        }
        xElement = xElement.nextSiblingElement();
    }
    setExtensions(extensions);
}