43 #include <QDomDocument>
44 #include <QDomElement>
45 #include <QGraphicsRectItem>
55 , mMapRenderer( mapRenderer )
59 , mSpaceBetweenPages( 10 )
60 , mPageStyleSymbol( 0 )
61 , mPrintAsRaster( false )
62 , mGenerateWorldFile( false )
64 , mUseAdvancedEffects( true )
65 , mSnapToGrid( false )
66 , mGridVisible( false )
67 , mSnapGridResolution( 0 )
68 , mSnapGridTolerance( 0 )
69 , mSnapGridOffsetX( 0 )
70 , mSnapGridOffsetY( 0 )
71 , mAlignmentSnap( true )
72 , mGuidesVisible( true )
73 , mSmartGuides( true )
74 , mAlignmentSnapTolerance( 0 )
75 , mSelectionHandles( 0 )
76 , mActiveItemCommand( 0 )
77 , mActiveMultiFrameCommand( 0 )
78 , mAtlasComposition( this )
80 , mPreventCursorChange( false )
82 setBackgroundBrush( QColor( 215, 215, 215 ) );
102 : QGraphicsScene( 0 ),
107 mSpaceBetweenPages( 10 ),
108 mPageStyleSymbol( 0 ),
109 mPrintAsRaster( false ),
110 mGenerateWorldFile( false ),
112 mUseAdvancedEffects( true ),
113 mSnapToGrid( false ),
114 mGridVisible( false ),
115 mSnapGridResolution( 0 ),
116 mSnapGridTolerance( 0 ),
117 mSnapGridOffsetX( 0 ),
118 mSnapGridOffsetY( 0 ),
119 mAlignmentSnap( true ),
120 mGuidesVisible( true ),
121 mSmartGuides( true ),
122 mAlignmentSnapTolerance( 0 ),
123 mSelectionHandles( 0 ),
124 mActiveItemCommand( 0 ),
125 mActiveMultiFrameCommand( 0 ),
126 mAtlasComposition( this ),
128 mPreventCursorChange( false )
152 mSnapGridResolution = settings.value(
"/Composer/defaultSnapGridResolution", 10.0 ).toDouble();
153 mSnapGridTolerance = settings.value(
"/Composer/defaultSnapGridTolerance", 2 ).toDouble();
154 mSnapGridOffsetX = settings.value(
"/Composer/defaultSnapGridOffsetX", 0 ).toDouble();
155 mSnapGridOffsetY = settings.value(
"/Composer/defaultSnapGridOffsetY", 0 ).toDouble();
167 QRectF bounds = QRectF( 0, 0, 0, 0 );
170 QList<QGraphicsItem *> itemList = items();
171 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
172 for ( ; itemIt != itemList.end(); ++itemIt )
176 if (( composerItem || paperItem ) )
179 bounds = bounds.united(( *itemIt )->sceneBoundingRect() );
194 for (
int i = 0; i <
mPages.size(); ++i )
196 mPages.at( i )->setSceneRect( QRectF( 0, currentY, width, height ) );
216 int diff = pages - currentPages;
219 for (
int i = 0; i < diff; ++i )
227 for (
int i = 0; i < diff; ++i )
257 properties.insert(
"color",
"white" );
258 properties.insert(
"style",
"solid" );
259 properties.insert(
"style_border",
"no" );
277 return QPointF( position.x(), y );
283 pageNumber = pageNumber < 1 ? 1 : pageNumber;
284 pageNumber = pageNumber >
mPages.size() ?
mPages.size() : pageNumber;
301 QList<QGraphicsItem*> itemList;
302 itemList = items( position, Qt::IntersectsItemShape, Qt::DescendingOrder );
303 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
305 bool foundBelowItem =
false;
306 for ( ; itemIt != itemList.end(); ++itemIt )
310 if ( composerItem && !paperItem )
314 if ( ! belowItem || foundBelowItem )
320 if ( composerItem == belowItem )
323 foundBelowItem =
true;
338 return pageNumberAt( QPointF( item->pos().x(), item->pos().y() ) );
343 QList<QgsComposerItem*> composerItemList;
345 QList<QGraphicsItem *> graphicsItemList = selectedItems();
346 QList<QGraphicsItem *>::iterator itemIter = graphicsItemList.begin();
348 for ( ; itemIter != graphicsItemList.end(); ++itemIter )
353 composerItemList.push_back( composerItem );
357 return composerItemList;
362 QList<const QgsComposerMap*> resultList;
364 QList<QGraphicsItem *> itemList = items();
365 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
366 for ( ; itemIt != itemList.end(); ++itemIt )
371 resultList.push_back( composerMap );
380 QList<QGraphicsItem *> itemList = items();
381 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
382 for ( ; itemIt != itemList.end(); ++itemIt )
387 if ( composerMap->
id() == id )
417 QList<QGraphicsItem *> itemList = items();
418 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
419 for ( ; itemIt != itemList.end(); ++itemIt )
424 if ( mypItem->
id() == theId )
437 QSet<QgsComposer*> composers = QSet<QgsComposer*>();
439 if ( inAllComposers )
441 composers = QgisApp::instance()->printComposers();
445 composers.insert(
this )
448 QSet<QgsComposer*>::const_iterator it = composers.constBegin();
449 for ( ; it != composers.constEnd(); ++it )
451 QList<QGraphicsItem *> itemList = ( *it )->items();
452 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
453 for ( ; itemIt != itemList.end(); ++itemIt )
458 if ( mypItem->
uuid() == theUuid )
472 QList<QGraphicsItem *> itemList = items();
473 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
474 for ( ; itemIt != itemList.end(); ++itemIt )
479 if ( mypItem->
uuid() == theUuid )
495 QList<QGraphicsItem*> itemList = items();
496 QList<QGraphicsItem*>::const_iterator itemIt = itemList.constBegin();
497 for ( ; itemIt != itemList.constEnd(); ++itemIt )
510 double sizeMillimeters = pointSize * 0.3527;
511 return qRound( sizeMillimeters );
516 double sizePoint = pixelSize / 0.3527;
522 if ( composerElem.isNull() )
527 QDomElement compositionElem = doc.createElement(
"Composition" );
528 compositionElem.setAttribute(
"paperWidth", QString::number(
mPageWidth ) );
529 compositionElem.setAttribute(
"paperHeight", QString::number(
mPageHeight ) );
530 compositionElem.setAttribute(
"numPages",
mPages.size() );
533 compositionElem.appendChild( pageStyleElem );
538 compositionElem.setAttribute(
"snapping",
"1" );
542 compositionElem.setAttribute(
"snapping",
"0" );
546 compositionElem.setAttribute(
"gridVisible",
"1" );
550 compositionElem.setAttribute(
"gridVisible",
"0" );
552 compositionElem.setAttribute(
"snapGridResolution", QString::number(
mSnapGridResolution ) );
553 compositionElem.setAttribute(
"snapGridTolerance", QString::number(
mSnapGridTolerance ) );
554 compositionElem.setAttribute(
"snapGridOffsetX", QString::number(
mSnapGridOffsetX ) );
555 compositionElem.setAttribute(
"snapGridOffsetY", QString::number(
mSnapGridOffsetY ) );
558 QList< QGraphicsLineItem* >::const_iterator snapLineIt =
mSnapLines.constBegin();
559 for ( ; snapLineIt !=
mSnapLines.constEnd(); ++snapLineIt )
561 QDomElement snapLineElem = doc.createElement(
"SnapLine" );
562 QLineF line = ( *snapLineIt )->line();
563 snapLineElem.setAttribute(
"x1", QString::number( line.x1() ) );
564 snapLineElem.setAttribute(
"y1", QString::number( line.y1() ) );
565 snapLineElem.setAttribute(
"x2", QString::number( line.x2() ) );
566 snapLineElem.setAttribute(
"y2", QString::number( line.y2() ) );
567 compositionElem.appendChild( snapLineElem );
579 compositionElem.setAttribute(
"alignmentSnap",
mAlignmentSnap ? 1 : 0 );
580 compositionElem.setAttribute(
"guidesVisible",
mGuidesVisible ? 1 : 0 );
581 compositionElem.setAttribute(
"smartGuides",
mSmartGuides ? 1 : 0 );
585 QList<QGraphicsItem*> itemList = items();
586 QList<QGraphicsItem*>::const_iterator itemIt = itemList.constBegin();
587 for ( ; itemIt != itemList.constEnd(); ++itemIt )
594 composerItem->
writeXML( compositionElem, doc );
600 QSet<QgsComposerMultiFrame*>::const_iterator multiFrameIt =
mMultiFrames.constBegin();
601 for ( ; multiFrameIt !=
mMultiFrames.constEnd(); ++multiFrameIt )
603 ( *multiFrameIt )->writeXML( compositionElem, doc );
605 composerElem.appendChild( compositionElem );
613 if ( compositionElem.isNull() )
619 bool widthConversionOk, heightConversionOk;
620 mPageWidth = compositionElem.attribute(
"paperWidth" ).toDouble( &widthConversionOk );
621 mPageHeight = compositionElem.attribute(
"paperHeight" ).toDouble( &heightConversionOk );
623 int numPages = compositionElem.attribute(
"numPages",
"1" ).toInt();
625 QDomElement pageStyleSymbolElem = compositionElem.firstChildElement(
"symbol" );
626 if ( !pageStyleSymbolElem.isNull() )
632 if ( widthConversionOk && heightConversionOk )
635 for (
int i = 0; i <
numPages; ++i )
642 mSnapToGrid = compositionElem.attribute(
"snapping",
"0" ).toInt() == 0 ?
false :
true;
643 mGridVisible = compositionElem.attribute(
"gridVisible",
"0" ).toInt() == 0 ?
false :
true;
646 mSnapGridTolerance = compositionElem.attribute(
"snapGridTolerance",
"2.0" ).toDouble();
647 mSnapGridOffsetX = compositionElem.attribute(
"snapGridOffsetX" ).toDouble();
648 mSnapGridOffsetY = compositionElem.attribute(
"snapGridOffsetY" ).toDouble();
650 mAlignmentSnap = compositionElem.attribute(
"alignmentSnap",
"1" ).toInt() == 0 ?
false :
true;
651 mGuidesVisible = compositionElem.attribute(
"guidesVisible",
"1" ).toInt() == 0 ?
false :
true;
652 mSmartGuides = compositionElem.attribute(
"smartGuides",
"1" ).toInt() == 0 ?
false :
true;
656 QDomNodeList snapLineNodes = compositionElem.elementsByTagName(
"SnapLine" );
657 for (
int i = 0; i < snapLineNodes.size(); ++i )
659 QDomElement snapLineElem = snapLineNodes.at( i ).toElement();
661 double x1 = snapLineElem.attribute(
"x1" ).toDouble();
662 double y1 = snapLineElem.attribute(
"y1" ).toDouble();
663 double x2 = snapLineElem.attribute(
"x2" ).toDouble();
664 double y2 = snapLineElem.attribute(
"y2" ).toDouble();
665 snapItem->setLine( x1, y1, x2, y2 );
668 mPrintAsRaster = compositionElem.attribute(
"printAsRaster" ).toInt();
669 mPrintResolution = compositionElem.attribute(
"printResolution",
"300" ).toInt();
671 mGenerateWorldFile = compositionElem.attribute(
"generateWorldFile",
"0" ).toInt() == 1 ?
true :
false;
685 QList<QGraphicsItem *> itemList = items();
686 QList<QGraphicsItem *>::iterator itemIter = itemList.begin();
687 for ( ; itemIter != itemList.end(); ++itemIter )
702 QDomDocument importDoc;
703 if ( substitutionMap )
705 QString xmlString = doc.toString();
706 QMap<QString, QString>::const_iterator sIt = substitutionMap->constBegin();
707 for ( ; sIt != substitutionMap->constEnd(); ++sIt )
709 xmlString = xmlString.replace(
"[" + sIt.key() +
"]",
encodeStringForXML( sIt.value() ) );
713 int errorLine, errorColumn;
714 if ( !importDoc.setContent( xmlString, &errorMsg, &errorLine, &errorColumn ) )
725 QDomElement compositionElem = importDoc.documentElement().firstChildElement(
"Composition" );
726 if ( compositionElem.isNull() )
731 bool ok =
readXML( compositionElem, importDoc );
738 QDomNodeList composerItemsNodes = importDoc.elementsByTagName(
"ComposerItem" );
739 for (
int i = 0; i < composerItemsNodes.count(); ++i )
741 QDomNode composerItemNode = composerItemsNodes.at( i );
742 if ( composerItemNode.isElement() )
744 composerItemNode.toElement().setAttribute(
"templateUuid", composerItemNode.toElement().attribute(
"uuid" ) );
745 composerItemNode.toElement().removeAttribute(
"uuid" );
750 addItemsFromXML( importDoc.documentElement(), importDoc, 0, addUndoCommands, 0 );
753 QDomElement atlasElem = importDoc.documentElement().firstChildElement(
"Atlas" );
762 QDomNodeList composerItemList = elem.elementsByTagName(
"ComposerItem" );
763 for (
int i = 0; i < composerItemList.size(); ++i )
765 QDomElement currentComposerItemElem = composerItemList.at( i ).toElement();
768 x = currentComposerItemElem.attribute(
"x" ).toDouble( &xOk );
769 y = currentComposerItemElem.attribute(
"y" ).toDouble( &yOk );
774 minX = qMin( minX, x );
775 minY = qMin( minY, y );
779 return QPointF( minX, minY );
783 return QPointF( 0, 0 );
788 bool addUndoCommands, QPointF* pos,
bool pasteInPlace )
790 QPointF* pasteInPlacePt = 0;
797 QPointF pasteShiftPos;
807 pasteShiftPos = *pos - minItemPos;
817 QDomNodeList composerLabelList = elem.elementsByTagName(
"ComposerLabel" );
818 for (
int i = 0; i < composerLabelList.size(); ++i )
820 QDomElement currentComposerLabelElem = composerLabelList.at( i ).toElement();
822 newLabel->
readXML( currentComposerLabelElem, doc );
825 if ( pasteInPlacePt )
828 newLabel->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
832 newLabel->
move( pasteShiftPos.x(), pasteShiftPos.y() );
835 lastPastedItem = newLabel;
838 newLabel->setZValue( newLabel->zValue() + zOrderOffset );
839 if ( addUndoCommands )
845 QDomNodeList composerMapList = elem.elementsByTagName(
"ComposerMap" );
846 for (
int i = 0; i < composerMapList.size(); ++i )
848 QDomElement currentComposerMapElem = composerMapList.at( i ).toElement();
850 newMap->
readXML( currentComposerMapElem, doc );
855 mapsToRestore->insert( newMap, (
int )( newMap->
previewMode() ) );
859 newMap->setZValue( newMap->zValue() + zOrderOffset );
865 newMap->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
869 newMap->
move( pasteShiftPos.x(), pasteShiftPos.y() );
872 lastPastedItem = newMap;
875 if ( addUndoCommands )
881 QList<QgsComposerMap*> maps;
883 for ( QList<QgsComposerMap*>::iterator mit = maps.begin(); mit != maps.end(); ++mit )
885 if (( *mit )->overviewFrameMapId() != -1 )
890 QObject::connect( overviewMap, SIGNAL( extentChanged() ), *mit, SLOT( overviewExtentChanged() ) );
896 QDomNodeList composerArrowList = elem.elementsByTagName(
"ComposerArrow" );
897 for (
int i = 0; i < composerArrowList.size(); ++i )
899 QDomElement currentComposerArrowElem = composerArrowList.at( i ).toElement();
901 newArrow->
readXML( currentComposerArrowElem, doc );
907 newArrow->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
911 newArrow->
move( pasteShiftPos.x(), pasteShiftPos.y() );
914 lastPastedItem = newArrow;
917 newArrow->setZValue( newArrow->zValue() + zOrderOffset );
918 if ( addUndoCommands )
924 QDomNodeList composerScaleBarList = elem.elementsByTagName(
"ComposerScaleBar" );
925 for (
int i = 0; i < composerScaleBarList.size(); ++i )
927 QDomElement currentComposerScaleBarElem = composerScaleBarList.at( i ).toElement();
929 newScaleBar->
readXML( currentComposerScaleBarElem, doc );
935 newScaleBar->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
939 newScaleBar->
move( pasteShiftPos.x(), pasteShiftPos.y() );
942 lastPastedItem = newScaleBar;
945 newScaleBar->setZValue( newScaleBar->zValue() + zOrderOffset );
946 if ( addUndoCommands )
952 QDomNodeList composerShapeList = elem.elementsByTagName(
"ComposerShape" );
953 for (
int i = 0; i < composerShapeList.size(); ++i )
955 QDomElement currentComposerShapeElem = composerShapeList.at( i ).toElement();
957 newShape->
readXML( currentComposerShapeElem, doc );
965 newShape->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
969 newShape->
move( pasteShiftPos.x(), pasteShiftPos.y() );
972 lastPastedItem = newShape;
975 newShape->setZValue( newShape->zValue() + zOrderOffset );
976 if ( addUndoCommands )
982 QDomNodeList composerPictureList = elem.elementsByTagName(
"ComposerPicture" );
983 for (
int i = 0; i < composerPictureList.size(); ++i )
985 QDomElement currentComposerPictureElem = composerPictureList.at( i ).toElement();
987 newPicture->
readXML( currentComposerPictureElem, doc );
993 newPicture->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
997 newPicture->
move( pasteShiftPos.x(), pasteShiftPos.y() );
1000 lastPastedItem = newPicture;
1003 newPicture->setZValue( newPicture->zValue() + zOrderOffset );
1004 if ( addUndoCommands )
1010 QDomNodeList composerLegendList = elem.elementsByTagName(
"ComposerLegend" );
1011 for (
int i = 0; i < composerLegendList.size(); ++i )
1013 QDomElement currentComposerLegendElem = composerLegendList.at( i ).toElement();
1015 newLegend->
readXML( currentComposerLegendElem, doc );
1021 newLegend->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
1025 newLegend->
move( pasteShiftPos.x(), pasteShiftPos.y() );
1028 lastPastedItem = newLegend;
1031 newLegend->setZValue( newLegend->zValue() + zOrderOffset );
1032 if ( addUndoCommands )
1038 QDomNodeList composerTableList = elem.elementsByTagName(
"ComposerAttributeTable" );
1039 for (
int i = 0; i < composerTableList.size(); ++i )
1041 QDomElement currentComposerTableElem = composerTableList.at( i ).toElement();
1043 newTable->
readXML( currentComposerTableElem, doc );
1049 newTable->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
1053 newTable->
move( pasteShiftPos.x(), pasteShiftPos.y() );
1056 lastPastedItem = newTable;
1059 newTable->setZValue( newTable->zValue() + zOrderOffset );
1060 if ( addUndoCommands )
1067 QDomNodeList composerHtmlList = elem.elementsByTagName(
"ComposerHtml" );
1068 for (
int i = 0; i < composerHtmlList.size(); ++i )
1070 QDomElement currentHtmlElem = composerHtmlList.at( i ).toElement();
1072 newHtml->
readXML( currentHtmlElem, doc );
1088 QDomNodeList groupList = elem.elementsByTagName(
"ComposerItemGroup" );
1089 for (
int i = 0; i < groupList.size(); ++i )
1091 QDomElement groupElem = groupList.at( i ).toElement();
1093 newGroup->
readXML( groupElem, doc );
1094 addItem( newGroup );
1102 if ( lastPastedItem )
1107 delete pasteInPlacePt;
1134 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
1135 for ( ; it != selectedItems.end(); ++it )
1148 QMutableLinkedListIterator<QgsComposerItem*> it(
mItemZList );
1149 if ( it.findNext( item ) )
1163 QLinkedListIterator<QgsComposerItem*> it(
mItemZList );
1164 if ( it.findNext( item ) )
1178 QLinkedListIterator<QgsComposerItem*> it(
mItemZList );
1179 if ( it.findNext( item ) )
1184 if ( it.hasPrevious() )
1186 return it.previous();
1196 if ( selectedItems.size() > 0 )
1198 previousSelectedItem = selectedItems.at( 0 );
1201 if ( !previousSelectedItem )
1208 switch ( direction )
1218 if ( !selectedItem )
1232 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
1233 for ( ; it != selectedItems.end(); ++it )
1246 QMutableLinkedListIterator<QgsComposerItem*> it(
mItemZList );
1247 if ( it.findNext( item ) )
1250 if ( it.hasPrevious() )
1262 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
1264 for ( ; it != selectedItems.end(); ++it )
1277 QMutableLinkedListIterator<QgsComposerItem*> it(
mItemZList );
1278 if ( it.findNext( item ) )
1288 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
1289 for ( ; it != selectedItems.end(); ++it )
1302 QMutableLinkedListIterator<QgsComposerItem*> it(
mItemZList );
1303 if ( it.findNext( item ) )
1313 if ( selectedItems.size() < 2 )
1318 QRectF selectedItemBBox;
1324 double minXCoordinate = selectedItemBBox.left();
1327 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items left" ) );
1328 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1329 for ( ; align_it != selectedItems.end(); ++align_it )
1333 ( *align_it )->setPos( minXCoordinate, ( *align_it )->pos().y() );
1342 if ( selectedItems.size() < 2 )
1347 QRectF selectedItemBBox;
1353 double averageXCoord = ( selectedItemBBox.left() + selectedItemBBox.right() ) / 2.0;
1356 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items horizontal center" ) );
1357 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1358 for ( ; align_it != selectedItems.end(); ++align_it )
1362 ( *align_it )->setPos( averageXCoord - ( *align_it )->rect().width() / 2.0, ( *align_it )->pos().y() );
1371 if ( selectedItems.size() < 2 )
1376 QRectF selectedItemBBox;
1382 double maxXCoordinate = selectedItemBBox.right();
1385 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items right" ) );
1386 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1387 for ( ; align_it != selectedItems.end(); ++align_it )
1391 ( *align_it )->setPos( maxXCoordinate - ( *align_it )->rect().width(), ( *align_it )->pos().y() );
1400 if ( selectedItems.size() < 2 )
1405 QRectF selectedItemBBox;
1411 double minYCoordinate = selectedItemBBox.top();
1413 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items top" ) );
1414 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1415 for ( ; align_it != selectedItems.end(); ++align_it )
1419 ( *align_it )->setPos(( *align_it )->pos().x(), minYCoordinate );
1428 if ( selectedItems.size() < 2 )
1433 QRectF selectedItemBBox;
1439 double averageYCoord = ( selectedItemBBox.top() + selectedItemBBox.bottom() ) / 2.0;
1440 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items vertical center" ) );
1441 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1442 for ( ; align_it != selectedItems.end(); ++align_it )
1446 ( *align_it )->setPos(( *align_it )->pos().x(), averageYCoord - ( *align_it )->rect().height() / 2 );
1455 if ( selectedItems.size() < 2 )
1460 QRectF selectedItemBBox;
1466 double maxYCoord = selectedItemBBox.bottom();
1467 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items bottom" ) );
1468 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1469 for ( ; align_it != selectedItems.end(); ++align_it )
1473 ( *align_it )->setPos(( *align_it )->pos().x(), maxYCoord - ( *align_it )->rect().height() );
1481 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Items locked" ) );
1483 QList<QgsComposerItem*>::iterator itemIter = selectionList.begin();
1484 for ( ; itemIter != selectionList.end(); ++itemIter )
1488 ( *itemIter )->setPositionLock(
true );
1500 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Items unlocked" ) );
1505 QList<QGraphicsItem *> itemList = items();
1506 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
1507 for ( ; itemIt != itemList.end(); ++itemIt )
1527 QLinkedList<QgsComposerItem*>::iterator it =
mItemZList.begin();
1530 QUndoCommand* parentCommand = 0;
1531 if ( addUndoCommands )
1533 parentCommand =
new QUndoCommand(
tr(
"Item z-order changed" ) );
1541 if ( addUndoCommands )
1546 currentItem->setZValue( counter );
1547 if ( addUndoCommands )
1554 if ( addUndoCommands )
1567 QLinkedList<QgsComposerItem*>::const_iterator lIt =
mItemZList.constBegin();
1568 QLinkedList<QgsComposerItem*> sortedList;
1570 for ( ; lIt !=
mItemZList.constEnd(); ++lIt )
1572 QLinkedList<QgsComposerItem*>::iterator insertIt = sortedList.begin();
1573 for ( ; insertIt != sortedList.end(); ++insertIt )
1575 if (( *lIt )->zValue() < ( *insertIt )->zValue() )
1580 sortedList.insert( insertIt, ( *lIt ) );
1588 QLinkedList<QgsComposerItem*> sortedList;
1593 QList<QGraphicsItem*> itemList = items();
1594 QList<QGraphicsItem*>::iterator itemIt = itemList.begin();
1595 for ( ; itemIt != itemList.end(); ++itemIt )
1603 sortedList.prepend( composerItem );
1625 double yPage = scenePoint.y() - yOffset;
1637 xSnapped = scenePoint.x();
1642 ySnapped = scenePoint.y();
1645 return QPointF( xSnapped, ySnapped );
1650 QGraphicsLineItem* item =
new QGraphicsLineItem();
1651 QPen linePen( Qt::SolidLine );
1652 linePen.setColor( Qt::red );
1655 linePen.setWidthF( 0 );
1656 item->setPen( linePen );
1657 item->setZValue( 100 );
1673 QList< QGraphicsLineItem* >::iterator it =
mSnapLines.begin();
1676 removeItem(( *it ) );
1685 QList< QGraphicsLineItem* >::iterator it =
mSnapLines.begin();
1700 QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode> >& snappedItems )
1702 double minSqrDist = DBL_MAX;
1703 QGraphicsLineItem* item = 0;
1704 double currentXCoord = 0;
1705 double currentYCoord = 0;
1706 double currentSqrDist = 0;
1707 double sqrTolerance = tolerance * tolerance;
1709 snappedItems.clear();
1711 QList< QGraphicsLineItem* >::const_iterator it =
mSnapLines.constBegin();
1714 bool itemHorizontal =
qgsDoubleNear(( *it )->line().y2() - ( *it )->line().y1(), 0 );
1715 if ( horizontal && itemHorizontal )
1717 currentYCoord = ( *it )->line().y1();
1718 currentSqrDist = ( y - currentYCoord ) * ( y - currentYCoord );
1720 else if ( !horizontal && !itemHorizontal )
1722 currentXCoord = ( *it )->line().x1();
1723 currentSqrDist = ( x - currentXCoord ) * ( x - currentXCoord );
1730 if ( currentSqrDist < minSqrDist && currentSqrDist < sqrTolerance )
1733 minSqrDist = currentSqrDist;
1737 double itemTolerance = 0.0000001;
1741 QList<QGraphicsItem *> itemList = items();
1742 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
1743 for ( ; itemIt != itemList.end(); ++itemIt )
1753 if (
qgsDoubleNear( currentYCoord, currentItem->pos().y() + currentItem->rect().top(), itemTolerance ) )
1757 else if (
qgsDoubleNear( currentYCoord, currentItem->pos().y() + currentItem->rect().center().y(), itemTolerance ) )
1761 else if (
qgsDoubleNear( currentYCoord, currentItem->pos().y() + currentItem->rect().bottom(), itemTolerance ) )
1768 if (
qgsDoubleNear( currentXCoord, currentItem->pos().x(), itemTolerance ) )
1772 else if (
qgsDoubleNear( currentXCoord, currentItem->pos().x() + currentItem->rect().center().x(), itemTolerance ) )
1776 else if (
qgsDoubleNear( currentXCoord, currentItem->pos().x() + currentItem->rect().width(), itemTolerance ) )
1790 if ( selectedItems.size() < 1 )
1797 double minX = currentItem->pos().x();
1798 double minY = currentItem->pos().y();
1799 double maxX = minX + currentItem->rect().width();
1800 double maxY = minY + currentItem->rect().height();
1802 double currentMinX, currentMinY, currentMaxX, currentMaxY;
1804 for (
int i = 1; i < selectedItems.size(); ++i )
1806 currentItem = selectedItems.at( i );
1807 currentMinX = currentItem->pos().x();
1808 currentMinY = currentItem->pos().y();
1809 currentMaxX = currentMinX + currentItem->rect().width();
1810 currentMaxY = currentMinY + currentItem->rect().height();
1812 if ( currentMinX < minX )
1814 if ( currentMaxX > maxX )
1816 if ( currentMinY < minY )
1818 if ( currentMaxY > maxY )
1822 bRect.setTopLeft( QPointF( minX, minY ) );
1823 bRect.setBottomRight( QPointF( maxX, maxY ) );
1889 QString gridStyleString;
1890 gridStyleString = s.value(
"/Composer/gridStyle",
"Dots" ).toString();
1892 int gridRed, gridGreen, gridBlue, gridAlpha;
1893 gridRed = s.value(
"/Composer/gridRed", 190 ).toInt();
1894 gridGreen = s.value(
"/Composer/gridGreen", 190 ).toInt();
1895 gridBlue = s.value(
"/Composer/gridBlue", 190 ).toInt();
1896 gridAlpha = s.value(
"/Composer/gridAlpha", 100 ).toInt();
1897 QColor gridColor = QColor( gridRed, gridGreen, gridBlue, gridAlpha );
1902 if ( gridStyleString ==
"Dots" )
1906 else if ( gridStyleString ==
"Crosses" )
2004 connect( arrow, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2014 connect( label, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2022 if ( setDefaultPreviewStyle )
2034 connect( map, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2041 addItem( scaleBar );
2044 connect( scaleBar, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2054 connect( legend, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2064 connect( picture, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2074 connect( shape, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2084 connect( table, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2094 connect( frame, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2110 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Remove item group" ) );
2112 QSet<QgsComposerItem*> groupedItems = itemGroup->
items();
2113 QSet<QgsComposerItem*>::iterator it = groupedItems.begin();
2114 for ( ; it != groupedItems.end(); ++it )
2129 if ( createCommand )
2150 if ( frameItem && multiFrame )
2155 if ( createCommand )
2158 multiFrame,
this,
tr(
"Multiframe removed" ) );
2269 QList< QgsPaperItem* >::iterator paperIt =
mPages.begin();
2270 for ( ; paperIt !=
mPages.end(); ++paperIt )
2272 ( *paperIt )->update();
2282 paperItem->setBrush( Qt::white );
2283 addItem( paperItem );
2284 paperItem->setZValue( 0 );
2285 mPages.push_back( paperItem );
2292 for (
int i = 0; i <
mPages.size(); ++i )
2302 QSet<QgsComposerMultiFrame*>::iterator multiFrameIt =
mMultiFrames.begin();
2303 for ( ; multiFrameIt !=
mMultiFrames.end(); ++multiFrameIt )
2305 delete *multiFrameIt;
2312 printer.setOutputFormat( QPrinter::PdfFormat );
2313 printer.setOutputFileName( file );
2329 int fromPage = ( printer.fromPage() < 1 ) ? 0 : printer.fromPage() - 1 ;
2330 int toPage = ( printer.toPage() < 1 ) ?
numPages() - 1 : printer.toPage() - 1;
2334 for (
int i = fromPage; i <= toPage; ++i )
2342 if ( !image.isNull() )
2344 QRectF targetArea( 0, 0, image.width(), image.height() );
2345 p.drawImage( targetArea, image, targetArea );
2352 for (
int i = fromPage; i <= toPage; ++i )
2366 printer.setFullPage(
true );
2367 printer.setColorMode( QPrinter::Color );
2376 QPainter p( &printer );
2385 QImage image( QSize( width, height ), QImage::Format_ARGB32 );
2386 if ( !image.isNull() )
2391 QPainter imagePainter( &image );
2393 if ( !imagePainter.isActive() )
return QImage();
2400 if (
mPages.size() <= page )
2411 QPaintDevice* paintDevice = p->device();
2417 QRectF paperRect = QRectF( paperItem->pos().x(), paperItem->pos().y(), paperItem->rect().width(), paperItem->rect().height() );
2424 setBackgroundBrush( Qt::NoBrush );
2425 render( p, QRectF( 0, 0, paintDevice->width(), paintDevice->height() ), paperRect );
2427 setBackgroundBrush( QColor( 215, 215, 215 ) );
2435 QString modifiedStr( str );
2436 modifiedStr.replace(
"&",
"&" );
2437 modifiedStr.replace(
"\"",
""" );
2438 modifiedStr.replace(
"'",
"'" );
2439 modifiedStr.replace(
"<",
"<" );
2440 modifiedStr.replace(
">",
">" );
2459 double xr = extent.
width() / brect.width();
2460 double yr = extent.
height() / brect.height();
2462 double XC = extent.
center().
x();
2463 double YC = extent.
center().
y();
2470 double X0 = paperExtent.
xMinimum();
2471 double Y0 = paperExtent.
yMinimum();
2476 double Ww = paperExtent.
width() / widthPx;
2477 double Hh = paperExtent.
height() / heightPx;
2486 s[5] = Y0 + paperExtent.
height();
2490 r[0] = cos( alpha );
2491 r[1] = -sin( alpha );
2492 r[2] = XC * ( 1 - cos( alpha ) ) + YC * sin( alpha );
2493 r[3] = sin( alpha );
2494 r[4] = cos( alpha );
2495 r[5] = - XC * sin( alpha ) + YC * ( 1 - cos( alpha ) );
2498 a = r[0] * s[0] + r[1] * s[3];
2499 b = r[0] * s[1] + r[1] * s[4];
2500 c = r[0] * s[2] + r[1] * s[5] + r[2];
2501 d = r[3] * s[0] + r[4] * s[3];
2502 e = r[3] * s[1] + r[4] * s[4];
2503 f = r[3] * s[2] + r[4] * s[5] + r[5];
2517 if ( ! atlasHasFeatures )
2524 QList<QgsComposerMap*> maps;
2526 for ( QList<QgsComposerMap*>::iterator mit = maps.begin(); mit != maps.end(); ++mit )
2543 double left =
relativePosition( rectToResize.left(), boundsBefore.left(), boundsBefore.right(), boundsAfter.left(), boundsAfter.right() );
2544 double right =
relativePosition( rectToResize.right(), boundsBefore.left(), boundsBefore.right(), boundsAfter.left(), boundsAfter.right() );
2545 double top =
relativePosition( rectToResize.top(), boundsBefore.top(), boundsBefore.bottom(), boundsAfter.top(), boundsAfter.bottom() );
2546 double bottom =
relativePosition( rectToResize.bottom(), boundsBefore.top(), boundsBefore.bottom(), boundsAfter.top(), boundsAfter.bottom() );
2548 rectToResize.setRect( left, top, right - left, bottom - top );
2554 double m = ( afterMax - afterMin ) / ( beforeMax - beforeMin );
2555 double c = afterMin - ( beforeMin * m );
2558 return m * position + c;