当前位置: 首页>>代码示例>>C++>>正文


C++ QDomNodeList::at方法代码示例

本文整理汇总了C++中QDomNodeList::at方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomNodeList::at方法的具体用法?C++ QDomNodeList::at怎么用?C++ QDomNodeList::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QDomNodeList的用法示例。


在下文中一共展示了QDomNodeList::at方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: readFile

int XmlGspInterface::readFile(const QString &fileName)
{
	QFile* file = new QFile(fileName);
	QFileInfo fi(fileName);
	QString path = (fi.path().length() > 3) ? QString(fi.path() + "/") : fi.path();

	QFileInfo si(QString::fromStdString(_schemaName));
	QString schemaPath(si.absolutePath() + "/");

	if (!file->open(QIODevice::ReadOnly | QIODevice::Text))
	{
		std::cout << "XmlGspInterface::readFile() - Can't open xml-file " <<
		fileName.toStdString() << "." << "\n";
		delete file;
		return 0;
	}
	if (!checkHash(fileName))
	{
		delete file;
		return 0;
	}

	QDomDocument doc("OGS-PROJECT-DOM");
	doc.setContent(file);
	QDomElement docElement = doc.documentElement(); //OpenGeoSysProject
	if (docElement.nodeName().compare("OpenGeoSysProject"))
	{
		std::cout << "XmlGspInterface::readFile() - Unexpected XML root." << "\n";
		delete file;
		return 0;
	}

	QDomNodeList fileList = docElement.childNodes();

	for(int i = 0; i < fileList.count(); i++)
	{
		const QString file_node(fileList.at(i).nodeName());
		if (file_node.compare("geo") == 0)
		{
			XmlGmlInterface gml(_project, schemaPath.toStdString() + "OpenGeoSysGLI.xsd");
			const QDomNodeList childList = fileList.at(i).childNodes();
			for(int j = 0; j < childList.count(); j++)
			{
				const QDomNode child_node (childList.at(j));
				if (child_node.nodeName().compare("file") == 0) 
				{
					std::cout << "path: " << path.toStdString() << "#" << "\n";
					std::cout << "file name: " << (child_node.toElement().text()).toStdString() << "#" << "\n";
					gml.readFile(QString(path + child_node.toElement().text()));
				}
			}
		}
		else if (file_node.compare("stn") == 0)
		{
			XmlStnInterface stn(_project, schemaPath.toStdString() + "OpenGeoSysSTN.xsd");
			const QDomNodeList childList = fileList.at(i).childNodes();
			for(int j = 0; j < childList.count(); j++)
				if (childList.at(j).nodeName().compare("file") == 0)
					stn.readFile(QString(path + childList.at(j).toElement().text()));
		}
		else if (file_node.compare("msh") == 0)
		{
			const std::string msh_name = path.toStdString() +
			                       fileList.at(i).toElement().text().toStdString();
			FileIO::OGSMeshIO meshIO;
			MeshLib::CFEMesh* msh = meshIO.loadMeshFromFile(msh_name);
			QFileInfo fi(QString::fromStdString(msh_name));
			std::string name = fi.fileName().toStdString();
			_project->addMesh(msh, name);
			//GridAdapter msh(fileList.at(i).toElement().text().toStdString());
			// TODO gridadapter to mesh-models
		}
	}

	return 1;
}
开发者ID:wolf-pf,项目名称:ogs_kb1,代码行数:76,代码来源:XmlGspInterface.cpp

示例2: docElement

