Пример #1
0
QDomComment QDomDocumentProto::createComment(const QString& data)
{
    QDomDocument *item = qscriptvalue_cast<QDomDocument*>(thisObject());
    if (item)
        return item->createComment(data);
    return QDomComment();
}
Пример #2
0
bool XmlNotation::write(const std::vector<Moves> &mv)
{
    QDomDocument doc;

    auto proc = doc.createProcessingInstruction(
            u8"xml", u8"version=\"1.0\" encoding=\"utf-8\"");
    doc.appendChild(proc);

    auto cAuthors = doc.createComment(fromU8Str(impl::comment));
    doc.appendChild(cAuthors), doc.appendChild(doc.createTextNode("\n"));

    auto eRoot = doc.createElementNS(fromU8Str(impl::xmlns),
                                     fromU8Str(impl::eRoot));
    doc.appendChild(eRoot);

    for (auto &i : mv) {
        auto eTurn = doc.createElement(fromU8Str(impl::eTurn));
        eRoot.appendChild(eTurn);

        eTurn.setAttribute(fromU8Str(impl::aWhite),
            QString::fromStdString(i.white_move.to_string()));

        eTurn.setAttribute(fromU8Str(impl::aBlack),
            QString::fromStdString(i.black_move.to_string()));
    }

    QByteArray raw = doc.toByteArray(4);

    std::ofstream f(_pImpl->fileName,
                    std::ios_base::binary |
                    std::ios_base::trunc);
    f.write(raw.data(), raw.count());

    return true;
}
void QgsSVGFillSymbolLayer::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
{
  QDomElement symbolizerElem = doc.createElement( "se:PolygonSymbolizer" );
  if ( !props.value( "uom", "" ).isEmpty() )
    symbolizerElem.setAttribute( "uom", props.value( "uom", "" ) );
  element.appendChild( symbolizerElem );

  QgsSymbolLayerV2Utils::createGeometryElement( doc, symbolizerElem, props.value( "geom", "" ) );

  QDomElement fillElem = doc.createElement( "se:Fill" );
  symbolizerElem.appendChild( fillElem );

  QDomElement graphicFillElem = doc.createElement( "se:GraphicFill" );
  fillElem.appendChild( graphicFillElem );

  QDomElement graphicElem = doc.createElement( "se:Graphic" );
  graphicFillElem.appendChild( graphicElem );

  if ( !mSvgFilePath.isEmpty() )
  {
    QgsSymbolLayerV2Utils::externalGraphicToSld( doc, graphicElem, mSvgFilePath, "image/svg+xml", mSvgFillColor, mPatternWidth );
  }
  else
  {
    // TODO: create svg from data
    // <se:InlineContent>
    symbolizerElem.appendChild( doc.createComment( "SVG from data not implemented yet" ) );
  }

  if ( mSvgOutlineColor.isValid() || mSvgOutlineWidth >= 0 )
  {
    QgsSymbolLayerV2Utils::lineToSld( doc, graphicElem, Qt::SolidLine, mSvgOutlineColor, mSvgOutlineWidth );
  }

  // <Rotation>
  QString angleFunc;
  bool ok;
  double angle = props.value( "angle", "0" ).toDouble( &ok );
  if ( !ok )
  {
    angleFunc = QString( "%1 + %2" ).arg( props.value( "angle", "0" ) ).arg( mAngle );
  }
  else if ( angle + mAngle != 0 )
  {
    angleFunc = QString::number( angle + mAngle );
  }
  QgsSymbolLayerV2Utils::createRotationElement( doc, graphicElem, angleFunc );

  if ( mOutline )
  {
    // the outline sub symbol should be stored within the Stroke element,
    // but it will be stored in a separated LineSymbolizer because it could
    // have more than one layer
    mOutline->toSld( doc, element, props );
  }
}
Пример #4
0
void TOC::meinprocExited( int exitCode, QProcess::ExitStatus exitStatus)
{
    KProcess *meinproc = static_cast<KProcess *>(sender());
    KXmlGuiWindow *mainWindow = dynamic_cast<KXmlGuiWindow *>( kapp->activeWindow() );

    if ( exitStatus == QProcess::CrashExit || exitCode != 0 ) {
        kError() << "running" << meinproc->program() << "failed with exitCode" << exitCode;
        kError() << "stderr output:" << meinproc->readAllStandardError(); 
        if (mainWindow && !m_alreadyWarned) {
            ; // add warning message box with don't display again option 
              // http://api.kde.org/4.0-api/kdelibs-apidocs/kdeui/html/classKDialog.html
            m_alreadyWarned = true;
        }
        delete meinproc;
        return;
    }

    delete meinproc;

    // add a timestamp to the meinproc4 created xml file
    QFile f( m_cacheFile );
    if ( !f.open( QIODevice::ReadWrite ) )
        return;

    QDomDocument doc;
    if ( !doc.setContent( &f ) )
        return;

    QDomComment timestamp = doc.createComment( QString::number( sourceFileCTime() ) );
    doc.documentElement().appendChild( timestamp );

    // write back updated xml content 
    f.seek( 0 );
    QTextStream stream( &f );
    stream.setCodec( "UTF-8" );
#ifdef Q_WS_WIN
    /*
      the problem that on german systems umlauts are displayed as '?' for unknown (Qt'r related ?) reasons
      is caused by wrong encoding type conversations and has been fixed in kdelibs/kdoctools
      To have propper encoding tags in the xml file, QXmlDocument::save() is used. 
    */
    doc.save(stream, 1, QDomNode::EncodingFromTextStream);

#else
    stream << doc.toString();
#endif
    f.close();
    fillTree();
}
Пример #5
0
/**
 * @details
 * Imports and appends a file to the given \p parent XML node.
 * All element nodes under (but not including) the root node of the
 * file are copied to the \p document.
 *
 * If not an absolute path, the name of the file to import must be relative
 * to the executable.
 *
 * @param[in] document A reference to the XML document.
 * @param[in] parent   A reference to the parent XML node.
 * @param[in] name     Name of the file to import.
 */
