40 #include <QDomDocument>
41 #include <QDomElement>
42 #include <QGraphicsRectItem>
51 , mMapRenderer( mapRenderer )
55 , mSpaceBetweenPages( 10 )
56 , mPrintAsRaster( false )
57 , mUseAdvancedEffects( true )
58 , mSelectionTolerance( 0.0 )
59 , mSnapToGrid( false )
60 , mSnapGridResolution( 10.0 )
61 , mSnapGridOffsetX( 0.0 )
62 , mSnapGridOffsetY( 0.0 )
63 , mAlignmentSnap( true )
64 , mAlignmentSnapTolerance( 2 )
65 , mActiveItemCommand( 0 )
66 , mActiveMultiFrameCommand( 0 )
67 , mAtlasComposition( this )
69 setBackgroundBrush( Qt::gray );
77 : QGraphicsScene( 0 ),
82 mSpaceBetweenPages( 10 ),
83 mPrintAsRaster( false ),
84 mUseAdvancedEffects( true ),
85 mSelectionTolerance( 0.0 ),
87 mSnapGridResolution( 10.0 ),
88 mSnapGridOffsetX( 0.0 ),
89 mSnapGridOffsetY( 0.0 ),
90 mAlignmentSnap( true ),
91 mAlignmentSnapTolerance( 2 ),
92 mActiveItemCommand( 0 ),
93 mActiveMultiFrameCommand( 0 ),
94 mAtlasComposition( this )
118 for (
int i = 0; i <
mPages.size(); ++i )
120 mPages.at( i )->setSceneRect( QRectF( 0, currentY, width, height ) );
138 int diff = pages - currentPages;
141 for (
int i = 0; i < diff; ++i )
149 for (
int i = 0; i < diff; ++i )
169 QList<QGraphicsItem*> itemList;
172 itemList = items( position );
177 Qt::IntersectsItemShape, Qt::DescendingOrder );
179 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
181 for ( ; itemIt != itemList.end(); ++itemIt )
185 if ( composerItem && !paperItem )
200 return pageNumberAt( QPointF( item->transform().dx(), item->transform().dy() ) );
205 QList<QgsComposerItem*> composerItemList;
207 QList<QGraphicsItem *> graphicsItemList = selectedItems();
208 QList<QGraphicsItem *>::iterator itemIter = graphicsItemList.begin();
210 for ( ; itemIter != graphicsItemList.end(); ++itemIter )
215 composerItemList.push_back( composerItem );
219 return composerItemList;
224 QList<const QgsComposerMap*> resultList;
226 QList<QGraphicsItem *> itemList = items();
227 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
228 for ( ; itemIt != itemList.end(); ++itemIt )
233 resultList.push_back( composerMap );
242 QList<QGraphicsItem *> itemList = items();
243 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
244 for ( ; itemIt != itemList.end(); ++itemIt )
249 if ( composerMap->
id() == id )
279 QList<QGraphicsItem *> itemList = items();
280 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
281 for ( ; itemIt != itemList.end(); ++itemIt )
286 if ( mypItem->
id() == theId )
299 QSet<QgsComposer*> composers = QSet<QgsComposer*>();
301 if ( inAllComposers )
303 composers = QgisApp::instance()->printComposers();
307 composers.insert(
this )
310 QSet<QgsComposer*>::const_iterator it = composers.constBegin();
311 for ( ; it != composers.constEnd(); ++it )
313 QList<QGraphicsItem *> itemList = ( *it )->items();
314 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
315 for ( ; itemIt != itemList.end(); ++itemIt )
320 if ( mypItem->
uuid() == theUuid )
334 QList<QGraphicsItem *> itemList = items();
335 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
336 for ( ; itemIt != itemList.end(); ++itemIt )
341 if ( mypItem->
uuid() == theUuid )
357 QList<QGraphicsItem*> itemList = items();
358 QList<QGraphicsItem*>::const_iterator itemIt = itemList.constBegin();
359 for ( ; itemIt != itemList.constEnd(); ++itemIt )
372 double sizeMillimeters = pointSize * 0.3527;
373 return qRound( sizeMillimeters );
378 double sizePoint = pixelSize / 0.3527;
384 if ( composerElem.isNull() )
389 QDomElement compositionElem = doc.createElement(
"Composition" );
390 compositionElem.setAttribute(
"paperWidth", QString::number(
mPageWidth ) );
391 compositionElem.setAttribute(
"paperHeight", QString::number(
mPageHeight ) );
392 compositionElem.setAttribute(
"numPages",
mPages.size() );
397 compositionElem.setAttribute(
"snapping",
"1" );
401 compositionElem.setAttribute(
"snapping",
"0" );
403 compositionElem.setAttribute(
"snapGridResolution", QString::number(
mSnapGridResolution ) );
404 compositionElem.setAttribute(
"snapGridOffsetX", QString::number(
mSnapGridOffsetX ) );
405 compositionElem.setAttribute(
"snapGridOffsetY", QString::number(
mSnapGridOffsetY ) );
408 QList< QGraphicsLineItem* >::const_iterator snapLineIt =
mSnapLines.constBegin();
409 for ( ; snapLineIt !=
mSnapLines.constEnd(); ++snapLineIt )
411 QDomElement snapLineElem = doc.createElement(
"SnapLine" );
412 QLineF line = ( *snapLineIt )->line();
413 snapLineElem.setAttribute(
"x1", QString::number( line.x1() ) );
414 snapLineElem.setAttribute(
"y1", QString::number( line.y1() ) );
415 snapLineElem.setAttribute(
"x2", QString::number( line.x2() ) );
416 snapLineElem.setAttribute(
"y2", QString::number( line.y2() ) );
417 compositionElem.appendChild( snapLineElem );
423 compositionElem.setAttribute(
"alignmentSnap",
mAlignmentSnap ? 1 : 0 );
427 QList<QGraphicsItem*> itemList = items();
428 QList<QGraphicsItem*>::const_iterator itemIt = itemList.constBegin();
429 for ( ; itemIt != itemList.constEnd(); ++itemIt )
436 composerItem->
writeXML( compositionElem, doc );
442 QSet<QgsComposerMultiFrame*>::const_iterator multiFrameIt =
mMultiFrames.constBegin();
443 for ( ; multiFrameIt !=
mMultiFrames.constEnd(); ++multiFrameIt )
445 ( *multiFrameIt )->writeXML( compositionElem, doc );
447 composerElem.appendChild( compositionElem );
455 if ( compositionElem.isNull() )
461 bool widthConversionOk, heightConversionOk;
462 mPageWidth = compositionElem.attribute(
"paperWidth" ).toDouble( &widthConversionOk );
463 mPageHeight = compositionElem.attribute(
"paperHeight" ).toDouble( &heightConversionOk );
465 int numPages = compositionElem.attribute(
"numPages",
"1" ).toInt();
467 if ( widthConversionOk && heightConversionOk )
470 for (
int i = 0; i <
numPages; ++i )
477 if ( compositionElem.attribute(
"snapping" ) ==
"0" )
486 mSnapGridOffsetX = compositionElem.attribute(
"snapGridOffsetX" ).toDouble();
487 mSnapGridOffsetY = compositionElem.attribute(
"snapGridOffsetY" ).toDouble();
490 QDomNodeList snapLineNodes = compositionElem.elementsByTagName(
"SnapLine" );
491 for (
int i = 0; i < snapLineNodes.size(); ++i )
493 QDomElement snapLineElem = snapLineNodes.at( i ).toElement();
495 double x1 = snapLineElem.attribute(
"x1" ).toDouble();
496 double y1 = snapLineElem.attribute(
"y1" ).toDouble();
497 double x2 = snapLineElem.attribute(
"x2" ).toDouble();
498 double y2 = snapLineElem.attribute(
"y2" ).toDouble();
499 snapItem->setLine( x1, y1, x2, y2 );
502 mAlignmentSnap = compositionElem.attribute(
"alignmentSnap",
"1" ).toInt() == 0 ?
false :
true;
505 mPrintAsRaster = compositionElem.attribute(
"printAsRaster" ).toInt();
506 mPrintResolution = compositionElem.attribute(
"printResolution",
"300" ).toInt();
518 QList<QGraphicsItem *> itemList = items();
519 QList<QGraphicsItem *>::iterator itemIter = itemList.begin();
520 for ( ; itemIter != itemList.end(); ++itemIter )
535 QDomDocument importDoc;
536 if ( substitutionMap )
538 QString xmlString = doc.toString();
539 QMap<QString, QString>::const_iterator sIt = substitutionMap->constBegin();
540 for ( ; sIt != substitutionMap->constEnd(); ++sIt )
542 xmlString = xmlString.replace(
"[" + sIt.key() +
"]",
encodeStringForXML( sIt.value() ) );
546 int errorLine, errorColumn;
547 if ( !importDoc.setContent( xmlString, &errorMsg, &errorLine, &errorColumn ) )
558 QDomElement compositionElem = importDoc.documentElement().firstChildElement(
"Composition" );
559 if ( compositionElem.isNull() )
564 bool ok =
readXML( compositionElem, importDoc );
571 QDomNodeList composerItemsNodes = importDoc.elementsByTagName(
"ComposerItem" );
572 for (
int i = 0; i < composerItemsNodes.count(); ++i )
574 QDomNode composerItemNode = composerItemsNodes.at( i );
575 if ( composerItemNode.isElement() )
577 composerItemNode.toElement().setAttribute(
"templateUuid", composerItemNode.toElement().attribute(
"uuid" ) );
578 composerItemNode.toElement().removeAttribute(
"uuid" );
583 addItemsFromXML( importDoc.documentElement(), importDoc, 0, addUndoCommands, 0 );
586 QDomElement atlasElem = importDoc.documentElement().firstChildElement(
"Atlas" );
592 bool addUndoCommands, QPointF* pos,
bool pasteInPlace )
594 QPointF* pasteInPlacePt = 0;
599 QDomNodeList composerLabelList = elem.elementsByTagName(
"ComposerLabel" );
600 for (
int i = 0; i < composerLabelList.size(); ++i )
602 QDomElement currentComposerLabelElem = composerLabelList.at( i ).toElement();
604 newLabel->
readXML( currentComposerLabelElem, doc );
607 if ( pasteInPlacePt )
610 newLabel->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
618 if ( addUndoCommands )
624 QDomNodeList composerMapList = elem.elementsByTagName(
"ComposerMap" );
625 for (
int i = 0; i < composerMapList.size(); ++i )
627 QDomElement currentComposerMapElem = composerMapList.at( i ).toElement();
629 newMap->
readXML( currentComposerMapElem, doc );
634 mapsToRestore->insert( newMap, (
int )( newMap->
previewMode() ) );
644 newMap->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
652 if ( addUndoCommands )
658 QDomNodeList composerArrowList = elem.elementsByTagName(
"ComposerArrow" );
659 for (
int i = 0; i < composerArrowList.size(); ++i )
661 QDomElement currentComposerArrowElem = composerArrowList.at( i ).toElement();
663 newArrow->
readXML( currentComposerArrowElem, doc );
669 newArrow->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
677 if ( addUndoCommands )
683 QDomNodeList composerScaleBarList = elem.elementsByTagName(
"ComposerScaleBar" );
684 for (
int i = 0; i < composerScaleBarList.size(); ++i )
686 QDomElement currentComposerScaleBarElem = composerScaleBarList.at( i ).toElement();
688 newScaleBar->
readXML( currentComposerScaleBarElem, doc );
694 newScaleBar->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
702 if ( addUndoCommands )
708 QDomNodeList composerShapeList = elem.elementsByTagName(
"ComposerShape" );
709 for (
int i = 0; i < composerShapeList.size(); ++i )
711 QDomElement currentComposerShapeElem = composerShapeList.at( i ).toElement();
713 newShape->
readXML( currentComposerShapeElem, doc );
719 newShape->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
727 if ( addUndoCommands )
733 QDomNodeList composerPictureList = elem.elementsByTagName(
"ComposerPicture" );
734 for (
int i = 0; i < composerPictureList.size(); ++i )
736 QDomElement currentComposerPictureElem = composerPictureList.at( i ).toElement();
738 newPicture->
readXML( currentComposerPictureElem, doc );
744 newPicture->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
752 if ( addUndoCommands )
758 QDomNodeList composerLegendList = elem.elementsByTagName(
"ComposerLegend" );
759 for (
int i = 0; i < composerLegendList.size(); ++i )
761 QDomElement currentComposerLegendElem = composerLegendList.at( i ).toElement();
763 newLegend->
readXML( currentComposerLegendElem, doc );
769 newLegend->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
777 if ( addUndoCommands )
783 QDomNodeList composerTableList = elem.elementsByTagName(
"ComposerAttributeTable" );
784 for (
int i = 0; i < composerTableList.size(); ++i )
786 QDomElement currentComposerTableElem = composerTableList.at( i ).toElement();
788 newTable->
readXML( currentComposerTableElem, doc );
794 newTable->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
802 if ( addUndoCommands )
808 QDomNodeList composerHtmlList = elem.elementsByTagName(
"ComposerHtml" );
809 for (
int i = 0; i < composerHtmlList.size(); ++i )
811 QDomElement currentHtmlElem = composerHtmlList.at( i ).toElement();
813 newHtml->
readXML( currentHtmlElem, doc );
820 QDomNodeList groupList = elem.elementsByTagName(
"ComposerItemGroup" );
821 for (
int i = 0; i < groupList.size(); ++i )
823 QDomElement groupElem = groupList.at( i ).toElement();
825 newGroup->
readXML( groupElem, doc );
852 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
853 for ( ; it != selectedItems.end(); ++it )
866 QMutableLinkedListIterator<QgsComposerItem*> it(
mItemZList );
867 if ( it.findNext( item ) )
881 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
882 for ( ; it != selectedItems.end(); ++it )
895 QMutableLinkedListIterator<QgsComposerItem*> it(
mItemZList );
896 if ( it.findNext( item ) )
899 if ( it.hasPrevious() )
911 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
913 for ( ; it != selectedItems.end(); ++it )
926 QMutableLinkedListIterator<QgsComposerItem*> it(
mItemZList );
927 if ( it.findNext( item ) )
937 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
938 for ( ; it != selectedItems.end(); ++it )
951 QMutableLinkedListIterator<QgsComposerItem*> it(
mItemZList );
952 if ( it.findNext( item ) )
962 if ( selectedItems.size() < 2 )
967 QRectF selectedItemBBox;
973 double minXCoordinate = selectedItemBBox.left();
976 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items left" ) );
977 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
978 for ( ; align_it != selectedItems.end(); ++align_it )
982 QTransform itemTransform = ( *align_it )->transform();
983 itemTransform.translate( minXCoordinate - itemTransform.dx(), 0 );
984 ( *align_it )->setTransform( itemTransform );
993 if ( selectedItems.size() < 2 )
998 QRectF selectedItemBBox;
1004 double averageXCoord = ( selectedItemBBox.left() + selectedItemBBox.right() ) / 2.0;
1007 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items horizontal center" ) );
1008 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1009 for ( ; align_it != selectedItems.end(); ++align_it )
1013 QTransform itemTransform = ( *align_it )->transform();
1014 itemTransform.translate( averageXCoord - itemTransform.dx() - ( *align_it )->rect().width() / 2.0, 0 );
1015 ( *align_it )->setTransform( itemTransform );
1024 if ( selectedItems.size() < 2 )
1029 QRectF selectedItemBBox;
1035 double maxXCoordinate = selectedItemBBox.right();
1038 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items right" ) );
1039 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1040 for ( ; align_it != selectedItems.end(); ++align_it )
1044 QTransform itemTransform = ( *align_it )->transform();
1045 itemTransform.translate( maxXCoordinate - itemTransform.dx() - ( *align_it )->rect().width(), 0 );
1046 ( *align_it )->setTransform( itemTransform );
1055 if ( selectedItems.size() < 2 )
1060 QRectF selectedItemBBox;
1066 double minYCoordinate = selectedItemBBox.top();
1068 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items top" ) );
1069 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1070 for ( ; align_it != selectedItems.end(); ++align_it )
1074 QTransform itemTransform = ( *align_it )->transform();
1075 itemTransform.translate( 0, minYCoordinate - itemTransform.dy() );
1076 ( *align_it )->setTransform( itemTransform );
1085 if ( selectedItems.size() < 2 )
1090 QRectF selectedItemBBox;
1096 double averageYCoord = ( selectedItemBBox.top() + selectedItemBBox.bottom() ) / 2.0;
1097 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items vertical center" ) );
1098 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1099 for ( ; align_it != selectedItems.end(); ++align_it )
1103 QTransform itemTransform = ( *align_it )->transform();
1104 itemTransform.translate( 0, averageYCoord - itemTransform.dy() - ( *align_it )->rect().height() / 2 );
1105 ( *align_it )->setTransform( itemTransform );
1114 if ( selectedItems.size() < 2 )
1119 QRectF selectedItemBBox;
1125 double maxYCoord = selectedItemBBox.bottom();
1126 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items bottom" ) );
1127 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1128 for ( ; align_it != selectedItems.end(); ++align_it )
1132 QTransform itemTransform = ( *align_it )->transform();
1133 itemTransform.translate( 0, maxYCoord - itemTransform.dy() - ( *align_it )->rect().height() );
1134 ( *align_it )->setTransform( itemTransform );
1143 QLinkedList<QgsComposerItem*>::iterator it =
mItemZList.begin();
1146 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Item z-order changed" ) );
1154 currentItem->setZValue( counter );
1169 QLinkedList<QgsComposerItem*>::const_iterator lIt =
mItemZList.constBegin();
1170 QLinkedList<QgsComposerItem*> sortedList;
1172 for ( ; lIt !=
mItemZList.constEnd(); ++lIt )
1174 QLinkedList<QgsComposerItem*>::iterator insertIt = sortedList.begin();
1175 for ( ; insertIt != sortedList.end(); ++insertIt )
1177 if (( *lIt )->zValue() < ( *insertIt )->zValue() )
1182 sortedList.insert( insertIt, ( *lIt ) );
1198 double yPage = scenePoint.y() - yOffset;
1214 double left = item->transform().dx() + dx;
1215 double right = left + item->rect().width();
1216 double midH = ( left + right ) / 2.0;
1217 double top = item->transform().dy() + dy;
1218 double bottom = top + item->rect().height();
1219 double midV = ( top + bottom ) / 2.0;
1221 QMap<double, const QgsComposerItem* > xAlignCoordinates;
1222 QMap<double, const QgsComposerItem* > yAlignCoordinates;
1226 double xItemLeft = left;
1227 double xAlignCoord = 0;
1228 double smallestDiffX = DBL_MAX;
1230 checkNearestItem( left, xAlignCoordinates, smallestDiffX, 0, xItemLeft, xAlignCoord );
1231 checkNearestItem( midH, xAlignCoordinates, smallestDiffX, ( left - right ) / 2.0, xItemLeft, xAlignCoord );
1232 checkNearestItem( right, xAlignCoordinates, smallestDiffX, left - right, xItemLeft, xAlignCoord );
1235 double yItemTop = top;
1236 double yAlignCoord = 0;
1237 double smallestDiffY = DBL_MAX;
1239 checkNearestItem( top, yAlignCoordinates, smallestDiffY, 0, yItemTop, yAlignCoord );
1240 checkNearestItem( midV, yAlignCoordinates, smallestDiffY, ( top - bottom ) / 2.0, yItemTop, yAlignCoord );
1241 checkNearestItem( bottom, yAlignCoordinates, smallestDiffY, top - bottom, yItemTop, yAlignCoord );
1243 double xCoord = ( smallestDiffX < 5 ) ? xItemLeft : item->transform().dx() + dx;
1244 alignX = ( smallestDiffX < 5 ) ? xAlignCoord : -1;
1245 double yCoord = ( smallestDiffY < 5 ) ? yItemTop : item->transform().dy() + dy;
1246 alignY = ( smallestDiffY < 5 ) ? yAlignCoord : -1;
1247 return QPointF( xCoord, yCoord );
1252 QMap<double, const QgsComposerItem* > xAlignCoordinates;
1253 QMap<double, const QgsComposerItem* > yAlignCoordinates;
1256 double nearestX = pos.x();
1257 double nearestY = pos.y();
1258 if ( !
nearestItem( xAlignCoordinates, pos.x(), nearestX )
1259 || !
nearestItem( yAlignCoordinates, pos.y(), nearestY ) )
1266 QPointF result( pos.x(), pos.y() );
1269 result.setX( nearestX );
1279 result.setY( nearestY );
1291 QGraphicsLineItem* item =
new QGraphicsLineItem();
1292 QPen linePen( Qt::SolidLine );
1293 linePen.setColor( Qt::red );
1296 linePen.setWidthF( 0 );
1297 item->setPen( linePen );
1298 item->setZValue( 100 );
1313 QList< QGraphicsLineItem* >::iterator it =
mSnapLines.begin();
1328 QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode> >& snappedItems )
1330 double minSqrDist = DBL_MAX;
1331 QGraphicsLineItem* item = 0;
1332 double currentXCoord = 0;
1333 double currentYCoord = 0;
1334 double currentSqrDist = 0;
1335 double sqrTolerance = tolerance * tolerance;
1337 snappedItems.clear();
1339 QList< QGraphicsLineItem* >::const_iterator it =
mSnapLines.constBegin();
1342 bool itemHorizontal =
qgsDoubleNear(( *it )->line().y2() - ( *it )->line().y1(), 0 );
1343 if ( horizontal && itemHorizontal )
1345 currentYCoord = ( *it )->line().y1();
1346 currentSqrDist = ( y - currentYCoord ) * ( y - currentYCoord );
1348 else if ( !itemHorizontal )
1350 currentXCoord = ( *it )->line().x1();
1351 currentSqrDist = ( x - currentXCoord ) * ( x - currentXCoord );
1354 if ( currentSqrDist < minSqrDist && currentSqrDist < sqrTolerance )
1357 minSqrDist = currentSqrDist;
1361 double itemTolerance = 0.0000001;
1365 QList<QGraphicsItem *> itemList = items();
1366 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
1367 for ( ; itemIt != itemList.end(); ++itemIt )
1377 if (
qgsDoubleNear( currentYCoord, currentItem->transform().dy() + currentItem->rect().top(), itemTolerance ) )
1381 else if (
qgsDoubleNear( currentYCoord, currentItem->transform().dy() + currentItem->rect().center().y(), itemTolerance ) )
1385 else if (
qgsDoubleNear( currentYCoord, currentItem->transform().dy() + currentItem->rect().bottom(), itemTolerance ) )
1392 if (
qgsDoubleNear( currentXCoord, currentItem->transform().dx(), itemTolerance ) )
1396 else if (
qgsDoubleNear( currentXCoord, currentItem->transform().dx() + currentItem->rect().center().x(), itemTolerance ) )
1400 else if (
qgsDoubleNear( currentXCoord, currentItem->transform().dx() + currentItem->rect().width(), itemTolerance ) )
1414 if ( selectedItems.size() < 1 )
1421 double minX = currentItem->transform().dx();
1422 double minY = currentItem->transform().dy();
1423 double maxX = minX + currentItem->rect().width();
1424 double maxY = minY + currentItem->rect().height();
1426 double currentMinX, currentMinY, currentMaxX, currentMaxY;
1428 for (
int i = 1; i < selectedItems.size(); ++i )
1430 currentItem = selectedItems.at( i );
1431 currentMinX = currentItem->transform().dx();
1432 currentMinY = currentItem->transform().dy();
1433 currentMaxX = currentMinX + currentItem->rect().width();
1434 currentMaxY = currentMinY + currentItem->rect().height();
1436 if ( currentMinX < minX )
1438 if ( currentMaxX > maxX )
1440 if ( currentMinY < minY )
1442 if ( currentMaxY > maxY )
1446 bRect.setTopLeft( QPointF( minX, minY ) );
1447 bRect.setBottomRight( QPointF( maxX, maxY ) );
1504 QString gridStyleString;
1505 int red, green, blue;
1508 gridStyleString = s.value(
"/qgis/composerGridStyle",
"Dots" ).toString();
1509 penWidth = s.value(
"/qgis/composerGridWidth", 0.5 ).toDouble();
1510 red = s.value(
"/qgis/composerGridRed", 0 ).toInt();
1511 green = s.value(
"/qgis/composerGridGreen", 0 ).toInt();
1512 blue = s.value(
"/qgis/composerGridBlue", 0 ).toInt();
1514 mGridPen.setColor( QColor( red, green, blue ) );
1517 if ( gridStyleString ==
"Dots" )
1521 else if ( gridStyleString ==
"Crosses" )
1537 s.setValue(
"/qgis/composerGridWidth",
mGridPen.widthF() );
1538 s.setValue(
"/qgis/composerGridRed",
mGridPen.color().red() );
1539 s.setValue(
"/qgis/composerGridGreen",
mGridPen.color().green() );
1540 s.setValue(
"/qgis/composerGridBlue",
mGridPen.color().blue() );
1544 s.setValue(
"/qgis/composerGridStyle",
"Solid" );
1548 s.setValue(
"/qgis/composerGridStyle",
"Dots" );
1552 s.setValue(
"/qgis/composerGridStyle",
"Crosses" );
1659 if ( setDefaultPreviewStyle )
1678 addItem( scaleBar );
1689 if ( mapItemList.size() > 0 )
1747 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Remove item group" ) );
1749 QSet<QgsComposerItem*> groupedItems = itemGroup->
items();
1750 QSet<QgsComposerItem*>::iterator it = groupedItems.begin();
1751 for ( ; it != groupedItems.end(); ++it )
1766 if ( createCommand )
1787 if ( frameItem && multiFrame )
1792 if ( createCommand )
1795 multiFrame,
this,
tr(
"Multiframe removed" ) );
1904 QList< QgsPaperItem* >::iterator paperIt =
mPages.begin();
1905 for ( ; paperIt !=
mPages.end(); ++paperIt )
1907 ( *paperIt )->update();
1917 paperItem->setBrush( Qt::white );
1918 addItem( paperItem );
1919 paperItem->setZValue( 0 );
1920 mPages.push_back( paperItem );
1927 for (
int i = 0; i <
mPages.size(); ++i )
1937 QSet<QgsComposerMultiFrame*>::iterator multiFrameIt =
mMultiFrames.begin();
1938 for ( ; multiFrameIt !=
mMultiFrames.end(); ++multiFrameIt )
1940 delete *multiFrameIt;
1947 printer.setOutputFormat( QPrinter::PdfFormat );
1948 printer.setOutputFileName( file );
1964 int fromPage = ( printer.fromPage() < 1 ) ? 0 : printer.fromPage() - 1 ;
1965 int toPage = ( printer.toPage() < 1 ) ?
numPages() - 1 : printer.toPage() - 1;
1969 for (
int i = fromPage; i <= toPage; ++i )
1977 if ( !image.isNull() )
1979 QRectF targetArea( 0, 0, image.width(), image.height() );
1980 p.drawImage( targetArea, image, targetArea );
1987 for (
int i = fromPage; i <= toPage; ++i )
2001 printer.setFullPage(
true );
2002 printer.setColorMode( QPrinter::Color );
2011 QPainter p( &printer );
2020 QImage image( QSize( width, height ), QImage::Format_ARGB32 );
2021 if ( !image.isNull() )
2026 QPainter imagePainter( &image );
2028 if ( !imagePainter.isActive() )
return QImage();
2035 if (
mPages.size() <= page )
2046 QPaintDevice* paintDevice = p->device();
2052 QRectF paperRect = QRectF( paperItem->transform().dx(), paperItem->transform().dy(), paperItem->rect().width(), paperItem->rect().height() );
2058 render( p, QRectF( 0, 0, paintDevice->width(), paintDevice->height() ), paperRect );
2066 QString modifiedStr( str );
2067 modifiedStr.replace(
"&",
"&" );
2068 modifiedStr.replace(
"\"",
""" );
2069 modifiedStr.replace(
"'",
"'" );
2070 modifiedStr.replace(
"<",
"<" );
2071 modifiedStr.replace(
">",
">" );
2078 alignCoordsX.clear();
2079 alignCoordsY.clear();
2081 QList<QGraphicsItem *> itemList = items();
2082 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
2083 for ( ; itemIt != itemList.end(); ++itemIt )
2088 if ( !currentItem || currentItem == excludeItem )
2092 alignCoordsX.insert( currentItem->transform().dx(), currentItem );
2093 alignCoordsX.insert( currentItem->transform().dx() + currentItem->rect().width(), currentItem );
2094 alignCoordsX.insert( currentItem->transform().dx() + currentItem->rect().center().x(), currentItem );
2095 alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().top(), currentItem );
2096 alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().center().y(), currentItem );
2097 alignCoordsY.insert( currentItem->transform().dy() + currentItem->rect().bottom(), currentItem );
2102 QList< QGraphicsLineItem* >::const_iterator sIt =
mSnapLines.constBegin();
2103 for ( ; sIt !=
mSnapLines.constEnd(); ++sIt )
2105 double x = ( *sIt )->line().x1();
2106 double y = ( *sIt )->line().y1();
2109 alignCoordsX.insert( x, 0 );
2113 alignCoordsY.insert( y, 0 );
2119 double itemCoordOffset,
double& itemCoord,
double& alignCoord )
const
2121 double currentCoord = 0;
2122 if ( !
nearestItem( alignCoords, checkCoord, currentCoord ) )
2127 double currentDiff = abs( checkCoord - currentCoord );
2130 itemCoord = currentCoord + itemCoordOffset;
2131 alignCoord = currentCoord;
2132 smallestDiff = currentDiff;
2138 if ( coords.size() < 1 )
2143 QMap< double, const QgsComposerItem* >::const_iterator it = coords.lowerBound( value );
2144 if ( it == coords.constBegin() )
2146 nearestValue = it.key();
2149 else if ( it == coords.constEnd() )
2152 nearestValue = it.key();
2158 double upperVal = it.key();
2160 double lowerVal = it.key();
2162 double lowerDiff = value - lowerVal;
2163 double upperDiff = upperVal - value;
2164 if ( lowerDiff < upperDiff )
2166 nearestValue = lowerVal;
2171 nearestValue = upperVal;
void lowerSelectedItems()
QgsComposition::PlotStyle mPlotStyle
Item representing the paper.
A scale bar item that can be added to a map composition.
QUndoStack * undoStack()
Returns pointer to undo/redo command storage.
double paperWidth() const
Returns width of paper item.
bool writeXML(QDomElement &composerElem, QDomDocument &doc)
Writes settings to xml (paper dimension)
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
const QgsComposerItem * getComposerItemById(QString theId) const
Returns a composer item given its text identifier.
void setEffectsEnabled(bool effectsEnabled)
Sets whether effects (eg blend modes) are enabled for the item.
double mAlignmentSnapTolerance
int boundingRectOfSelectedItems(QRectF &bRect)
Returns the bounding rectangle of the selected items in scene coordinates.
An item that draws an arrow between to points.
void addItemToZList(QgsComposerItem *item)
Adds item to z list.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
void composerArrowAdded(QgsComposerArrow *arrow)
Is emitted when new composer arrow has been added to the view.
void setSnapLinesVisible(bool visible)
Hides / shows custom snap lines.
void assignFreeId()
Sets mId to a number not yet used in the composition.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
virtual void beginItemCommand(const QString &text)
GridStyle
Style to draw the snapping grid.
void alignSelectedItemsTop()
void composerPictureAdded(QgsComposerPicture *picture)
Is emitted when a new composer picture has been added.
void setNumPages(int pages)
Note: added in version 1.9.
void cache()
Create cache image.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
QList< const QgsComposerMap * > composerMapItems() const
Returns pointers to all composer maps in the scene.
void addComposerScaleBar(QgsComposerScaleBar *scaleBar)
Adds scale bar to the graphics scene and advices composer to create a widget for it (through signal) ...
A item that forms part of a map composition.
void removeItemFromZList(QgsComposerItem *item)
Removes item from z list.
void setSnapGridOffsetY(double offset)
void updateZValues()
Reset z-values of items based on position in z list.
QPointF snapPointToGrid(const QPointF &scenePoint) const
Snaps a scene coordinate point to grid.
void removeComposerItem(QgsComposerItem *item, bool createCommand=true)
Remove item from the graphics scene.
A container for grouping several QgsComposerItems.
void sendItemAddedSignal(QgsComposerItem *item)
Casts object to the proper subclass type and calls corresponding itemAdded signal.
virtual void setSelected(bool s)
Set selected, selected item should be highlighted.
void setItemPosition(double x, double y, ItemPositionMode itemPoint=UpperLeft)
Moves the item to a new position (in canvas coordinates)
void savePreviousState()
Saves current item state as previous state.
QImage printPageAsRaster(int page)
print composer page to image If the image does not fit into memory, a null image is returned ...
A composer command that merges together with other commands having the same context (=id)...
bool mPrintAsRaster
Flag if map should be printed as a raster (via QImage).
void setCreateUndoCommands(bool enabled)
QGraphicsLineItem * nearestSnapLine(bool horizontal, double x, double y, double tolerance, QList< QPair< QgsComposerItem *, QgsComposerItem::ItemPositionMode > > &snappedItems)
Get nearest snap line.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
void beginPrintAsPDF(QPrinter &printer, const QString &file)
Prepare the printer for printing in a PDF.
QList< QgsPaperItem * > mPages
A non GUI class for rendering a map layer set onto a QPainter.
void composerScaleBarAdded(QgsComposerScaleBar *scalebar)
Is emitted when new composer scale bar has been added.
void moveSelectedItemsToBottom()
void alignSelectedItemsHCenter()
double spaceBetweenPages() const
void beginMultiFrameCommand(QgsComposerMultiFrame *multiFrame, const QString &text)
bool loadFromTemplate(const QDomDocument &doc, QMap< QString, QString > *substitutionMap=0, bool addUndoCommands=false)
Load a template document.
void composerMapAdded(QgsComposerMap *map)
Is emitted when new composer map has been added to the view.
int numPages() const
Note: added in version 1.9.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
void alignSelectedItemsVCenter()
A composer class that displays svg files or raster format (jpg, png, ...)
void readXML(const QDomElement &elem, const QDomDocument &doc)
void endMultiFrameCommand()
QSet< QgsComposerItem * > items()
void beginPrint(QPrinter &printer)
Prepare the printer for printing.
bool isDrawing() const
True if a draw is already in progress.
void composerLegendAdded(QgsComposerLegend *legend)
Is emitted when a new composer legend has been added.
virtual int type() const
return correct graphics item type.
QgsComposerItem * composerItemAt(const QPointF &position)
Returns the topmost composer item.
void addComposerShape(QgsComposerShape *shape)
Adds a composer shape to the graphics scene and advices composer to create a widget for it (through s...
void setGridPen(const QPen &p)
void lowerItem(QgsComposerItem *item)
void setSelectionTolerance(double tol)
QString uuid() const
Get item identification name.
void checkNearestItem(double checkCoord, const QMap< double, const QgsComposerItem * > &alignCoords, double &smallestDiff, double itemCoordOffset, double &itemCoord, double &alignCoord) const
int itemPageNumber(const QgsComposerItem *) const
Returns on which page number (0-based) is displayed an item.
void cancelCommand()
Deletes current command.
bool containsChange() const
Returns true if previous state and after state are valid and different.
int pageNumberAt(const QPointF &position) const
Returns the page number (0-bsaed) given a coordinate.
void endCommand()
Saves end state of item and pushes command to the undo history.
void itemRemoved(QgsComposerItem *)
Is emitted when a composer item has been removed from the scene.
int printResolution() const
void setSnapGridResolution(double r)
QSet< QgsComposerMultiFrame * > mMultiFrames
List multiframe objects.
void removeSnapLine(QGraphicsLineItem *line)
Remove custom snap line (and delete the object)
void alignSelectedItemsRight()
QLinkedList< QgsComposerItem * > mItemZList
Maintains z-Order of items.
Abstract base class for composer entries with the ability to distribute the content to several frames...
void setComposerMap(const QgsComposerMap *map)
QgsComposerItemCommand * mActiveItemCommand
void moveItemToTop(QgsComposerItem *item)
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
void moveSelectedItemsToTop()
int frameCount() const
Return the number of frames associated with this multiframeset.
int mPrintResolution
Dpi for printout.
void sortZList()
Sorts the zList.
Graphics scene for map printing.
void removeMultiFrame(QgsComposerMultiFrame *multiFrame)
Removes multi frame (but does not delete it)
Object representing map window.
Frame for html, table, text which can be divided onto several frames.
bool readXML(const QDomElement &compositionElem, const QDomDocument &doc)
Reads settings from xml file.
QPointF alignItem(const QgsComposerItem *item, double &alignX, double &alignY, double dx=0, double dy=0)
Snaps item position to align with other items (left / middle / right or top / middle / bottom...
void addItemsFromXML(const QDomElement &elem, const QDomDocument &doc, QMap< QgsComposerMap *, int > *mapsToRestore=0, bool addUndoCommands=false, QPointF *pos=0, bool pasteInPlace=false)
Add items from XML representation to the graphics scene (for project file reading, pasting items from clipboard)
void setSnapToGridEnabled(bool b)
int pixelFontSize(double pointSize) const
Returns the pixel font size for a font that has point size set.
PreviewMode previewMode() const
void saveAfterState()
Saves current item state as after state.
double mSpaceBetweenPages
static QString encodeStringForXML(const QString &str)
bool mSnapToGrid
Parameters for snap to grid function.
void raiseItem(QgsComposerItem *item)
void composerTableAdded(QgsComposerAttributeTable *table)
Is emitted when a new composer table has been added.
int id() const
Get identification number.
void composerShapeAdded(QgsComposerShape *shape)
Is emitted when a new composer shape has been added.
A composer command class for adding / removing composer items.
void print(QPrinter &printer)
Convenience function that prepares the printer and prints.
A table class that displays a vector attribute table.
bool mAlignmentSnap
Parameters for alignment snap.
Undo command to undo/redo all composer item related changes.
void connectAddRemoveCommandSignals(QgsAddRemoveItemCommand *c)
A composer items that draws common shapes (ellipse, triangle, rectangle)
virtual void endItemCommand()
void raiseSelectedItems()
void setSnapGridOffsetX(double offset)
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
void addComposerHtmlFrame(QgsComposerHtml *html, QgsComposerFrame *frame)
Adds composer html frame and advices composer to create a widget for it (through signal) ...
static QgsProject * instance()
access to canonical QgsProject instance
void alignSelectedItemsBottom()
static void fixEngineFlags(QPaintEngine *engine)
void alignSelectedItemsLeft()
QList< QGraphicsLineItem * > mSnapLines
Arbitraty snap lines (horizontal and vertical)
double paperHeight() const
Returns height of paper item.
QgsComposerMultiFrameCommand * mActiveMultiFrameCommand
void selectedItemChanged(QgsComposerItem *selected)
Is emitted when selected item changed.
void renderPage(QPainter *p, int page)
Render a page to a paint device.
void pushAddRemoveCommand(QgsComposerItem *item, const QString &text, QgsAddRemoveItemCommand::State state=QgsAddRemoveItemCommand::Added)
Convenience function to create a QgsAddRemoveItemCommand, connect its signals and push it to the undo...
A label that can be placed onto a map composition.
void setUseAdvancedEffects(bool effectsEnabled)
Used to enable or disable advanced effects such as blend modes in a composition.
void composerLabelAdded(QgsComposerLabel *label)
Is emitted when new composer label has been added to the view.
void addComposerPicture(QgsComposerPicture *picture)
Adds picture to the graphics scene and advices composer to create a widget for it (through signal) ...
QgsAtlasComposition & atlasComposition()
void composerHtmlFrameAdded(QgsComposerHtml *html, QgsComposerFrame *frame)
Is emitted when a new composer html has been added to the view.
void doPrint(QPrinter &printer, QPainter &painter)
Print on a preconfigured printer.
void addComposerTable(QgsComposerAttributeTable *table)
Adds a composer table to the graphics scene and advices composer to create a widget for it (through s...
const QgsComposerHtml * getComposerHtmlByItem(QgsComposerItem *item) const
QPointF alignPos(const QPointF &pos, const QgsComposerItem *excludeItem, double &alignX, double &alignY)
Snaps position to align with the boundaries of other items.
double mSelectionTolerance
Distance tolerance for item selection (in mm)
static void setSpecialColumn(const QString &name, QVariant value)
Assign a special column.
double pointFontSize(int pixelSize) const
Does the inverse calculation and returns points for pixels (equals to mm in QgsComposition) ...
QGraphicsLineItem * addSnapLine()
Add a custom snap line (can be horizontal or vertical)
void moveItemToBottom(QgsComposerItem *item)
void setPreviewMode(PreviewMode m)
QgsComposerMultiFrame * multiFrame() const
bool mUseAdvancedEffects
Flag if advanced visual effects such as blend modes should be used.
QList< QgsComposerItem * > selectedComposerItems()
void deleteAndRemoveMultiFrames()
const QgsComposerMap * getComposerMapById(int id) const
Returns the composer map with specified id.
void move(double dx, double dy)
Moves item in canvas coordinates.
double mSnapGridResolution
A legend that can be placed onto a map composition.
void addComposerLabel(QgsComposerLabel *label)
Adds label to the graphics scene and advices composer to create a widget for it (through signal) ...
void addMultiFrame(QgsComposerMultiFrame *multiFrame)
Adds multiframe.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
void setGridStyle(GridStyle s)
void exportAsPDF(const QString &file)
Convenience function that prepares the printer for printing in PDF and prints.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const =0
stores state in Dom element
void addComposerArrow(QgsComposerArrow *arrow)
Adds an arrow item to the graphics scene and advices composer to create a widget for it (through sign...
void addComposerMap(QgsComposerMap *map, bool setDefaultPreviewStyle=true)
Adds map to the graphics scene and advices composer to create a widget for it (through signal) ...
void collectAlignCoordinates(QMap< double, const QgsComposerItem * > &alignCoordsX, QMap< double, const QgsComposerItem * > &alignCoordsY, const QgsComposerItem *excludeItem)
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
void setPaperSize(double width, double height)
Changes size of paper item.
void addComposerLegend(QgsComposerLegend *legend)
Adds legend to the graphics scene and advices composer to create a widget for it (through signal) ...
bool containsChange() const
Returns true if previous state and after state are valid and different.
const QgsComposerItem * getComposerItemByUuid(QString theUuid) const
Returns a composer item given its unique identifier.
static bool nearestItem(const QMap< double, const QgsComposerItem * > &coords, double value, double &nearestValue)
Find nearest item in coordinate map to a double.
void beginCommand(QgsComposerItem *item, const QString &commandText, QgsComposerMergeCommand::Context c=QgsComposerMergeCommand::Unknown)
Allocates new item command and saves initial state in it.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false)
QString id() const
Get item's id (which is not necessarly unique)