Esempio n. 1
0
int QgsSOAPRequestHandler::parseBoundingBoxElement( QMap<QString, QString>& parameterMap, const QDomElement& boundingBoxElement ) const
{
  QString minx, miny, maxx, maxy;

  //leftBound
  QDomNodeList leftBoundList = boundingBoxElement.elementsByTagName( "leftBound" );
  if ( !leftBoundList.isEmpty() )
  {
    minx = leftBoundList.item( 0 ).toElement().text();
  }

  //rightBound
  QDomNodeList rightBoundList = boundingBoxElement.elementsByTagName( "rightBound" );
  if ( !rightBoundList.isEmpty() )
  {
    maxx = rightBoundList.item( 0 ).toElement().text();
  }

  //lowerBound
  QDomNodeList lowerBoundList = boundingBoxElement.elementsByTagName( "lowerBound" );
  if ( !lowerBoundList.isEmpty() )
  {
    miny = lowerBoundList.item( 0 ).toElement().text();
  }

  //upperBound
  QDomNodeList upperBoundList = boundingBoxElement.elementsByTagName( "upperBound" );
  if ( !upperBoundList.isEmpty() )
  {
    maxy = upperBoundList.item( 0 ).toElement().text();
  }
  parameterMap.insert( "BBOX", minx + "," + miny + "," + maxx + "," + maxy );
  return 0;
}
Esempio n. 2
0
Event Event::fromQDomElement(const QDomElement& fr, const QString& srvcId, const QString& accountId, const QString& friendId)
{
    Event ret = Event();

    ret.setObjectId(fr.elementsByTagName(NODE_EVENT_ID).at(0).firstChild().toText().data());
    //ret.setOwnerId(fr.elementsByTagName(NODE_EVENT_OWNER_ID).at(0).firstChild().toText().data());
    ret.setTitle(fr.elementsByTagName(NODE_EVENT_TITLE).at(0).firstChild().toText().data());
    QDomNodeList description = fr.elementsByTagName(NODE_EVENT_DESCRIPTION);
    if (!description.isEmpty())
        ret.setDescription(fr.elementsByTagName(NODE_EVENT_DESCRIPTION).at(0).firstChild().toText().data());
    else
        ret.setDescription("");
    ret.setStartTime(fr.elementsByTagName(NODE_EVENT_START_TIME).at(0).firstChild().toText().data());
    QDomNodeList endTime = fr.elementsByTagName(NODE_EVENT_END_TIME);
    if (!endTime.isEmpty())
        ret.setEndTime(fr.elementsByTagName(NODE_EVENT_END_TIME).at(0).firstChild().toText().data());
    else
        ret.setEndTime("");
    ret.setUpdateTime(fr.elementsByTagName(NODE_EVENT_UPDATE_TIME).at(0).firstChild().toText().data());
    QDomNodeList location = fr.elementsByTagName(NODE_EVENT_END_TIME);
    if (!location.isEmpty())
        ret.setLocation(fr.elementsByTagName(NODE_EVENT_LOCATION).at(0).firstChild().toText().data());
    else
        ret.setLocation("");
    ret.setCreator(fr.elementsByTagName(NODE_EVENT_CREATOR).at(0).firstChild().toText().data());
    ret.setPrivacy(fr.elementsByTagName(NODE_EVENT_PRIVACY).at(0).firstChild().toText().data());
    ret.setIconUrl(fr.elementsByTagName(NODE_EVENT_ICON_URL).at(0).firstChild().toText().data());
    ret.setRsvpStatus(fr.elementsByTagName(NODE_EVENT_RSVP_STATUS).at(0).firstChild().toText().data());

    ret.setOwnerId(friendId);
    ret.setServiceId(srvcId);
    ret.setAccountId(accountId);

    return ret;
}
Esempio n. 3
0
bool AttentionPlugin::outgoingStanza(int /*account*/, QDomElement& xml) {
    if(enabled) {
        if(xml.tagName() == "iq" && xml.attribute("type") == "result")
        {
            QDomNodeList list = xml.elementsByTagNameNS("http://jabber.org/protocol/disco#info", "query");
            if(!list.isEmpty())
            {
                QDomElement query = list.at(0).toElement();
                if(!query.hasAttribute("node")) {
                    QDomDocument doc = xml.ownerDocument();
                    QDomElement feature = doc.createElement("feature");
                    feature.setAttribute("var", "urn:xmpp:attention:0");
                    query.appendChild(feature);
                }
            }
        }
        else if(xml.tagName() == "presence")
        {
            QDomNodeList list = xml.elementsByTagNameNS("http://jabber.org/protocol/caps", "c");
            if(!list.isEmpty())
            {
                QDomElement c = list.at(0).toElement();
                if(c.hasAttribute("ext")) {
                    QString ext = c.attribute("ext");
                    ext += " at-pl";
                    c.setAttribute("ext", ext);
                }
            }
        }
    }
    return false;
}
Esempio n. 4
0
QList<CollinsInfo> Collins::zhCollins(QString word)
{
        QList<CollinsInfo> empty;
        QSqlQuery query(zhCollinsdb_);
    //    QString sql = QString("select * from zhmultiwords where word='%1'").arg(word);
        query.prepare("select * from zhmultiwords where word=:word and type=1");
        query.bindValue(":word",word);
        if (query.exec()) {
            while (query.next()) {
                CollinsInfo info;
                info.wordID = query.value(0).toInt();
                info.word = query.value(1).toString();
                info.frequency = query.value(2).toInt();
                info.type = query.value(3).toInt();
                info.num = query.value(4).toInt();
                info.st = query.value(5).toString();
                info.cn = query.value(6).toString();
                info.sentences = query.value(7).toString();
                info.grammer = query.value(8).toString();
                info.explain = query.value(9).toString();
                info.usagenote = query.value(10).toString();
                info.exampleXML = query.value(11).toString();
                QDomDocument doc;
                if (doc.setContent(info.exampleXML)) {
                    QDomNodeList list = doc.elementsByTagName("pair");
                    for (int i = 0; i < list.size(); ++i) {
                        QString entext;
                        QString zhtext;
                        QDomNode one = list.at(i);
                        if (one.isElement()) {
                            QDomElement ele = one.toElement();
                            QDomNodeList enlist = ele.elementsByTagName("en");
                            if (!enlist.isEmpty()) {
                                QDomElement en = enlist.at(0).toElement();
                                entext = en.text();
                            }

                            QDomNodeList znlist = ele.elementsByTagName("zh");
                            if (!znlist.isEmpty()) {
                                QDomElement zh = znlist.at(0).toElement();
                                zhtext = zh.text();
                            }
                            info.example.insert(entext,zhtext);
                        }

                    }
                }
                empty.append(info);



            }

        }else {
            qDebug() << "sql exec ERROR"<< query.lastError().text()<<query.lastQuery();
        }
        return empty;
}
Esempio n. 5
0
int QgsSOAPRequestHandler::parseGetMapElement( QMap<QString, QString>& parameterMap, const QDomElement& getMapElement ) const
{
  QDomNodeList boundingBoxList = getMapElement.elementsByTagName( "BoundingBox" );
  if ( !boundingBoxList.isEmpty() )
  {
    parseBoundingBoxElement( parameterMap, boundingBoxList.item( 0 ).toElement() );
  }
  QDomNodeList CRSList = getMapElement.elementsByTagName( "coordinateReferenceSystem" );
  if ( !CRSList.isEmpty() )
  {
    QString crsText = CRSList.item( 0 ).toElement().text();
    QString epsgNumber;
    if ( !crsText.startsWith( "EPSG_" ) ) //use underscore in SOAP because ':' is reserved for namespaces
    {
      //error
    }
    else
    {
      epsgNumber = crsText.replace( 4, 1, ":" );//replace the underscore with a ':' to make it WMS compatible
    }
    parameterMap.insert( "CRS", epsgNumber );
  }
  QDomNodeList GMLList = getMapElement.elementsByTagNameNS( "http://www.eu-orchestra.org/services/ms", "GML" );
  if ( !GMLList.isEmpty() )
  {
    QString gmlText;
    QTextStream gmlStream( &gmlText );
    GMLList.at( 0 ).save( gmlStream, 2 );
    parameterMap.insert( "GML", gmlText );
  }

  //outputAttributes
  QDomNodeList imageDocumentAttributesList = getMapElement.elementsByTagName( "Output" );
  if ( !imageDocumentAttributesList.isEmpty() )
  {
    parseOutputAttributesElement( parameterMap, imageDocumentAttributesList.item( 0 ).toElement() );
  }

  //SLD
  QDomNodeList sldList = getMapElement.elementsByTagName( "StyledLayerDescriptor" );
  if ( !sldList.isEmpty() )
  {
    QString sldString;
    QTextStream sldStream( &sldString );
    sldList.item( 0 ).save( sldStream, 0 );
    //Replace some special characters
    sldString.replace( "&lt;", "<" );
    sldString.replace( "&gt;", ">" );
    parameterMap.insert( "SLD", sldString );
  }

  return 0;
}
Esempio n. 6
0
GLVector * GLVector::fromXml(const QDomElement &object)
{

    if (object.isNull() || object.attribute("type","") != "vector")
        return NULL;

    QString id = object.attribute("id","");

    GLdouble sx = 0.0;
    GLdouble sy = 0.0;
    GLdouble sz = 0.0;

    GLdouble ex = 0.0;
    GLdouble ey = 0.0;
    GLdouble ez = 0.0;

    QDomNodeList points = object.elementsByTagName("point");
    if (points.count() == 2)
    {
        QDomElement point = points.at(0).toElement();
        sx = point.attribute("x","0").toDouble();
        sy = point.attribute("y","0").toDouble();
        sz = point.attribute("z","0").toDouble();
        point = points.at(1).toElement();
        ex = point.attribute("x","0").toDouble();
        ey = point.attribute("y","0").toDouble();
        ez = point.attribute("z","0").toDouble();
    }

    uchar r=0,g=0,b=0,a=255;

    QDomNodeList colors = object.elementsByTagName("color");
    if (!colors.isEmpty())
    {
        QDomElement colorNode = colors.at(0).toElement();
        r = (uchar)colorNode.attribute("r","0").toUShort(NULL, 16);
        g = (uchar)colorNode.attribute("g","0").toUShort(NULL, 16);
        b = (uchar)colorNode.attribute("b","0").toUShort(NULL, 16);
        a = (uchar)colorNode.attribute("a","ff").toUShort(NULL, 16);
    }

    int time = 0;
    QDomNodeList times = object.elementsByTagName("time");
    if (!times.isEmpty())
    {
        QDomElement timeNode = times.at(0).toElement();
        time = timeNode.text().toInt();
    }

    return new GLVector(sx,sy,sz,ex,ey,ez,GLColor(r,g,b,a),id,time);
}
Esempio n. 7
0
/// Returns a string containing the standardized version of
/// \p formula from \p inputFormat in \p outputFormat. If an error
/// occurs an empty string is returned.
///
/// For example, to convert an InChI string to standardized SMILES:
/// \code
/// std::string formula = pubchem.standardizeFormula("InChI=1/C6H6/c1-2-4-6-5-3-1/h1-6H", "inchi", "smiles");
/// \endcode
std::string PubChem::standardizeFormula(const std::string &formula, const std::string &inputFormat, const std::string &outputFormat) const
{
    if(formula.empty()){
        return std::string();
    }

    PubChemQuery query = PubChemQuery::standardizationQuery(formula, inputFormat, outputFormat);

    PubChemQueryThread thread(query);
    thread.start();
    thread.wait();

    QByteArray response = thread.response();

    QDomDocument document;
    document.setContent(response, false);

    QDomNodeList nodes = document.elementsByTagName("PCT-Structure_structure_string");
    if(nodes.isEmpty()){
        return std::string();
    }

    QDomNode node = nodes.at(0);
    QDomElement element = node.toElement();
    QByteArray elementText = element.text().toAscii();
    std::string standardizedFormula = elementText.constData();

    return standardizedFormula;
}
Esempio n. 8
0
/// Downloads and returns the file data for the compounds with ID's
/// in the list \p ids. If an error occurs an empty QByteArray is
/// returned.
QByteArray PubChem::downloadFileData(const QStringList &ids, const QString &format) const
{
    PubChemQuery query = PubChemQuery::downloadQuery(ids, format);

    PubChemQueryThread thread(query);
    thread.start();
    thread.wait();

    // the response contains a URL where the file can be downloaded
    QByteArray response = thread.response();

    QDomDocument document;
    document.setContent(response, false);

    QDomNodeList nodes = document.elementsByTagName("PCT-Download-URL_url");
    if(nodes.isEmpty()){
        return QByteArray();
    }

    QDomNode node = nodes.at(0);
    QDomElement element = node.toElement();
    QString url = element.text();

    return DownloadThread::download(QUrl(url));
}
Esempio n. 9
0
void QgsProjectFileTransform::transform1400to1500()
{
  //Adapt the XML description of the composer legend model to version 1.5
  if ( mDom.isNull() )
  {
    return;
  }
  //Add layer id to <VectorClassificationItem>
  QDomNodeList layerItemList = mDom.elementsByTagName( QStringLiteral( "LayerItem" ) );
  QDomElement currentLayerItemElem;
  QString currentLayerId;

  for ( int i = 0; i < layerItemList.size(); ++i )
  {
    currentLayerItemElem = layerItemList.at( i ).toElement();
    if ( currentLayerItemElem.isNull() )
    {
      continue;
    }
    currentLayerId = currentLayerItemElem.attribute( QStringLiteral( "layerId" ) );

    QDomNodeList vectorClassificationList = currentLayerItemElem.elementsByTagName( QStringLiteral( "VectorClassificationItem" ) );
    QDomElement currentClassificationElem;
    for ( int j = 0; j < vectorClassificationList.size(); ++j )
    {
      currentClassificationElem = vectorClassificationList.at( j ).toElement();
      if ( !currentClassificationElem.isNull() )
      {
        currentClassificationElem.setAttribute( QStringLiteral( "layerId" ), currentLayerId );
      }
    }

    //replace the text items with VectorClassification or RasterClassification items
    QDomNodeList textItemList = currentLayerItemElem.elementsByTagName( QStringLiteral( "TextItem" ) );
    QDomElement currentTextItem;

    for ( int j = 0; j < textItemList.size(); ++j )
    {
      currentTextItem = textItemList.at( j ).toElement();
      if ( currentTextItem.isNull() )
      {
        continue;
      }

      QDomElement classificationElement;
      if ( !vectorClassificationList.isEmpty() ) //we guess it is a vector layer
      {
        classificationElement = mDom.createElement( QStringLiteral( "VectorClassificationItem" ) );
      }
      else
      {
        classificationElement = mDom.createElement( QStringLiteral( "RasterClassificationItem" ) );
      }

      classificationElement.setAttribute( QStringLiteral( "layerId" ), currentLayerId );
      classificationElement.setAttribute( QStringLiteral( "text" ), currentTextItem.attribute( QStringLiteral( "text" ) ) );
      currentLayerItemElem.replaceChild( classificationElement, currentTextItem );
    }
  }
}
Esempio n. 10
0
TrussMaterial& TrussMaterialLibrary::createMaterial ( const QString& xmlProps )
{
    // Create empty material
    TrussMaterial& material = createMaterial( 0, 0, 0, "" );

    // Save material UUID 
    QString mUUID = material.getUUID();

    QDomDocument doc;
    if ( ! doc.setContent( xmlProps ) )
        return material;

    QDomNodeList nodeList = doc.elementsByTagName( "TrussMaterial" );
    if ( nodeList.isEmpty() )
        return material;
    
    QDomElement materialElem = nodeList.at( 0 ).toElement();
    if ( materialElem.isNull() )
        return material;

    material.loadFromXML( materialElem );

    // Restore UUID
    material.setUUID( mUUID );

    return material;
}
Esempio n. 11
0
void
MusixMatchPlugin::trackSearchSlot()
{
    tDebug() << Q_FUNC_INFO;
    QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() );
    if ( !oldReply )
        return; //timeout will handle it
    oldReply->deleteLater();

    QDomDocument doc;
    doc.setContent(oldReply->readAll());
    qDebug() << Q_FUNC_INFO << doc.toString();
    QDomNodeList domNodeList = doc.elementsByTagName("track_id");
    if ( domNodeList.isEmpty() )
    {
        emit info( oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        return;
    }
    QString track_id = domNodeList.at(0).toElement().text();
    QString requestString( "http://api.musixmatch.com/ws/1.1/track.lyrics.get?track_id=%1&format=xml&apikey=%2" );
    QUrl url( requestString );

    TomahawkUtils::urlAddQueryItem( url, "apikey", m_apiKey );
    TomahawkUtils::urlAddQueryItem( url, "track_id", track_id );

    QNetworkReply* newReply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
    newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
    connect( newReply, SIGNAL( finished() ), SLOT( trackLyricsSlot() ) );
}
Esempio n. 12
0
void WSettings::searchFinished(QNetworkReply *reply)
{
	reply->deleteLater();
	ui.addButton->setEnabled(true);
	ui.searchEdit->clear();

	QDomDocument doc;
	if (!doc.setContent(reply->readAll()))
		return;
	QDomElement rootElement = doc.documentElement();

	QDomNodeList locations = rootElement.elementsByTagName(QLatin1String("location"));
	if (locations.isEmpty())
		ui.searchEdit->addItem(tr("Not found"));
	for (int i = 0; i < locations.count(); i++) {
		QDomNamedNodeMap attributes = locations.at(i).attributes();
		QString cityId = attributes.namedItem(QLatin1String("location")).nodeValue();
		QString cityName = attributes.namedItem(QLatin1String("city")).nodeValue();
		QString stateName = attributes.namedItem(QLatin1String("state")).nodeValue();
		QString cityFullName = cityName + ", " + stateName;
		int index = ui.searchEdit->count();
		ui.searchEdit->addItem(cityFullName);
		ui.searchEdit->setItemData(index, cityId, CodeRole);
		ui.searchEdit->setItemData(index, cityName, CityRole);
		ui.searchEdit->setItemData(index, stateName, StateRole);
	}
}
Esempio n. 13
0
void
MusicBrainzPlugin::albumSearchSlot()
{
    QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() );
    if ( !oldReply )
        return; //timeout will handle it

    QDomDocument doc;
    doc.setContent( oldReply->readAll() );
    QDomNodeList domNodeList = doc.elementsByTagName( "artist" );
    if ( domNodeList.isEmpty() )
    {
        emit info( oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        return;
    }

    QString artist_id = domNodeList.at( 0 ).toElement().attribute( "id" );
    QString requestString( "http://musicbrainz.org/ws/2/release?status=official&type=album|ep" );
    QUrl url( requestString );
    url.addQueryItem( "artist", artist_id );

    QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
    newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
    connect( newReply, SIGNAL( finished() ), SLOT( tracksSearchSlot() ) );
}
Esempio n. 14
0
bool QgsComposerTableColumn::readXml( const QDomElement &columnElem )
{
  mHAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "hAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
  mVAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "vAlignment" ), QString::number( Qt::AlignVCenter ) ).toInt() );
  mHeading = columnElem.attribute( QStringLiteral( "heading" ), QLatin1String( "" ) );
  mAttribute = columnElem.attribute( QStringLiteral( "attribute" ), QLatin1String( "" ) );
  mSortByRank = columnElem.attribute( QStringLiteral( "sortByRank" ), QStringLiteral( "0" ) ).toInt();
  mSortOrder = static_cast< Qt::SortOrder >( columnElem.attribute( QStringLiteral( "sortOrder" ), QString::number( Qt::AscendingOrder ) ).toInt() );
  mWidth = columnElem.attribute( QStringLiteral( "width" ), QStringLiteral( "0.0" ) ).toDouble();

  QDomNodeList bgColorList = columnElem.elementsByTagName( QStringLiteral( "backgroundColor" ) );
  if ( !bgColorList.isEmpty() )
  {
    QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
    bool redOk, greenOk, blueOk, alphaOk;
    int bgRed, bgGreen, bgBlue, bgAlpha;
    bgRed = bgColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
    bgGreen = bgColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
    bgBlue = bgColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
    bgAlpha = bgColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
    if ( redOk && greenOk && blueOk && alphaOk )
    {
      mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
    }
  }

  return true;
}
Esempio n. 15
0
bool QgsComposerNodesItem::readXML( const QDomElement& itemElem,
                                    const QDomDocument& doc )
{
  // restore general composer item properties
  const QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
  if ( !composerItemList.isEmpty() )
  {
    QDomElement composerItemElem = composerItemList.at( 0 ).toElement();

    if ( !qgsDoubleNear( composerItemElem.attribute( "rotation", "0" ).toDouble(), 0.0 ) )
      setItemRotation( composerItemElem.attribute( "rotation", "0" ).toDouble() );

    _readXML( composerItemElem, doc );
  }

  // restore style
  QDomElement styleSymbolElem = itemElem.firstChildElement( "symbol" );
  if ( !styleSymbolElem.isNull() )
    _readXMLStyle( styleSymbolElem );

  // restore nodes
  mPolygon.clear();
  QDomNodeList nodesList = itemElem.elementsByTagName( "node" );
  for ( int i = 0; i < nodesList.size(); i++ )
  {
    QDomElement nodeElem = nodesList.at( i ).toElement();
    QPointF newPt;
    newPt.setX( nodeElem.attribute( "x" ).toDouble() );
    newPt.setY( nodeElem.attribute( "y" ).toDouble() );
    mPolygon.append( newPt );
  }

  emit itemChanged();
  return true;
}
Esempio n. 16
0
void
MusicBrainzPlugin::albumFoundSlot()
{
    QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
    if ( !reply )
        return; //timeout will handle it

    QDomDocument doc;
    doc.setContent( reply->readAll() );
    QDomNodeList domNodeList = doc.elementsByTagName( "title" );
    if ( domNodeList.isEmpty() )
    {
        emit info( reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        return;
    }

    QStringList albums;
    for ( int i = 0; i < domNodeList.count(); i++ )
    {
        QString album = domNodeList.at( i ).toElement().text();
        if ( !albums.contains( album ) )
            albums << album;
    }

    Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
    QVariantMap returnedData;
    returnedData["albums"] = albums;
    emit info( requestData, returnedData );

    Tomahawk::InfoSystem::InfoStringHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash>();
    Tomahawk::InfoSystem::InfoStringHash criteria;
    criteria["artist"] = origData["artist"];
    emit updateCache( criteria, 0, requestData.type, returnedData );
}
Esempio n. 17
0
QString Unpacker::getVarAppTitle(QString contents) const
{
    QString manifest;

    QFile f(contents + "/AndroidManifest.xml");
    if (f.open(QFile::ReadOnly | QFile::Text)) {
        manifest = f.readAll();
        f.close();
    }
    else {
        return QString();
    }

    // Parse application title variable name:

    QDomDocument dom;
    dom.setContent(manifest);
    QDomNodeList nodes = dom.elementsByTagName("application");
    if (!nodes.isEmpty()) {
        QDomNamedNodeMap attr = nodes.at(0).attributes();
        const QString LABEL = attr.namedItem("android:label").nodeValue();
        if (LABEL.startsWith("@string/")) {
            return LABEL.mid(8);
        }
        else {
            return QString();
        }
    }
    else {
        return QString();
    }
}
Esempio n. 18
0
/*
 * Saves the folder state to file when it is expanded/collapsed.
 */
void BookmarkWidget::saveFolderState(QTreeWidgetItem* item)
{
    if(!item || !mw()->VTKA() ) return;

    QString path = getBookmarkFilepath();
    QFile f(path);
    if(!f.open(QIODevice::ReadWrite | QIODevice::Text)) {
        showFileOpenError();
        return;
    }

    QDomDocument doc;
    doc.setContent(&f);
    QDomNodeList list = doc.elementsByTagName(BOOKMARK_XML_ROOT);
    if(list.isEmpty()) {
        showInvalidFileError();
        return;
    }

    QDomElement root = list.at(0).toElement();
    QString dt = QDateTime::currentDateTimeUtc().toString();
    root.setAttribute(DATE_ACCESSED, dt);

    QDomNodeList folders = root.elementsByTagName(FOLDER_NAME);
    for(int i = 0; i < folders.length(); i++) {
        QDomElement elt = folders.at(i).toElement();
        QString value = elt.attribute(TITLE);
        if(value == item->text(0)) {
            elt.setAttribute(FOLDED, item->isExpanded() ? "no" : "yes");
            elt.setAttribute(DATE_ACCESSED, dt);
        }
    }

    saveDOMToFile(doc);
}
Esempio n. 19
0
QString EBTextEdit::itemNameFromDocument()
{
    QString sItemName("");
    if (m_ViewType == EditorView::XmlSource) {
        //Is there any problem with QTextEdit::toPlainText and QDomDocument::setContent?
        QDomDocument xmlDocument(m_FullFileName);
        QString errotMsg("");
        int iErrorLine(0), iErrorCol(0);
        if (!xmlDocument.setContent(toPlainText(),false, &errotMsg, &iErrorLine, &iErrorCol))
        {
            qCritical()<< "QDomDocument::setContent: " <<  errotMsg << " Line " << iErrorLine << " column: " << iErrorCol;
            return sItemName;
        }
        QDomNodeList nodeList = xmlDocument.elementsByTagName(DataOwnerSingl::XmlKeywords::KEYWORD_NAME);
        if (nodeList.isEmpty())
            return sItemName;
        sItemName =  nodeList.at(0).toElement().text();
    }
    else if (m_ViewType == EditorView::Text) {
        QTextCursor cursor = document()->find(DataOwnerSingl::TxtKeywords::KEYWORD_NAME);
        const QTextBlock block = cursor.block();
        if (!block.isValid())
            return QString("");
        sItemName = block.text();
        sItemName.remove(QRegExp("^"+ DataOwnerSingl::TxtKeywords::KEYWORD_NAME));
        //qDebug() << "itemNameFromDocument:" << sItemName;
    }
    else if(m_ViewType == EditorView::OnlyPlainData) {
        //todo
        sItemName = DataOwnerSingl::XmlKeywords::itemNameFromFile(m_FullFileName);
    } else
        Q_ASSERT(0);
    return sItemName;
}
Esempio n. 20
0
QDomElement findLastElementByTag(const QDomElement element, const QString tagName)
{
    QDomNodeList l = element.elementsByTagName(tagName);
    if (l.isEmpty())
        return QDomElement();

    return l.at(l.length()-1).toElement();
}
Esempio n. 21
0
bool SdfRenderer::checkShowConditions(QDomElement const &element, bool isIcon) const
{
	QDomNodeList showConditions = element.elementsByTagName("showIf");
	// a hack, need to be removed when there is another version of icons
	if (!showConditions.isEmpty() && isIcon) {
		return false;
	}
	if (showConditions.isEmpty() || !mElementRepo) {
		return true;
	}
	for (int i = 0; i < showConditions.length(); ++i) {
		if (!checkCondition(showConditions.at(i).toElement())) {
			return false;
		}
	}
	return true;
}
Esempio n. 22
0
void
MusicBrainzPlugin::gotReleaseGroupsSlot()
{
    QNetworkReply* oldReply = qobject_cast<QNetworkReply*>( sender() );
    if ( !oldReply )
        return; //timeout will handle it

    QDomDocument doc;
    doc.setContent( oldReply->readAll() );
    QDomNodeList releaseGroupsNL = doc.elementsByTagName( "release-group" );
    if ( releaseGroupsNL.isEmpty() )
    {
        emit info( oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(), QVariant() );
        tDebug() << Q_FUNC_INFO << doc.toString();
        return;
    }

    Tomahawk::InfoSystem::InfoRequestData requestData = oldReply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
    InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >();
    switch ( requestData.type )
    {
        case InfoArtistReleases:
        {
            QString popularId = releaseGroupsNL.at(0).firstChildElement( "artist-credit" ).firstChildElement( "name-credit" ).firstChildElement( "artist" ).attribute( "id" );

            QStringList albums;
            for ( int i = 0; i < releaseGroupsNL.count(); i++ )
            {
                QString groupTitle = releaseGroupsNL.at(i).firstChildElement("title").text();
                QString a = releaseGroupsNL.at(i).firstChildElement( "artist-credit" ).firstChildElement( "name-credit" ).firstChildElement( "artist" ).firstChildElement( "name" ).text();
                QString id = releaseGroupsNL.at(i).firstChildElement( "artist-credit" ).firstChildElement( "name-credit" ).firstChildElement( "artist" ).attribute( "id" );
                if ( !albums.contains( groupTitle ) && id == popularId && a.normalized( QString::NormalizationForm_KC ) == hash["artist"].normalized( QString::NormalizationForm_KC ) )
                {
                    albums << groupTitle;
                    tDebug() << Q_FUNC_INFO << groupTitle;
                }
            }

            QVariantMap returnedData;
            returnedData["albums"] = albums;
            emit info( requestData, returnedData );

            Tomahawk::InfoSystem::InfoStringHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash>();
            Tomahawk::InfoSystem::InfoStringHash criteria;
            criteria["artist"] = origData["artist"];
            emit updateCache( criteria, 0, requestData.type, returnedData );
            break;
        }

        default:
        {
            Q_ASSERT( false );
            break;
        }
    }
}
Esempio n. 23
0
int QgsSOAPRequestHandler::parseOutputAttributesElement( QMap<QString, QString>& parameterMap, const QDomElement& outputAttributesElement ) const
{
  //height
  QDomNodeList heightList = outputAttributesElement.elementsByTagName( "Height" );
  if ( !heightList.isEmpty() )
  {
    QString heightString = heightList.item( 0 ).toElement().text();
    parameterMap.insert( "HEIGHT", heightString );
  }

  //width
  QDomNodeList widthList = outputAttributesElement.elementsByTagName( "Width" );
  if ( !widthList.isEmpty() )
  {
    QString widthString = widthList.item( 0 ).toElement().text();
    parameterMap.insert( "WIDTH", widthString );
  }

  //format
  QDomNodeList formatList = outputAttributesElement.elementsByTagName( "Format" );
  if ( !formatList.isEmpty() )
  {
    QString formatString = formatList.item( 0 ).toElement().text();
    parameterMap.insert( "FORMAT", formatString );
  }

  //background transparendy
  QDomNodeList bgTransparencyList = outputAttributesElement.elementsByTagName/*NS*/( /*"http://www.eu-orchestra.org/services/ms",*/ "Transparent" );
  if ( !bgTransparencyList.isEmpty() )
  {
    QString bgTransparencyString = bgTransparencyList.item( 0 ).toElement().text();
    if ( bgTransparencyString.compare( "true", Qt::CaseInsensitive ) == 0
         || bgTransparencyString == "1" )
    {
      parameterMap.insert( "TRANSPARENT", "TRUE" );
    }
    else
    {
      parameterMap.insert( "TRANSPARENT", "FALSE" );
    }
  }
  return 0;
}
Esempio n. 24
0
  boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateConstruction(const QDomElement& element, const QDomNodeList& layerElements, const QDomDocument& doc, openstudio::model::Model& model)
  {
    // Krishnan, this constructor should only be used for unique objects like Building and Site
    //openstudio::model::Construction construction = model.getUniqueModelObject<openstudio::model::Construction>();

    openstudio::model::Construction construction(model);
    QString constructionId = element.attribute("id");
    m_idToObjectMap.insert(std::make_pair(constructionId, construction));

    QString constructionName = element.firstChildElement("Name").toElement().text();
    construction.setName(escapeName(constructionId, constructionName));
        
    QDomNodeList layerIdList = element.elementsByTagName("LayerId");

    if (layerIdList.isEmpty()){
      return construction;
    }

    QString layerId = layerIdList.at(0).toElement().attribute("layerIdRef");

    std::vector<openstudio::model::Material> materials;
    for (int i = 0; i < layerElements.count(); i++){
      QDomElement layerElement = layerElements.at(i).toElement();
      if (layerId == layerElement.attribute("id")){
        QDomNodeList materialIdElements = layerElement.elementsByTagName("MaterialId");
        for (int j = 0; j < materialIdElements.count(); j++){
          QString materialId = materialIdElements.at(j).toElement().attribute("materialIdRef");
          auto materialIt = m_idToObjectMap.find(materialId);
          if (materialIt != m_idToObjectMap.end()){
            boost::optional<openstudio::model::Material> material = materialIt->second.optionalCast<openstudio::model::Material>();
            OS_ASSERT(material); // Krishnan, what type of error handling do you want?
            materials.push_back(*material);
          }
        }
        break;
      }
    }

    // now assign all layers to real material, does gbXML have same layer order convention as E+?
    for (unsigned i = 0; i < materials.size(); ++i){
      bool test = false;
          
      if (materials[i].optionalCast<openstudio::model::OpaqueMaterial>()){
        test = construction.insertLayer(i, materials[i].cast<openstudio::model::OpaqueMaterial>());
      }else if (materials[i].optionalCast<openstudio::model::FenestrationMaterial>()){
        test = construction.insertLayer(i, materials[i].cast<openstudio::model::FenestrationMaterial>());
      }else if (materials[i].optionalCast<openstudio::model::ModelPartitionMaterial>()){
        test = construction.setLayer(materials[i].cast<openstudio::model::ModelPartitionMaterial>());
      }
          
      OS_ASSERT(test); // Krishnan, what type of error handling do you want?
    }

    return construction;
  }
Esempio n. 25
0
GLPoint * GLPoint::fromXml(const QDomElement &object)
{
    if (object.isNull() || object.attribute("type","") != "point")
        return NULL;

    QString id = object.attribute("id","");

    GLdouble x = 0.0;
    GLdouble y = 0.0;
    GLdouble z = 0.0;

    QDomNodeList points = object.elementsByTagName("point");
    if (!points.isEmpty())
    {
        QDomElement point = points.at(0).toElement();
        x = point.attribute("x","0").toDouble();
        y = point.attribute("y","0").toDouble();
        z = point.attribute("z","0").toDouble();
    }

    uchar r=0,g=0,b=0,a=255;

    QDomNodeList colors = object.elementsByTagName("color");
    if (!colors.isEmpty())
    {
        QDomElement colorNode = colors.at(0).toElement();
        r = (uchar)colorNode.attribute("r","0").toUShort(NULL, 16);
        g = (uchar)colorNode.attribute("g","0").toUShort(NULL, 16);
        b = (uchar)colorNode.attribute("b","0").toUShort(NULL, 16);
        a = (uchar)colorNode.attribute("a","ff").toUShort(NULL, 16);
    }

    int time = 0;
    QDomNodeList times = object.elementsByTagName("time");
    if (!times.isEmpty())
    {
        QDomElement timeNode = times.at(0).toElement();
        time = timeNode.text().toInt();
    }

    return new GLPoint(x,y,z, GLColor(r,g,b,a), id, time);
}
Esempio n. 26
0
QDomElement XmlCndInterface::getCondListElement( QDomDocument doc, QDomElement &root, const QString &text ) const
{
	QDomNodeList list = root.elementsByTagName(text);
	if (list.isEmpty())
	{
		QDomElement newListTag ( doc.createElement(text) );
		root.appendChild(newListTag);
		return newListTag;
	}
	return list.at(0).toElement();
}
Esempio n. 27
0
/**
 * Returns jabber:x:delay timestamp if present, otherwise returns current timestamp.
 */
QDateTime Message::timestamp() const
{
    QDomNodeList list = doc()->documentElement().elementsByTagNameNS("jabber:x:delay", "x");
    if ( list.isEmpty() ) {
        return QDateTime::currentDateTime();
    }
    QDomElement eStamp = list.at(0).toElement();
    QString stamp = eStamp.attribute("stamp",
                                     QDateTime::currentDateTime().toString("yyyyMMddThh:mm:ss"));
    return QDateTime::fromString(stamp, "yyyyMMddThh:mm:ss");
}
Esempio n. 28
0
/**
 *   We do this to support both
 *
 *   <pre>
 *   <class name="Test Name"> </class>
 *   </pre>
 *
 *   and
 *
 *   <pre>
 *   <class>
 *      <name>Test Name</name>
 *   </class>
 *   </pre>
 **/
QString ConfigLoader::getFromHierarcy(QDomElement const &classElement, QString const &name)
{
    QString value = classElement.attribute(name);
    if (!value.isEmpty())
        return value;
    QDomNodeList fields = classElement.elementsByTagName(name);
    if (fields.isEmpty())
        return QString();

    QDomElement subElement = fields.at(0).toElement();
    return subElement.text();
}
Esempio n. 29
0
void BookmarkWidget::createFolder()
{
    if(!mw()->VTKA() ) return;
    bool ok = true;

    QString path = getBookmarkFilepath();
    QFile bf(path);
    if(!bf.open(QFile::ReadWrite | QFile::Text)) {
        showFileOpenError();
        bf.close();
        return;
    }

    QDomDocument doc;
    QDomElement root;
    QDomNodeList list;
    if(bf.size() == 0) {
        buildDOMDocument(doc, root);
    } else {
        qDebug() << bf.size();
        doc.setContent(&bf);
        list = doc.elementsByTagName(BOOKMARK_XML_ROOT);
        if(list.isEmpty()) {
            showInvalidFileError();
            return;
        }
        root = list.at(0).toElement();
    }

    QInputDialog* titleBox = new QInputDialog(this);
    QString title;
    do
    {
        title = titleBox->getText(this, tr("New Folder"),
                                  tr("Enter the title for your new folder:"), QLineEdit::Normal, "", &ok);
    } while(title.isEmpty() && ok);

    if(!ok) return;

    QDomElement fldr = doc.createElement(FOLDER_NAME);
    fldr.setAttribute(TITLE, title);
    QString dt = QDateTime::currentDateTimeUtc().toString();
    fldr.setAttribute(DATE_CREATED, dt);
    fldr.setAttribute(DATE_MODIFIED, dt);
    fldr.setAttribute(DATE_ACCESSED, dt);
    fldr.setAttribute(UUID_NAME, QUuid::createUuid());
    fldr.setAttribute(FOLDED, "yes");
    root.appendChild(fldr);

    saveDOMToFile(doc);
    refreshBookmarkList();
}
Esempio n. 30
0
void QgsComposerUtils::readDataDefinedPropertyMap( const QDomElement &itemElem, QMap<QgsComposerObject::DataDefinedProperty, QString> *dataDefinedNames, QMap<QgsComposerObject::DataDefinedProperty, QgsDataDefined *> *dataDefinedProperties )
{
  QMap<QgsComposerObject::DataDefinedProperty, QString>::const_iterator i = dataDefinedNames->constBegin();
  for ( ; i != dataDefinedNames->constEnd(); ++i )
  {
    QString elemName = i.value();
    QDomNodeList ddNodeList = itemElem.elementsByTagName( elemName );
    if ( !ddNodeList.isEmpty() )
    {
      QDomElement ddElem = ddNodeList.at( 0 ).toElement();
      readDataDefinedProperty( i.key(), ddElem, dataDefinedProperties );
    }
  }
}