22 #include <QDomDocument>
23 #include <QDomElement>
24 #include <QGraphicsRectItem>
28 QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle(
QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ), mSnapToGrid( false ),
29 mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
31 setBackgroundBrush( Qt::gray );
43 QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle(
QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ),
44 mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
63 mPaperItem->setRect( QRectF( 0, 0, width, height ) );
80 QList<QGraphicsItem *> itemList = items( position );
81 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
83 for ( ; itemIt != itemList.end(); ++itemIt )
86 if ( composerItem && composerItem !=
mPaperItem )
96 QList<QgsComposerItem*> composerItemList;
98 QList<QGraphicsItem *> graphicsItemList = selectedItems();
99 QList<QGraphicsItem *>::iterator itemIter = graphicsItemList.begin();
101 for ( ; itemIter != graphicsItemList.end(); ++itemIter )
106 composerItemList.push_back( composerItem );
110 return composerItemList;
115 QList<const QgsComposerMap*> resultList;
117 QList<QGraphicsItem *> itemList = items();
118 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
119 for ( ; itemIt != itemList.end(); ++itemIt )
124 resultList.push_back( composerMap );
133 QList<const QgsComposerMap*> resultList;
135 QList<QGraphicsItem *> itemList = items();
136 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
137 for ( ; itemIt != itemList.end(); ++itemIt )
142 if ( composerMap->
id() == id )
155 double sizeMillimeters = pointSize * 0.3527;
156 return ( sizeMillimeters + 0.5 );
161 double sizePoint = pixelSize / 0.3527;
167 if ( composerElem.isNull() )
172 QDomElement compositionElem = doc.createElement(
"Composition" );
175 compositionElem.setAttribute(
"paperWidth",
mPaperItem->rect().width() );
176 compositionElem.setAttribute(
"paperHeight",
mPaperItem->rect().height() );
182 compositionElem.setAttribute(
"snapping",
"1" );
186 compositionElem.setAttribute(
"snapping",
"0" );
195 composerElem.appendChild( compositionElem );
202 if ( compositionElem.isNull() )
208 bool widthConversionOk, heightConversionOk;
209 double paperWidth = compositionElem.attribute(
"paperWidth" ).toDouble( &widthConversionOk );
210 double paperHeight = compositionElem.attribute(
"paperHeight" ).toDouble( &heightConversionOk );
212 if ( widthConversionOk && heightConversionOk )
222 if ( compositionElem.attribute(
"snapping" ) ==
"0" )
231 mSnapGridOffsetX = compositionElem.attribute(
"snapGridOffsetX" ).toDouble();
232 mSnapGridOffsetY = compositionElem.attribute(
"snapGridOffsetY" ).toDouble();
233 mPrintAsRaster = compositionElem.attribute(
"printAsRaster" ).toInt();
235 mPrintResolution = compositionElem.attribute(
"printResolution",
"300" ).toInt();
268 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
269 for ( ; it != selectedItems.end(); ++it )
282 QMutableLinkedListIterator<QgsComposerItem*> it(
mItemZList );
283 if ( it.findNext( item ) )
297 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
298 for ( ; it != selectedItems.end(); ++it )
311 QMutableLinkedListIterator<QgsComposerItem*> it(
mItemZList );
312 if ( it.findNext( item ) )
315 if ( it.hasPrevious() )
327 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
329 for ( ; it != selectedItems.end(); ++it )
342 QMutableLinkedListIterator<QgsComposerItem*> it(
mItemZList );
343 if ( it.findNext( item ) )
353 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
354 for ( ; it != selectedItems.end(); ++it )
367 QMutableLinkedListIterator<QgsComposerItem*> it(
mItemZList );
368 if ( it.findNext( item ) )
378 if ( selectedItems.size() < 2 )
383 QRectF selectedItemBBox;
389 double minXCoordinate = selectedItemBBox.left();
392 QUndoCommand* parentCommand =
new QUndoCommand( tr(
"Aligned items left" ) );
393 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
394 for ( ; align_it != selectedItems.end(); ++align_it )
398 QTransform itemTransform = ( *align_it )->transform();
399 itemTransform.translate( minXCoordinate - itemTransform.dx(), 0 );
400 ( *align_it )->setTransform( itemTransform );
409 if ( selectedItems.size() < 2 )
414 QRectF selectedItemBBox;
420 double averageXCoord = ( selectedItemBBox.left() + selectedItemBBox.right() ) / 2.0;
423 QUndoCommand* parentCommand =
new QUndoCommand( tr(
"Aligned items hcenter" ) );
424 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
425 for ( ; align_it != selectedItems.end(); ++align_it )
429 QTransform itemTransform = ( *align_it )->transform();
430 itemTransform.translate( averageXCoord - itemTransform.dx() - ( *align_it )->rect().width() / 2.0, 0 );
431 ( *align_it )->setTransform( itemTransform );
440 if ( selectedItems.size() < 2 )
445 QRectF selectedItemBBox;
451 double maxXCoordinate = selectedItemBBox.right();
454 QUndoCommand* parentCommand =
new QUndoCommand( tr(
"Aligned items right" ) );
455 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
456 for ( ; align_it != selectedItems.end(); ++align_it )
460 QTransform itemTransform = ( *align_it )->transform();
461 itemTransform.translate( maxXCoordinate - itemTransform.dx() - ( *align_it )->rect().width(), 0 );
462 ( *align_it )->setTransform( itemTransform );
471 if ( selectedItems.size() < 2 )
476 QRectF selectedItemBBox;
482 double minYCoordinate = selectedItemBBox.top();
484 QUndoCommand* parentCommand =
new QUndoCommand( tr(
"Aligned items top" ) );
485 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
486 for ( ; align_it != selectedItems.end(); ++align_it )
490 QTransform itemTransform = ( *align_it )->transform();
491 itemTransform.translate( 0, minYCoordinate - itemTransform.dy() );
492 ( *align_it )->setTransform( itemTransform );
501 if ( selectedItems.size() < 2 )
506 QRectF selectedItemBBox;
512 double averageYCoord = ( selectedItemBBox.top() + selectedItemBBox.bottom() ) / 2.0;
513 QUndoCommand* parentCommand =
new QUndoCommand( tr(
"Aligned items vcenter" ) );
514 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
515 for ( ; align_it != selectedItems.end(); ++align_it )
519 QTransform itemTransform = ( *align_it )->transform();
520 itemTransform.translate( 0, averageYCoord - itemTransform.dy() - ( *align_it )->rect().height() / 2 );
521 ( *align_it )->setTransform( itemTransform );
530 if ( selectedItems.size() < 2 )
535 QRectF selectedItemBBox;
541 double maxYCoord = selectedItemBBox.bottom();
542 QUndoCommand* parentCommand =
new QUndoCommand( tr(
"Aligned items bottom" ) );
543 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
544 for ( ; align_it != selectedItems.end(); ++align_it )
548 QTransform itemTransform = ( *align_it )->transform();
549 itemTransform.translate( 0, maxYCoord - itemTransform.dy() - ( *align_it )->rect().height() );
550 ( *align_it )->setTransform( itemTransform );
559 QLinkedList<QgsComposerItem*>::iterator it =
mItemZList.begin();
562 QUndoCommand* parentCommand =
new QUndoCommand( tr(
"Item z-order changed" ) );
570 currentItem->setZValue( counter );
585 QLinkedList<QgsComposerItem*>::const_iterator lIt =
mItemZList.constBegin();
586 QLinkedList<QgsComposerItem*> sortedList;
590 QLinkedList<QgsComposerItem*>::iterator insertIt = sortedList.begin();
591 for ( ; insertIt != sortedList.end(); ++insertIt )
593 if (( *lIt )->zValue() < ( *insertIt )->zValue() )
598 sortedList.insert( insertIt, ( *lIt ) );
621 if ( selectedItems.size() < 1 )
628 double minX = currentItem->transform().dx();
629 double minY = currentItem->transform().dy();
630 double maxX = minX + currentItem->rect().width();
631 double maxY = minY + currentItem->rect().height();
633 double currentMinX, currentMinY, currentMaxX, currentMaxY;
635 for (
int i = 1; i < selectedItems.size(); ++i )
637 currentItem = selectedItems.at( i );
638 currentMinX = currentItem->transform().dx();
639 currentMinY = currentItem->transform().dy();
640 currentMaxX = currentMinX + currentItem->rect().width();
641 currentMaxY = currentMinY + currentItem->rect().height();
643 if ( currentMinX < minX )
645 if ( currentMaxX > maxX )
647 if ( currentMinY < minY )
649 if ( currentMaxY > maxY )
653 bRect.setTopLeft( QPointF( minX, minY ) );
654 bRect.setBottomRight( QPointF( maxX, maxY ) );
719 QString gridStyleString;
720 int red, green, blue;
723 gridStyleString = s.value(
"/qgis/composerGridStyle",
"Dots" ).toString();
724 penWidth = s.value(
"/qgis/composerGridWidth", 0.5 ).toDouble();
725 red = s.value(
"/qgis/composerGridRed", 0 ).toInt();
726 green = s.value(
"/qgis/composerGridGreen", 0 ).toInt();
727 blue = s.value(
"/qgis/composerGridBlue", 0 ).toInt();
729 mGridPen.setColor( QColor( red, green, blue ) );
732 if ( gridStyleString ==
"Dots" )
736 else if ( gridStyleString ==
"Crosses" )
750 s.setValue(
"/qgis/composerGridWidth",
mGridPen.widthF() );
751 s.setValue(
"/qgis/composerGridRed",
mGridPen.color().red() );
752 s.setValue(
"/qgis/composerGridGreen",
mGridPen.color().green() );
753 s.setValue(
"/qgis/composerGridBlue",
mGridPen.color().blue() );
757 s.setValue(
"/qgis/composerGridStyle",
"Solid" );
761 s.setValue(
"/qgis/composerGridStyle",
"Dots" );
765 s.setValue(
"/qgis/composerGridStyle",
"Crosses" );