void QgsLayoutItemGroup::updateBoundingRect( QgsLayoutItem *item ) { //update extent if ( mBoundingRectangle.isEmpty() ) //we add the first item { mBoundingRectangle = QRectF( 0, 0, item->rect().width(), item->rect().height() ); setSceneRect( QRectF( item->pos().x(), item->pos().y(), item->rect().width(), item->rect().height() ) ); if ( !qgsDoubleNear( item->rotation(), 0.0 ) ) { setItemRotation( item->rotation() ); } } else { if ( !qgsDoubleNear( item->rotation(), rotation() ) ) { //items have mixed rotation, so reset rotation of group mBoundingRectangle = mapRectToScene( mBoundingRectangle ); setItemRotation( 0 ); mBoundingRectangle = mBoundingRectangle.united( item->mapRectToScene( item->rect() ) ); setSceneRect( mBoundingRectangle ); } else { //items have same rotation, so keep rotation of group mBoundingRectangle = mBoundingRectangle.united( mapRectFromItem( item, item->rect() ) ); QPointF newPos = mapToScene( mBoundingRectangle.topLeft().x(), mBoundingRectangle.topLeft().y() ); mBoundingRectangle = QRectF( 0, 0, mBoundingRectangle.width(), mBoundingRectangle.height() ); setSceneRect( QRectF( newPos.x(), newPos.y(), mBoundingRectangle.width(), mBoundingRectangle.height() ) ); } } }
bool QgsComposerNodesItem::readXML( const QDomElement& itemElem, const QDomDocument& doc ) { // restore general composer item properties const QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" ); if ( !composerItemList.isEmpty() ) { QDomElement composerItemElem = composerItemList.at( 0 ).toElement(); if ( !qgsDoubleNear( composerItemElem.attribute( "rotation", "0" ).toDouble(), 0.0 ) ) setItemRotation( composerItemElem.attribute( "rotation", "0" ).toDouble() ); _readXML( composerItemElem, doc ); } // restore style QDomElement styleSymbolElem = itemElem.firstChildElement( "symbol" ); if ( !styleSymbolElem.isNull() ) _readXMLStyle( styleSymbolElem ); // restore nodes mPolygon.clear(); QDomNodeList nodesList = itemElem.elementsByTagName( "node" ); for ( int i = 0; i < nodesList.size(); i++ ) { QDomElement nodeElem = nodesList.at( i ).toElement(); QPointF newPt; newPt.setX( nodeElem.attribute( "x" ).toDouble() ); newPt.setY( nodeElem.attribute( "y" ).toDouble() ); mPolygon.append( newPt ); } emit itemChanged(); return true; }
bool QgsComposerShape::readXML( const QDomElement& itemElem, const QDomDocument& doc ) { mShape = QgsComposerShape::Shape( itemElem.attribute( "shapeType", "0" ).toInt() ); mCornerRadius = itemElem.attribute( "cornerRadius", "0" ).toDouble(); //restore general composer item properties QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" ); if ( composerItemList.size() > 0 ) { QDomElement composerItemElem = composerItemList.at( 0 ).toElement(); //rotation if ( composerItemElem.attribute( "rotation", "0" ).toDouble() != 0 ) { //check for old (pre 2.1) rotation attribute setItemRotation( composerItemElem.attribute( "rotation", "0" ).toDouble() ); } _readXML( composerItemElem, doc ); } QDomElement shapeStyleSymbolElem = itemElem.firstChildElement( "symbol" ); if ( !shapeStyleSymbolElem.isNull() ) { delete mShapeStyleSymbol; mShapeStyleSymbol = dynamic_cast<QgsFillSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( shapeStyleSymbolElem ) ); } else { //upgrade project file from 2.0 to use symbolV2 styling delete mShapeStyleSymbol; QgsStringMap properties; properties.insert( "color", QgsSymbolLayerV2Utils::encodeColor( brush().color() ) ); if ( hasBackground() ) { properties.insert( "style", "solid" ); } else { properties.insert( "style", "no" ); } if ( hasFrame() ) { properties.insert( "style_border", "solid" ); } else { properties.insert( "style_border", "no" ); } properties.insert( "color_border", QgsSymbolLayerV2Utils::encodeColor( pen().color() ) ); properties.insert( "width_border", QString::number( pen().widthF() ) ); mShapeStyleSymbol = QgsFillSymbolV2::createSimple( properties ); } emit itemChanged(); return true; }
bool QgsComposerItem::_readXml( const QDomElement &itemElem, const QDomDocument &doc ) { Q_UNUSED( doc ); if ( itemElem.isNull() ) { return false; } QgsComposerObject::readXml( itemElem, doc ); //rotation setItemRotation( itemElem.attribute( QStringLiteral( "itemRotation" ), QStringLiteral( "0" ) ).toDouble() ); //uuid mUuid = itemElem.attribute( QStringLiteral( "uuid" ), QUuid::createUuid().toString() ); // temporary for groups imported from templates mTemplateUuid = itemElem.attribute( QStringLiteral( "templateUuid" ) ); //id QString id = itemElem.attribute( QStringLiteral( "id" ), QLatin1String( "" ) ); setId( id ); //frame QString frame = itemElem.attribute( QStringLiteral( "frame" ) ); if ( frame.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 ) { mFrame = true; } else { mFrame = false; } //frame QString background = itemElem.attribute( QStringLiteral( "background" ) ); if ( background.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 ) { mBackground = true; } else { mBackground = false; } //position lock for mouse moves/resizes QString positionLock = itemElem.attribute( QStringLiteral( "positionLock" ) ); if ( positionLock.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 ) { setPositionLock( true ); } else { setPositionLock( false ); } //visibility setVisibility( itemElem.attribute( QStringLiteral( "visibility" ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) ); //position int page; double x, y, pagex, pagey, width, height; bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOK; x = itemElem.attribute( QStringLiteral( "x" ) ).toDouble( &xOk ); y = itemElem.attribute( QStringLiteral( "y" ) ).toDouble( &yOk ); page = itemElem.attribute( QStringLiteral( "page" ) ).toInt( &pageOk ); pagex = itemElem.attribute( QStringLiteral( "pagex" ) ).toDouble( &pagexOk ); pagey = itemElem.attribute( QStringLiteral( "pagey" ) ).toDouble( &pageyOk ); width = itemElem.attribute( QStringLiteral( "width" ) ).toDouble( &widthOk ); height = itemElem.attribute( QStringLiteral( "height" ) ).toDouble( &heightOk ); mLastUsedPositionMode = static_cast< ItemPositionMode >( itemElem.attribute( QStringLiteral( "positionMode" ) ).toInt( &positionModeOK ) ); if ( !positionModeOK ) { mLastUsedPositionMode = UpperLeft; } if ( pageOk && pagexOk && pageyOk ) { xOk = true; yOk = true; x = pagex; y = ( page - 1 ) * ( mComposition->paperHeight() + composition()->spaceBetweenPages() ) + pagey; } if ( !xOk || !yOk || !widthOk || !heightOk ) { return false; } mLastValidViewScaleFactor = itemElem.attribute( QStringLiteral( "lastValidViewScaleFactor" ), QStringLiteral( "-1" ) ).toDouble(); setZValue( itemElem.attribute( QStringLiteral( "zValue" ) ).toDouble() ); QgsExpressionContext context = createExpressionContext(); //pen QDomNodeList frameColorList = itemElem.elementsByTagName( QStringLiteral( "FrameColor" ) ); if ( !frameColorList.isEmpty() ) { QDomElement frameColorElem = frameColorList.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk, widthOk; int penRed, penGreen, penBlue, penAlpha; double penWidth; penWidth = itemElem.attribute( QStringLiteral( "outlineWidth" ) ).toDouble( &widthOk ); penRed = frameColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk ); penGreen = frameColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk ); penBlue = frameColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk ); penAlpha = frameColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk ); mFrameJoinStyle = QgsSymbolLayerUtils::decodePenJoinStyle( itemElem.attribute( QStringLiteral( "frameJoinStyle" ), QStringLiteral( "miter" ) ) ); if ( redOk && greenOk && blueOk && alphaOk && widthOk ) { mFrameColor = QColor( penRed, penGreen, penBlue, penAlpha ); mFrameWidth = penWidth; QPen framePen( mFrameColor ); framePen.setWidthF( mFrameWidth ); framePen.setJoinStyle( mFrameJoinStyle ); setPen( framePen ); //apply any data defined settings refreshFrameColor( false, context ); } } //brush QDomNodeList bgColorList = itemElem.elementsByTagName( QStringLiteral( "BackgroundColor" ) ); if ( !bgColorList.isEmpty() ) { QDomElement bgColorElem = bgColorList.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk; int bgRed, bgGreen, bgBlue, bgAlpha; bgRed = bgColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk ); bgGreen = bgColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk ); bgBlue = bgColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk ); bgAlpha = bgColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk ); if ( redOk && greenOk && blueOk && alphaOk ) { mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha ); setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) ); } //apply any data defined settings refreshBackgroundColor( false, context ); } //blend mode setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( itemElem.attribute( QStringLiteral( "blendMode" ), QStringLiteral( "0" ) ).toUInt() ) ) ); //opacity if ( itemElem.hasAttribute( QStringLiteral( "opacity" ) ) ) { setItemOpacity( itemElem.attribute( QStringLiteral( "opacity" ), QStringLiteral( "1" ) ).toDouble() ); } else { setItemOpacity( 1.0 - itemElem.attribute( QStringLiteral( "transparency" ), QStringLiteral( "0" ) ).toInt() / 100.0 ); } mExcludeFromExports = itemElem.attribute( QStringLiteral( "excludeFromExports" ), QStringLiteral( "0" ) ).toInt(); mEvaluatedExcludeFromExports = mExcludeFromExports; QRectF evaluatedRect = evalItemRect( QRectF( x, y, width, height ) ); setSceneRect( evaluatedRect ); return true; }
bool QgsComposerShape::readXml( const QDomElement& itemElem, const QDomDocument& doc ) { mShape = QgsComposerShape::Shape( itemElem.attribute( "shapeType", "0" ).toInt() ); mCornerRadius = itemElem.attribute( "cornerRadius", "0" ).toDouble(); //restore general composer item properties QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" ); if ( !composerItemList.isEmpty() ) { QDomElement composerItemElem = composerItemList.at( 0 ).toElement(); //rotation if ( !qgsDoubleNear( composerItemElem.attribute( "rotation", "0" ).toDouble(), 0.0 ) ) { //check for old (pre 2.1) rotation attribute setItemRotation( composerItemElem.attribute( "rotation", "0" ).toDouble() ); } _readXml( composerItemElem, doc ); } QDomElement shapeStyleSymbolElem = itemElem.firstChildElement( "symbol" ); if ( !shapeStyleSymbolElem.isNull() ) { delete mShapeStyleSymbol; mShapeStyleSymbol = QgsSymbolLayerUtils::loadSymbol<QgsFillSymbolV2>( shapeStyleSymbolElem ); } else { //upgrade project file from 2.0 to use symbolV2 styling delete mShapeStyleSymbol; QgsStringMap properties; properties.insert( "color", QgsSymbolLayerUtils::encodeColor( brush().color() ) ); if ( hasBackground() ) { properties.insert( "style", "solid" ); } else { properties.insert( "style", "no" ); } if ( hasFrame() ) { properties.insert( "style_border", "solid" ); } else { properties.insert( "style_border", "no" ); } properties.insert( "color_border", QgsSymbolLayerUtils::encodeColor( pen().color() ) ); properties.insert( "width_border", QString::number( pen().widthF() ) ); //for pre 2.0 projects, shape color and outline were specified in a different element... QDomNodeList outlineColorList = itemElem.elementsByTagName( "OutlineColor" ); if ( !outlineColorList.isEmpty() ) { QDomElement frameColorElem = outlineColorList.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 ) { properties.insert( "color_border", QgsSymbolLayerUtils::encodeColor( QColor( penRed, penGreen, penBlue, penAlpha ) ) ); properties.insert( "width_border", QString::number( penWidth ) ); } } QDomNodeList fillColorList = itemElem.elementsByTagName( "FillColor" ); if ( !fillColorList.isEmpty() ) { QDomElement fillColorElem = fillColorList.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk; int fillRed, fillGreen, fillBlue, fillAlpha; fillRed = fillColorElem.attribute( "red" ).toDouble( &redOk ); fillGreen = fillColorElem.attribute( "green" ).toDouble( &greenOk ); fillBlue = fillColorElem.attribute( "blue" ).toDouble( &blueOk ); fillAlpha = fillColorElem.attribute( "alpha" ).toDouble( &alphaOk ); if ( redOk && greenOk && blueOk && alphaOk ) { properties.insert( "color", QgsSymbolLayerUtils::encodeColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) ) ); properties.insert( "style", "solid" ); } } if ( itemElem.hasAttribute( "transparentFill" ) ) { //old style (pre 2.0) of specifying that shapes had no fill bool hasOldTransparentFill = itemElem.attribute( "transparentFill", "0" ).toInt(); if ( hasOldTransparentFill ) { properties.insert( "style", "no" ); } } mShapeStyleSymbol = QgsFillSymbolV2::createSimple( properties ); } emit itemChanged(); return true; }
void QgsComposerItem::setRotation( double r ) { //kept for api compatibility with QGIS 2.0 //remove after 2.0 series setItemRotation( r, true ); }
bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument& doc ) { Q_UNUSED( doc ); if ( itemElem.isNull() ) { return false; } //rotation setItemRotation( itemElem.attribute( "itemRotation", "0" ).toDouble() ); //uuid mUuid = itemElem.attribute( "uuid", QUuid::createUuid().toString() ); // temporary for groups imported from templates mTemplateUuid = itemElem.attribute( "templateUuid" ); //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 ) { setPositionLock( true ); } else { setPositionLock( false ); } //position int page; double x, y, pagex, pagey, width, height; bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOK; x = itemElem.attribute( "x" ).toDouble( &xOk ); y = itemElem.attribute( "y" ).toDouble( &yOk ); page = itemElem.attribute( "page" ).toInt( &pageOk ); pagex = itemElem.attribute( "pagex" ).toDouble( &pagexOk ); pagey = itemElem.attribute( "pagey" ).toDouble( &pageyOk ); width = itemElem.attribute( "width" ).toDouble( &widthOk ); height = itemElem.attribute( "height" ).toDouble( &heightOk ); mLastUsedPositionMode = ( ItemPositionMode )itemElem.attribute( "positionMode" ).toInt( &positionModeOK ); if ( !positionModeOK ) { mLastUsedPositionMode = UpperLeft; } if ( pageOk && pagexOk && pageyOk ) { xOk = true; yOk = true; x = pagex; y = ( page - 1 ) * ( mComposition->paperHeight() + composition()->spaceBetweenPages() ) + pagey; } 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 ); mFrameJoinStyle = QgsSymbolLayerV2Utils::decodePenJoinStyle( itemElem.attribute( "frameJoinStyle", "miter" ) ); if ( redOk && greenOk && blueOk && alphaOk && widthOk ) { QPen framePen( QColor( penRed, penGreen, penBlue, penAlpha ) ); framePen.setWidthF( penWidth ); framePen.setJoinStyle( mFrameJoinStyle ); setPen( framePen ); } } //brush QDomNodeList bgColorList = itemElem.elementsByTagName( "BackgroundColor" ); if ( bgColorList.size() > 0 ) { QDomElement bgColorElem = bgColorList.at( 0 ).toElement(); bool redOk, greenOk, blueOk, alphaOk; int bgRed, bgGreen, bgBlue, bgAlpha; bgRed = bgColorElem.attribute( "red" ).toDouble( &redOk ); bgGreen = bgColorElem.attribute( "green" ).toDouble( &greenOk ); bgBlue = bgColorElem.attribute( "blue" ).toDouble( &blueOk ); bgAlpha = bgColorElem.attribute( "alpha" ).toDouble( &alphaOk ); if ( redOk && greenOk && blueOk && alphaOk ) { QColor brushColor( bgRed, bgGreen, bgBlue, bgAlpha ); setBackgroundColor( brushColor ); } } //blend mode setBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) itemElem.attribute( "blendMode", "0" ).toUInt() ) ); //transparency setTransparency( itemElem.attribute( "transparency" , "0" ).toInt() ); return true; }
bool QgsComposerLabel::readXml( const QDomElement &itemElem, const QDomDocument &doc ) { if ( itemElem.isNull() ) { return false; } //restore label specific properties //text mText = itemElem.attribute( QStringLiteral( "labelText" ) ); //html state mHtmlState = itemElem.attribute( QStringLiteral( "htmlState" ) ).toInt(); //margin bool marginXOk = false; bool marginYOk = false; mMarginX = itemElem.attribute( QStringLiteral( "marginX" ) ).toDouble( &marginXOk ); mMarginY = itemElem.attribute( QStringLiteral( "marginY" ) ).toDouble( &marginYOk ); if ( !marginXOk || !marginYOk ) { //upgrade old projects where margins where stored in a single attribute double margin = itemElem.attribute( QStringLiteral( "margin" ), QStringLiteral( "1.0" ) ).toDouble(); mMarginX = margin; mMarginY = margin; } //Horizontal alignment mHAlignment = static_cast< Qt::AlignmentFlag >( itemElem.attribute( QStringLiteral( "halign" ) ).toInt() ); //Vertical alignment mVAlignment = static_cast< Qt::AlignmentFlag >( itemElem.attribute( QStringLiteral( "valign" ) ).toInt() ); //font QgsFontUtils::setFromXmlChildNode( mFont, itemElem, QStringLiteral( "LabelFont" ) ); //font color QDomNodeList fontColorList = itemElem.elementsByTagName( QStringLiteral( "FontColor" ) ); if ( !fontColorList.isEmpty() ) { QDomElement fontColorElem = fontColorList.at( 0 ).toElement(); int red = fontColorElem.attribute( QStringLiteral( "red" ), QStringLiteral( "0" ) ).toInt(); int green = fontColorElem.attribute( QStringLiteral( "green" ), QStringLiteral( "0" ) ).toInt(); int blue = fontColorElem.attribute( QStringLiteral( "blue" ), QStringLiteral( "0" ) ).toInt(); mFontColor = QColor( red, green, blue ); } else { mFontColor = QColor( 0, 0, 0 ); } //restore general composer item properties QDomNodeList composerItemList = itemElem.elementsByTagName( QStringLiteral( "ComposerItem" ) ); if ( !composerItemList.isEmpty() ) { QDomElement composerItemElem = composerItemList.at( 0 ).toElement(); //rotation if ( !qgsDoubleNear( composerItemElem.attribute( QStringLiteral( "rotation" ), QStringLiteral( "0" ) ).toDouble(), 0.0 ) ) { //check for old (pre 2.1) rotation attribute setItemRotation( composerItemElem.attribute( QStringLiteral( "rotation" ), QStringLiteral( "0" ) ).toDouble() ); } _readXml( composerItemElem, doc ); } emit itemChanged(); return true; }