void Config::importFile(QDomDocument& document,
        QDomNode& parent, const QString& name)
{
    // Return if name is empty.
    if (name.isEmpty()) return;

    // find the file
    QString filename = searchFile(name);

    // Write comment.
    parent.appendChild(document.createComment(
            "% Imported file " + filename) );

    // Import the file.
    QDomDocument newDoc = read(filename);

    // Loop over each child under the root node of the file, and append it.
    QDomNodeList list = newDoc.documentElement().childNodes();
    for (int j = 0; j < list.size(); j++) {
        parent.appendChild(list.at(j).cloneNode());
    }
}
Пример #6
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    // Prepare the XML file
    QFile file("list.xml");
    file.remove();
    QDomDocument xml;
    QDomNode declaration = xml.createProcessingInstruction("xml",QString("version=\"1.0\" encoding=\"UTF-8\""));
    xml.insertBefore(declaration,xml.firstChild());
    QDomComment comment = xml.createComment("Do not edit this file, it is regenerated automatically!");
    xml.appendChild(comment);
    QDomNode root = xml.createElement("files");
    xml.appendChild(root);

    // Liste tous les fichiers
    QStringList liste;
    QDirIterator it(".", QDir::Files, QDirIterator::Subdirectories);
    while (it.hasNext()) {
        if(QString(it.hasNext()).startsWith("./Assets/Modules/Custom_Civilizations_MCP/"))
        {}
        else{
            // Add the file to the list
            QDomElement entity = xml.createElement("file");
            entity.appendChild(xml.createTextNode(it.next()));
            entity.setAttribute("md5", checkMd5(it.next()));
            root.appendChild(entity);
        }
    }

    // Save the file
    file.open(QIODevice::Truncate | QIODevice::WriteOnly);
    QTextStream ts(&file);
    xml.save(ts, 4);
    file.close();

    return a.exec();
}
void QgsPointPatternFillSymbolLayer::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
{
  for ( int i = 0; i < mMarkerSymbol->symbolLayerCount(); i++ )
  {
    QDomElement symbolizerElem = doc.createElement( "se:PolygonSymbolizer" );
    if ( !props.value( "uom", "" ).isEmpty() )
      symbolizerElem.setAttribute( "uom", props.value( "uom", "" ) );
    element.appendChild( symbolizerElem );

    // <Geometry>
    QgsSymbolLayerV2Utils::createGeometryElement( doc, symbolizerElem, props.value( "geom", "" ) );

    QDomElement fillElem = doc.createElement( "se:Fill" );
    symbolizerElem.appendChild( fillElem );

    QDomElement graphicFillElem = doc.createElement( "se:GraphicFill" );
    fillElem.appendChild( graphicFillElem );

    // store distanceX, distanceY, displacementX, displacementY in a <VendorOption>
    QString dist =  QgsSymbolLayerV2Utils::encodePoint( QPointF( mDistanceX, mDistanceY ) );
    QDomElement distanceElem = QgsSymbolLayerV2Utils::createVendorOptionElement( doc, "distance", dist );
    symbolizerElem.appendChild( distanceElem );

    QgsSymbolLayerV2 *layer = mMarkerSymbol->symbolLayer( i );
    QgsMarkerSymbolLayerV2 *markerLayer = static_cast<QgsMarkerSymbolLayerV2 *>( layer );
    if ( !markerLayer )
    {
      QString errorMsg = QString( "MarkerSymbolLayerV2 expected, %1 found. Skip it." ).arg( layer->layerType() );
      graphicFillElem.appendChild( doc.createComment( errorMsg ) );
    }
    else
    {
      markerLayer->writeSldMarker( doc, graphicFillElem, props );
    }
  }
}
Пример #8
0
void QgsMarkerLineSymbolLayerV2::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
{
  for ( int i = 0; i < mMarker->symbolLayerCount(); i++ )
  {
    QDomElement symbolizerElem = doc.createElement( "se:LineSymbolizer" );
    if ( !props.value( "uom", "" ).isEmpty() )
      symbolizerElem.setAttribute( "uom", props.value( "uom", "" ) );
    element.appendChild( symbolizerElem );

    // <Geometry>
    QgsSymbolLayerV2Utils::createGeometryElement( doc, symbolizerElem, props.value( "geom", "" ) );

    QString gap;
    switch ( mPlacement )
    {
      case FirstVertex:
        symbolizerElem.appendChild( QgsSymbolLayerV2Utils::createVendorOptionElement( doc, "placement", "firstPoint" ) );
        break;
      case LastVertex:
        symbolizerElem.appendChild( QgsSymbolLayerV2Utils::createVendorOptionElement( doc, "placement", "lastPoint" ) );
        break;
      case CentralPoint:
        symbolizerElem.appendChild( QgsSymbolLayerV2Utils::createVendorOptionElement( doc, "placement", "centralPoint" ) );
        break;
      case Vertex:
        // no way to get line/polygon's vertices, use a VendorOption
        symbolizerElem.appendChild( QgsSymbolLayerV2Utils::createVendorOptionElement( doc, "placement", "points" ) );
        break;
      default:
        gap = QString::number( mInterval );
        break;
    }

    if ( !mRotateMarker )
    {
      // markers in LineSymbolizer must be drawn following the line orientation,
      // use a VendorOption when no marker rotation
      symbolizerElem.appendChild( QgsSymbolLayerV2Utils::createVendorOptionElement( doc, "rotateMarker", "0" ) );
    }

    // <Stroke>
    QDomElement strokeElem = doc.createElement( "se:Stroke" );
    symbolizerElem.appendChild( strokeElem );

    // <GraphicStroke>
    QDomElement graphicStrokeElem = doc.createElement( "se:GraphicStroke" );
    strokeElem.appendChild( graphicStrokeElem );

    QgsSymbolLayerV2 *layer = mMarker->symbolLayer( i );
    QgsMarkerSymbolLayerV2 *markerLayer = static_cast<QgsMarkerSymbolLayerV2 *>( layer );
    if ( !markerLayer )
    {
      graphicStrokeElem.appendChild( doc.createComment( QString( "MarkerSymbolLayerV2 expected, %1 found. Skip it." ).arg( markerLayer->layerType() ) ) );
    }
    else
    {
      markerLayer->writeSldMarker( doc, graphicStrokeElem, props );
    }

    if ( !gap.isEmpty() )
    {
      QDomElement gapElem = doc.createElement( "se:Gap" );
      QgsSymbolLayerV2Utils::createFunctionElement( doc, gapElem, gap );
      graphicStrokeElem.appendChild( gapElem );
    }

    if ( !qgsDoubleNear( mOffset, 0.0 ) )
    {
      QDomElement perpOffsetElem = doc.createElement( "se:PerpendicularOffset" );
      perpOffsetElem.appendChild( doc.createTextNode( QString::number( mOffset ) ) );
      symbolizerElem.appendChild( perpOffsetElem );
    }
  }
}
void QgsAbstractVectorLayerLabeling::writeTextSymbolizer( QDomNode &parent, QgsPalLayerSettings &settings, const QgsStringMap &props ) const
{
  QDomDocument doc = parent.ownerDocument();

  // text symbolizer
  QDomElement textSymbolizerElement = doc.createElement( QStringLiteral( "se:TextSymbolizer" ) );
  parent.appendChild( textSymbolizerElement );

  // label
  QgsTextFormat format = settings.format();
  QFont font = format.font();
  QDomElement labelElement = doc.createElement( QStringLiteral( "se:Label" ) );
  textSymbolizerElement.appendChild( labelElement );
  if ( settings.isExpression )
  {
    labelElement.appendChild( doc.createComment( QStringLiteral( "SE Export for %1 not implemented yet" ).arg( settings.getLabelExpression()->dump() ) ) );
    labelElement.appendChild( doc.createTextNode( "Placeholder" ) );
  }
  else
  {
    if ( font.capitalization() == QFont::AllUppercase )
    {
      appendSimpleFunction( doc, labelElement, QStringLiteral( "strToUpperCase" ), settings.fieldName );
    }
    else if ( font.capitalization() == QFont::AllLowercase )
    {
      appendSimpleFunction( doc, labelElement, QStringLiteral( "strToLowerCase" ), settings.fieldName );
    }
    else if ( font.capitalization() == QFont::Capitalize )
    {
      appendSimpleFunction( doc, labelElement, QStringLiteral( "strCapitalize" ), settings.fieldName );
    }
    else
    {
      QDomElement propertyNameElement = doc.createElement( QStringLiteral( "ogc:PropertyName" ) );
      propertyNameElement.appendChild( doc.createTextNode( settings.fieldName ) );
      labelElement.appendChild( propertyNameElement );
    }
  }

  // font
  QDomElement fontElement = doc.createElement( QStringLiteral( "se:Font" ) );
  textSymbolizerElement.appendChild( fontElement );
  fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "font-family" ), font.family() ) );
  double fontSize = QgsSymbolLayerUtils::rescaleUom( format.size(), format.sizeUnit(), props );
  fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "font-size" ), QString::number( fontSize ) ) );
  if ( format.font().italic() )
  {
    fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "font-style" ), QStringLiteral( "italic" ) ) );
  }
  if ( format.font().bold() )
  {
    fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "font-weight" ), QStringLiteral( "bold" ) ) );
  }

  // label placement
  QDomElement labelPlacement = doc.createElement( QStringLiteral( "se:LabelPlacement" ) );
  textSymbolizerElement.appendChild( labelPlacement );
  double maxDisplacement = 0;
  double repeatDistance = 0;
  switch ( settings.placement )
  {
    case QgsPalLayerSettings::OverPoint:
    {
      QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
      labelPlacement.appendChild( pointPlacement );
      // anchor point
      QPointF anchor = quadOffsetToSldAnchor( settings.quadOffset );
      QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, anchor );
      // displacement
      if ( settings.xOffset > 0 || settings.yOffset > 0 )
      {
        QgsUnitTypes::RenderUnit offsetUnit =  settings.offsetUnits;
        double dx = QgsSymbolLayerUtils::rescaleUom( settings.xOffset, offsetUnit, props );
        double dy = QgsSymbolLayerUtils::rescaleUom( settings.yOffset, offsetUnit, props );
        QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( dx, dy ) );
      }
      // rotation
      if ( settings.angleOffset != 0 )
      {
        QDomElement rotation = doc.createElement( "se:Rotation" );
        pointPlacement.appendChild( rotation );
        rotation.appendChild( doc.createTextNode( QString::number( settings.angleOffset ) ) );
      }
    }
    break;
    case QgsPalLayerSettings::AroundPoint:
    case QgsPalLayerSettings::OrderedPositionsAroundPoint:
    {
      QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
      labelPlacement.appendChild( pointPlacement );

      // SLD cannot do either, but let's do a best effort setting the distance using
      // anchor point and displacement
      QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, QPointF( 0, 0.5 ) );
      QgsUnitTypes::RenderUnit distUnit = settings.distUnits;
      double radius = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
      double offset = std::sqrt( radius * radius / 2 ); // make it start top/right
      maxDisplacement = radius + 1; // lock the distance
      QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( offset, offset ) );
    }
    break;
    case QgsPalLayerSettings::Horizontal:
    case QgsPalLayerSettings::Free:
    {
      // still a point placement (for "free" it's a fallback, there is no SLD equivalent)
      QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
      labelPlacement.appendChild( pointPlacement );
      QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, QPointF( 0.5, 0.5 ) );
      QgsUnitTypes::RenderUnit distUnit = settings.distUnits;
      double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
      QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( 0, dist ) );
      break;
    }
    case QgsPalLayerSettings::Line:
    case QgsPalLayerSettings::Curved:
    case QgsPalLayerSettings::PerimeterCurved:
    {
      QDomElement linePlacement = doc.createElement( "se:LinePlacement" );
      labelPlacement.appendChild( linePlacement );

      // perpendicular distance if required
      if ( settings.dist > 0 )
      {
        QgsUnitTypes::RenderUnit distUnit = settings.distUnits;
        double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
        QDomElement perpendicular = doc.createElement( "se:PerpendicularOffset" );
        linePlacement.appendChild( perpendicular );
        perpendicular.appendChild( doc.createTextNode( qgsDoubleToString( dist, 2 ) ) );
      }

      // repeat distance if required
      if ( settings.repeatDistance > 0 )
      {
        QDomElement repeat = doc.createElement( "se:Repeat" );
        linePlacement.appendChild( repeat );
        repeat.appendChild( doc.createTextNode( QStringLiteral( "true" ) ) );
        QDomElement gap = doc.createElement( "se:Gap" );
        linePlacement.appendChild( gap );
        repeatDistance = QgsSymbolLayerUtils::rescaleUom( settings.repeatDistance, settings.repeatDistanceUnit, props );
        gap.appendChild( doc.createTextNode( qgsDoubleToString( repeatDistance, 2 ) ) );
      }

      // always generalized
      QDomElement generalize = doc.createElement( "se:GeneralizeLine" );
      linePlacement.appendChild( generalize );
      generalize.appendChild( doc.createTextNode( QStringLiteral( "true" ) ) );
    }
    break;
  }

  // halo
  QgsTextBufferSettings buffer = format.buffer();
  if ( buffer.enabled() )
  {
    QDomElement haloElement = doc.createElement( QStringLiteral( "se:Halo" ) );
    textSymbolizerElement.appendChild( haloElement );

    QDomElement radiusElement = doc.createElement( QStringLiteral( "se:Radius" ) );
    haloElement.appendChild( radiusElement );
    // the SLD uses a radius, which is actually half of the link thickness the buffer size specifies
    double radius = QgsSymbolLayerUtils::rescaleUom( buffer.size(), buffer.sizeUnit(), props ) / 2;
    radiusElement.appendChild( doc.createTextNode( qgsDoubleToString( radius ) ) );

    QDomElement fillElement = doc.createElement( QStringLiteral( "se:Fill" ) );
    haloElement.appendChild( fillElement );
    fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill" ), buffer.color().name() ) );
    if ( buffer.opacity() != 1 )
    {
      fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill-opacity" ), QString::number( buffer.opacity() ) ) );
    }
  }

  // fill
  QDomElement fillElement = doc.createElement( QStringLiteral( "se:Fill" ) );
  textSymbolizerElement.appendChild( fillElement );
  fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill" ), format.color().name() ) );
  if ( format.opacity() != 1 )
  {
    fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill-opacity" ), QString::number( format.opacity() ) ) );
  }

  // background graphic (not supported by SE 1.1, but supported by the GeoTools ecosystem as an extension)
  QgsTextBackgroundSettings background = format.background();
  if ( background.enabled() )
  {
    std::unique_ptr<QgsMarkerSymbolLayer> layer = backgroundToMarkerLayer( background );
    layer->writeSldMarker( doc, textSymbolizerElement, props );
  }

  // priority and zIndex, the default values are 0 and 5 in qgis (and between 0 and 10),
  // in the GeoTools ecosystem there is a single priority value set at 1000 by default
  if ( settings.priority != 5 || settings.zIndex > 0 )
  {
    QDomElement priorityElement = doc.createElement( QStringLiteral( "se:Priority" ) );
    textSymbolizerElement.appendChild( priorityElement );
    int priority = 500 + 1000 * settings.zIndex + ( settings.priority - 5 ) * 100;
    if ( settings.priority == 0 && settings.zIndex > 0 )
    {
      // small adjustment to make sure labels in z index n+1 are all above level n despite the priority value
      priority += 1;
    }
    priorityElement.appendChild( doc.createTextNode( QString::number( priority ) ) );
  }

  // vendor options for text appearance
  if ( font.underline() )
  {
    QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "underlineText" ), QStringLiteral( "true" ) );
    textSymbolizerElement.appendChild( vo );
  }
  if ( font.strikeOut() )
  {
    QDomElement vo =  QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "strikethroughText" ), QStringLiteral( "true" ) );
    textSymbolizerElement.appendChild( vo );
  }
  // vendor options for text positioning
  if ( maxDisplacement > 0 )
  {
    QDomElement vo =  QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "maxDisplacement" ), qgsDoubleToString( maxDisplacement, 2 ) );
    textSymbolizerElement.appendChild( vo );
  }
  if ( settings.placement == QgsPalLayerSettings::Curved || settings.placement == QgsPalLayerSettings::PerimeterCurved )
  {
    QDomElement vo =  QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "followLine" ), QStringLiteral( "true" ) );
    textSymbolizerElement.appendChild( vo );
    if ( settings.maxCurvedCharAngleIn > 0 || settings.maxCurvedCharAngleOut > 0 )
    {
      // SLD has no notion for this, the GeoTools ecosystem can only do a single angle
      double angle = std::min( std::fabs( settings.maxCurvedCharAngleIn ), std::fabs( settings.maxCurvedCharAngleOut ) );
      QDomElement vo =  QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "maxAngleDelta" ), qgsDoubleToString( angle ) );
      textSymbolizerElement.appendChild( vo );
    }
  }
  if ( repeatDistance > 0 )
  {
    QDomElement vo =  QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "repeat" ), qgsDoubleToString( repeatDistance, 2 ) );
    textSymbolizerElement.appendChild( vo );
  }
  // miscellaneous options
  if ( settings.displayAll )
  {
    QDomElement vo =  QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "conflictResolution" ), QStringLiteral( "false" ) );
    textSymbolizerElement.appendChild( vo );
  }
  if ( settings.upsidedownLabels == QgsPalLayerSettings::ShowAll )
  {
    QDomElement vo =  QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "forceLeftToRight" ), QStringLiteral( "false" ) );
    textSymbolizerElement.appendChild( vo );
  }
  if ( settings.mergeLines )
  {
    QDomElement vo =  QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "group" ), QStringLiteral( "yes" ) );
    textSymbolizerElement.appendChild( vo );
    if ( settings.labelPerPart )
    {
      QDomElement vo =  QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "labelAllGroup" ), QStringLiteral( "true" ) );
      textSymbolizerElement.appendChild( vo );
    }
  }
  // background symbol resize handling
  if ( background.enabled() )
  {
    // enable resizing if needed
    switch ( background.sizeType() )
    {
      case QgsTextBackgroundSettings::SizeBuffer:
      {
        QString resizeType;
        if ( background.type() == QgsTextBackgroundSettings::ShapeRectangle || background.type() == QgsTextBackgroundSettings::ShapeEllipse )
        {
          resizeType = QStringLiteral( "stretch" );
        }
        else
        {
          resizeType = QStringLiteral( "proportional" );
        }
        QDomElement voResize =  QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "graphic-resize" ), resizeType );
        textSymbolizerElement.appendChild( voResize );

        // now hadle margin
        QSizeF size = background.size();
        if ( size.width() > 0 || size.height() > 0 )
        {
          double x = QgsSymbolLayerUtils::rescaleUom( size.width(), background.sizeUnit(), props );
          double y = QgsSymbolLayerUtils::rescaleUom( size.height(), background.sizeUnit(), props );
          // in case of ellipse qgis pads the size generously to make sure the text is inside the ellipse
          // the following seems to do the trick and keep visual output similar
          if ( background.type() == QgsTextBackgroundSettings::ShapeEllipse )
          {
            x += fontSize / 2;
            y += fontSize;
          }
          QString resizeSpec = QString( "%1 %2" ).arg( qgsDoubleToString( x, 2 ), qgsDoubleToString( y, 2 ) );
          QDomElement voMargin =  QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "graphic-margin" ), resizeSpec );
          textSymbolizerElement.appendChild( voMargin );
        }
        break;
      }
      case QgsTextBackgroundSettings::SizeFixed:
      case QgsTextBackgroundSettings::SizePercent:
        // nothing to do here
        break;
    }
  }
}
Пример #10
0
void QgsVectorFieldSymbolLayer::toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const
{
  element.appendChild( doc.createComment( "VectorField not implemented yet..." ) );
  mLineSymbol->toSld( doc, element, props );
}
Пример #11
0
QDomDocument  M_PageSize::fopMeta()
{
    QDomDocument dom;
    ////QString FopColor::foName( const QColor e )
    FopColor hc = FopColor();   ////  hc.foName( const QColor e )
    QDomProcessingInstruction header = dom.createProcessingInstruction( "xml",QString("version=\"1.0\" encoding=\"utf-8\"" ));
	dom.appendChild( header );
	//////QDateTime timer1( QDateTime::currentDateTime() );  /* time root */
	QDomElement basexslforoot = dom.createElement("fo:root");
                basexslforoot.setAttribute ("xmlns:fo","http://www.w3.org/1999/XSL/Format");
                basexslforoot.setAttribute ("xmlns:svg","http://www.w3.org/2000/svg");
                basexslforoot.setAttribute ("xmlns:cms","http://www.pulitzer.ch/2007/CMSFormat");
                basexslforoot.setAttribute ("xmlns:fox","http://xmlgraphics.apache.org/fop/extensions");
    dom.appendChild( basexslforoot );
    
    const int blocks = 10;
    ////////////  fox:outline
    
    QDomElement layout = dom.createElement("fo:layout-master-set");
    layout.setAttribute ("writing-mode","lr-tb");
    layout.setAttribute ("master-name","scribe");
	basexslforoot.appendChild( layout );

	QDomElement pmaster = dom.createElement("fo:simple-page-master");
    pmaster.setAttribute ("master-name","scribe");
    pmaster.setAttribute ("page-width",metrics(pageBoundingRect().width()));
    pmaster.setAttribute ("page-height",metrics(pageBoundingRect().height()));
    layout.appendChild( pmaster );
    
    QDomElement rbody = dom.createElement("fo:region-body");
	rbody.setAttribute ("region-name","xsl-region-body");
    rbody.setAttribute ("background-color",hc.foName(body.bg));
    rbody.setAttribute ("margin-top",metrics(body.margin_top));
    rbody.setAttribute ("margin-bottom",metrics(body.margin_bottom));
    rbody.setAttribute ("margin-left",metrics(body.margin_left));
    rbody.setAttribute ("margin-right",metrics(body.margin_right));
      
    if ( body.rpen.widthF() > 0 ) {
        /* make border */
        ////rbody.setAttribute ("background-color",body.penString());
    }
    
    
	pmaster.appendChild( rbody );
    /* bookmark here ..........   */
    
    QDomElement bbtree = dom.createElement("fo:bookmark-tree");
    
    
    QDomElement root_bookmark = dom.createElement("fo:bookmark");
    bbtree.appendChild( root_bookmark);
    root_bookmark.setAttribute ("internal-destination","sec0");
    
    QDomElement tree_a = dom.createElement("fo:bookmark-title");
    tree_a .appendChild( dom.createTextNode ( "Internal dest.0" )  );
    root_bookmark.appendChild( tree_a );
    
       for (int i = 1; i < blocks; ++i) {
           
           QDomElement sub = dom.createElement("fo:bookmark");
           sub.setAttribute ("internal-destination",QString("sec%1").arg(i));
           
           QDomElement label= dom.createElement("fo:bookmark-title");
           label.appendChild( dom.createTextNode ( QString("Internal dest.%1" ).arg(i)  ));
           sub.appendChild( label );
           
           root_bookmark.appendChild( sub );
       }
    
    
    
    basexslforoot.appendChild( bbtree );
       
       

    
    QDomElement rbefore = dom.createElement("fo:region-before");
	rbefore.setAttribute ("region-name","xsl-region-before");
    rbefore.setAttribute ("background-color",hc.foName(area[0].bg));
    rbefore.setAttribute ("extent",metrics(body.margin_top));
    
    
	pmaster.appendChild( rbefore );
    
    
    /*
    
     pmaster.setAttribute ("margin-top",QString("%1pt").arg(body.margin_top));
    pmaster.setAttribute ("margin-bottom",QString("%1pt").arg(body.margin_bottom));
    pmaster.setAttribute ("margin-left",QString("%1pt").arg(body.margin_left));
    pmaster.setAttribute ("margin-right",QString("%1pt").arg(body.margin_right));
    
    */
    
    
    
    
    
    
    
    QDomElement rafter = dom.createElement("fo:region-after");
	rafter.setAttribute ("region-name","xsl-region-after");
    rafter.setAttribute ("background-color",hc.foName(area[1].bg));
    rafter.setAttribute ("extent",metrics(body.margin_bottom));
	pmaster.appendChild( rafter );
    
    
    QDomElement rstart = dom.createElement("fo:region-start");
	rstart.setAttribute ("region-name","xsl-region-start");
    rstart.setAttribute ("background-color",hc.foName(area[2].bg));
    rstart.setAttribute ("extent",metrics(body.margin_left));
	pmaster.appendChild( rstart );
    
    QDomElement rend = dom.createElement("fo:region-end");
	rend.setAttribute ("region-name","xsl-region-end");
    rend.setAttribute ("background-color",hc.foName(area[3].bg));
    rend.setAttribute ("extent",metrics(body.margin_right));
	pmaster.appendChild( rend );
    
    
  	QDomElement pageseq1 = dom.createElement("fo:page-sequence");
	pageseq1.setAttribute ("master-reference","scribe");
	basexslforoot.appendChild( pageseq1 );
    
    QDomElement txt_1 = dom.createElement("fo:static-content");
    txt_1.setAttribute ("flow-name","xsl-region-before");
    QDomElement a_txt_1 = dom.createElement("fo:block-container");
    txt_1.appendChild( a_txt_1 );
    QDomElement b_txt_1 = dom.createElement("fo:block");
    b_txt_1.setAttribute ("color",hc.foName(area[0].bg));
    b_txt_1.appendChild( dom.createTextNode ( "." )  );
    a_txt_1.appendChild( b_txt_1 );
    b_txt_1.appendChild( dom.createComment(QString("Header region / xsl-region-before ")) );
    pageseq1.appendChild( txt_1 );
    
    
    QDomElement txt_2 = dom.createElement("fo:static-content");
    txt_2.setAttribute ("flow-name","xsl-region-after");
    QDomElement a_txt_2 = dom.createElement("fo:block-container");
    txt_2.appendChild( a_txt_2 );
    QDomElement b_txt_2 = dom.createElement("fo:block");
    b_txt_2.setAttribute ("color",hc.foName(area[1].bg));
    b_txt_2.appendChild( dom.createTextNode ( "." )  );
    a_txt_2.appendChild( b_txt_2 );
    b_txt_2.appendChild( dom.createComment(QString("Footer region / xsl-region-after ")) );
    pageseq1.appendChild( txt_2 );
    
    
    QDomElement txt_3 = dom.createElement("fo:static-content");
    txt_3.setAttribute ("flow-name","xsl-region-start");
    QDomElement a_txt_3 = dom.createElement("fo:block-container");
    txt_3.appendChild( a_txt_3 );
    QDomElement b_txt_3 = dom.createElement("fo:block");
    b_txt_3.setAttribute ("color",hc.foName(area[2].bg));
    b_txt_3.appendChild( dom.createTextNode ( "." )  );
    a_txt_3.appendChild( b_txt_3 );
    b_txt_3.appendChild( dom.createComment(QString("Left  region / xsl-region-start ")) );
    pageseq1.appendChild( txt_3 );
    
    
    QDomElement txt_4 = dom.createElement("fo:static-content");
    txt_4.setAttribute ("flow-name","xsl-region-end");
    QDomElement a_txt_4 = dom.createElement("fo:block-container");
    txt_4.appendChild( a_txt_4 );
    QDomElement b_txt_4 = dom.createElement("fo:block");
    b_txt_4.setAttribute ("color",hc.foName(area[3].bg));
    b_txt_4.appendChild( dom.createTextNode ( "." )  );
    a_txt_4.appendChild( b_txt_4 );
    b_txt_4.appendChild( dom.createComment(QString("Right  region / xsl-region-end ")) );
    pageseq1.appendChild( txt_4 );
    
    
    
    
 
    
    
    
    QDomElement body = dom.createElement("fo:flow");
	body.setAttribute ("flow-name","xsl-region-body");
    body.appendChild( dom.createComment (QString("body blocks")) );
    
    
    QDomElement sample = dom.createElement("fo:block");
    sample.setAttribute ("break-after","page");
    sample.setAttribute ("id",QString("sec0"));
    sample.setAttribute ("margin-top","2cm");
    sample.appendChild( dom.createTextNode ( "Hello World! .........." )  );
    body.appendChild( sample );
       
       
          for (int i = 1; i < blocks; ++i) {
           
           QDomElement bloc = dom.createElement("fo:block");
           bloc.setAttribute ("margin-top","2cm");
           bloc.setAttribute ("id",QString("sec%1").arg(i));
           bloc.setAttribute ("break-after","page");
           bloc.appendChild( dom.createTextNode ( QString("Hello World nr.%1" ).arg(i)  ));
           body.appendChild( bloc );
       }
    
    
    
    
    
    pageseq1.appendChild( body );
    
    
   //////////// body.appendChild( dom.createComment (QString("body blocks")) );
    
    
    
    return dom;
}