void
XSPFLoader::gotBody()
{
    qDebug() << Q_FUNC_INFO;

    QDomDocument xmldoc;
    bool namespaceProcessing = true;
    xmldoc.setContent( m_body, namespaceProcessing );
    QDomElement docElement( xmldoc.documentElement() );

    QString origTitle;
    QDomNodeList tracklist;
    QDomElement n = docElement.firstChildElement();
    for ( ; !n.isNull(); n = n.nextSiblingElement() ) {
        if (n.namespaceURI() == m_NS && n.localName() == "title") {
            origTitle = n.text();
        } else if (n.namespaceURI() == m_NS && n.localName() == "creator") {
            m_creator = n.text();
        } else if (n.namespaceURI() == m_NS && n.localName() == "info") {
            m_info = n.text();
        } else if (n.namespaceURI() == m_NS && n.localName() == "trackList") {
            tracklist = n.childNodes();
        }
    }

    m_title = origTitle;
    if ( m_title.isEmpty() )
        m_title = tr( "New Playlist" );
    if( !m_overrideTitle.isEmpty() )
        m_title = m_overrideTitle;

    bool shownError = false;
    for ( unsigned int i = 0; i < tracklist.length(); i++ )
    {
        QDomNode e = tracklist.at( i );

        QString artist, album, track, duration, annotation, url;
        QDomElement n = e.firstChildElement();
        for ( ; !n.isNull(); n = n.nextSiblingElement() )
        {
            if (n.namespaceURI() == m_NS && n.localName() == "duration") {
                duration = n.text();
            } else if (n.namespaceURI() == m_NS && n.localName() == "annotation") {
                annotation = n.text();
            } else if (n.namespaceURI() == m_NS && n.localName() == "creator") {
                artist = n.text();
            } else if (n.namespaceURI() == m_NS && n.localName() == "album") {
                album = n.text();
            } else if (n.namespaceURI() == m_NS && n.localName() == "title") {
                track = n.text();
            } else if (n.namespaceURI() == m_NS && n.localName() == "url") {
                url = n.text();
            }
        }

        if( artist.isEmpty() || track.isEmpty() )
        {
            if( !shownError )
            {
                QMessageBox::warning( 0, tr( "Failed to save tracks" ), tr( "Some tracks in the playlist do not contain an artist and a title. They will be ignored." ), QMessageBox::Ok );
                shownError = true;
            }
            continue;
        }

        query_ptr q = Tomahawk::Query::get( artist, track, album, uuid() );
        q->setDuration( duration.toInt() / 1000 );
        if( !url.isEmpty() )
            q->setResultHint( url );

        m_entries << q;
    }

    if ( origTitle.isEmpty() && m_entries.isEmpty() )
    {
        if ( m_autoCreate )
        {
            QMessageBox::critical( 0, tr( "XSPF Error" ), tr( "This is not a valid XSPF playlist." ) );
            deleteLater();
            return;
        }
        else
        {
            emit failed();
            return;
        }
    }

    if ( m_autoCreate )
    {
        m_playlist = Playlist::create( SourceList::instance()->getLocal(),
                                       uuid(),
                                       m_title,
                                       m_info,
                                       m_creator,
                                       false,
                                       m_entries );

        deleteLater();
    }
//.........这里部分代码省略.........
开发者ID:euroelessar,项目名称:tomahawk,代码行数:101,代码来源:xspfloader.cpp

示例3: capabilitiesReplyFinished

void QgsWfsCapabilities::capabilitiesReplyFinished()
{
  const QByteArray &buffer = mResponse;

  QgsDebugMsg( "parsing capabilities: " + buffer );

  // parse XML
  QString capabilitiesDocError;
  QDomDocument capabilitiesDocument;
  if ( !capabilitiesDocument.setContent( buffer, true, &capabilitiesDocError ) )
  {
    mErrorCode = QgsWfsRequest::XmlError;
    mErrorMessage = capabilitiesDocError;
    emit gotCapabilities();
    return;
  }

  QDomElement doc = capabilitiesDocument.documentElement();

  // handle exceptions
  if ( doc.tagName() == QLatin1String( "ExceptionReport" ) )
  {
    QDomNode ex = doc.firstChild();
    QString exc = ex.toElement().attribute( QStringLiteral( "exceptionCode" ), QStringLiteral( "Exception" ) );
    QDomElement ext = ex.firstChild().toElement();
    mErrorCode = QgsWfsRequest::ServerExceptionError;
    mErrorMessage = exc + ": " + ext.firstChild().nodeValue();
    emit gotCapabilities();
    return;
  }

  mCaps.clear();

  //test wfs version
  mCaps.version = doc.attribute( QStringLiteral( "version" ) );
  if ( !mCaps.version.startsWith( QLatin1String( "1.0" ) ) &&
       !mCaps.version.startsWith( QLatin1String( "1.1" ) ) &&
       !mCaps.version.startsWith( QLatin1String( "2.0" ) ) )
  {
    mErrorCode = WFSVersionNotSupported;
    mErrorMessage = tr( "WFS version %1 not supported" ).arg( mCaps.version );
    emit gotCapabilities();
    return;
  }

  // WFS 2.0 implementation are supposed to implement resultType=hits, and some
  // implementations (GeoServer) might advertize it, whereas others (MapServer) do not.
  // WFS 1.1 implementation too I think, but in the examples of the GetCapabilities
  // response of the WFS 1.1 standard (and in common implementations), this is
  // explicitly advertized
  if ( mCaps.version.startsWith( QLatin1String( "2.0" ) ) )
    mCaps.supportsHits = true;

  // Note: for conveniency, we do not use the elementsByTagNameNS() method as
  // the WFS and OWS namespaces URI are not the same in all versions

  if ( mCaps.version.startsWith( QLatin1String( "1.0" ) ) )
  {
    QDomElement capabilityElem = doc.firstChildElement( QStringLiteral( "Capability" ) );
    if ( !capabilityElem.isNull() )
    {
      QDomElement requestElem = capabilityElem.firstChildElement( QStringLiteral( "Request" ) );
      if ( !requestElem.isNull() )
      {
        QDomElement getFeatureElem = requestElem.firstChildElement( QStringLiteral( "GetFeature" ) );
        if ( !getFeatureElem.isNull() )
        {
          QDomElement resultFormatElem = getFeatureElem.firstChildElement( QStringLiteral( "ResultFormat" ) );
          if ( !resultFormatElem.isNull() )
          {
            QDomElement child = resultFormatElem.firstChildElement();
            while ( !child.isNull() )
            {
              mCaps.outputFormats << child.tagName();
              child = child.nextSiblingElement();
            }
          }
        }
      }
    }
  }

  // find <ows:OperationsMetadata>
  QDomElement operationsMetadataElem = doc.firstChildElement( QStringLiteral( "OperationsMetadata" ) );
  if ( !operationsMetadataElem.isNull() )
  {
    QDomNodeList contraintList = operationsMetadataElem.elementsByTagName( QStringLiteral( "Constraint" ) );
    for ( int i = 0; i < contraintList.size(); ++i )
    {
      QDomElement contraint = contraintList.at( i ).toElement();
      if ( contraint.attribute( QStringLiteral( "name" ) ) == QLatin1String( "DefaultMaxFeatures" ) /* WFS 1.1 */ )
      {
        QDomElement value = contraint.firstChildElement( QStringLiteral( "Value" ) );
        if ( !value.isNull() )
        {
          mCaps.maxFeatures = value.text().toInt();
          QgsDebugMsg( QString( "maxFeatures: %1" ).arg( mCaps.maxFeatures ) );
        }
      }
      else if ( contraint.attribute( QStringLiteral( "name" ) ) == QLatin1String( "CountDefault" ) /* WFS 2.0 (e.g. MapServer) */ )
//.........这里部分代码省略.........
开发者ID:ndavid,项目名称:QGIS,代码行数:101,代码来源:qgswfscapabilities.cpp

示例4: loadKxml

/**
 * Parse a kxml file and insert content into the document. Returns
 * true on success.
 */
bool KDocument::loadKxml(QString filename) {
    QFile file(filename);
    file.open(QIODevice::ReadOnly);
    QDomDocument document("kxml");
    
    if (!document.setContent(&file)) {
	return false;
    }

    /*
     * Meta information
     */
    QStringList meta;
    meta << "title" << "author" << "description" << "language";
    for (int i = 0; i < meta.size(); i++) {
	
	setProperty(
	    meta.at(i).toUtf8(),
	    document.elementsByTagName( meta.at(i) ).at(0).toElement().text()
	);

    }


    /*
     * Categories
     */
    QDomNodeList categories = document.elementsByTagName("category");
    for (uint i = 0; i < categories.length(); i++) {
	
	QDomElement category = categories.at(i).toElement();
	m_categories.append(category.attribute("name"));

	/*
	 * Questions
	 */
	QDomNodeList questions = category.elementsByTagName("question");
	for (uint j = 0; j < questions.length(); j++) {
	    
	    QDomElement question = questions.at(j).toElement();
	    KQuestion q;

	    q.setCategory(category.attribute("name"));

	    // Text
	    QDomElement text = question.elementsByTagName("text").at(0).toElement();
	    q.setText(text.text());

	    // Id
	    if (question.hasAttribute("id")) {
		q.setId(question.attribute("id").toInt());
	    }
	    
	    // Type
	    if (question.attribute("type") == "alternatives") {
		q.setType(KQuestion::Alternatives);
	    } else {
		q.setType(KQuestion::Manual);
	    }

	    // Level
	    if (question.attribute("level") == "easy") {
		q.setLevel(KQuestion::Easy);
	    } else if (question.attribute("level") == "medium") {
		q.setLevel(KQuestion::Medium);
	    } else {
		q.setLevel(KQuestion::Hard);
	    }

	    // Image
	    QDomNodeList images = question.elementsByTagName("image");
	    if (images.count() > 0) {
		QDomElement image = images.at(0).toElement();
		QByteArray ba = QByteArray::fromBase64(image.text().toUtf8());
		QPixmap p;
		p.loadFromData(ba, "PNG");
		q.setImage(p);
	    }

	    // Answers
	    QDomNodeList answers = question.elementsByTagName("answer");
	    for (uint k = 0; k < answers.length(); k++) {
		QDomElement answer = answers.at(k).toElement();
		
		if (answer.attribute("correct") != 0) {
		    q.m_answers.prepend(answer.text());
		} else {
		    q.m_answers.append(answer.text());
		}
	    }

	    m_questions.append(q);
	}
    }

    /*
//.........这里部分代码省略.........
开发者ID:KnutHelland,项目名称:Knowledge-,代码行数:101,代码来源:KDocument.cpp

示例5: readPropertiesFromElement

bool QgsLayoutItemScaleBar::readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &, const QgsReadWriteContext &context )
{
  mSettings.setHeight( itemElem.attribute( QStringLiteral( "height" ), QStringLiteral( "5.0" ) ).toDouble() );
  mSettings.setLabelBarSpace( itemElem.attribute( QStringLiteral( "labelBarSpace" ), QStringLiteral( "3.0" ) ).toDouble() );
  mSettings.setBoxContentSpace( itemElem.attribute( QStringLiteral( "boxContentSpace" ), QStringLiteral( "1.0" ) ).toDouble() );
  mSettings.setNumberOfSegments( itemElem.attribute( QStringLiteral( "numSegments" ), QStringLiteral( "2" ) ).toInt() );
  mSettings.setNumberOfSegmentsLeft( itemElem.attribute( QStringLiteral( "numSegmentsLeft" ), QStringLiteral( "0" ) ).toInt() );
  mSettings.setUnitsPerSegment( itemElem.attribute( QStringLiteral( "numUnitsPerSegment" ), QStringLiteral( "1.0" ) ).toDouble() );
  mSettings.setSegmentSizeMode( static_cast<QgsScaleBarSettings::SegmentSizeMode>( itemElem.attribute( QStringLiteral( "segmentSizeMode" ), QStringLiteral( "0" ) ).toInt() ) );
  mSettings.setMinimumBarWidth( itemElem.attribute( QStringLiteral( "minBarWidth" ), QStringLiteral( "50" ) ).toDouble() );
  mSettings.setMaximumBarWidth( itemElem.attribute( QStringLiteral( "maxBarWidth" ), QStringLiteral( "150" ) ).toDouble() );
  mSegmentMillimeters = itemElem.attribute( QStringLiteral( "segmentMillimeters" ), QStringLiteral( "0.0" ) ).toDouble();
  mSettings.setMapUnitsPerScaleBarUnit( itemElem.attribute( QStringLiteral( "numMapUnitsPerScaleBarUnit" ), QStringLiteral( "1.0" ) ).toDouble() );
  mSettings.setLineWidth( itemElem.attribute( QStringLiteral( "outlineWidth" ), QStringLiteral( "0.3" ) ).toDouble() );
  mSettings.setUnitLabel( itemElem.attribute( QStringLiteral( "unitLabel" ) ) );
  mSettings.setLineJoinStyle( QgsSymbolLayerUtils::decodePenJoinStyle( itemElem.attribute( QStringLiteral( "lineJoinStyle" ), QStringLiteral( "miter" ) ) ) );
  mSettings.setLineCapStyle( QgsSymbolLayerUtils::decodePenCapStyle( itemElem.attribute( QStringLiteral( "lineCapStyle" ), QStringLiteral( "square" ) ) ) );

  QDomNodeList textFormatNodeList = itemElem.elementsByTagName( QStringLiteral( "text-style" ) );
  if ( !textFormatNodeList.isEmpty() )
  {
    QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
    mSettings.textFormat().readXml( textFormatElem, context );
  }
  else
  {
    QFont f;
    if ( !QgsFontUtils::setFromXmlChildNode( f, itemElem, QStringLiteral( "scaleBarFont" ) ) )
    {
      f.fromString( itemElem.attribute( QStringLiteral( "font" ), QString() ) );
    }
    mSettings.textFormat().setFont( f );
    if ( f.pointSizeF() > 0 )
    {
      mSettings.textFormat().setSize( f.pointSizeF() );
      mSettings.textFormat().setSizeUnit( QgsUnitTypes::RenderPoints );
    }
    else if ( f.pixelSize() > 0 )
    {
      mSettings.textFormat().setSize( f.pixelSize() );
      mSettings.textFormat().setSizeUnit( QgsUnitTypes::RenderPixels );
    }
  }

  //colors
  //fill color
  QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral( "fillColor" ) );
  if ( !fillColorList.isEmpty() )
  {
    QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
    bool redOk, greenOk, blueOk, alphaOk;
    int fillRed, fillGreen, fillBlue, fillAlpha;

    fillRed = fillColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
    fillGreen = fillColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
    fillBlue = fillColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
    fillAlpha = fillColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );

    if ( redOk && greenOk && blueOk && alphaOk )
    {
      mSettings.setFillColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
    }
  }
  else
  {
    mSettings.setFillColor( QColor( itemElem.attribute( QStringLiteral( "brushColor" ), QStringLiteral( "#000000" ) ) ) );
  }

  //fill color 2
  QDomNodeList fillColor2List = itemElem.elementsByTagName( QStringLiteral( "fillColor2" ) );
  if ( !fillColor2List.isEmpty() )
  {
    QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
    bool redOk, greenOk, blueOk, alphaOk;
    int fillRed, fillGreen, fillBlue, fillAlpha;

    fillRed = fillColor2Elem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
    fillGreen = fillColor2Elem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
    fillBlue = fillColor2Elem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
    fillAlpha = fillColor2Elem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );

    if ( redOk && greenOk && blueOk && alphaOk )
    {
      mSettings.setFillColor2( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
    }
  }
  else
  {
    mSettings.setFillColor2( QColor( itemElem.attribute( QStringLiteral( "brush2Color" ), QStringLiteral( "#ffffff" ) ) ) );
  }

  //stroke color
  QDomNodeList strokeColorList = itemElem.elementsByTagName( QStringLiteral( "strokeColor" ) );
  if ( !strokeColorList.isEmpty() )
  {
    QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
    bool redOk, greenOk, blueOk, alphaOk;
    int strokeRed, strokeGreen, strokeBlue, strokeAlpha;

    strokeRed = strokeColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
//.........这里部分代码省略.........
开发者ID:AlisterH,项目名称:Quantum-GIS,代码行数:101,代码来源:qgslayoutitemscalebar.cpp

示例6: if

void QgsProjectFileTransform::transform1800to1900()
{
  if ( mDom.isNull() )
  {
    return;
  }

  QDomNodeList layerItemList = mDom.elementsByTagName( "rasterproperties" );
  for ( int i = 0; i < layerItemList.size(); ++i )
  {
    QDomElement rasterPropertiesElem = layerItemList.at( i ).toElement();
    QDomNode layerNode = rasterPropertiesElem.parentNode();
    QDomElement dataSourceElem = layerNode.firstChildElement( "datasource" );
    QDomElement layerNameElem = layerNode.firstChildElement( "layername" );
    QgsRasterLayer rasterLayer;
    // TODO: We have to use more data from project file to read the layer it correctly,
    // OTOH, we should not read it until it was converted
    rasterLayer.readXML( layerNode );
    convertRasterProperties( mDom, layerNode, rasterPropertiesElem, &rasterLayer );
  }

  //composer: replace mGridAnnotationPosition with mLeftGridAnnotationPosition & co.
  // and mGridAnnotationDirection with mLeftGridAnnotationDirection & co.
  QDomNodeList composerMapList = mDom.elementsByTagName( "ComposerMap" );
  for ( int i = 0; i < composerMapList.size(); ++i )
  {
    QDomNodeList gridList = composerMapList.at( i ).toElement().elementsByTagName( "Grid" );
    for ( int j = 0; j < gridList.size(); ++j )
    {
      QDomNodeList annotationList = gridList.at( j ).toElement().elementsByTagName( "Annotation" );
      for ( int k = 0; k < annotationList.size(); ++k )
      {
        QDomElement annotationElem = annotationList.at( k ).toElement();

        //position
        if ( annotationElem.hasAttribute( "position" ) )
        {
          int pos = annotationElem.attribute( "position" ).toInt();
          annotationElem.setAttribute( "leftPosition", pos );
          annotationElem.setAttribute( "rightPosition", pos );
          annotationElem.setAttribute( "topPosition", pos );
          annotationElem.setAttribute( "bottomPosition", pos );
          annotationElem.removeAttribute( "position" );
        }

        //direction
        if ( annotationElem.hasAttribute( "direction" ) )
        {
          int dir = annotationElem.attribute( "direction" ).toInt();
          if ( dir == 2 )
          {
            annotationElem.setAttribute( "leftDirection", 0 );
            annotationElem.setAttribute( "rightDirection", 0 );
            annotationElem.setAttribute( "topDirection", 1 );
            annotationElem.setAttribute( "bottomDirection", 1 );
          }
          else if ( dir == 3 )
          {
            annotationElem.setAttribute( "leftDirection", 1 );
            annotationElem.setAttribute( "rightDirection", 1 );
            annotationElem.setAttribute( "topDirection", 0 );
            annotationElem.setAttribute( "bottomDirection", 0 );
          }
          else
          {
            annotationElem.setAttribute( "leftDirection", dir );
            annotationElem.setAttribute( "rightDirection", dir );
            annotationElem.setAttribute( "topDirection", dir );
            annotationElem.setAttribute( "bottomDirection", dir );
          }
          annotationElem.removeAttribute( "direction" );
        }
      }
    }
  }

  QgsDebugMsg( mDom.toString() );
}
开发者ID:sebastiangz,项目名称:Quantum-GIS,代码行数:78,代码来源:qgsprojectfiletransform.cpp

示例7: convertRasterProperties

void QgsProjectFileTransform::convertRasterProperties( QDomDocument& doc, QDomNode& parentNode,
    QDomElement& rasterPropertiesElem, QgsRasterLayer* rlayer )
{
  QDomElement rasterRendererElem = doc.createElement( "rasterrenderer" );
  //convert general properties

  //invert color
  rasterRendererElem.setAttribute( "invertColor", "0" );
  QDomElement  invertColorElem = rasterPropertiesElem.firstChildElement( "mInvertColor" );
  if ( !invertColorElem.isNull() )
  {
    if ( invertColorElem.text() == "true" )
    {
      rasterRendererElem.setAttribute( "invertColor", "1" );
    }
  }

  //opacity
  rasterRendererElem.setAttribute( "opacity", "1" );
  QDomElement transparencyElem = parentNode.firstChildElement( "transparencyLevelInt" );
  if ( !transparencyElem.isNull() )
  {
    double transparency = transparencyElem.text().toInt();
    rasterRendererElem.setAttribute( "opacity", QString::number( transparency / 255.0 ) );
  }

  //alphaBand was not saved until now (bug)
  rasterRendererElem.setAttribute( "alphaBand", -1 );

  //gray band is used for several renderers
  int grayBand = rasterBandNumber( rasterPropertiesElem, "mGrayBandName", rlayer );

  //convert renderer specific properties
  QString drawingStyle = rasterPropertiesElem.firstChildElement( "mDrawingStyle" ).text();
  if ( drawingStyle == "SingleBandGray" )
  {
    rasterRendererElem.setAttribute( "type", "singlebandgray" );
    rasterRendererElem.setAttribute( "grayBand", grayBand );
    transformContrastEnhancement( doc, rasterPropertiesElem, rasterRendererElem );
  }
  else if ( drawingStyle == "SingleBandPseudoColor" )
  {
    rasterRendererElem.setAttribute( "type", "singlebandpseudocolor" );
    rasterRendererElem.setAttribute( "band", grayBand );
    QDomElement newRasterShaderElem = doc.createElement( "rastershader" );
    QDomElement newColorRampShaderElem = doc.createElement( "colorrampshader" );
    newRasterShaderElem.appendChild( newColorRampShaderElem );
    rasterRendererElem.appendChild( newRasterShaderElem );

    //switch depending on mColorShadingAlgorithm
    QString colorShadingAlgorithm = rasterPropertiesElem.firstChildElement( "mColorShadingAlgorithm" ).text();
    if ( colorShadingAlgorithm == "PseudoColorShader" || colorShadingAlgorithm == "FreakOutShader" )
    {
      newColorRampShaderElem.setAttribute( "colorRampType", "INTERPOLATED" );

      //get minmax from rasterlayer
      QgsRasterBandStats rasterBandStats = rlayer->bandStatistics( grayBand );
      double minValue = rasterBandStats.minimumValue;
      double maxValue = rasterBandStats.maximumValue;
      double breakSize = ( maxValue - minValue ) / 3;

      QStringList colorList;
      if ( colorShadingAlgorithm == "FreakOutShader" )
      {
        colorList << "#ff00ff" << "#00ffff" << "#ff0000" << "#00ff00";
      }
      else //pseudocolor
      {
        colorList << "#0000ff" << "#00ffff" << "#ffff00" << "#ff0000";
      }
      QStringList::const_iterator colorIt = colorList.constBegin();
      double boundValue = minValue;
      for ( ; colorIt != colorList.constEnd(); ++colorIt )
      {
        QDomElement newItemElem = doc.createElement( "item" );
        newItemElem.setAttribute( "value", QString::number( boundValue ) );
        newItemElem.setAttribute( "label", QString::number( boundValue ) );
        newItemElem.setAttribute( "color", *colorIt );
        newColorRampShaderElem.appendChild( newItemElem );
        boundValue += breakSize;
      }
    }
    else if ( colorShadingAlgorithm == "ColorRampShader" )
    {
      QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( "customColorRamp" );
      QString type = customColorRampElem.firstChildElement( "colorRampType" ).text();
      newColorRampShaderElem.setAttribute( "colorRampType", type );
      QDomNodeList colorNodeList = customColorRampElem.elementsByTagName( "colorRampEntry" );

      QString value, label;
      QColor newColor;
      int red, green, blue;
      QDomElement currentItemElem;
      for ( int i = 0; i < colorNodeList.size(); ++i )
      {
        currentItemElem = colorNodeList.at( i ).toElement();
        value = currentItemElem.attribute( "value" );
        label = currentItemElem.attribute( "label" );
        red = currentItemElem.attribute( "red" ).toInt();
        green = currentItemElem.attribute( "green" ).toInt();
//.........这里部分代码省略.........
开发者ID:sebastiangz,项目名称:Quantum-GIS,代码行数:101,代码来源:qgsprojectfiletransform.cpp

示例8: loadFromDomDoc

bool SM_ModelBackend::loadFromDomDoc (QDomDocument &doc)
{

    QMessageBox msgBox;

    // let us check if we have a valid subnetmap

    QDomElement docElem = doc.documentElement();
    if (docElem.nodeName()=="SubnetMap") {
        if (docElem.hasAttribute("fileformat")) {
            if ((docElem.attribute("fileformat")).toInt()!=2) {
                msgBox.setText("Warning: the SubnetMap you were trying to load has the wrong format. This Version of SubnetMapper can only read format version 2.");
                msgBox.setIcon(QMessageBox::Warning);
                msgBox.setDetailedText("The fileformat attribute of the SubnetMap node has a version number that is not equal to 2. Update SubnetMapper to the most recent version to read this file.");
                msgBox.exec();
                return false;
            };
        }
    } else return false;

    // now we know its one of ours.

    // we can clear all data now, but we do emit only the message to notify
    // everyone about the emptied model. The change-signals wil be emitted
    // at the end of this function. This makes sure that no widget will work
    // without a valid reason at this point.
    clearData(true);
    emit modelEmptied();

    QDomNodeList subnetNodes = docElem.elementsByTagName("subnet");

    // qDebug("SM_DataModel::loadFromDomDoc(): found %u subnet nodes in the document.",subnetNodes.count());

    for (int i=0;i<subnetNodes.count();i++){
        QDomElement currentSubnetNode=subnetNodes.at(i).toElement();

        QDomElement addressNode     = currentSubnetNode.firstChildElement("address");
        QDomElement netmaskNode     = currentSubnetNode.firstChildElement("netmask");
        QDomElement colorNode       = currentSubnetNode.firstChildElement("color");
        QDomElement descriptionNode = currentSubnetNode.firstChildElement("description");
        QDomElement notesNode       = currentSubnetNode.firstChildElement("notes");
        QDomElement identifierNode  = currentSubnetNode.firstChildElement("identifier");

        if (currentSubnetNode.hasAttribute("ipversion")) {
            if (currentSubnetNode.attribute("ipversion")=="IPv4") {

                Subnet_v4 *newSubnet = new Subnet_v4(this);

                QString mom=netmaskNode.text();
                newSubnet->setNM(mom);

                mom=addressNode.text();
                newSubnet->setIP(mom);

                mom=identifierNode.text();
                newSubnet->setIdentifier(mom);

                mom=descriptionNode.text();
                newSubnet->setDescription(mom);

                mom=notesNode.text();
                newSubnet->setNotes(mom);

                QColor momColor= QColor(colorNode.text());
                newSubnet->setColor(momColor);

                SubnetList.append(newSubnet);
                Subnet4List.append(newSubnet);


            } else if (currentSubnetNode.attribute("ipversion")=="IPv6") {

                Subnet_v6 *newSubnet = new Subnet_v6(this);

                QString mom=netmaskNode.text();
                //qDebug("SM_ModelBackend::loadFromDomDoc(): parsed IPv6 Netmask: %s",qPrintable(mom.toUtf8()));
                newSubnet->setNM(mom);

                mom=addressNode.text();
                //qDebug("SM_ModelBackend::loadFromDomDoc(): parsed IPv6 IP: %s",qPrintable(mom.toUtf8()));
                newSubnet->setIP(mom);

                mom=identifierNode.text();
                newSubnet->setIdentifier(mom);

                mom=descriptionNode.text();
                newSubnet->setDescription(mom);

                mom=notesNode.text();
                newSubnet->setNotes(mom);

                QColor momColor= QColor(colorNode.text());
                newSubnet->setColor(momColor);

                SubnetList.append(newSubnet);
                Subnet6List.append(newSubnet);

            } else {

                msgBox.setText("Warning: Subnet "+QString::number(i)+" was invalid! Subnet will be skipped...");
//.........这里部分代码省略.........
开发者ID:lordwolfchild,项目名称:subnetmapper,代码行数:101,代码来源:sm_modelbackend.cpp

示例9: QgsVectorLayer

void QgsProjectFileTransform::transform0110to1000()
{
  if ( ! mDom.isNull() )
  {
    QDomNodeList layerList = mDom.elementsByTagName( "maplayer" );
    for ( int i = 0; i < layerList.size(); ++i )
    {
      QDomElement layerElem = layerList.at( i ).toElement();
      QString typeString = layerElem.attribute( "type" );
      if ( typeString != "vector" )
      {
        continue;
      }

      //datasource
      QDomNode dataSourceNode = layerElem.namedItem( "datasource" );
      if ( dataSourceNode.isNull() )
      {
        return;
      }
      QString dataSource = dataSourceNode.toElement().text();

      //provider key
      QDomNode providerNode = layerElem.namedItem( "provider" );
      if ( providerNode.isNull() )
      {
        return;
      }
      QString providerKey = providerNode.toElement().text();

      //create the layer to get the provider for int->fieldName conversion
      QgsVectorLayer* theLayer = new QgsVectorLayer( dataSource, "", providerKey, false );
      if ( !theLayer->isValid() )
      {
        delete theLayer;
        return;
      }

      QgsVectorDataProvider* theProvider = theLayer->dataProvider();
      if ( !theProvider )
      {
        return;
      }
      QgsFieldMap theFieldMap = theProvider->fields();

      //read classificationfield
      QDomNodeList classificationFieldList = layerElem.elementsByTagName( "classificationfield" );
      for ( int j = 0; j < classificationFieldList.size(); ++j )
      {
        QDomElement classificationFieldElem = classificationFieldList.at( j ).toElement();
        int fieldNumber = classificationFieldElem.text().toInt();
        QgsFieldMap::const_iterator field_it = theFieldMap.find( fieldNumber );
        if ( field_it != theFieldMap.constEnd() )
        {
          QDomText fieldName = mDom.createTextNode( field_it.value().name() );
          QDomNode nameNode = classificationFieldElem.firstChild();
          classificationFieldElem.replaceChild( fieldName, nameNode );
        }
      }

    }
  }
}
开发者ID:sebastiangz,项目名称:Quantum-GIS,代码行数:63,代码来源:qgsprojectfiletransform.cpp

示例10: sfi

void
TagColorEditor::askGradientChoice()
{
  QString homePath = QDir::homePath();
  QFileInfo sfi(homePath, ".drishtigradients.xml");
  QString stopsflnm = sfi.absoluteFilePath();
  if (!sfi.exists())
    copyGradientFile(stopsflnm);

  QDomDocument document;
  QFile f(stopsflnm);
  if (f.open(QIODevice::ReadOnly))
    {
      document.setContent(&f);
      f.close();
    }

  QStringList glist;

  QDomElement main = document.documentElement();
  QDomNodeList dlist = main.childNodes();
  for(int i=0; i<dlist.count(); i++)
    {
      if (dlist.at(i).nodeName() == "gradient")
	{
	  QDomNodeList cnode = dlist.at(i).childNodes();
	  for(int j=0; j<cnode.count(); j++)
	    {
	      QDomElement dnode = cnode.at(j).toElement();
	      if (dnode.nodeName() == "name")
		glist << dnode.text();
	    }
	}
    }

  bool ok;
  QString gstr = QInputDialog::getItem(0,
				       "Color Gradient",
				       "Color Gradient",
				       glist, 0, false,
				       &ok);
  if (!ok)
    return;

  int cno = -1;
  for(int i=0; i<dlist.count(); i++)
    {
      if (dlist.at(i).nodeName() == "gradient")
	{
	  QDomNodeList cnode = dlist.at(i).childNodes();
	  for(int j=0; j<cnode.count(); j++)
	    {
	      QDomElement dnode = cnode.at(j).toElement();
	      if (dnode.tagName() == "name" && dnode.text() == gstr)
		{
		  cno = i;
		  break;
		}
	    }
	}
    }
	
  if (cno < 0)
    return;

  QGradientStops stops;
  QDomNodeList cnode = dlist.at(cno).childNodes();
  for(int j=0; j<cnode.count(); j++)
    {
      QDomElement de = cnode.at(j).toElement();
      if (de.tagName() == "gradientstops")
	{
	  QString str = de.text();
	  QStringList strlist = str.split(" ", QString::SkipEmptyParts);
	  for(int j=0; j<strlist.count()/5; j++)
	    {
	      float pos, r,g,b,a;
	      pos = strlist[5*j].toFloat();
	      r = strlist[5*j+1].toInt();
	      g = strlist[5*j+2].toInt();
	      b = strlist[5*j+3].toInt();
	      a = strlist[5*j+4].toInt();
	      stops << QGradientStop(pos, QColor(r,g,b,a));
	    }
	}
    }

  int mapSize = QInputDialog::getInt(0,
				     "Number of Colors",
				     "Number of Colors",
				     50, 2, 255, 1, &ok);
  if (!ok)
    mapSize = 50;

  QGradientStops gstops;
  gstops = StaticFunctions::resampleGradientStops(stops, mapSize);

  uchar *colors = Global::tagColors();  
  for(int i=0; i<gstops.size(); i++)
    {
//.........这里部分代码省略.........
开发者ID:drancom,项目名称:drishti,代码行数:101,代码来源:tagcoloreditor.cpp

示例11: _readXML

bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument& doc )
{
  Q_UNUSED( doc );
  if ( itemElem.isNull() )
  {
    return false;
  }

  //rotation
  mRotation = itemElem.attribute( "rotation", "0" ).toDouble();

  //uuid
  mUuid = itemElem.attribute( "uuid", QUuid::createUuid().toString() );

  //id
  QString id = itemElem.attribute( "id", "" );
  setId( id );

  //frame
  QString frame = itemElem.attribute( "frame" );
  if ( frame.compare( "true", Qt::CaseInsensitive ) == 0 )
  {
    mFrame = true;
  }
  else
  {
    mFrame = false;
  }

  //frame
  QString background = itemElem.attribute( "background" );
  if ( background.compare( "true", Qt::CaseInsensitive ) == 0 )
  {
    mBackground = true;
  }
  else
  {
    mBackground = false;
  }

  //position lock for mouse moves/resizes
  QString positionLock = itemElem.attribute( "positionLock" );
  if ( positionLock.compare( "true", Qt::CaseInsensitive ) == 0 )
  {
    mItemPositionLocked = true;
  }
  else
  {
    mItemPositionLocked = false;
  }

  //position
  double x, y, width, height;
  bool xOk, yOk, widthOk, heightOk, positionModeOK;

  x = itemElem.attribute( "x" ).toDouble( &xOk );
  y = itemElem.attribute( "y" ).toDouble( &yOk );
  width = itemElem.attribute( "width" ).toDouble( &widthOk );
  height = itemElem.attribute( "height" ).toDouble( &heightOk );
  mLastUsedPositionMode = ( ItemPositionMode )itemElem.attribute( "positionMode" ).toInt( &positionModeOK );
  if ( !positionModeOK )
  {
    mLastUsedPositionMode = UpperLeft;
  }

  if ( !xOk || !yOk || !widthOk || !heightOk )
  {
    return false;
  }

  mLastValidViewScaleFactor = itemElem.attribute( "lastValidViewScaleFactor", "-1" ).toDouble();

  setSceneRect( QRectF( x, y, width, height ) );
  setZValue( itemElem.attribute( "zValue" ).toDouble() );

  //pen
  QDomNodeList frameColorList = itemElem.elementsByTagName( "FrameColor" );
  if ( frameColorList.size() > 0 )
  {
    QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
    bool redOk, greenOk, blueOk, alphaOk, widthOk;
    int penRed, penGreen, penBlue, penAlpha;
    double penWidth;

    penWidth = itemElem.attribute( "outlineWidth" ).toDouble( &widthOk );
    penRed = frameColorElem.attribute( "red" ).toDouble( &redOk );
    penGreen = frameColorElem.attribute( "green" ).toDouble( &greenOk );
    penBlue = frameColorElem.attribute( "blue" ).toDouble( &blueOk );
    penAlpha = frameColorElem.attribute( "alpha" ).toDouble( &alphaOk );
    if ( redOk && greenOk && blueOk && alphaOk && widthOk )
    {
      QPen framePen( QColor( penRed, penGreen, penBlue, penAlpha ) );
      framePen.setWidthF( penWidth );
      setPen( framePen );
    }
  }

  //brush
  QDomNodeList bgColorList = itemElem.elementsByTagName( "BackgroundColor" );
  if ( bgColorList.size() > 0 )
//.........这里部分代码省略.........
开发者ID:PhilippeDorelon,项目名称:Quantum-GIS,代码行数:101,代码来源:qgscomposeritem.cpp

示例12: loadConfigFile

/**
 * Loads the current config file (m_configFileName).
 */
void CreateSceFile::loadConfigFile(void)
{
    if(!m_configFileName.isEmpty())
    {
        setGuiElementsToDefault();
        setTitle(m_configFileName);

        if(!m_configFileName.isEmpty())
        {
            QFile file(m_configFileName);
            QDomDocument doc("SceConfiguration");

            if (file.open(QFile::ReadOnly))
            {
                file.close();

                if (!doc.setContent(&file))
                {
                    if(!file.readAll().isEmpty())
                    {
                        QMessageBox::critical(this, "parse error", "could not parse " + m_configFileName);

                        m_configFileName = "";
                        setTitle(m_configFileName);
                        emit configHasToBeSavedSignal();
                    }
                }
                else
                {

                    QDomElement docElem = doc.documentElement();
                    ui->filesTableWidget->blockSignals(true);

                    QDomNodeList nodeList = docElem.elementsByTagName("ScriptWindowState");
                    QDomNode nodeItem = nodeList.at(0);
                    ui->withScriptWindowCheckBox->setChecked((nodeItem.attributes().namedItem("withScriptWindow").nodeValue() == "1"));
                    ui->notMinimized->setChecked((nodeItem.attributes().namedItem("notMinimized").nodeValue() == "1"));
                    ui->fileLineEdit->setText(MainWindow::convertToAbsolutePath(m_configFileName, nodeItem.attributes().namedItem("sceFileName").nodeValue()));

                    QStringList versionList = nodeItem.attributes().namedItem("minScVersion").nodeValue().split(".");
                    if(versionList.length() == 2)
                    {
                        ui->minScVersionMajor->setValue(versionList[0].toUInt());
                        ui->minScVersionMinor->setValue(versionList[1].toUInt());
                    }

                    nodeList = docElem.elementsByTagName("File");
                    for (int i = 0; i < nodeList.size(); i++)
                    {
                        nodeItem = nodeList.at(i);
                        QString subDirectory = nodeItem.attributes().namedItem("subDirectory").nodeValue();
                        QString type = (nodeItem.attributes().namedItem("type").nodeValue());
                        QString source = MainWindow::convertToAbsolutePath(m_configFileName, nodeItem.attributes().namedItem("source").nodeValue());
                        addTableRow(subDirectory, type, source);
                    }

                    nodeList = docElem.elementsByTagName("ScriptArgument");
                    for (int i = 0; i < nodeList.size(); i++)
                    {
                        nodeItem = nodeList.at(i);
                        QString value = nodeItem.attributes().namedItem("value").nodeValue();
                        ui->argumentsListWidget->addItem(value);
                    }

                    ui->filesTableWidget->blockSignals(false);
                    resizeTableColumnsSlot();

                    QStringList showStrList = m_configFileName.split("/");
                    statusBar()->showMessage(showStrList[showStrList.size() - 1] + " loaded", 5000);
                    setMenuState();
                }
            }
        }
        else
        {
            QMessageBox::critical(this, "could not open file", m_configFileName);

            m_configFileName = "";
            setTitle(m_configFileName);
            emit configHasToBeSavedSignal();
        }
    }
}
开发者ID:szieke,项目名称:ScriptCommunicator_serial-terminal,代码行数:86,代码来源:createSceFile.cpp

示例13: loadPressed

void ScreenWidget::loadPressed()
{
    QString fileName = QFileDialog::getOpenFileName(this, tr("Load Scene"), "",tr("DSS XML Scene File (*.xml);;All Files (*)"));

    if (fileName.isEmpty())
    {
        return;
    }
    else
    {
        QDomDocument doc("loadedscene");
        QFile file(fileName);
        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        {
            return;
        }

        if (!doc.setContent(&file))
        {
            file.close();
            return;
        }
        file.close();

        QDomElement scene = doc.documentElement();

        qDebug()<<scene.text();

        QDomNode field=scene.firstChildElement("field");
        if (field.isElement())
        {
            this->scene->addField(field.firstChildElement("width").text().toUInt(),field.firstChildElement("height").text().toUInt());
        }
        QDomNode targetEntity = scene.firstChildElement("targetEntity");
        if (targetEntity.isElement())
        {

            TargetEntity* newTargetEntity = new TargetEntity();
            Point2i targetPos(targetEntity.firstChildElement("x").text().toInt(),targetEntity.firstChildElement("y").text().toInt());
            this->scene->setTargetEntity(newTargetEntity,targetPos);
        }
        QDomNode entities = scene.firstChildElement("entities");
        if (entities.isElement())
        {
            QDomNodeList entityList =entities.toElement().elementsByTagName("entity");

            for(int i=0;i<entityList.count();i++)
            {
                QDomElement entity = entityList.at(i).toElement();

                int type = entity.firstChildElement("type").text().toInt();
                Point2i entityPos(entity.firstChildElement("x").text().toInt(),entity.firstChildElement("y").text().toInt());

                this->scene->addEntityAtPosition(type,entityPos);
            }
        }
/*
            for(int i=0;i<fieldList.count();i++)
            {
                QDomElement field = fieldList.at(i).toElement();

                qDebug()<<field.attribute("width");
                qDebug()<<field.attribute("height");


                QDomNodeList lll=e1.elementsByTagName("a");
                qDebug(QString::number(lll.count()).toAscii());

                for(int j=0;j<lll.count();j++)
                {
                    QDomElement e2 = lll.at(j).toElement();
                    qDebug(e2.tagName().toAscii()+" "+e2.attribute("ITEM").toAscii());
                    QDomNodeList llll=e2.elementsByTagName("b");
                    for(int k=0;k<llll.count();k++)
                    {
                        QDomElement e3 = llll.at(k).toElement();
                        qDebug(e3.tagName().toAscii()+" "+e3.text().toAscii());
                    }
                }

            }
            */
    }
}
开发者ID:blazovics,项目名称:DSS-Q,代码行数:84,代码来源:screenwidget.cpp

示例14: transformContrastEnhancement

void QgsProjectFileTransform::transformContrastEnhancement( QDomDocument& doc, const QDomElement& rasterproperties, QDomElement& rendererElem )
{
  if ( rasterproperties.isNull() || rendererElem.isNull() )
  {
    return;
  }

  double minimumValue = 0;
  double maximumValue = 0;
  QDomElement contrastMinMaxElem = rasterproperties.firstChildElement( "contrastEnhancementMinMaxValues" );
  if ( contrastMinMaxElem.isNull() )
  {
    return;
  }

  QDomElement contrastEnhancementAlgorithmElem = rasterproperties.firstChildElement( "mContrastEnhancementAlgorithm" );
  if ( contrastEnhancementAlgorithmElem.isNull() )
  {
    return;
  }

  //convert enhancement name to enumeration
  int algorithmEnum = 0;
  QString algorithmString = contrastEnhancementAlgorithmElem.text();
  if ( algorithmString == "StretchToMinimumMaximum" )
  {
    algorithmEnum = 1;
  }
  else if ( algorithmString == "StretchAndClipToMinimumMaximum" )
  {
    algorithmEnum = 2;
  }
  else if ( algorithmString == "ClipToMinimumMaximum" )
  {
    algorithmEnum = 3;
  }
  else if ( algorithmString == "UserDefinedEnhancement" )
  {
    algorithmEnum = 4;
  }

  QDomNodeList minMaxEntryList = contrastMinMaxElem.elementsByTagName( "minMaxEntry" );
  QStringList enhancementNameList;
  if ( minMaxEntryList.size() == 1 )
  {
    enhancementNameList << "contrastEnhancement";
  }
  if ( minMaxEntryList.size() ==  3 )
  {
    enhancementNameList << "redContrastEnhancement" << "greenContrastEnhancement" << "blueContrastEnhancement";
  }
  if ( minMaxEntryList.size() > enhancementNameList.size() )
  {
    return;
  }

  QDomElement minMaxEntryElem;
  for ( int i = 0; i < minMaxEntryList.size(); ++i )
  {
    minMaxEntryElem = minMaxEntryList.at( i ).toElement();
    QDomElement minElem = minMaxEntryElem.firstChildElement( "min" );
    if ( minElem.isNull() )
    {
      return;
    }
    minimumValue = minElem.text().toDouble();

    QDomElement maxElem = minMaxEntryElem.firstChildElement( "max" );
    if ( maxElem.isNull() )
    {
      return;
    }
    maximumValue = maxElem.text().toDouble();

    QDomElement newContrastEnhancementElem = doc.createElement( enhancementNameList.at( i ) );
    QDomElement newMinValElem = doc.createElement( "minValue" );
    QDomText minText = doc.createTextNode( QString::number( minimumValue ) );
    newMinValElem.appendChild( minText );
    newContrastEnhancementElem.appendChild( newMinValElem );
    QDomElement newMaxValElem = doc.createElement( "maxValue" );
    QDomText maxText = doc.createTextNode( QString::number( maximumValue ) );
    newMaxValElem.appendChild( maxText );
    newContrastEnhancementElem.appendChild( newMaxValElem );

    QDomElement newAlgorithmElem = doc.createElement( "algorithm" );
    QDomText newAlgorithmText = doc.createTextNode( QString::number( algorithmEnum ) );
    newAlgorithmElem.appendChild( newAlgorithmText );
    newContrastEnhancementElem.appendChild( newAlgorithmElem );

    rendererElem.appendChild( newContrastEnhancementElem );
  }
}
开发者ID:sebastiangz,项目名称:Quantum-GIS,代码行数:92,代码来源:qgsprojectfiletransform.cpp

示例15: slot_GetMusicXML

//得到音乐(xml格式)
void DownloadThread::slot_GetMusicXML(QNetworkReply *replay)
{
    QTextCodec *codec = QTextCodec::codecForName("utf8");//转换成utf8编码格式
    QString musicStr = codec ->toUnicode(replay ->readAll());

    //没有连接到网络
    if (musicStr == "")
    {
        QMessageBox::information(NULL, tr("信息"), tr("下载超时,请检查您的网络或者本机防火墙设置!"), QMessageBox::Yes);
        QString musicTitle = m_musicArtist + "-" + m_musicName;
        emit sig_DelCurrentMusicMapItem(musicTitle);
        return;
    }

	QString errorStr;
	int errorLine;
	int errorColumn;

	QDomDocument doc;
	if (!doc.setContent(musicStr, false, &errorStr, &errorLine, &errorColumn))
	{
		qDebug() << "在第" << errorLine << "行,第" << errorColumn << "列,读取字符串到doc中错误:" << errorStr;
        QMessageBox::information(NULL, tr("信息"), tr("没有找到该歌曲!"), QMessageBox::Yes);
		return;
	}

	QDomElement root = doc.documentElement();//获取根元素
	if (root.tagName() != "result")
	{
		QMessageBox::information(NULL, tr("信息"), tr("没有找到该歌曲!"), QMessageBox::Yes);
		return;
	}

	//获取音乐url
	QString sFirstPartUrl;	//前半部分
	QString sLastPartUrl;	//后半部分
	QDomNodeList nodeList = root.childNodes();//获得root所有子节点的列表
	for (int i = 0; i < nodeList.count(); ++i)
	{
		QDomNode node = nodeList.at(i);
		if (!node.isNull())//如果节点不为空
		{
			if (node.isElement())//如果节点是元素
			{
				QDomElement element = node.toElement();//转换成元素
				if (element.tagName() == "count")
				{
					qDebug() << "element.text() = " << element.text();
					if (element.text() == "0")//返回元素文本
					{
						QMessageBox::information(NULL, tr("信息"), tr("没有找到该歌曲!"), QMessageBox::Yes);
						return;
					}
				}
				else if (element.tagName() == "url")
				{
					QDomNodeList nodeList2 = element.childNodes();//获得url所有子节点的列表
					for (int i = 0; i < nodeList2.count(); ++i)
					{
						QDomNode node2 = nodeList2.at(i);
						if (!node2.isNull())//如果节点不为空
						{
							if (node2.isElement())//如果节点是元素
							{
								QDomElement element2 = node2.toElement();//转换成元素
								if (element2.tagName() == "encode")
								{
									//qDebug() << element2.text();
									sFirstPartUrl = element2.text();
								}
								else if (element2.tagName() == "decode")
								{
									//qDebug() << element2.text();
									sLastPartUrl = element2.text();
									break;
								}
							}
							else
							{
								QMessageBox::information(NULL, tr("信息"), tr("没有找到该歌曲!"), QMessageBox::Yes);
								return;
							}
						}
						else
						{
							QMessageBox::information(NULL, tr("信息"), tr("没有找到该歌曲!"), QMessageBox::Yes);
							return;
						}
					}
					break;
				}
			}
			else
			{
				QMessageBox::information(NULL, tr("信息"), tr("没有找到该歌曲!"), QMessageBox::Yes);
				return;
			}
		}
		else
//.........这里部分代码省略.........
开发者ID:Beenking,项目名称:CZPlayer2.0,代码行数:101,代码来源:downloadthread.cpp


注:本文中的QDomNodeList::at方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。