Ejemplo n.º 1
0
void QgsConfigParser::appendCRSElementsToLayer( QDomElement& layerElement, QDomDocument& doc, const QStringList &crsList ) const
{
  if ( layerElement.isNull() )
  {
    return;
  }

  //insert the CRS elements after the title element to be in accordance with the WMS 1.3 specification
  QDomElement titleElement = layerElement.firstChildElement( "Title" );

  //In case the number of advertised CRS is constrained
  QSet<QString> crsSet = supportedOutputCrsSet();

  QStringList::const_iterator crsIt = crsList.constBegin();
  for ( ; crsIt != crsList.constEnd(); ++crsIt )
  {
    if ( !crsSet.isEmpty() && !crsSet.contains( *crsIt ) ) //consider epsg output constraint
    {
      continue;
    }
    QDomElement crsElement = doc.createElement( "CRS" );
    QDomText crsText = doc.createTextNode( *crsIt );
    crsElement.appendChild( crsText );
    layerElement.insertAfter( crsElement, titleElement );
  }
}
Ejemplo n.º 2
0
void QgsConfigParser::appendExGeographicBoundingBox( QDomElement& layerElem,
    QDomDocument& doc,
    const QgsRectangle& layerExtent,
    const QgsCoordinateReferenceSystem& layerCRS ) const
{
  if ( layerElem.isNull() )
  {
    return;
  }

  QgsCoordinateReferenceSystem wgs84;
  wgs84.createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );

  //Ex_GeographicBoundingBox
  //transform the layers native CRS into WGS84
  QgsCoordinateTransform exGeoTransform( layerCRS, wgs84 );
  QgsRectangle wgs84BoundingRect = exGeoTransform.transformBoundingBox( layerExtent );

  QDomElement ExGeoBBoxElement = doc.createElement( "EX_GeographicBoundingBox" );
  QDomElement wBoundLongitudeElement = doc.createElement( "westBoundLongitude" );
  QDomText wBoundLongitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.xMinimum() ) );
  wBoundLongitudeElement.appendChild( wBoundLongitudeText );
  ExGeoBBoxElement.appendChild( wBoundLongitudeElement );
  QDomElement eBoundLongitudeElement = doc.createElement( "eastBoundLongitude" );
  QDomText eBoundLongitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.xMaximum() ) );
  eBoundLongitudeElement.appendChild( eBoundLongitudeText );
  ExGeoBBoxElement.appendChild( eBoundLongitudeElement );
  QDomElement sBoundLatitudeElement = doc.createElement( "southBoundLatitude" );
  QDomText sBoundLatitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.yMinimum() ) );
  sBoundLatitudeElement.appendChild( sBoundLatitudeText );
  ExGeoBBoxElement.appendChild( sBoundLatitudeElement );
  QDomElement nBoundLatitudeElement = doc.createElement( "northBoundLatitude" );
  QDomText nBoundLatitudeText = doc.createTextNode( QString::number( wgs84BoundingRect.yMaximum() ) );
  nBoundLatitudeElement.appendChild( nBoundLatitudeText );
  ExGeoBBoxElement.appendChild( nBoundLatitudeElement );

  //BoundingBox element
  QDomElement bBoxElement = doc.createElement( "BoundingBox" );
  if ( layerCRS.isValid() )
  {
    bBoxElement.setAttribute( "CRS", layerCRS.authid() );
  }

  bBoxElement.setAttribute( "minx", QString::number( layerExtent.xMinimum() ) );
  bBoxElement.setAttribute( "miny", QString::number( layerExtent.yMinimum() ) );
  bBoxElement.setAttribute( "maxx", QString::number( layerExtent.xMaximum() ) );
  bBoxElement.setAttribute( "maxy", QString::number( layerExtent.yMaximum() ) );

  QDomElement lastCRSElem = layerElem.lastChildElement( "CRS" );
  if ( !lastCRSElem.isNull() )
  {
    layerElem.insertAfter( ExGeoBBoxElement, lastCRSElem );
    layerElem.insertAfter( bBoxElement, ExGeoBBoxElement );
  }
  else
  {
    layerElem.appendChild( ExGeoBBoxElement );
    layerElem.appendChild( bBoxElement );
  }
}
//static
QDomElement RKComponentMap::findOrCreateElement (QDomElement& parent, const QString& tagname, const QString& name, const QString& label, int index) {
	RK_TRACE (PLUGIN);

	XMLHelper* xml = XMLHelper::getStaticHelper ();
	XMLChildList list = xml->getChildElements (parent, QString::null, DL_INFO);		// we need to look at all children, so we get the order right
	QDomElement insert_after_element;
	for (XMLChildList::const_iterator it=list.begin (); it != list.end (); ++it) {
		if ((tagname == (*it).tagName ()) && (name == xml->getStringAttribute ((*it), "name", "", DL_ERROR))) {
			return (*it);
		} else {
			if (index >= 0) {
				if (index > xml->getIntAttribute ((*it), "index", -1, DL_INFO)) {
					insert_after_element = *it;
				}
			}
		}
	}

	// element not found. Create a new one instead
	QDomElement ret = xmlguiBuildDocument ().createElement (tagname);
	ret.setAttribute ("name", name);
	ret.setAttribute ("index", index);
	if (!label.isEmpty ()) {
		QDomElement text = xmlguiBuildDocument ().createElement ("text");
		text.appendChild (xmlguiBuildDocument ().createTextNode (label));
		ret.appendChild (text);
	}
	parent.insertAfter (ret, insert_after_element);	// if index_after_element.isNull, this add the new element as the last child of parent!

	return ret;
}
Ejemplo n.º 4
0
static void replaceNode(QDomElement &docElem, QDomNode &n, const QStringList &list, const QString &tag)
{
    for(QStringList::ConstIterator it = list.begin();
            it != list.end(); ++it)
    {
        QDomElement e = docElem.ownerDocument().createElement(tag);
        QDomText txt = docElem.ownerDocument().createTextNode(*it);
        e.appendChild(txt);
        docElem.insertAfter(e, n);
    }

    QDomNode next = n.nextSibling();
    docElem.removeChild(n);
    n = next;
//   kDebug(7021) << "Next tag = " << n.toElement().tagName();
}
Ejemplo n.º 5
0
void MainWindow::on_actionPage_forward_activated()
{
    QDomElement root = document->documentElement();
    QDomElement picture = album.toElement();
    root.insertAfter( picture, picture.nextSiblingElement("photo") );

    if(album.nextSibling().isNull())
    {
        ui->actionMove_forward->setEnabled(false);
        ui->actionPage_forward->setEnabled(false);
    }

    if(!album.previousSibling().isNull())
    {
        ui->actionMove_backward->setEnabled(true);
        ui->actionPage_backward->setEnabled(true);
    }
    ui->statusBar->showMessage("Moved photo forward one in album");
}
Ejemplo n.º 6
0
void QgsSingleBandGrayRenderer::toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const
{
  QgsStringMap newProps = props;

  // create base structure
  QgsRasterRenderer::toSld( doc, element, props );

  // look for RasterSymbolizer tag
  QDomNodeList elements = element.elementsByTagName( QStringLiteral( "sld:RasterSymbolizer" ) );
  if ( elements.size() == 0 )
    return;

  // there SHOULD be only one
  QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();

  // add Channel Selection tags
  // Need to insert channelSelection in the correct sequence as in SLD standard e.g.
  // after opacity or geometry or as first element after sld:RasterSymbolizer
  QDomElement channelSelectionElem = doc.createElement( QStringLiteral( "sld:ChannelSelection" ) );
  elements = rasterSymbolizerElem.elementsByTagName( QStringLiteral( "sld:Opacity" ) );
  if ( elements.size() != 0 )
  {
    rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at( 0 ) );
  }
  else
  {
    elements = rasterSymbolizerElem.elementsByTagName( QStringLiteral( "sld:Geometry" ) );
    if ( elements.size() != 0 )
    {
      rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at( 0 ) );
    }
    else
    {
      rasterSymbolizerElem.insertBefore( channelSelectionElem, rasterSymbolizerElem.firstChild() );
    }
  }

  // for gray band
  QDomElement channelElem = doc.createElement( QStringLiteral( "sld:GrayChannel" ) );
  channelSelectionElem.appendChild( channelElem );

  // set band
  QDomElement sourceChannelNameElem = doc.createElement( QStringLiteral( "sld:SourceChannelName" ) );
  sourceChannelNameElem.appendChild( doc.createTextNode( QString::number( grayBand() ) ) );
  channelElem.appendChild( sourceChannelNameElem );

  // set ContrastEnhancement
  if ( contrastEnhancement() )
  {
    QDomElement contrastEnhancementElem = doc.createElement( QStringLiteral( "sld:ContrastEnhancement" ) );
    contrastEnhancement()->toSld( doc, contrastEnhancementElem );

    // do changes to minValue/maxValues depending on stretching algorithm. This is necessary because
    // geoserver do a first stretch on min/max, then apply colo map rules. In some combination is necessary
    // to use real min/max values and in othere the actual edited min/max values
    switch ( contrastEnhancement()->contrastEnhancementAlgorithm() )
    {
      case QgsContrastEnhancement::StretchAndClipToMinimumMaximum:
      case QgsContrastEnhancement::ClipToMinimumMaximum:
      {
        // with this renderer export have to be check against real min/max values of the raster
        QgsRasterBandStats myRasterBandStats = mInput->bandStatistics( grayBand(), QgsRasterBandStats::Min | QgsRasterBandStats::Max );

        // if minimum range differ from the real minimum => set is in exported SLD vendor option
        if ( !qgsDoubleNear( contrastEnhancement()->minimumValue(), myRasterBandStats.minimumValue ) )
        {
          // look for VendorOption tag to look for that with minValue attribute
          QDomNodeList elements = contrastEnhancementElem.elementsByTagName( QStringLiteral( "sld:VendorOption" ) );
          for ( int i = 0; i < elements.size(); ++i )
          {
            QDomElement vendorOption = elements.at( i ).toElement();
            if ( vendorOption.attribute( QStringLiteral( "name" ) ) != QStringLiteral( "minValue" ) )
              continue;

            // remove old value and add the new one
            vendorOption.removeChild( vendorOption.firstChild() );
            vendorOption.appendChild( doc.createTextNode( QString::number( myRasterBandStats.minimumValue ) ) );
          }
        }
        break;
      }
      case QgsContrastEnhancement::UserDefinedEnhancement:
        break;
      case QgsContrastEnhancement::NoEnhancement:
        break;
      case QgsContrastEnhancement::StretchToMinimumMaximum:
        break;
    }

    channelElem.appendChild( contrastEnhancementElem );
  }

  // for each color set a ColorMapEntry tag nested into "sld:ColorMap" tag
  // e.g. <ColorMapEntry color="#EEBE2F" quantity="-300" label="label" opacity="0"/>
  QList< QPair< QString, QColor > > classes;
  legendSymbologyItems( classes );

  // add ColorMap tag
  QDomElement colorMapElem = doc.createElement( QStringLiteral( "sld:ColorMap" ) );
  rasterSymbolizerElem.appendChild( colorMapElem );

  // TODO: add clip intervals basing on real min/max without trigger
  // min/max calculation again that can takes a lot for remote or big images
  //
  // contrast enhancement against a color map can be SLD simulated playing with ColorMapEntryies
  // each ContrastEnhancementAlgorithm need a specific management.
  // set type of ColorMap ramp [ramp, intervals, values]
  // basing on interpolation algorithm of the raster shader
  QList< QPair< QString, QColor > > colorMapping( classes );
  switch ( contrastEnhancement()->contrastEnhancementAlgorithm() )
  {
    case ( QgsContrastEnhancement::StretchAndClipToMinimumMaximum ):
    case ( QgsContrastEnhancement::ClipToMinimumMaximum ):
    {
      QString lowValue = classes[0].first;
      QColor lowColor = classes[0].second;
      lowColor.setAlpha( 0 );
      QString highValue = classes[1].first;
      QColor highColor = classes[1].second;
      highColor.setAlpha( 0 );

      colorMapping.prepend( QPair< QString, QColor >( lowValue, lowColor ) );
      colorMapping.append( QPair< QString, QColor >( highValue, highColor ) );
      break;
    }
    case ( QgsContrastEnhancement::StretchToMinimumMaximum ):
    {
      colorMapping[0].first = QStringLiteral( "0" );
      colorMapping[1].first = QStringLiteral( "255" );
      break;
    }
    case ( QgsContrastEnhancement::UserDefinedEnhancement ):
      break;
    case ( QgsContrastEnhancement::NoEnhancement ):
      break;
  }

  // create tags
  QList< QPair< QString, QColor > >::ConstIterator it;
  for ( it = colorMapping.begin(); it != colorMapping.constEnd() ; ++it )
  {
    // set low level color mapping
    QDomElement lowColorMapEntryElem = doc.createElement( QStringLiteral( "sld:ColorMapEntry" ) );
    colorMapElem.appendChild( lowColorMapEntryElem );
    lowColorMapEntryElem.setAttribute( QStringLiteral( "color" ), it->second.name() );
    lowColorMapEntryElem.setAttribute( QStringLiteral( "quantity" ), it->first );
    if ( it->second.alphaF() == 0.0 )
    {
      lowColorMapEntryElem.setAttribute( QStringLiteral( "opacity" ), QString::number( it->second.alpha() ) );
    }
  }
}
Ejemplo n.º 7
0
void StatusDialog::savePreset(const QString &preset_caption)
{
  QFile presets_file(m_preset_file);

  if ( presets_file.exists() )
  {
    if (presets_file.open(QIODevice::ReadOnly) )
    {
      QDomDocument doc;
      if ( doc.setContent(&presets_file) )
      {
        QDomElement rootElement = doc.documentElement();
        QDomElement preset_element = doc.createElement("preset");
        QDomElement caption_element = doc.createElement("caption");
        QDomText caption_text = doc.createTextNode(preset_caption);
        caption_element.appendChild(caption_text);
        QDomElement message_element = doc.createElement("message");
        QDomText message_text = doc.createTextNode(ui.statusTextEdit->toPlainText());
        message_element.appendChild(message_text);
        preset_element.appendChild(caption_element);
        preset_element.appendChild(message_element);
        rootElement.insertAfter(preset_element, rootElement.lastChild());

        presets_file.close();
        if ( presets_file.open(QIODevice::WriteOnly) )
        {
          QTextStream preset_stream(&presets_file);
          preset_stream.setCodec("UTF-8");
          preset_stream<<doc.toString();
          presets_file.close();
        }
      }
    }
  }
  else
  {
    if ( presets_file.open(QIODevice::WriteOnly) )
    {
      QDomDocument doc("stauspresets");
      QDomProcessingInstruction process = doc.createProcessingInstruction(
                                            "xml", "version=\"1.0\" encoding=\"utf-8\"");
      doc.appendChild(process);
      QDomElement rootElement = doc.createElement("stauspresets");
      doc.appendChild(rootElement);

      QDomElement preset_element = doc.createElement("preset");
      QDomElement caption_element = doc.createElement("caption");
      QDomText caption_text = doc.createTextNode(preset_caption);
      caption_element.appendChild(caption_text);
      QDomElement message_element = doc.createElement("message");
      QDomText message_text = doc.createTextNode(ui.statusTextEdit->toPlainText());
      message_element.appendChild(message_text);

      preset_element.appendChild(caption_element);
      preset_element.appendChild(message_element);
      rootElement.appendChild(preset_element);
      doc.appendChild(rootElement);

      QTextStream presets_stream(&presets_file);
      presets_stream.setCodec("UTF-8");
      presets_stream<<doc.toString();
      presets_file.close();
    }
  }
  ui.presetComboBox->addItem(preset_caption,ui.statusTextEdit->toPlainText());

}
Ejemplo n.º 8
0
void writeJob::dragModuleName(const QString name, const int index, const int allRow, const QString upOrDown)
{
    qDebug()<<"4.dragModuleName";
    QDomElement root = doc.documentElement();
    QDomElement modEle = root.firstChildElement("Module");
    if(index==0)  //插到头
    {
        while (!modEle.isNull())
        {
            if(modEle.attribute("name")==name && modEle.attribute("id")==moduleID)
            {
                QDomElement firstModEle=root.firstChildElement("Module");
                root.insertBefore(modEle,firstModEle);
                break;
            }
            modEle = modEle.nextSiblingElement("Module");
        }
    }
    else if(index==(allRow-1))  // 插到尾
    {
        while (!modEle.isNull())
        {
            if(modEle.attribute("name")==name && modEle.attribute("id")==moduleID)
            {
                QDomElement lastModEle=root.lastChildElement("Module");
                root.insertAfter(modEle,lastModEle);
                break;
            }
            modEle = modEle.nextSiblingElement("Module");
        }
    }

    else   //其他情况
    {
        QDomElement insertAfterEle;
        QDomElement rightEle;

        insertAfterEle=modEle;
        //难道还要分上到下,下到上??
        if(upOrDown=="up")
        {
            for(int i=0; i<index-1;i++)
            {
                modEle = modEle.nextSiblingElement("Module");
                insertAfterEle=modEle;
                qDebug()<<i<<insertAfterEle.attribute("name");
            }
        }
        if(upOrDown=="down")
        {
            for(int i=0; i<index;i++)
            {
                modEle = modEle.nextSiblingElement("Module");
                insertAfterEle=modEle;
                qDebug()<<i<<insertAfterEle.attribute("name");
            }
        }
        modEle=root.firstChildElement("Module");
        while (!modEle.isNull())
        {
            if(modEle.attribute("name")==name && modEle.attribute("id")==moduleID)
            {
                rightEle=modEle;
                qDebug()<<rightEle.attribute("name")<<insertAfterEle.attribute("name");
                root.insertAfter(rightEle,insertAfterEle);
                break;
            }
            modEle = modEle.nextSiblingElement("Module");
        }
    }

    if(!write())
        qDebug()<<"delete job failed";
}
Ejemplo n.º 9
0
void saveScene(QWidget *parent, SceneContext *ctx, const QString &targetFile) {
	QDomElement root = ctx->doc.documentElement();

	// ====================================================================
	//   Serialize the sensor configuration
	// ====================================================================

	QList<QDomElement> oldSensors = findAllChildren(root, "sensor");

	const ref_vector<Sensor> sensors = ctx->scene->getSensors();
	ref_vector<Sensor>::const_iterator it = std::find(sensors.begin(),
			sensors.end(), ctx->scene->getSensor());
	if (it == sensors.end())
		SLog(EError, "Number of sensors did not match between loaded scene and XML file!");

	QDomElement sensor, oldSensor;

	if (oldSensors.size() == 0)
		; // ok -- scene did not contain a sensor before
	else if ((size_t) oldSensors.size() != ctx->scene->getSensors().size())
		SLog(EError, "Number of sensors did not match between loaded scene and XML file!");
	else
		oldSensor = oldSensors[it-sensors.begin()];

	if (oldSensor.isNull()) {
		sensor = ctx->doc.createElement("sensor");
		root.insertAfter(sensor, QDomNode());
	} else {
		sensor = ctx->doc.createElement("sensor");
		root.insertAfter(sensor, oldSensor);
		root.removeChild(oldSensor);
	}

	setProperties(ctx->doc, sensor, ctx->scene->getSensor()->getProperties());

	// ====================================================================
	//   Serialize the sampler configuration
	// ====================================================================

	QDomElement sampler = ctx->doc.createElement("sampler");
	sensor.appendChild(sampler);

	setProperties(ctx->doc, sampler,
		ctx->scene->getSampler()->getProperties());

	// ====================================================================
	//   Serialize the film configuration
	// ====================================================================

	QDomElement film = ctx->doc.createElement("film");
	sensor.appendChild(film);

	Properties filmProps(ctx->scene->getFilm()->getProperties());
	if (filmProps.getPluginName() == "ldrfilm") {
		/* Also export the tonemapper settings */
		if (ctx->toneMappingMethod == EGamma) {
			filmProps.setString("tonemapMethod", "gamma", false);
			filmProps.setFloat("exposure", ctx->exposure, false);
			filmProps.removeProperty("key");
			filmProps.removeProperty("burn");
		} else {
			filmProps.setString("tonemapMethod", "reinhard", false);
			filmProps.setFloat("key", ctx->reinhardKey, false);
			filmProps.setFloat("burn", (ctx->reinhardBurn + 10) / 20.0f, false);
			filmProps.removeProperty("exposure");
		}
		filmProps.setFloat("gamma", ctx->srgb ? -1 : ctx->gamma, false);
	}

	setProperties(ctx->doc, film, filmProps);

	// ====================================================================
	//   Serialize the reconstruction filter configuration
	// ====================================================================

	QDomElement rfilter = ctx->doc.createElement("rfilter");
	film.appendChild(rfilter);

	setProperties(ctx->doc, rfilter,
		ctx->scene->getFilm()->getReconstructionFilter()->getProperties());

	// ====================================================================
	//   Serialize medium references of the sensor
	// ====================================================================

	QList<QDomElement> oldSensorReferences = findAllChildren(oldSensor, "ref");
	oldSensorReferences.append(findAllChildren(oldSensor, "medium"));

	for (int i=0; i<oldSensorReferences.size(); ++i)
		sensor.appendChild(ctx->doc.importNode(oldSensorReferences[i], true));

	// ====================================================================
	//   Serialize the integrator configuration
	// ====================================================================

	QDomElement oldIntegratorNode = findUniqueChild(root, "integrator");
	QDomElement newIntegratorNode = ctx->doc.createElement("integrator");

	const Integrator *integrator = ctx->scene->getIntegrator();
	setProperties(ctx->doc, newIntegratorNode, integrator->getProperties());
	processSubIntegrators(ctx->doc, integrator, newIntegratorNode);

	root.insertBefore(newIntegratorNode, oldIntegratorNode);
	root.removeChild(oldIntegratorNode);

	QFile file;
	file.setFileName(targetFile);
	if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
		QMessageBox::critical(parent, parent->tr("Unable to save"),
			parent->tr("Unable to save changes: could not open the destination file <b>%1</b>.").arg(targetFile),
			QMessageBox::Ok);
		return;
	}

	/* Clean up the XML output generated by Qt so that it
	   is more suitable for human consumption ..
	   Beware: the code below is tailored to Qt's
	   output and won't work on arbitrary XML files */
	QString textContent = ctx->doc.toString();
	QTextStream input(&textContent);
	QTextStream output(&file);
	cleanupXML(input, output);
	file.close();
}