49 #include <QDomDocument> 50 #include <QDomElement> 51 #include <QGraphicsRectItem> 52 #include <QGraphicsView> 62 , mMapRenderer( mapRenderer )
63 , mMapSettings( mapRenderer->mapSettings() )
64 , mAtlasComposition( this )
72 , mMapSettings( mapSettings )
73 , mAtlasComposition( this )
84 mSpaceBetweenPages = 10;
86 mPrintAsRaster =
false;
87 mGenerateWorldFile =
false;
89 mUseAdvancedEffects =
true;
92 mSnapGridResolution = 0;
95 mAlignmentSnap =
true;
96 mGuidesVisible =
true;
99 mBoundingBoxesVisible =
true;
100 mSelectionHandles = 0;
101 mActiveItemCommand = 0;
102 mActiveMultiFrameCommand = 0;
104 mPreventCursorChange =
false;
106 mUndoStack =
new QUndoStack();
123 connect( &mAtlasComposition, SIGNAL( toggled(
bool ) ),
this, SLOT( prepareAllDataDefinedExpressions() ) );
124 connect( &mAtlasComposition, SIGNAL( coverageLayerChanged(
QgsVectorLayer* ) ),
this, SLOT( prepareAllDataDefinedExpressions() ) );
126 setBackgroundBrush( QColor( 215, 215, 215 ) );
127 createDefaultPageStyleSymbol();
135 addItem( mSelectionHandles );
136 mSelectionHandles->hide();
137 mSelectionHandles->setZValue( 500 );
139 mPrintResolution = 300;
189 deleteAndRemoveMultiFrames();
194 QList<QGraphicsItem*> itemList = items();
195 qDeleteAll( itemList );
198 qDeleteAll( mDataDefinedProperties );
199 mDataDefinedProperties.clear();
206 delete mActiveItemCommand;
207 delete mActiveMultiFrameCommand;
208 delete mPageStyleSymbol;
212 void QgsComposition::loadDefaults()
215 mSnapGridResolution = settings.value(
"/Composer/defaultSnapGridResolution", 10.0 ).toDouble();
216 mSnapGridOffsetX = settings.value(
"/Composer/defaultSnapGridOffsetX", 0 ).toDouble();
217 mSnapGridOffsetY = settings.value(
"/Composer/defaultSnapGridOffsetY", 0 ).toDouble();
218 mSnapTolerance = settings.value(
"/Composer/defaultSnapTolerancePixels", 5 ).toInt();
223 setSceneRect( compositionBounds() );
230 QList<QgsComposerMap*> maps;
232 QList<QgsComposerMap*>::iterator mapIt = maps.begin();
233 for ( ; mapIt != maps.end(); ++mapIt )
236 ( *mapIt )->update();
256 QList<QGraphicsItem *> selectedItemList = selectedItems();
257 QList<QGraphicsItem *>::iterator itemIter = selectedItemList.begin();
259 for ( ; itemIter != selectedItemList.end(); ++itemIter )
284 QRectF QgsComposition::compositionBounds()
const 287 QRectF bounds = QRectF( 0, 0, 0, 0 );
290 QList<QGraphicsItem *> itemList = items();
291 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
292 for ( ; itemIt != itemList.end(); ++itemIt )
296 if (( composerItem || paperItem ) )
299 bounds = bounds.united(( *itemIt )->sceneBoundingRect() );
304 bounds.adjust( -mPageWidth * 0.05, -mPageWidth * 0.05, mPageWidth * 0.05, mPageWidth * 0.05 );
311 if ( width == mPageWidth && height == mPageHeight )
317 QList<QGraphicsItem *> itemList = items();
318 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
319 for ( ; itemIt != itemList.end(); ++itemIt )
328 QList< QGraphicsLineItem* >* guides =
snapLines();
329 QList< QGraphicsLineItem* >::iterator guideIt = guides->begin();
331 for ( ; guideIt != guides->end(); ++guideIt )
333 QLineF line = ( *guideIt )->line();
334 if ( line.dx() == 0 )
337 ( *guideIt )->setLine( line.x1(), 0, line.x1(), totalHeight );
346 ( *guideIt )->setLine( 0, newY, width, newY );
351 mPageHeight = height;
353 for (
int i = 0; i < mPages.size(); ++i )
355 mPages.at( i )->setSceneRect( QRectF( 0, currentY, width, height ) );
356 currentY += ( height + mSpaceBetweenPages );
376 int desiredPages =
pages;
383 int pagesD = exprVal.toInt( &ok );
384 QgsDebugMsg( QString(
"exprVal NumPages:%1" ).arg( pagesD ) );
387 desiredPages = pagesD;
391 int diff = desiredPages - currentPages;
394 for (
int i = 0; i < diff; ++i )
402 for (
int i = 0; i < diff; ++i )
404 delete mPages.last();
410 QList< QGraphicsLineItem* >* guides =
snapLines();
411 QList< QGraphicsLineItem* >::iterator guideIt = guides->begin();
412 double totalHeight = ( mPageHeight +
spaceBetweenPages() ) * ( pages - 1 ) + mPageHeight;
413 for ( ; guideIt != guides->end(); ++guideIt )
415 QLineF line = ( *guideIt )->line();
416 if ( line.dx() == 0 )
419 ( *guideIt )->setLine( line.x1(), 0, line.x1(), totalHeight );
434 return mPages.size();
440 QList<QgsComposerItem*> items;
445 QList<QgsComposerItem*>::const_iterator itemIt = items.constBegin();
446 for ( ; itemIt != items.constEnd(); ++itemIt )
462 if ( page >
numPages() || page < 1 )
469 QList<QgsComposerFrame*> frames;
472 QList<QgsComposerFrame*>::const_iterator frameIt = frames.constBegin();
473 for ( ; frameIt != frames.constEnd(); ++frameIt )
475 if (( *frameIt )->hidePageIfEmpty() && ( *frameIt )->isEmpty() )
486 delete mPageStyleSymbol;
487 mPageStyleSymbol = symbol;
491 void QgsComposition::createDefaultPageStyleSymbol()
493 delete mPageStyleSymbol;
495 properties.insert(
"color",
"white" );
496 properties.insert(
"style",
"solid" );
497 properties.insert(
"style_border",
"no" );
498 properties.insert(
"joinstyle",
"miter" );
516 return QPointF( position.x(), y );
522 pageNumber = pageNumber < 1 ? 1 : pageNumber;
523 pageNumber = pageNumber > mPages.size() ? mPages.size() : pageNumber;
540 QList<QGraphicsItem*> itemList;
541 itemList = items( position, Qt::IntersectsItemShape, Qt::DescendingOrder );
542 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
544 bool foundBelowItem =
false;
545 for ( ; itemIt != itemList.end(); ++itemIt )
549 if ( composerItem && !paperItem )
553 if (( ! belowItem || foundBelowItem ) && ( !ignoreLocked || !composerItem->
positionLock() ) )
559 if ( composerItem == belowItem )
562 foundBelowItem =
true;
577 return pageNumberAt( QPointF( item->pos().x(), item->pos().y() ) );
582 QList<QgsComposerItem*> composerItemList;
584 QList<QGraphicsItem *> graphicsItemList = selectedItems();
585 QList<QGraphicsItem *>::iterator itemIter = graphicsItemList.begin();
587 for ( ; itemIter != graphicsItemList.end(); ++itemIter )
590 if ( composerItem && ( includeLockedItems || !composerItem->
positionLock() ) )
592 composerItemList.push_back( composerItem );
596 return composerItemList;
601 QList<const QgsComposerMap*> resultList;
603 QList<QGraphicsItem *> itemList = items();
604 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
605 for ( ; itemIt != itemList.end(); ++itemIt )
610 resultList.push_back( composerMap );
619 QList<QGraphicsItem *> itemList = items();
620 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
621 for ( ; itemIt != itemList.end(); ++itemIt )
626 if ( composerMap->
id() == id )
656 QList<QGraphicsItem *> itemList = items();
657 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
658 for ( ; itemIt != itemList.end(); ++itemIt )
663 if ( mypItem->
id() == theId )
676 QSet<QgsComposer*> composers = QSet<QgsComposer*>();
678 if ( inAllComposers )
680 composers = QgisApp::instance()->printComposers();
684 composers.insert(
this )
687 QSet<QgsComposer*>::const_iterator it = composers.constBegin();
688 for ( ; it != composers.constEnd(); ++it )
690 QList<QGraphicsItem *> itemList = ( *it )->items();
691 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
692 for ( ; itemIt != itemList.end(); ++itemIt )
697 if ( mypItem->
uuid() == theUuid )
711 QList<QGraphicsItem *> itemList = items();
712 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
713 for ( ; itemIt != itemList.end(); ++itemIt )
718 if ( mypItem->
uuid() == theUuid )
730 mPrintResolution = dpi;
737 mUseAdvancedEffects = effectsEnabled;
740 QList<QGraphicsItem*> itemList = items();
741 QList<QGraphicsItem*>::const_iterator itemIt = itemList.constBegin();
742 for ( ; itemIt != itemList.constEnd(); ++itemIt )
764 if ( composerElem.isNull() )
769 QDomElement compositionElem = doc.createElement(
"Composition" );
770 compositionElem.setAttribute(
"paperWidth", QString::number( mPageWidth ) );
771 compositionElem.setAttribute(
"paperHeight", QString::number( mPageHeight ) );
772 compositionElem.setAttribute(
"numPages", mPages.size() );
775 compositionElem.appendChild( pageStyleElem );
780 compositionElem.setAttribute(
"snapping",
"1" );
784 compositionElem.setAttribute(
"snapping",
"0" );
788 compositionElem.setAttribute(
"gridVisible",
"1" );
792 compositionElem.setAttribute(
"gridVisible",
"0" );
794 compositionElem.setAttribute(
"snapGridResolution", QString::number( mSnapGridResolution ) );
795 compositionElem.setAttribute(
"snapGridOffsetX", QString::number( mSnapGridOffsetX ) );
796 compositionElem.setAttribute(
"snapGridOffsetY", QString::number( mSnapGridOffsetY ) );
799 QList< QGraphicsLineItem* >::const_iterator snapLineIt = mSnapLines.constBegin();
800 for ( ; snapLineIt != mSnapLines.constEnd(); ++snapLineIt )
802 QDomElement snapLineElem = doc.createElement(
"SnapLine" );
803 QLineF line = ( *snapLineIt )->line();
804 snapLineElem.setAttribute(
"x1", QString::number( line.x1() ) );
805 snapLineElem.setAttribute(
"y1", QString::number( line.y1() ) );
806 snapLineElem.setAttribute(
"x2", QString::number( line.x2() ) );
807 snapLineElem.setAttribute(
"y2", QString::number( line.y2() ) );
808 compositionElem.appendChild( snapLineElem );
811 compositionElem.setAttribute(
"printResolution", mPrintResolution );
812 compositionElem.setAttribute(
"printAsRaster", mPrintAsRaster );
814 compositionElem.setAttribute(
"generateWorldFile", mGenerateWorldFile ? 1 : 0 );
815 if ( mGenerateWorldFile && mWorldFileMap )
817 compositionElem.setAttribute(
"worldFileMap", mWorldFileMap->
id() );
820 compositionElem.setAttribute(
"alignmentSnap", mAlignmentSnap ? 1 : 0 );
821 compositionElem.setAttribute(
"guidesVisible", mGuidesVisible ? 1 : 0 );
822 compositionElem.setAttribute(
"smartGuides", mSmartGuides ? 1 : 0 );
823 compositionElem.setAttribute(
"snapTolerancePixels", mSnapTolerance );
826 QList<QGraphicsItem*> itemList = items();
827 QList<QGraphicsItem*>::const_iterator itemIt = itemList.constBegin();
828 for ( ; itemIt != itemList.constEnd(); ++itemIt )
835 composerItem->
writeXML( compositionElem, doc );
841 QSet<QgsComposerMultiFrame*>::const_iterator multiFrameIt = mMultiFrames.constBegin();
842 for ( ; multiFrameIt != mMultiFrames.constEnd(); ++multiFrameIt )
844 ( *multiFrameIt )->writeXML( compositionElem, doc );
846 composerElem.appendChild( compositionElem );
857 if ( compositionElem.isNull() )
863 bool widthConversionOk, heightConversionOk;
864 mPageWidth = compositionElem.attribute(
"paperWidth" ).toDouble( &widthConversionOk );
865 mPageHeight = compositionElem.attribute(
"paperHeight" ).toDouble( &heightConversionOk );
867 int numPages = compositionElem.attribute(
"numPages",
"1" ).toInt();
869 QDomElement pageStyleSymbolElem = compositionElem.firstChildElement(
"symbol" );
870 if ( !pageStyleSymbolElem.isNull() )
872 delete mPageStyleSymbol;
873 mPageStyleSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( pageStyleSymbolElem );
876 if ( widthConversionOk && heightConversionOk )
879 for (
int i = 0; i <
numPages; ++i )
886 mSnapToGrid = compositionElem.attribute(
"snapping",
"0" ).toInt() == 0 ?
false :
true;
887 mGridVisible = compositionElem.attribute(
"gridVisible",
"0" ).toInt() == 0 ?
false :
true;
889 mSnapGridResolution = compositionElem.attribute(
"snapGridResolution" ).toDouble();
890 mSnapGridOffsetX = compositionElem.attribute(
"snapGridOffsetX" ).toDouble();
891 mSnapGridOffsetY = compositionElem.attribute(
"snapGridOffsetY" ).toDouble();
893 mAlignmentSnap = compositionElem.attribute(
"alignmentSnap",
"1" ).toInt() == 0 ?
false :
true;
894 mGuidesVisible = compositionElem.attribute(
"guidesVisible",
"1" ).toInt() == 0 ?
false :
true;
895 mSmartGuides = compositionElem.attribute(
"smartGuides",
"1" ).toInt() == 0 ?
false :
true;
896 mSnapTolerance = compositionElem.attribute(
"snapTolerancePixels",
"10" ).toInt();
899 QDomNodeList snapLineNodes = compositionElem.elementsByTagName(
"SnapLine" );
900 for (
int i = 0; i < snapLineNodes.size(); ++i )
902 QDomElement snapLineElem = snapLineNodes.at( i ).toElement();
904 double x1 = snapLineElem.attribute(
"x1" ).toDouble();
905 double y1 = snapLineElem.attribute(
"y1" ).toDouble();
906 double x2 = snapLineElem.attribute(
"x2" ).toDouble();
907 double y2 = snapLineElem.attribute(
"y2" ).toDouble();
908 snapItem->setLine( x1, y1, x2, y2 );
911 mPrintAsRaster = compositionElem.attribute(
"printAsRaster" ).toInt();
912 mPrintResolution = compositionElem.attribute(
"printResolution",
"300" ).toInt();
914 mGenerateWorldFile = compositionElem.attribute(
"generateWorldFile",
"0" ).toInt() == 1 ?
true :
false;
928 if ( clearComposition )
930 deleteAndRemoveMultiFrames();
933 QList<QGraphicsItem *> itemList = items();
934 QList<QGraphicsItem *>::iterator itemIter = itemList.begin();
935 for ( ; itemIter != itemList.end(); ++itemIter )
939 if ( cItem && !pItem )
946 mItemsModel->
clear();
952 QDomDocument importDoc;
953 if ( substitutionMap )
955 QString xmlString = doc.toString();
956 QMap<QString, QString>::const_iterator sIt = substitutionMap->constBegin();
957 for ( ; sIt != substitutionMap->constEnd(); ++sIt )
959 xmlString = xmlString.replace(
"[" + sIt.key() +
"]", encodeStringForXML( sIt.value() ) );
963 int errorLine, errorColumn;
964 if ( !importDoc.setContent( xmlString, &errorMsg, &errorLine, &errorColumn ) )
975 QDomElement atlasElem;
976 if ( clearComposition )
978 QDomElement compositionElem = importDoc.documentElement().firstChildElement(
"Composition" );
979 if ( compositionElem.isNull() )
984 bool ok =
readXML( compositionElem, importDoc );
991 atlasElem = importDoc.documentElement().firstChildElement(
"Atlas" );
996 QDomNodeList composerItemsNodes = importDoc.elementsByTagName(
"ComposerItem" );
997 for (
int i = 0; i < composerItemsNodes.count(); ++i )
999 QDomNode composerItemNode = composerItemsNodes.at( i );
1000 if ( composerItemNode.isElement() )
1002 composerItemNode.toElement().setAttribute(
"templateUuid", composerItemNode.toElement().attribute(
"uuid" ) );
1003 composerItemNode.toElement().removeAttribute(
"uuid" );
1008 addItemsFromXML( importDoc.documentElement(), importDoc, 0, addUndoCommands, 0 );
1012 if ( clearComposition )
1019 QPointF QgsComposition::minPointFromXml(
const QDomElement& elem )
const 1023 QDomNodeList composerItemList = elem.elementsByTagName(
"ComposerItem" );
1024 for (
int i = 0; i < composerItemList.size(); ++i )
1026 QDomElement currentComposerItemElem = composerItemList.at( i ).toElement();
1029 x = currentComposerItemElem.attribute(
"x" ).toDouble( &xOk );
1030 y = currentComposerItemElem.attribute(
"y" ).toDouble( &yOk );
1035 minX = qMin( minX, x );
1036 minY = qMin( minY, y );
1040 return QPointF( minX, minY );
1044 return QPointF( 0, 0 );
1049 bool addUndoCommands, QPointF* pos,
bool pasteInPlace )
1051 QPointF* pasteInPlacePt = 0;
1058 QPointF pasteShiftPos;
1065 QPointF minItemPos = minPointFromXml( elem );
1068 pasteShiftPos = *pos - minItemPos;
1075 pasteInPlacePt =
new QPointF( 0,
pageNumberAt( *pos ) * ( mPageHeight + mSpaceBetweenPages ) );
1078 QDomNodeList composerLabelList = elem.elementsByTagName(
"ComposerLabel" );
1079 for (
int i = 0; i < composerLabelList.size(); ++i )
1081 QDomElement currentComposerLabelElem = composerLabelList.at( i ).toElement();
1083 newLabel->
readXML( currentComposerLabelElem, doc );
1086 if ( pasteInPlacePt )
1089 newLabel->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
1093 newLabel->
move( pasteShiftPos.x(), pasteShiftPos.y() );
1096 lastPastedItem = newLabel;
1099 newLabel->setZValue( newLabel->zValue() + zOrderOffset );
1100 if ( addUndoCommands )
1106 QDomNodeList composerMapList = elem.elementsByTagName(
"ComposerMap" );
1107 for (
int i = 0; i < composerMapList.size(); ++i )
1109 QDomElement currentComposerMapElem = composerMapList.at( i ).toElement();
1112 if ( mapsToRestore )
1117 newMap->
readXML( currentComposerMapElem, doc );
1120 if ( mapsToRestore )
1122 mapsToRestore->insert( newMap, (
int )( newMap->
previewMode() ) );
1127 newMap->setZValue( newMap->zValue() + zOrderOffset );
1133 newMap->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
1137 newMap->
move( pasteShiftPos.x(), pasteShiftPos.y() );
1140 lastPastedItem = newMap;
1143 if ( addUndoCommands )
1149 QList<QgsComposerMap*> maps;
1151 for ( QList<QgsComposerMap*>::iterator mit = maps.begin(); mit != maps.end(); ++mit )
1156 QList<QgsComposerMapOverview* > overviews = map->
overviews()->
asList();
1157 QList<QgsComposerMapOverview* >::iterator overviewIt = overviews.begin();
1158 for ( ; overviewIt != overviews.end(); ++overviewIt )
1160 ( *overviewIt )->connectSignals();
1166 QDomNodeList composerArrowList = elem.elementsByTagName(
"ComposerArrow" );
1167 for (
int i = 0; i < composerArrowList.size(); ++i )
1169 QDomElement currentComposerArrowElem = composerArrowList.at( i ).toElement();
1171 newArrow->
readXML( currentComposerArrowElem, doc );
1177 newArrow->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
1181 newArrow->
move( pasteShiftPos.x(), pasteShiftPos.y() );
1184 lastPastedItem = newArrow;
1187 newArrow->setZValue( newArrow->zValue() + zOrderOffset );
1188 if ( addUndoCommands )
1194 QDomNodeList composerScaleBarList = elem.elementsByTagName(
"ComposerScaleBar" );
1195 for (
int i = 0; i < composerScaleBarList.size(); ++i )
1197 QDomElement currentComposerScaleBarElem = composerScaleBarList.at( i ).toElement();
1199 newScaleBar->
readXML( currentComposerScaleBarElem, doc );
1205 newScaleBar->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
1209 newScaleBar->
move( pasteShiftPos.x(), pasteShiftPos.y() );
1212 lastPastedItem = newScaleBar;
1215 newScaleBar->setZValue( newScaleBar->zValue() + zOrderOffset );
1216 if ( addUndoCommands )
1222 QDomNodeList composerShapeList = elem.elementsByTagName(
"ComposerShape" );
1223 for (
int i = 0; i < composerShapeList.size(); ++i )
1225 QDomElement currentComposerShapeElem = composerShapeList.at( i ).toElement();
1227 newShape->
readXML( currentComposerShapeElem, doc );
1235 newShape->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
1239 newShape->
move( pasteShiftPos.x(), pasteShiftPos.y() );
1242 lastPastedItem = newShape;
1245 newShape->setZValue( newShape->zValue() + zOrderOffset );
1246 if ( addUndoCommands )
1252 QDomNodeList composerPictureList = elem.elementsByTagName(
"ComposerPicture" );
1253 for (
int i = 0; i < composerPictureList.size(); ++i )
1255 QDomElement currentComposerPictureElem = composerPictureList.at( i ).toElement();
1257 newPicture->
readXML( currentComposerPictureElem, doc );
1263 newPicture->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
1267 newPicture->
move( pasteShiftPos.x(), pasteShiftPos.y() );
1270 lastPastedItem = newPicture;
1273 newPicture->setZValue( newPicture->zValue() + zOrderOffset );
1274 if ( addUndoCommands )
1280 QDomNodeList composerLegendList = elem.elementsByTagName(
"ComposerLegend" );
1281 for (
int i = 0; i < composerLegendList.size(); ++i )
1283 QDomElement currentComposerLegendElem = composerLegendList.at( i ).toElement();
1285 newLegend->
readXML( currentComposerLegendElem, doc );
1291 newLegend->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
1295 newLegend->
move( pasteShiftPos.x(), pasteShiftPos.y() );
1298 lastPastedItem = newLegend;
1301 newLegend->setZValue( newLegend->zValue() + zOrderOffset );
1302 if ( addUndoCommands )
1308 QDomNodeList composerTableList = elem.elementsByTagName(
"ComposerAttributeTable" );
1309 for (
int i = 0; i < composerTableList.size(); ++i )
1311 QDomElement currentComposerTableElem = composerTableList.at( i ).toElement();
1313 newTable->
readXML( currentComposerTableElem, doc );
1319 newTable->
move( pasteInPlacePt->x(), pasteInPlacePt->y() );
1323 newTable->
move( pasteShiftPos.x(), pasteShiftPos.y() );
1326 lastPastedItem = newTable;
1329 newTable->setZValue( newTable->zValue() + zOrderOffset );
1330 if ( addUndoCommands )
1337 QDomNodeList composerHtmlList = elem.elementsByTagName(
"ComposerHtml" );
1338 for (
int i = 0; i < composerHtmlList.size(); ++i )
1340 QDomElement currentHtmlElem = composerHtmlList.at( i ).toElement();
1342 newHtml->
readXML( currentHtmlElem, doc );
1354 QDomNodeList composerAttributeTableV2List = elem.elementsByTagName(
"ComposerAttributeTableV2" );
1355 for (
int i = 0; i < composerAttributeTableV2List.size(); ++i )
1357 QDomElement currentTableElem = composerAttributeTableV2List.at( i ).toElement();
1359 newTable->
readXML( currentTableElem, doc );
1375 QDomNodeList groupList = elem.elementsByTagName(
"ComposerItemGroup" );
1376 for (
int i = 0; i < groupList.size(); ++i )
1378 QDomElement groupElem = groupList.at( i ).toElement();
1380 newGroup->
readXML( groupElem, doc );
1381 addItem( newGroup );
1389 if ( lastPastedItem )
1394 delete pasteInPlacePt;
1424 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
1425 bool itemsRaised =
false;
1426 for ( ; it != selectedItems.end(); ++it )
1428 itemsRaised = itemsRaised |
raiseItem( *it );
1462 if ( selectedItems.size() > 0 )
1464 previousSelectedItem = selectedItems.at( 0 );
1467 if ( !previousSelectedItem )
1474 switch ( direction )
1484 if ( !selectedItem )
1498 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
1499 bool itemsLowered =
false;
1500 for ( ; it != selectedItems.end(); ++it )
1502 itemsLowered = itemsLowered |
lowerItem( *it );
1505 if ( !itemsLowered )
1525 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
1526 bool itemsRaised =
false;
1527 for ( ; it != selectedItems.end(); ++it )
1552 QList<QgsComposerItem*>::iterator it = selectedItems.begin();
1553 bool itemsLowered =
false;
1554 for ( ; it != selectedItems.end(); ++it )
1559 if ( !itemsLowered )
1579 if ( selectedItems.size() < 2 )
1584 QRectF selectedItemBBox;
1585 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1590 double minXCoordinate = selectedItemBBox.left();
1593 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items left" ) );
1594 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1595 for ( ; align_it != selectedItems.end(); ++align_it )
1599 ( *align_it )->setPos( minXCoordinate, ( *align_it )->pos().y() );
1602 mUndoStack->push( parentCommand );
1609 if ( selectedItems.size() < 2 )
1614 QRectF selectedItemBBox;
1615 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1620 double averageXCoord = ( selectedItemBBox.left() + selectedItemBBox.right() ) / 2.0;
1623 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items horizontal center" ) );
1624 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1625 for ( ; align_it != selectedItems.end(); ++align_it )
1629 ( *align_it )->setPos( averageXCoord - ( *align_it )->rect().width() / 2.0, ( *align_it )->pos().y() );
1632 mUndoStack->push( parentCommand );
1639 if ( selectedItems.size() < 2 )
1644 QRectF selectedItemBBox;
1645 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1650 double maxXCoordinate = selectedItemBBox.right();
1653 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items right" ) );
1654 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1655 for ( ; align_it != selectedItems.end(); ++align_it )
1659 ( *align_it )->setPos( maxXCoordinate - ( *align_it )->rect().width(), ( *align_it )->pos().y() );
1662 mUndoStack->push( parentCommand );
1669 if ( selectedItems.size() < 2 )
1674 QRectF selectedItemBBox;
1675 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1680 double minYCoordinate = selectedItemBBox.top();
1682 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items top" ) );
1683 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1684 for ( ; align_it != selectedItems.end(); ++align_it )
1688 ( *align_it )->setPos(( *align_it )->pos().x(), minYCoordinate );
1691 mUndoStack->push( parentCommand );
1698 if ( selectedItems.size() < 2 )
1703 QRectF selectedItemBBox;
1704 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1709 double averageYCoord = ( selectedItemBBox.top() + selectedItemBBox.bottom() ) / 2.0;
1710 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items vertical center" ) );
1711 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1712 for ( ; align_it != selectedItems.end(); ++align_it )
1716 ( *align_it )->setPos(( *align_it )->pos().x(), averageYCoord - ( *align_it )->rect().height() / 2 );
1719 mUndoStack->push( parentCommand );
1726 if ( selectedItems.size() < 2 )
1731 QRectF selectedItemBBox;
1732 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1737 double maxYCoord = selectedItemBBox.bottom();
1738 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Aligned items bottom" ) );
1739 QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
1740 for ( ; align_it != selectedItems.end(); ++align_it )
1744 ( *align_it )->setPos(( *align_it )->pos().x(), maxYCoord - ( *align_it )->rect().height() );
1747 mUndoStack->push( parentCommand );
1753 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Items locked" ) );
1755 QList<QgsComposerItem*>::iterator itemIter = selectionList.begin();
1756 for ( ; itemIter != selectionList.end(); ++itemIter )
1760 ( *itemIter )->setPositionLock(
true );
1765 mUndoStack->push( parentCommand );
1773 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Items unlocked" ) );
1778 QList<QGraphicsItem *> itemList = items();
1779 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
1780 for ( ; itemIt != itemList.end(); ++itemIt )
1794 mUndoStack->push( parentCommand );
1800 if ( items.size() < 2 )
1808 QList<QgsComposerItem*>::iterator itemIter = items.begin();
1809 for ( ; itemIter != items.end(); ++itemIter )
1811 itemGroup->
addItem( *itemIter );
1814 addItem( itemGroup );
1820 QList<QgsComposerItem *> ungroupedItems;
1823 return ungroupedItems;
1826 QSet<QgsComposerItem*> groupedItems = group->
items();
1827 QSet<QgsComposerItem*>::iterator itemIt = groupedItems.begin();
1828 for ( ; itemIt != groupedItems.end(); ++itemIt )
1830 ungroupedItems << ( *itemIt );
1839 return ungroupedItems;
1842 void QgsComposition::updateZValues(
const bool addUndoCommands )
1845 QList<QgsComposerItem*>::const_iterator it = mItemsModel->
zOrderList()->constBegin();
1848 QUndoCommand* parentCommand = 0;
1849 if ( addUndoCommands )
1851 parentCommand =
new QUndoCommand(
tr(
"Item z-order changed" ) );
1853 for ( ; it != mItemsModel->
zOrderList()->constEnd(); ++it )
1859 if ( addUndoCommands )
1864 currentItem->setZValue( counter );
1865 if ( addUndoCommands )
1872 if ( addUndoCommands )
1874 mUndoStack->push( parentCommand );
1886 updateZValues(
false );
1891 if ( !mSnapToGrid || mSnapGridResolution <= 0 || !graphicsView() )
1897 int pageNr = ( int )( scenePoint.y() / ( mPageHeight + mSpaceBetweenPages ) );
1898 double yOffset = pageNr * ( mPageHeight + mSpaceBetweenPages );
1899 double yPage = scenePoint.y() - yOffset;
1902 int xRatio = ( int )(( scenePoint.x() - mSnapGridOffsetX ) / mSnapGridResolution + 0.5 );
1903 int yRatio = ( int )(( yPage - mSnapGridOffsetY ) / mSnapGridResolution + 0.5 );
1905 double xSnapped = xRatio * mSnapGridResolution + mSnapGridOffsetX;
1906 double ySnapped = yRatio * mSnapGridResolution + mSnapGridOffsetY + yOffset;
1909 double viewScaleFactor = graphicsView()->transform().m11();
1910 double alignThreshold = mSnapTolerance / viewScaleFactor;
1912 if ( fabs( xSnapped - scenePoint.x() ) > alignThreshold )
1915 xSnapped = scenePoint.x();
1917 if ( fabs( ySnapped - scenePoint.y() ) > alignThreshold )
1920 ySnapped = scenePoint.y();
1923 return QPointF( xSnapped, ySnapped );
1928 QGraphicsLineItem* item =
new QGraphicsLineItem();
1929 QPen linePen( Qt::SolidLine );
1930 linePen.setColor( Qt::red );
1933 linePen.setWidthF( 0 );
1934 item->setPen( linePen );
1935 item->setZValue( 100 );
1936 item->setVisible( mGuidesVisible );
1938 mSnapLines.push_back( item );
1945 mSnapLines.removeAll( line );
1951 QList< QGraphicsLineItem* >::iterator it = mSnapLines.begin();
1952 for ( ; it != mSnapLines.end(); ++it )
1954 removeItem(( *it ) );
1962 mGuidesVisible = visible;
1963 QList< QGraphicsLineItem* >::iterator it = mSnapLines.begin();
1964 for ( ; it != mSnapLines.end(); ++it )
1978 QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode> >& snappedItems )
const 1980 double minSqrDist = DBL_MAX;
1981 QGraphicsLineItem* item = 0;
1982 double currentXCoord = 0;
1983 double currentYCoord = 0;
1984 double currentSqrDist = 0;
1985 double sqrTolerance = tolerance * tolerance;
1987 snappedItems.clear();
1989 QList< QGraphicsLineItem* >::const_iterator it = mSnapLines.constBegin();
1990 for ( ; it != mSnapLines.constEnd(); ++it )
1992 bool itemHorizontal =
qgsDoubleNear(( *it )->line().y2() - ( *it )->line().y1(), 0 );
1993 if ( horizontal && itemHorizontal )
1995 currentYCoord = ( *it )->line().y1();
1996 currentSqrDist = ( y - currentYCoord ) * ( y - currentYCoord );
1998 else if ( !horizontal && !itemHorizontal )
2000 currentXCoord = ( *it )->line().x1();
2001 currentSqrDist = ( x - currentXCoord ) * ( x - currentXCoord );
2008 if ( currentSqrDist < minSqrDist && currentSqrDist < sqrTolerance )
2011 minSqrDist = currentSqrDist;
2015 double itemTolerance = 0.0000001;
2019 QList<QGraphicsItem *> itemList = items();
2020 QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
2021 for ( ; itemIt != itemList.end(); ++itemIt )
2031 if (
qgsDoubleNear( currentYCoord, currentItem->pos().y() + currentItem->rect().top(), itemTolerance ) )
2035 else if (
qgsDoubleNear( currentYCoord, currentItem->pos().y() + currentItem->rect().center().y(), itemTolerance ) )
2039 else if (
qgsDoubleNear( currentYCoord, currentItem->pos().y() + currentItem->rect().bottom(), itemTolerance ) )
2046 if (
qgsDoubleNear( currentXCoord, currentItem->pos().x(), itemTolerance ) )
2050 else if (
qgsDoubleNear( currentXCoord, currentItem->pos().x() + currentItem->rect().center().x(), itemTolerance ) )
2054 else if (
qgsDoubleNear( currentXCoord, currentItem->pos().x() + currentItem->rect().width(), itemTolerance ) )
2065 int QgsComposition::boundingRectOfSelectedItems( QRectF& bRect )
2068 if ( selectedItems.size() < 1 )
2075 double minX = currentItem->pos().x();
2076 double minY = currentItem->pos().y();
2077 double maxX = minX + currentItem->rect().width();
2078 double maxY = minY + currentItem->rect().height();
2080 double currentMinX, currentMinY, currentMaxX, currentMaxY;
2082 for (
int i = 1; i < selectedItems.size(); ++i )
2084 currentItem = selectedItems.at( i );
2085 currentMinX = currentItem->pos().x();
2086 currentMinY = currentItem->pos().y();
2087 currentMaxX = currentMinX + currentItem->rect().width();
2088 currentMaxY = currentMinY + currentItem->rect().height();
2090 if ( currentMinX < minX )
2092 if ( currentMaxX > maxX )
2094 if ( currentMinY < minY )
2096 if ( currentMaxY > maxY )
2100 bRect.setTopLeft( QPointF( minX, minY ) );
2101 bRect.setBottomRight( QPointF( maxX, maxY ) );
2119 mSnapGridResolution = r;
2125 mSnapGridOffsetX = offset;
2131 mSnapGridOffsetY = offset;
2139 mGridPen.setWidthF( 0 );
2151 mBoundingBoxesVisible = boundsVisible;
2153 if ( mSelectionHandles )
2155 mSelectionHandles->update();
2167 void QgsComposition::loadSettings()
2172 QString gridStyleString;
2173 gridStyleString = s.value(
"/Composer/gridStyle",
"Dots" ).toString();
2175 int gridRed, gridGreen, gridBlue, gridAlpha;
2176 gridRed = s.value(
"/Composer/gridRed", 190 ).toInt();
2177 gridGreen = s.value(
"/Composer/gridGreen", 190 ).toInt();
2178 gridBlue = s.value(
"/Composer/gridBlue", 190 ).toInt();
2179 gridAlpha = s.value(
"/Composer/gridAlpha", 100 ).toInt();
2180 QColor gridColor = QColor( gridRed, gridGreen, gridBlue, gridAlpha );
2182 mGridPen.setColor( gridColor );
2183 mGridPen.setWidthF( 0 );
2185 if ( gridStyleString ==
"Dots" )
2189 else if ( gridStyleString ==
"Crosses" )
2201 delete mActiveItemCommand;
2204 mActiveItemCommand = 0;
2221 if ( mActiveItemCommand )
2226 mUndoStack->push( mActiveItemCommand );
2231 delete mActiveItemCommand;
2233 mActiveItemCommand = 0;
2239 delete mActiveItemCommand;
2240 mActiveItemCommand = 0;
2245 delete mActiveMultiFrameCommand;
2249 mActiveMultiFrameCommand = 0;
2266 if ( mActiveMultiFrameCommand )
2271 mUndoStack->push( mActiveMultiFrameCommand );
2276 delete mActiveMultiFrameCommand;
2278 mActiveMultiFrameCommand = 0;
2284 delete mActiveMultiFrameCommand;
2285 mActiveMultiFrameCommand = 0;
2290 mMultiFrames.insert( multiFrame );
2297 mMultiFrames.remove( multiFrame );
2307 connect( arrow, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2317 connect( label, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2325 if ( setDefaultPreviewStyle )
2337 connect( map, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2344 addItem( scaleBar );
2347 connect( scaleBar, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2357 connect( legend, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2367 connect( picture, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2377 connect( shape, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2387 connect( table, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2397 connect( frame, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2407 connect( frame, SIGNAL( sizeChanged() ),
this, SLOT(
updateBounds() ) );
2422 if ( itemGroup && removeGroupItems )
2425 QUndoCommand* parentCommand =
new QUndoCommand(
tr(
"Remove item group" ) );
2427 QSet<QgsComposerItem*> groupedItems = itemGroup->
items();
2428 QSet<QgsComposerItem*>::iterator it = groupedItems.begin();
2429 for ( ; it != groupedItems.end(); ++it )
2432 connectAddRemoveCommandSignals( subcommand );
2444 if ( createCommand )
2465 if ( frameItem && multiFrame )
2470 if ( createCommand )
2473 multiFrame,
this,
tr(
"Multiframe removed" ) );
2491 connectAddRemoveCommandSignals( c );
2587 void QgsComposition::updatePaperItems()
2589 QList< QgsPaperItem* >::iterator paperIt = mPages.begin();
2590 for ( ; paperIt != mPages.end(); ++paperIt )
2592 ( *paperIt )->update();
2596 void QgsComposition::addPaperItem()
2600 double currentY = paperHeight * mPages.size() + mPages.size() * mSpaceBetweenPages;
2602 paperItem->setBrush( Qt::white );
2603 addItem( paperItem );
2604 paperItem->setZValue( 0 );
2605 mPages.push_back( paperItem );
2610 void QgsComposition::removePaperItems()
2612 qDeleteAll( mPages );
2617 void QgsComposition::deleteAndRemoveMultiFrames()
2619 QSet<QgsComposerMultiFrame*>::iterator multiFrameIt = mMultiFrames.begin();
2620 for ( ; multiFrameIt != mMultiFrames.end(); ++multiFrameIt )
2622 delete *multiFrameIt;
2624 mMultiFrames.clear();
2629 printer.setOutputFileName( file );
2636 printer.setOutputFormat( QPrinter::PdfFormat );
2641 printer.setOrientation( QPrinter::Portrait );
2655 return print( printer );
2660 if ( ddPageSizeActive() )
2666 printer.setOrientation( QPrinter::Portrait );
2671 int fromPage = ( printer.fromPage() < 1 ) ? 0 : printer.fromPage() - 1;
2672 int toPage = ( printer.toPage() < 1 ) ?
numPages() - 1 : printer.toPage() - 1;
2674 bool pageExported =
false;
2675 if ( mPrintAsRaster )
2677 for (
int i = fromPage; i <= toPage; ++i )
2683 if (( pageExported && i > fromPage ) || startNewPage )
2689 if ( !image.isNull() )
2691 QRectF targetArea( 0, 0, image.width(), image.height() );
2692 p.drawImage( targetArea, image, targetArea );
2694 pageExported =
true;
2698 if ( !mPrintAsRaster )
2700 for (
int i = fromPage; i <= toPage; ++i )
2706 if (( pageExported && i > fromPage ) || startNewPage )
2711 pageExported =
true;
2719 printer.setFullPage(
true );
2720 printer.setColorMode( QPrinter::Color );
2725 if ( evaluateDDPageSize && ddPageSizeActive() )
2731 printer.setOrientation( QPrinter::Portrait );
2740 bool ready = p.begin( &printer );
2756 QImage image( QSize( width, height ), QImage::Format_ARGB32 );
2757 if ( !image.isNull() )
2762 QPainter imagePainter( &image );
2764 if ( !imagePainter.isActive() )
return QImage();
2771 if ( mPages.size() <= page )
2782 QPaintDevice* paintDevice = p->device();
2788 QRectF paperRect = QRectF( paperItem->pos().x(), paperItem->pos().y(), paperItem->rect().width(), paperItem->rect().height() );
2795 setBackgroundBrush( Qt::NoBrush );
2796 render( p, QRectF( 0, 0, paintDevice->width(), paintDevice->height() ), paperRect );
2798 setBackgroundBrush( QColor( 215, 215, 215 ) );
2801 mPlotStyle = savedPlotStyle;
2804 QString QgsComposition::encodeStringForXML(
const QString& str )
2806 QString modifiedStr( str );
2807 modifiedStr.replace(
"&",
"&" );
2808 modifiedStr.replace(
"\"",
""" );
2809 modifiedStr.replace(
"'",
"'" );
2810 modifiedStr.replace(
"<",
"<" );
2811 modifiedStr.replace(
">",
">" );
2815 QGraphicsView *QgsComposition::graphicsView()
const 2818 QList<QGraphicsView*> viewList = views();
2819 if ( viewList.size() > 0 )
2821 return viewList.at( 0 );
2832 if ( !mWorldFileMap )
2840 QRectF mapItemSceneRect = mWorldFileMap->mapRectToScene( mWorldFileMap->rect() );
2845 double xRatio = mapExtent.
width() / mapItemSceneRect.width();
2846 double yRatio = mapExtent.
height() / mapItemSceneRect.height();
2848 double xCenter = mapExtent.
center().
x();
2849 double yCenter = mapExtent.
center().
y();
2852 QPointF mapItemPosOnPage = mWorldFileMap->
pagePos();
2853 double xmin = mapExtent.
xMinimum() - mapItemPosOnPage.x() * xRatio;
2854 double ymax = mapExtent.
yMaximum() + mapItemPosOnPage.y() * yRatio;
2855 QgsRectangle paperExtent( xmin, ymax - destinationHeight * yRatio, xmin + destinationWidth * xRatio, ymax );
2857 double X0 = paperExtent.
xMinimum();
2858 double Y0 = paperExtent.
yMinimum();
2861 int heightPx = ( int )(
printResolution() * destinationHeight / 25.4 );
2863 double Ww = paperExtent.
width() / widthPx;
2864 double Hh = paperExtent.
height() / heightPx;
2873 s[5] = Y0 + paperExtent.
height();
2877 r[0] = cos( alpha );
2878 r[1] = -sin( alpha );
2879 r[2] = xCenter * ( 1 - cos( alpha ) ) + yCenter * sin( alpha );
2880 r[3] = sin( alpha );
2881 r[4] = cos( alpha );
2882 r[5] = - xCenter * sin( alpha ) + yCenter * ( 1 - cos( alpha ) );
2885 a = r[0] * s[0] + r[1] * s[3];
2886 b = r[0] * s[1] + r[1] * s[4];
2887 c = r[0] * s[2] + r[1] * s[5] + r[2];
2888 d = r[3] * s[0] + r[4] * s[3];
2889 e = r[3] * s[1] + r[4] * s[4];
2890 f = r[3] * s[2] + r[4] * s[5] + r[5];
2903 bool atlasHasFeatures = mAtlasComposition.
beginRender();
2904 if ( ! atlasHasFeatures )
2916 bool QgsComposition::ddPageSizeActive()
const 2925 void QgsComposition::refreshPageSize()
2927 double pageWidth = mPageWidth;
2928 double pageHeight = mPageHeight;
2934 QString presetString = exprVal.toString().trimmed();
2935 QgsDebugMsg( QString(
"exprVal Paper Preset size :%1" ).arg( presetString ) );
2941 pageHeight = heightD;
2949 double widthD = exprVal.toDouble( &ok );
2950 QgsDebugMsg( QString(
"exprVal Paper Width:%1" ).arg( widthD ) );
2959 double heightD = exprVal.toDouble( &ok );
2960 QgsDebugMsg( QString(
"exprVal Paper Height:%1" ).arg( heightD ) );
2963 pageHeight = heightD;
2971 QString orientationString = exprVal.toString().trimmed();
2973 QgsDebugMsg( QString(
"exprVal Paper Orientation:%1" ).arg( orientationString ) );
2976 double heightD, widthD;
2979 heightD = qMax( pageHeight, pageWidth );
2980 widthD = qMin( pageHeight, pageWidth );
2984 heightD = qMin( pageHeight, pageWidth );
2985 widthD = qMax( pageHeight, pageWidth );
2988 pageHeight = heightD;
3004 QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >::const_iterator it = mDataDefinedProperties.find( property );
3005 if ( it != mDataDefinedProperties.constEnd() )
3022 bool defaultVals = ( !active && !useExpression && expression.isEmpty() && field.isEmpty() );
3024 if ( mDataDefinedProperties.contains( property ) )
3026 QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >::const_iterator it = mDataDefinedProperties.find( property );
3027 if ( it != mDataDefinedProperties.constEnd() )
3036 else if ( !defaultVals )
3039 mDataDefinedProperties.insert( property, dd );
3043 bool QgsComposition::dataDefinedEvaluate(
QgsComposerObject::DataDefinedProperty property, QVariant &expressionValue, QMap<QgsComposerObject::DataDefinedProperty, QgsDataDefined *> *dataDefinedProperties )
3052 expressionValue.clear();
3057 if ( mAtlasComposition.
enabled() )
3071 QVariant result = dataDefinedValue( property, currentFeature, layerFields, dataDefinedProperties );
3073 if ( result.isValid() )
3075 expressionValue = result;
3082 bool QgsComposition::dataDefinedActive(
const QgsComposerObject::DataDefinedProperty property,
const QMap<QgsComposerObject::DataDefinedProperty, QgsDataDefined *> *dataDefinedProperties )
const 3089 if ( !dataDefinedProperties->contains( property ) )
3096 QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >::const_iterator it = dataDefinedProperties->find( property );
3097 if ( it != dataDefinedProperties->constEnd() )
3118 if ( !dataDefinedProperties->contains( property ) )
3125 QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >::const_iterator it = dataDefinedProperties->find( property );
3126 if ( it != dataDefinedProperties->constEnd() )
3141 QVariant result = QVariant();
3143 QString field = dd->
field();
3147 prepareDataDefinedExpression( dd, dataDefinedProperties );
3154 result = expr->
evaluate( feature );
3161 else if ( !useExpression && !field.isEmpty() && fields )
3177 void QgsComposition::prepareDataDefinedExpression(
QgsDataDefined *dd, QMap<QgsComposerObject::DataDefinedProperty, QgsDataDefined *> *dataDefinedProperties )
const 3181 if ( mAtlasComposition.
enabled() )
3194 QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >::const_iterator it = dataDefinedProperties->constBegin();
3195 for ( ; it != dataDefinedProperties->constEnd(); ++it )
3197 it.value()->prepareExpression( atlasLayer );
3202 void QgsComposition::prepareAllDataDefinedExpressions()
3204 prepareDataDefinedExpression( 0, &mDataDefinedProperties );
void lowerSelectedItems()
bool positionLock() const
Returns whether position lock for mouse drags is enabled returns true if item is locked for mouse mov...
Class for parsing and evaluation of expressions (formerly called "search strings").
void beginPrint(QPrinter &printer, const bool evaluateDDPageSize=false)
Prepare the printer for printing.
static void relativeResizeRect(QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter)
Resizes a QRectF relative to a resized bounding rectangle.
Item representing the paper.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
A scale bar item that can be added to a map composition.
QUndoStack * undoStack()
Returns pointer to undo/redo command storage.
QgsComposerItem * composerItemAt(const QPointF &position, const bool ignoreLocked=false) const
Returns the topmost composer item at a specified position.
void unlockAllItems()
Unlock all items.
void setActive(bool active)
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets state from Dom document.
A rectangle specified with double values.
double paperWidth() const
Width of paper item.
bool writeXML(QDomElement &composerElem, QDomDocument &doc)
Writes settings to xml (paper dimension)
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
void setAllUnselected()
Clears any selected items in the composition.
QgsComposerItem * getComposerItemAbove(QgsComposerItem *item) const
Finds the next composer item above an item.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
sets state from Dom document
A container class for data source field mapping or expression.
An item that draws an arrow between to points.
QgsComposerMapOverviewStack * overviews()
Returns the map item's overview stack, which is used to control how overviews are drawn over the map'...
void addItemToZList(QgsComposerItem *item)
Adds item to z list.
void composerArrowAdded(QgsComposerArrow *arrow)
Is emitted when new composer arrow has been added to the view.
void setBoundingBoxesVisible(const bool boundsVisible)
Sets whether selection bounding boxes should be shown in the composition.
QgsExpression * expression()
void setPageStyleSymbol(QgsFillSymbolV2 *symbol)
Note: added in version 2.1.
void assignFreeId()
Sets mId to a number not yet used in the composition.
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
virtual void beginItemCommand(const QString &text)
void computeWorldFileParameters(double &a, double &b, double &c, double &d, double &e, double &f) const
Compute world file parameters.
double yMaximum() const
Get the y maximum value (top side of rectangle)
GridStyle
Style to draw the snapping grid.
void alignSelectedItemsTop()
void rebuildZList()
Rebuilds the z-order list, based on the current stacking of items in the composition.
void composerPictureAdded(QgsComposerPicture *picture)
Is emitted when a new composer picture has been added.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
static double relativePosition(const double position, const double beforeMin, const double beforeMax, const double afterMin, const double afterMax)
Returns a scaled position given a before and after range.
int pageNumberForPoint(const QPointF &position) const
Returns the page number corresponding to a point in the composition.
QgsDataDefined * dataDefinedProperty(const QgsComposerObject::DataDefinedProperty property)
Returns a reference to the data defined settings for one of the composition's data defined properties...
void removeItems() override
Removes the items but does not delete them.
QPointF pagePos() const
Returns the item's position relative to its current page.
static QgsFillSymbolV2 * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
void cache()
Create cache image.
int zOrderListSize() const
Returns the size of the z-order list, which includes items which may have been removed from the compo...
QgsComposerItemGroup * groupItems(QList< QgsComposerItem * > items)
Creates a new group from a list of composer items and adds it to the composition. ...
static void readDataDefinedPropertyMap(const QDomElement &itemElem, QMap< QgsComposerObject::DataDefinedProperty, QString > *dataDefinedNames, QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined * > *dataDefinedProperties)
Reads all data defined properties from xml.
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 setSelectedItem(QgsComposerItem *item)
Clears any selected items and sets an item as the current selection.
void pushAddRemoveCommand(QgsComposerItem *item, const QString &text, const QgsAddRemoveItemCommand::State state=QgsAddRemoveItemCommand::Added)
Convenience function to create a QgsAddRemoveItemCommand, connect its signals and push it to the undo...
void removeItemFromZList(QgsComposerItem *item)
Removes item from z list.
bool enabled() const
Returns whether the atlas generation is enabled.
QPointF snapPointToGrid(const QPointF &scenePoint) const
Snaps a scene coordinate point to grid.
void updateBounds()
Updates the scene bounds of the composition.
Container of fields for a vector layer.
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 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 moveItemToBottom(QgsComposerItem *item)
void setCreateUndoCommands(bool enabled)
Sets whether undo commands should be created for interactions with the multiframe.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void beginPrintAsPDF(QPrinter &printer, const QString &file)
Prepare the printer for printing in a PDF.
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()
static void writeDataDefinedPropertyMap(QDomElement &itemElem, QDomDocument &doc, const QMap< QgsComposerObject::DataDefinedProperty, QString > *dataDefinedNames, const QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined * > *dataDefinedProperties)
Writes data defined properties to xml.
bool reorderItemDown(QgsComposerItem *item)
Moves an item down the z-order list.
void alignSelectedItemsHCenter()
double spaceBetweenPages() const
Returns the vertical space between pages in a composer view.
void doPrint(QPrinter &printer, QPainter &painter, bool startNewPage=false)
Print on a preconfigured printer.
void setStatusMessage(const QString &message)
Sets the status bar message for the composer window.
QMap< QString, QString > QgsStringMap
void composerMapAdded(QgsComposerMap *map)
Is emitted when new composer map has been added to the view.
int numPages() const
Returns the number of pages in the composition.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false) override
Reads the properties specific to an attribute table from xml.
static Q_DECL_DEPRECATED double relativePosition(double position, double beforeMin, double beforeMax, double afterMin, double afterMax)
Returns a scaled position given a before and after range.
void setGridVisible(const bool b)
void alignSelectedItemsVCenter()
bool shouldExportPage(const int page) const
Returns whether a specified page number should be included in exports of the composition.
A table that displays attributes from a vector layer.
DataDefinedProperty
Data defined properties for different item types.
void composerItemsOnPage(QList< T * > &itemList, const int pageNumber) const
Return composer items of a specific type on a specified page.
void endRender()
Ends the rendering.
A composer class that displays svg files or raster format (jpg, png, ...)
void readXML(const QDomElement &elem, const QDomDocument &doc)
Reads general atlas settings from xml.
void endMultiFrameCommand()
QSet< QgsComposerItem * > items()
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.
void setItemPosition(double x, double y, ItemPositionMode itemPoint=UpperLeft, int page=-1)
Moves the item to a new position (in canvas coordinates)
The QgsMapSettings class contains configuration for rendering of the map.
QList< QgsComposerItem * > * zOrderList()
Returns the item z-order list.
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)
static QDomElement saveSymbol(QString symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Reads the properties specific to an attribute table from xml.
void setUseExpression(bool use)
QgsComposerItem * getComposerItemBelow(QgsComposerItem *item) const
QString uuid() const
Get item identification name.
void setNumPages(const int pages)
Sets the number of pages for the composition.
void refreshItemsTriggered()
Is emitted when item in the composition must be refreshed.
bool beginRender()
Begins the rendering.
void setSnapLinesVisible(const bool visible)
Hides / shows custom snap lines.
int itemPageNumber(const QgsComposerItem *) const
Returns on which page number (0-based) is displayed an item.
static QgsComposition::PaperOrientation decodePaperOrientation(const QString orientationString, bool &ok)
Decodes a string representing a paper orientation.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
void cancelCommand()
Deletes current command.
void setSnapGridOffsetX(const double offset)
#define QgsDebugMsgLevel(str, level)
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-based) given a coordinate.
void setUseSymbolV2(bool useSymbolV2)
Controls whether the shape should be drawn using a QgsFillSymbolV2.
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 updatePagePos(double newPageWidth, double newPageHeight)
Moves the item so that it retains its relative position on the page when the paper size changes...
void setField(const QString &field)
void clear()
Clears all items from z-order list and resets the model.
void removeSnapLine(QGraphicsLineItem *line)
Remove custom snap line (and delete the object)
void addItem(QgsComposerItem *item) override
Adds an item to the group.
void alignSelectedItemsRight()
Abstract base class for composer items with the ability to distribute the content to several frames (...
void addComposerTableFrame(QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame)
Adds composer tablev2 frame and advises composer to create a widget for it (through signal) ...
const QgsComposerItem * getComposerItemByUuid(const QString theUuid) const
Returns a composer item given its unique identifier.
QList< QgsComposerItem * > ungroupItems(QgsComposerItemGroup *group)
Ungroups items by removing them from an item group and removing the group from the composition...
void cancelMultiFrameCommand()
Deletes current multi frame command.
void removeComposerItem(QgsComposerItem *item, const bool createCommand=true, const bool removeGroupItems=true)
Remove item from the graphics scene.
static bool decodePresetPaperSize(const QString presetString, double &width, double &height)
Decodes a string representing a preset page size.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
sets state from Dom document
bool loadFromTemplate(const QDomDocument &doc, QMap< QString, QString > *substitutionMap=0, bool addUndoCommands=false, const bool clearComposition=true)
Load a template document.
void moveSelectedItemsToTop()
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
sets state from Dom document
int frameCount() const
Returns the number of frames associated with this multiframe.
A composer command that merges together with other commands having the same context (=id) for multi f...
double mapRotation(QgsComposerObject::PropertyValueType valueType=QgsComposerObject::EvaluatedValue) const
Returns the rotation used for drawing the map within the composer item.
void setSnapGridResolution(const double r)
bool pageIsEmpty(const int page) const
Returns whether a page is empty, ie, it contains no items except for the background paper item...
QgsFeature * currentFeature()
Returns the current atlas feature.
void removeMultiFrame(QgsComposerMultiFrame *multiFrame)
Removes multi frame (but does not delete it)
Object representing map window.
Frame item for a composer multiframe item.
bool readXML(const QDomElement &compositionElem, const QDomDocument &doc)
Reads settings from xml file.
bool useExpression() const
int indexFromName(const QString &name) const
Look up field's index from name. Returns -1 on error.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
sets state from Dom document
QgsRectangle * currentMapExtent()
Returns a pointer to the current map extent, which is either the original user specified extent or th...
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 refreshItems()
Forces items in the composition to refresh.
void setUpdatesEnabled(bool enabled)
Sets whether updates to the composer map are enabled.
QgsComposerItem * getComposerItemAbove(QgsComposerItem *item) const
Q_DECL_DEPRECATED int pixelFontSize(double pointSize) const
Returns the mm font size for a font that has point size set.
void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties)
Refreshes a data defined property for the composition by reevaluating the property's value and redraw...
PreviewMode previewMode() const
void removeItem(QgsComposerItem *item)
Removes an item from the z-order list.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
sets state from Dom document
void updateSettings()
Refreshes the composition when composer related options change.
void saveAfterState()
Saves current item state as after state.
bool setAtlasMode(const QgsComposition::AtlasMode mode)
Sets the current atlas mode of the composition.
void setPositionLock(const bool lock)
Locks / unlocks the item position for mouse drags.
void setPrintResolution(const int dpi)
bool print(QPrinter &printer, const bool evaluateDDPageSize=false)
Convenience function that prepares the printer and prints.
void composerTableAdded(QgsComposerAttributeTable *table)
Is emitted when a new composer table has been added.
QList< QgsPaperItem * > pages()
Return pages in the correct order.
void refreshZList()
Rebuilds the z order list by adding any item which are present in the composition but missing from th...
int id() const
Get identification number.
void composerShapeAdded(QgsComposerShape *shape)
Is emitted when a new composer shape has been added.
bool exportAsPDF(const QString &file)
Convenience function that prepares the printer for printing in PDF and prints.
void lockSelectedItems()
Lock the selected items.
void setGridStyle(const GridStyle s)
A composer command class for adding / removing composer items.
const QgsComposerItem * getComposerItemById(const QString theId) const
Returns a composer item given its text identifier.
void selectNextByZOrder(const ZValueDirection direction)
void statusMsgChanged(QString message)
Is emitted when the composition has an updated status bar message for the composer window...
void clearSnapLines()
Removes all snap lines.
A table class that displays a vector attribute table.
bool reorderItemUp(QgsComposerItem *item)
Moves an item up the z-order list.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QgsComposerItem * getComposerItemBelow(QgsComposerItem *item) const
Finds the next composer item below an item.
Undo command to undo/redo all composer item related changes.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
sets state from Dom document
void setDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property, bool active, bool useExpression, const QString &expression, const QString &field)
Sets parameters for a data defined property for the composition.
A composer items that draws common shapes (ellipse, triangle, rectangle)
virtual void endItemCommand()
void readXMLMapSettings(const QDomElement &elem, const QDomDocument &doc)
Reads old (pre 2.2) map related atlas settings from xml.
void raiseSelectedItems()
bool prepareExpression(QgsVectorLayer *layer)
bool expressionIsPrepared() const
void addComposerHtmlFrame(QgsComposerHtml *html, QgsComposerFrame *frame)
Adds composer html frame and advises composer to create a widget for it (through signal) ...
QList< QgsComposerMapOverview * > asList() const
Returns a list of QgsComposerMapOverviews contained by the stack.
AtlasMode
Composition atlas modes.
static QgsProject * instance()
access to canonical QgsProject instance
QPointF positionOnPage(const QPointF &position) const
Returns the position within a page of a point in the composition.
void addComposerMap(QgsComposerMap *map, const bool setDefaultPreviewStyle=true)
Adds map to the graphics scene and advices composer to create a widget for it (through signal) ...
void alignSelectedItemsBottom()
static void fixEngineFlags(QPaintEngine *engine)
void alignSelectedItemsLeft()
QGraphicsLineItem * nearestSnapLine(const bool horizontal, const double x, const double y, const double tolerance, QList< QPair< QgsComposerItem *, QgsComposerItem::ItemPositionMode > > &snappedItems) const
Get nearest snap line.
double paperHeight() const
Height of paper item.
static double pointsToMM(const double pointSize)
Returns the size in mm corresponding to a font point size.
void selectedItemChanged(QgsComposerItem *selected)
Is emitted when selected item changed.
void renderPage(QPainter *p, int page)
Render a page to a paint device.
A label that can be placed onto a map composition.
void setUseAdvancedEffects(const bool effectsEnabled)
Used to enable or disable advanced effects such as blend modes in a composition.
void setEffectsEnabled(const bool effectsEnabled)
Sets whether effects (eg blend modes) are enabled for the item.
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.
static Q_DECL_DEPRECATED void relativeResizeRect(QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter)
Resizes a QRectF relative to the change from boundsBefore to boundsAfter.
void addComposerTable(QgsComposerAttributeTable *table)
Adds a composer table to the graphics scene and advices composer to create a widget for it (through s...
Handles drawing of selection outlines and mouse handles.
void composerTableFrameAdded(QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame)
Is emitted when a new composer table frame has been added to the view.
Q_DECL_DEPRECATED const QgsComposerHtml * getComposerHtmlByItem(QgsComposerItem *item) const
Returns the composer html with specified id (a string as named in the composer user interface item pr...
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
void setItemRemoved(QgsComposerItem *item)
Marks an item as removed from the composition.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets state from DOM document.
friend class QgsComposerModel
static void setSpecialColumn(const QString &name, QVariant value)
Assign a special column.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false) override
Reads multiframe state information from a DOM element.
Q_DECL_DEPRECATED double pointFontSize(int pixelSize) const
Does the inverse calculation and returns points for mm.
QGraphicsLineItem * addSnapLine()
Add a custom snap line (can be horizontal or vertical)
void composerItems(QList< T * > &itemList)
Return composer items of a specific type.
void printResolutionChanged()
Is emitted when the compositions print resolution changes.
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
void setPreviewMode(PreviewMode m)
double width() const
Width of the rectangle.
bool raiseItem(QgsComposerItem *item)
QgsComposerMultiFrame * multiFrame() const
Returns the parent multiframe for the frame.
void setSnapToGridEnabled(const bool b)
bool reorderItemToTop(QgsComposerItem *item)
Moves an item to the top of the z-order list.
Represents a vector layer which manages a vector based data sets.
void move(double dx, double dy)
Moves item in canvas coordinates.
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) ...
double xMinimum() const
Get the x minimum value (left side of rectangle)
void addMultiFrame(QgsComposerMultiFrame *multiFrame)
Adds multiframe.
void addItemAtTop(QgsComposerItem *item)
Adds an item to the top of the composition z stack.
QgsPoint center() const
Center point of the rectangle.
QString evalErrorString() const
Returns evaluation error.
void setExpressionString(const QString &expr)
bool lowerItem(QgsComposerItem *item)
void addComposerArrow(QgsComposerArrow *arrow)
Adds an arrow item to the graphics scene and advices composer to create a widget for it (through sign...
bool reorderItemToBottom(QgsComposerItem *item)
Moves an item to the bottom of the z-order list.
bool moveItemToTop(QgsComposerItem *item)
void setPaperSize(const double width, const 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.
Q_DECL_DEPRECATED QgsComposition(QgsMapRenderer *mapRenderer)
double height() const
Height of the rectangle.
virtual int type() const override
return correct graphics item type.
void setSnapGridOffsetY(const double offset)
void beginCommand(QgsComposerItem *item, const QString &commandText, const QgsComposerMergeCommand::Context c=QgsComposerMergeCommand::Unknown)
Allocates new item command and saves initial state in it.
QList< QgsComposerItem * > selectedComposerItems(const bool includeLockedItems=true)
Returns list of selected composer items.
QList< QGraphicsLineItem * > * snapLines()
Returns pointer to snap lines collection.
void beginMultiFrameCommand(QgsComposerMultiFrame *multiFrame, const QString &text, const QgsComposerMultiFrameMergeCommand::Context c=QgsComposerMultiFrameMergeCommand::Unknown)
static double mmToPoints(const double mmSize)
Returns the size in mm corresponding to a font point size.
QString id() const
Get item's id (which is not necessarly unique)