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;