49 #include <QDomDocument> 50 #include <QDomElement> 51 #include <QGraphicsRectItem> 52 #include <QGraphicsView> 62 , mMapRenderer( mapRenderer )
63 , mMapSettings( mapRenderer->mapSettings() )
64 , mAtlasComposition( this )
71 , mMapRenderer( nullptr )
72 , mMapSettings( mapSettings )
73 , mAtlasComposition( this )
84 mSpaceBetweenPages = 10;
85 mPageStyleSymbol =
nullptr;
86 mPrintAsRaster =
false;
87 mGenerateWorldFile =
false;
88 mWorldFileMap =
nullptr;
89 mUseAdvancedEffects =
true;
93 mSnapGridResolution = 0;
96 mAlignmentSnap =
true;
97 mGuidesVisible =
true;
100 mBoundingBoxesVisible =
true;
101 mSelectionHandles =
nullptr;
102 mActiveItemCommand =
nullptr;
103 mActiveMultiFrameCommand =
nullptr;
105 mPreventCursorChange =
false;
106 mItemsModel =
nullptr;
109 mResizeToContentsMarginTop = 0;
110 mResizeToContentsMarginRight = 0;
111 mResizeToContentsMarginBottom = 0;
112 mResizeToContentsMarginLeft = 0;
129 connect( &mAtlasComposition, SIGNAL( toggled(
bool ) ),
this, SLOT( prepareAllDataDefinedExpressions() ) );
130 connect( &mAtlasComposition, SIGNAL( coverageLayerChanged(
QgsVectorLayer* ) ),
this, SLOT( prepareAllDataDefinedExpressions() ) );
133 createDefaultPageStyleSymbol();
142 mSelectionHandles->
hide();
145 mPrintResolution = 300;
195 deleteAndRemoveMultiFrames();
201 qDeleteAll( itemList );
204 qDeleteAll( mDataDefinedProperties );
205 mDataDefinedProperties.
clear();
212 delete mActiveItemCommand;
213 delete mActiveMultiFrameCommand;
214 delete mPageStyleSymbol;
218 void QgsComposition::loadDefaults()
221 mSnapGridResolution = settings.
value(
"/Composer/defaultSnapGridResolution", 10.0 ).
toDouble();
222 mSnapGridOffsetX = settings.
value(
"/Composer/defaultSnapGridOffsetX", 0 ).
toDouble();
223 mSnapGridOffsetY = settings.
value(
"/Composer/defaultSnapGridOffsetY", 0 ).
toDouble();
224 mSnapTolerance = settings.
value(
"/Composer/defaultSnapTolerancePixels", 5 ).
toInt();
239 for ( ; mapIt != maps.
end(); ++mapIt )
242 ( *mapIt )->update();
265 for ( ; itemIter != selectedItemList.
end(); ++itemIter )
282 evalContext = scopedContext.
data();
294 refreshPageSize( evalContext );
306 for ( ; itemIt != itemList.
end(); ++itemIt )
310 if (( composerItem && ( !paperItem || !ignorePages ) ) )
314 bounds = bounds.
united(( *itemIt )->sceneBoundingRect() );
316 bounds = ( *itemIt )->sceneBoundingRect();
320 if ( bounds.
isValid() && margin > 0.0 )
323 bounds.
adjust( -mPageWidth * margin, -mPageWidth * margin, mPageWidth * margin, mPageWidth * margin );
337 for ( ; itemIt != itemList.
end(); ++itemIt )
341 if ( composerItem && !paperItem &&
itemPageNumber( composerItem ) == pageNumber )
343 if ( visibleOnly && !composerItem->
isVisible() )
348 bounds = bounds.
united(( *itemIt )->sceneBoundingRect() );
350 bounds = ( *itemIt )->sceneBoundingRect();
364 if ( keepRelativeItemPosition )
369 for ( ; itemIt != itemList.
end(); ++itemIt )
383 for ( ; guideIt != guides->
end(); ++guideIt )
385 QLineF line = ( *guideIt )->line();
389 ( *guideIt )->
setLine( line.
x1(), 0, line.
x1(), totalHeight );
394 if ( keepRelativeItemPosition )
400 ( *guideIt )->setLine( 0, newY, width, newY );
405 ( *guideIt )->setLine( 0, line.
y1(),
width, line.
y1() );
413 for (
int i = 0; i < mPages.
size(); ++i )
415 mPages.
at( i )->setSceneRect(
QRectF( 0, currentY, width, height ) );
416 currentY += ( height + mSpaceBetweenPages );
439 double newWidth = bounds.
width() + marginLeft + marginRight;
440 double newHeight = bounds.
height() + marginTop + marginBottom;
444 double diffX = marginLeft - bounds.
left();
445 double diffY = marginTop - bounds.
top();
456 composerItem->
move( diffX, diffY );
467 guide->
setLine( line.
x1() + diffX, 0, line.
x1() + diffX, newHeight );
472 guide->
setLine( 0, line.
y1() + diffY, newWidth, line.
y1() + diffY );
479 mResizeToContentsMarginTop = marginTop;
480 mResizeToContentsMarginRight = marginRight;
481 mResizeToContentsMarginBottom = marginBottom;
482 mResizeToContentsMarginLeft = marginLeft;
487 marginTop = mResizeToContentsMarginTop;
488 marginRight = mResizeToContentsMarginRight;
489 marginBottom = mResizeToContentsMarginBottom;
490 marginLeft = mResizeToContentsMarginLeft;
496 int desiredPages =
pages;
504 int pagesD = exprVal.
toInt( &ok );
508 desiredPages = pagesD;
512 int diff = desiredPages - currentPages;
515 for (
int i = 0; i < diff; ++i )
523 for (
int i = 0; i < diff; ++i )
525 delete mPages.
last();
533 double totalHeight = ( mPageHeight +
spaceBetweenPages() ) * ( pages - 1 ) + mPageHeight;
534 for ( ; guideIt != guides->
end(); ++guideIt )
536 QLineF line = ( *guideIt )->line();
540 ( *guideIt )->
setLine( line.
x1(), 0, line.
x1(), totalHeight );
552 return mPages.
size();
564 for ( ; itemIt != items.
constEnd(); ++itemIt )
580 if ( page >
numPages() || page < 1 )
591 for ( ; frameIt != frames.
constEnd(); ++frameIt )
593 if (( *frameIt )->hidePageIfEmpty() && ( *frameIt )->isEmpty() )
604 delete mPageStyleSymbol;
609 void QgsComposition::createDefaultPageStyleSymbol()
611 delete mPageStyleSymbol;
613 properties.
insert(
"color",
"white" );
614 properties.
insert(
"style",
"solid" );
615 properties.
insert(
"style_border",
"no" );
616 properties.
insert(
"joinstyle",
"miter" );
640 pageNumber = pageNumber < 1 ? 1 : pageNumber;
641 pageNumber = pageNumber > mPages.
size() ? mPages.
size() : pageNumber;
659 itemList =
items( position, Qt::IntersectsItemShape, Qt::DescendingOrder );
662 bool foundBelowItem =
false;
663 for ( ; itemIt != itemList.
end(); ++itemIt )
667 if ( composerItem && !paperItem )
671 if (( ! belowItem || foundBelowItem ) && ( !ignoreLocked || !composerItem->
positionLock() ) )
677 if ( composerItem == belowItem )
680 foundBelowItem =
true;
705 for ( ; itemIter != graphicsItemList.
end(); ++itemIter )
708 if ( composerItem && ( includeLockedItems || !composerItem->
positionLock() ) )
710 composerItemList.
push_back( composerItem );
714 return composerItemList;
723 for ( ; itemIt != itemList.
end(); ++itemIt )
739 for ( ; itemIt != itemList.
end(); ++itemIt )
744 if ( composerMap->
id() == id )
776 for ( ; itemIt != itemList.
end(); ++itemIt )
781 if ( mypItem->
id() == theId )
796 if ( inAllComposers )
798 composers = QgisApp::instance()->printComposers();
806 for ( ; it != composers.
constEnd(); ++it )
810 for ( ; itemIt != itemList.
end(); ++itemIt )
815 if ( mypItem->
uuid() == theUuid )
831 for ( ; itemIt != itemList.
end(); ++itemIt )
836 if ( mypItem->
uuid() == theUuid )
848 mPrintResolution = dpi;
855 mUseAdvancedEffects = effectsEnabled;
860 for ( ; itemIt != itemList.
constEnd(); ++itemIt )
882 if ( composerElem.
isNull() )
916 compositionElem.
setAttribute(
"showPages", mPagesVisible );
920 for ( ; snapLineIt != mSnapLines.
constEnd(); ++snapLineIt )
923 QLineF line = ( *snapLineIt )->line();
931 compositionElem.
setAttribute(
"printResolution", mPrintResolution );
932 compositionElem.
setAttribute(
"printAsRaster", mPrintAsRaster );
934 compositionElem.
setAttribute(
"generateWorldFile", mGenerateWorldFile ? 1 : 0 );
935 if ( mGenerateWorldFile && mWorldFileMap )
937 compositionElem.
setAttribute(
"worldFileMap", mWorldFileMap->
id() );
940 compositionElem.
setAttribute(
"alignmentSnap", mAlignmentSnap ? 1 : 0 );
941 compositionElem.
setAttribute(
"guidesVisible", mGuidesVisible ? 1 : 0 );
942 compositionElem.
setAttribute(
"smartGuides", mSmartGuides ? 1 : 0 );
943 compositionElem.
setAttribute(
"snapTolerancePixels", mSnapTolerance );
945 compositionElem.
setAttribute(
"resizeToContentsMarginTop", mResizeToContentsMarginTop );
946 compositionElem.
setAttribute(
"resizeToContentsMarginRight", mResizeToContentsMarginRight );
947 compositionElem.
setAttribute(
"resizeToContentsMarginBottom", mResizeToContentsMarginBottom );
948 compositionElem.
setAttribute(
"resizeToContentsMarginLeft", mResizeToContentsMarginLeft );
953 for ( ; itemIt != itemList.
constEnd(); ++itemIt )
960 composerItem->
writeXML( compositionElem, doc );
967 for ( ; multiFrameIt != mMultiFrames.
constEnd(); ++multiFrameIt )
969 ( *multiFrameIt )->writeXML( compositionElem, doc );
977 mCustomProperties.
writeXml( compositionElem, doc );
985 if ( compositionElem.
isNull() )
991 bool widthConversionOk, heightConversionOk;
992 mPageWidth = compositionElem.
attribute(
"paperWidth" ).
toDouble( &widthConversionOk );
993 mPageHeight = compositionElem.
attribute(
"paperHeight" ).
toDouble( &heightConversionOk );
998 if ( !pageStyleSymbolElem.
isNull() )
1000 delete mPageStyleSymbol;
1001 mPageStyleSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( pageStyleSymbolElem );
1004 if ( widthConversionOk && heightConversionOk )
1007 for (
int i = 0; i <
numPages; ++i )
1014 mSnapToGrid = compositionElem.
attribute(
"snapping",
"0" ).
toInt() == 0 ?
false :
true;
1015 mGridVisible = compositionElem.
attribute(
"gridVisible",
"0" ).
toInt() == 0 ?
false :
true;
1017 mSnapGridResolution = compositionElem.
attribute(
"snapGridResolution" ).
toDouble();
1021 mAlignmentSnap = compositionElem.
attribute(
"alignmentSnap",
"1" ).
toInt() == 0 ?
false :
true;
1022 mGuidesVisible = compositionElem.
attribute(
"guidesVisible",
"1" ).
toInt() == 0 ?
false :
true;
1023 mSmartGuides = compositionElem.
attribute(
"smartGuides",
"1" ).
toInt() == 0 ?
false :
true;
1024 mSnapTolerance = compositionElem.
attribute(
"snapTolerancePixels",
"10" ).
toInt();
1026 mResizeToContentsMarginTop = compositionElem.
attribute(
"resizeToContentsMarginTop",
"0" ).
toDouble();
1027 mResizeToContentsMarginRight = compositionElem.
attribute(
"resizeToContentsMarginRight",
"0" ).
toDouble();
1028 mResizeToContentsMarginBottom = compositionElem.
attribute(
"resizeToContentsMarginBottom",
"0" ).
toDouble();
1029 mResizeToContentsMarginLeft = compositionElem.
attribute(
"resizeToContentsMarginLeft",
"0" ).
toDouble();
1033 for (
int i = 0; i < snapLineNodes.
size(); ++i )
1041 snapItem->
setLine( x1, y1, x2, y2 );
1044 mPagesVisible = ( compositionElem.
attribute(
"showPages",
"1" ) !=
"0" );
1045 mPrintAsRaster = compositionElem.
attribute(
"printAsRaster" ).
toInt();
1046 mPrintResolution = compositionElem.
attribute(
"printResolution",
"300" ).
toInt();
1048 mGenerateWorldFile = compositionElem.
attribute(
"generateWorldFile",
"0" ).
toInt() == 1 ?
true :
false;
1054 mCustomProperties.
readXml( compositionElem );
1065 if ( clearComposition )
1067 deleteAndRemoveMultiFrames();
1072 for ( ; itemIter != itemList.
end(); ++itemIter )
1076 if ( cItem && !pItem )
1083 mItemsModel->
clear();
1086 mUndoStack->
clear();
1090 if ( substitutionMap )
1094 for ( ; sIt != substitutionMap->
constEnd(); ++sIt )
1096 xmlString = xmlString.
replace(
'[' + sIt.
key() +
']', encodeStringForXML( sIt.
value() ) );
1100 int errorLine, errorColumn;
1101 if ( !importDoc.
setContent( xmlString, &errorMsg, &errorLine, &errorColumn ) )
1113 if ( clearComposition )
1116 if ( compositionElem.
isNull() )
1121 bool ok =
readXML( compositionElem, importDoc );
1134 for (
int i = 0; i < composerItemsNodes.
count(); ++i )
1136 QDomNode composerItemNode = composerItemsNodes.
at( i );
1149 if ( clearComposition )
1161 for (
int i = 0; i < composerItemList.
size(); ++i )
1172 minX = qMin( minX, x );
1173 minY = qMin( minY, y );
1186 bool addUndoCommands,
QPointF* pos,
bool pasteInPlace )
1188 QPointF* pasteInPlacePt =
nullptr;
1202 QPointF minItemPos = minPointFromXml( elem );
1205 pasteShiftPos = *pos - minItemPos;
1212 pasteInPlacePt =
new QPointF( 0,
pageNumberAt( *pos ) * ( mPageHeight + mSpaceBetweenPages ) );
1216 for (
int i = 0; i < composerLabelList.
size(); ++i )
1220 newLabel->
readXML( currentComposerLabelElem, doc );
1223 if ( pasteInPlacePt )
1226 newLabel->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1230 newLabel->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1233 lastPastedItem = newLabel;
1237 if ( addUndoCommands )
1244 for (
int i = 0; i < composerMapList.
size(); ++i )
1249 if ( mapsToRestore )
1254 newMap->
readXML( currentComposerMapElem, doc );
1257 if ( mapsToRestore )
1270 newMap->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1274 newMap->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1277 lastPastedItem = newMap;
1280 if ( addUndoCommands )
1295 for ( ; overviewIt != overviews.
end(); ++overviewIt )
1297 ( *overviewIt )->connectSignals();
1304 for (
int i = 0; i < composerArrowList.
size(); ++i )
1308 newArrow->
readXML( currentComposerArrowElem, doc );
1314 newArrow->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1318 newArrow->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1321 lastPastedItem = newArrow;
1325 if ( addUndoCommands )
1332 for (
int i = 0; i < composerScaleBarList.
size(); ++i )
1336 newScaleBar->
readXML( currentComposerScaleBarElem, doc );
1342 newScaleBar->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1346 newScaleBar->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1349 lastPastedItem = newScaleBar;
1353 if ( addUndoCommands )
1360 for (
int i = 0; i < composerShapeList.
size(); ++i )
1364 newShape->
readXML( currentComposerShapeElem, doc );
1372 newShape->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1376 newShape->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1379 lastPastedItem = newShape;
1383 if ( addUndoCommands )
1390 for (
int i = 0; i < composerPictureList.
size(); ++i )
1394 newPicture->
readXML( currentComposerPictureElem, doc );
1400 newPicture->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1404 newPicture->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1407 lastPastedItem = newPicture;
1411 if ( addUndoCommands )
1418 for (
int i = 0; i < composerLegendList.
size(); ++i )
1422 newLegend->
readXML( currentComposerLegendElem, doc );
1428 newLegend->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1432 newLegend->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1435 lastPastedItem = newLegend;
1439 if ( addUndoCommands )
1446 for (
int i = 0; i < composerTableList.
size(); ++i )
1450 newTable->
readXML( currentComposerTableElem, doc );
1456 newTable->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1460 newTable->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1463 lastPastedItem = newTable;
1467 if ( addUndoCommands )
1475 for (
int i = 0; i < composerHtmlList.
size(); ++i )
1479 newHtml->
readXML( currentHtmlElem, doc );
1492 for (
int i = 0; i < composerAttributeTableV2List.
size(); ++i )
1496 newTable->
readXML( currentTableElem, doc );
1513 for (
int i = 0; i < groupList.
size(); ++i )
1517 newGroup->
readXML( groupElem, doc );
1519 if ( addUndoCommands )
1530 if ( lastPastedItem )
1535 delete pasteInPlacePt;
1536 pasteInPlacePt =
nullptr;
1566 bool itemsRaised =
false;
1567 for ( ; it != selectedItems.
end(); ++it )
1569 itemsRaised = itemsRaised |
raiseItem( *it );
1603 if ( !selectedItems.
isEmpty() )
1605 previousSelectedItem = selectedItems.
at( 0 );
1608 if ( !previousSelectedItem )
1615 switch ( direction )
1625 if ( !selectedItem )
1640 bool itemsLowered =
false;
1641 for ( ; it != selectedItems.
end(); ++it )
1643 itemsLowered = itemsLowered |
lowerItem( *it );
1646 if ( !itemsLowered )
1667 bool itemsRaised =
false;
1668 for ( ; it != selectedItems.
end(); ++it )
1694 bool itemsLowered =
false;
1695 for ( ; it != selectedItems.
end(); ++it )
1700 if ( !itemsLowered )
1720 if ( selectedItems.
size() < 2 )
1726 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1731 double minXCoordinate = selectedItemBBox.
left();
1736 for ( ; align_it != selectedItems.
end(); ++align_it )
1740 ( *align_it )->setPos( minXCoordinate, ( *align_it )->pos().y() );
1743 mUndoStack->
push( parentCommand );
1750 if ( selectedItems.
size() < 2 )
1756 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1761 double averageXCoord = ( selectedItemBBox.
left() + selectedItemBBox.
right() ) / 2.0;
1766 for ( ; align_it != selectedItems.
end(); ++align_it )
1770 ( *align_it )->setPos( averageXCoord - ( *align_it )->rect().width() / 2.0, ( *align_it )->pos().y() );
1773 mUndoStack->
push( parentCommand );
1780 if ( selectedItems.
size() < 2 )
1786 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1791 double maxXCoordinate = selectedItemBBox.
right();
1796 for ( ; align_it != selectedItems.
end(); ++align_it )
1800 ( *align_it )->setPos( maxXCoordinate - ( *align_it )->rect().width(), ( *align_it )->pos().y() );
1803 mUndoStack->
push( parentCommand );
1810 if ( selectedItems.
size() < 2 )
1816 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1821 double minYCoordinate = selectedItemBBox.
top();
1825 for ( ; align_it != selectedItems.
end(); ++align_it )
1829 ( *align_it )->setPos(( *align_it )->pos().x(), minYCoordinate );
1832 mUndoStack->
push( parentCommand );
1839 if ( selectedItems.
size() < 2 )
1845 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1850 double averageYCoord = ( selectedItemBBox.
top() + selectedItemBBox.
bottom() ) / 2.0;
1853 for ( ; align_it != selectedItems.
end(); ++align_it )
1857 ( *align_it )->setPos(( *align_it )->pos().x(), averageYCoord - ( *align_it )->rect().height() / 2 );
1860 mUndoStack->
push( parentCommand );
1867 if ( selectedItems.
size() < 2 )
1873 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1878 double maxYCoord = selectedItemBBox.
bottom();
1881 for ( ; align_it != selectedItems.
end(); ++align_it )
1885 ( *align_it )->setPos(( *align_it )->pos().x(), maxYCoord - ( *align_it )->rect().height() );
1888 mUndoStack->
push( parentCommand );
1897 for ( ; itemIter != selectionList.
end(); ++itemIter )
1901 ( *itemIter )->setPositionLock(
true );
1906 mUndoStack->
push( parentCommand );
1921 for ( ; itemIt != itemList.
end(); ++itemIt )
1935 mUndoStack->
push( parentCommand );
1941 if ( items.
size() < 2 )
1951 for ( ; itemIter != items.
end(); ++itemIter )
1953 itemGroup->
addItem( *itemIter );
1978 return ungroupedItems;
1994 for ( ; itemIt != groupedItems.
end(); ++itemIt )
1996 ungroupedItems << ( *itemIt );
2004 return ungroupedItems;
2007 void QgsComposition::updateZValues(
const bool addUndoCommands )
2014 if ( addUndoCommands )
2016 parentCommand =
new QUndoCommand(
tr(
"Item z-order changed" ) );
2024 if ( addUndoCommands )
2030 if ( addUndoCommands )
2037 if ( addUndoCommands )
2039 mUndoStack->
push( parentCommand );
2051 updateZValues(
false );
2056 if ( !mSnapToGrid || mSnapGridResolution <= 0 || !graphicsView() )
2062 int pageNr =
static_cast< int >( scenePoint.
y() / ( mPageHeight + mSpaceBetweenPages ) );
2063 double yOffset = pageNr * ( mPageHeight + mSpaceBetweenPages );
2064 double yPage = scenePoint.
y() - yOffset;
2067 int xRatio =
static_cast< int >(( scenePoint.
x() - mSnapGridOffsetX ) / mSnapGridResolution + 0.5 );
2068 int yRatio =
static_cast< int >(( yPage - mSnapGridOffsetY ) / mSnapGridResolution + 0.5 );
2070 double xSnapped = xRatio * mSnapGridResolution + mSnapGridOffsetX;
2071 double ySnapped = yRatio * mSnapGridResolution + mSnapGridOffsetY + yOffset;
2074 double viewScaleFactor = graphicsView()->
transform().
m11();
2075 double alignThreshold = mSnapTolerance / viewScaleFactor;
2077 if ( fabs( xSnapped - scenePoint.
x() ) > alignThreshold )
2080 xSnapped = scenePoint.
x();
2082 if ( fabs( ySnapped - scenePoint.
y() ) > alignThreshold )
2085 ySnapped = scenePoint.
y();
2088 return QPointF( xSnapped, ySnapped );
2094 QPen linePen( Qt::SolidLine );
2126 mGuidesVisible = visible;
2135 mPagesVisible = visible;
2142 double minSqrDist = DBL_MAX;
2144 double currentXCoord = 0;
2145 double currentYCoord = 0;
2146 double currentSqrDist = 0;
2147 double sqrTolerance = tolerance * tolerance;
2149 snappedItems.clear();
2152 for ( ; it != mSnapLines.
constEnd(); ++it )
2154 bool itemHorizontal =
qgsDoubleNear(( *it )->line().y2() - ( *it )->line().y1(), 0 );
2155 if ( horizontal && itemHorizontal )
2157 currentYCoord = ( *it )->line().y1();
2158 currentSqrDist = ( y - currentYCoord ) * ( y - currentYCoord );
2160 else if ( !horizontal && !itemHorizontal )
2162 currentXCoord = ( *it )->line().x1();
2163 currentSqrDist = ( x - currentXCoord ) * ( x - currentXCoord );
2170 if ( currentSqrDist < minSqrDist && currentSqrDist < sqrTolerance )
2173 minSqrDist = currentSqrDist;
2177 double itemTolerance = 0.0000001;
2183 for ( ; itemIt != itemList.
end(); ++itemIt )
2227 int QgsComposition::boundingRectOfSelectedItems(
QRectF& bRect )
2230 if ( selectedItems.
size() < 1 )
2237 double minX = currentItem->
pos().
x();
2238 double minY = currentItem->
pos().
y();
2239 double maxX = minX + currentItem->
rect().
width();
2240 double maxY = minY + currentItem->
rect().
height();
2242 double currentMinX, currentMinY, currentMaxX, currentMaxY;
2244 for (
int i = 1; i < selectedItems.
size(); ++i )
2246 currentItem = selectedItems.
at( i );
2247 currentMinX = currentItem->
pos().
x();
2248 currentMinY = currentItem->
pos().
y();
2249 currentMaxX = currentMinX + currentItem->
rect().
width();
2250 currentMaxY = currentMinY + currentItem->
rect().
height();
2252 if ( currentMinX < minX )
2254 if ( currentMaxX > maxX )
2256 if ( currentMinY < minY )
2258 if ( currentMaxY > maxY )
2281 mSnapGridResolution = r;
2287 mSnapGridOffsetX = offset;
2293 mSnapGridOffsetY = offset;
2313 mBoundingBoxesVisible = boundsVisible;
2315 if ( mSelectionHandles )
2317 mSelectionHandles->
update();
2329 void QgsComposition::loadSettings()
2335 gridStyleString = s.
value(
"/Composer/gridStyle",
"Dots" ).
toString();
2337 int gridRed, gridGreen, gridBlue, gridAlpha;
2338 gridRed = s.
value(
"/Composer/gridRed", 190 ).
toInt();
2339 gridGreen = s.
value(
"/Composer/gridGreen", 190 ).
toInt();
2340 gridBlue = s.
value(
"/Composer/gridBlue", 190 ).
toInt();
2341 gridAlpha = s.
value(
"/Composer/gridAlpha", 100 ).
toInt();
2342 QColor gridColor =
QColor( gridRed, gridGreen, gridBlue, gridAlpha );
2347 if ( gridStyleString ==
"Dots" )
2351 else if ( gridStyleString ==
"Crosses" )
2363 delete mActiveItemCommand;
2366 mActiveItemCommand =
nullptr;
2383 if ( mActiveItemCommand )
2388 mUndoStack->
push( mActiveItemCommand );
2393 delete mActiveItemCommand;
2395 mActiveItemCommand =
nullptr;
2401 delete mActiveItemCommand;
2402 mActiveItemCommand =
nullptr;
2407 delete mActiveMultiFrameCommand;
2411 mActiveMultiFrameCommand =
nullptr;
2428 if ( mActiveMultiFrameCommand )
2433 mUndoStack->
push( mActiveMultiFrameCommand );
2438 delete mActiveMultiFrameCommand;
2440 mActiveMultiFrameCommand =
nullptr;
2446 delete mActiveMultiFrameCommand;
2447 mActiveMultiFrameCommand =
nullptr;
2452 mMultiFrames.
insert( multiFrame );
2459 mMultiFrames.
remove( multiFrame );
2487 if ( setDefaultPreviewStyle )
2585 QgsDebugMsg(
QString(
"removeComposerItem called, createCommand:%1 removeGroupItems:%2" )
2586 .arg( createCommand ).arg( removeGroupItems ) );
2589 if ( itemGroup && removeGroupItems )
2596 tr(
"Remove item group" ) );
2597 connectAddRemoveCommandSignals( parentCommand );
2603 for ( ; it != groupedItems.
end(); ++it )
2608 connectAddRemoveCommandSignals( subcommand );
2618 if ( createCommand )
2633 if ( frameItem && multiFrame )
2638 if ( createCommand )
2641 multiFrame,
this,
tr(
"Multiframe removed" ) );
2659 connectAddRemoveCommandSignals( c );
2760 void QgsComposition::updatePaperItems()
2768 void QgsComposition::addPaperItem()
2772 double currentY = paperHeight * mPages.
size() + mPages.
size() * mSpaceBetweenPages;
2780 void QgsComposition::removePaperItems()
2782 qDeleteAll( mPages );
2786 void QgsComposition::deleteAndRemoveMultiFrames()
2788 qDeleteAll( mMultiFrames );
2789 mMultiFrames.
clear();
2820 return print( printer );
2825 if ( ddPageSizeActive() )
2839 bool pageExported =
false;
2840 if ( mPrintAsRaster )
2842 for (
int i = fromPage; i <= toPage; ++i )
2848 if (( pageExported && i > fromPage ) || startNewPage )
2857 p.
drawImage( targetArea, image, targetArea );
2859 pageExported =
true;
2863 if ( !mPrintAsRaster )
2865 for (
int i = fromPage; i <= toPage; ++i )
2871 if (( pageExported && i > fromPage ) || startNewPage )
2876 pageExported =
true;
2890 if ( evaluateDDPageSize && ddPageSizeActive() )
2905 bool ready = p.
begin( &printer );
2918 int resolution = mPrintResolution;
2923 resolution = ( imageSize.
width() / mPageWidth
2924 + imageSize.
height() / mPageHeight ) / 2.0 * 25.4;
2933 :
static_cast< int >( resolution * mPageWidth / 25.4 );
2935 :
static_cast< int >( resolution * mPageHeight / 25.4 );
2937 QImage image(
QSize( width, height ), QImage::Format_ARGB32 );
2952 int resolution = mPrintResolution;
2957 resolution = ( imageSize.
width() / rect.
width()
2967 :
static_cast< int >( resolution * rect.
width() / 25.4 );
2969 :
static_cast< int >( resolution * rect.
height() / 25.4 );
2971 QImage image(
QSize( width, height ), QImage::Format_ARGB32 );
2976 image.
fill( Qt::transparent );
2986 if ( mPages.
size() <= page )
3020 mPlotStyle = savedPlotStyle;
3026 modifiedStr.
replace(
'&',
"&" );
3027 modifiedStr.
replace(
'\"',
""" );
3028 modifiedStr.
replace(
'\'',
"'" );
3029 modifiedStr.
replace(
'<',
"<" );
3030 modifiedStr.
replace(
'>',
">" );
3040 return viewList.
at( 0 );
3049 if ( !mWorldFileMap )
3054 int pageNumber = mWorldFileMap->
page() - 1;
3055 double pageY = pageNumber * ( mPageHeight + mSpaceBetweenPages );
3056 QRectF pageRect( 0, pageY, mPageWidth, mPageHeight );
3064 if ( !mWorldFileMap )
3069 double destinationHeight = exportRegion.
height();
3070 double destinationWidth = exportRegion.
width();
3077 double xRatio = mapExtent.
width() / mapItemSceneRect.
width();
3078 double yRatio = mapExtent.
height() / mapItemSceneRect.
height();
3080 double xCenter = mapExtent.
center().
x();
3081 double yCenter = mapExtent.
center().
y();
3086 mapItemPos.
rx() -= exportRegion.
left();
3087 mapItemPos.
ry() -= exportRegion.
top();
3089 double xmin = mapExtent.
xMinimum() - mapItemPos.
x() * xRatio;
3090 double ymax = mapExtent.
yMaximum() + mapItemPos.
y() * yRatio;
3091 QgsRectangle paperExtent( xmin, ymax - destinationHeight * yRatio, xmin + destinationWidth * xRatio, ymax );
3093 double X0 = paperExtent.
xMinimum();
3094 double Y0 = paperExtent.
yMinimum();
3096 int widthPx =
static_cast< int >(
printResolution() * destinationWidth / 25.4 );
3097 int heightPx =
static_cast< int >(
printResolution() * destinationHeight / 25.4 );
3099 double Ww = paperExtent.
width() / widthPx;
3100 double Hh = paperExtent.
height() / heightPx;
3109 s[5] = Y0 + paperExtent.
height();
3113 r[0] = cos( alpha );
3114 r[1] = -sin( alpha );
3115 r[2] = xCenter * ( 1 - cos( alpha ) ) + yCenter * sin( alpha );
3116 r[3] = sin( alpha );
3117 r[4] = cos( alpha );
3118 r[5] = - xCenter * sin( alpha ) + yCenter * ( 1 - cos( alpha ) );
3121 a = r[0] * s[0] + r[1] * s[3];
3122 b = r[0] * s[1] + r[1] * s[4];
3123 c = r[0] * s[2] + r[1] * s[5] + r[2];
3124 d = r[3] * s[0] + r[4] * s[3];
3125 e = r[3] * s[1] + r[4] * s[4];
3126 f = r[3] * s[2] + r[4] * s[5] + r[5];
3139 bool atlasHasFeatures = mAtlasComposition.
beginRender();
3140 if ( ! atlasHasFeatures )
3152 bool QgsComposition::ddPageSizeActive()
const 3168 evalContext = scopedContext.
data();
3171 double pageWidth = mPageWidth;
3172 double pageHeight = mPageHeight;
3185 pageHeight = heightD;
3193 double widthD = exprVal.
toDouble( &ok );
3203 double heightD = exprVal.
toDouble( &ok );
3207 pageHeight = heightD;
3220 double heightD, widthD;
3223 heightD = qMax( pageHeight, pageWidth );
3224 widthD = qMin( pageHeight, pageWidth );
3228 heightD = qMin( pageHeight, pageWidth );
3229 widthD = qMax( pageHeight, pageWidth );
3232 pageHeight = heightD;
3249 if ( it != mDataDefinedProperties.
constEnd() )
3266 bool defaultVals = ( !active && !useExpression && expression.
isEmpty() && field.
isEmpty() );
3268 if ( mDataDefinedProperties.
contains( property ) )
3271 if ( it != mDataDefinedProperties.
constEnd() )
3280 else if ( !defaultVals )
3283 mDataDefinedProperties.
insert( property, dd );
3289 mCustomProperties.
setValue( key, value );
3294 return mCustomProperties.
value( key, defaultValue );
3299 mCustomProperties.
remove( key );
3304 return mCustomProperties.
keys();
3318 expressionValue.
clear();
3323 bool useFeature =
false;
3324 if ( mAtlasComposition.
enabled() )
3329 layerFields = atlasLayer->
fields();
3334 currentFeature = mAtlasComposition.
feature();
3339 QVariant result = dataDefinedValue(
property, useFeature ? ¤tFeature :
nullptr, layerFields, context, dataDefinedProperties );
3343 expressionValue = result;
3365 if ( it != dataDefinedProperties->
constEnd() )
3394 if ( it != dataDefinedProperties->
constEnd() )
3415 prepareDataDefinedExpression( dd, dataDefinedProperties, context );
3422 result = expr->
evaluate( &context );
3429 else if ( !useExpression && !field.
isEmpty() )
3457 for ( ; it != dataDefinedProperties->
constEnd(); ++it )
3459 it.
value()->prepareExpression( context );
3470 if ( mAtlasComposition.
enabled() )
3477 void QgsComposition::prepareAllDataDefinedExpressions()
3480 prepareDataDefinedExpression(
nullptr, &mDataDefinedProperties, *context.
data() );
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.
void composerItemGroupAdded(QgsComposerItemGroup *group)
Is emitted when a new item group has been added to the view.
A scale bar item that can be added to a map composition.
QUndoStack * undoStack()
Returns pointer to undo/redo command storage.
QDomNodeList elementsByTagName(const QString &tagname) const
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.
void setDotsPerMeterX(int x)
void setDotsPerMeterY(int y)
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.
int pageNumberAt(QPointF position) const
Returns the page number (0-based) given a coordinate.
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.
bool contains(const Key &key) const
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
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 render(QPainter *painter, const QRectF &target, const QRectF &source, Qt::AspectRatioMode aspectRatioMode)
void setResolution(int dpi)
QDomNode appendChild(const QDomNode &newChild)
void addItemToZList(QgsComposerItem *item)
Adds item to z list.
void addItemsFromXML(const QDomElement &elem, const QDomDocument &doc, QMap< QgsComposerMap *, int > *mapsToRestore=nullptr, bool addUndoCommands=false, QPointF *pos=nullptr, bool pasteInPlace=false)
Add items from XML representation to the graphics scene (for project file reading, pasting items from clipboard)
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from XML.
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.
void push_back(const T &value)
QList< QGraphicsItem * > selectedItems() const
void setPageStyleSymbol(QgsFillSymbolV2 *symbol)
Note: added in version 2.1.
static QgsExpressionContextScope * atlasScope(const QgsAtlasComposition *atlas)
Creates a new scope which contains variables and functions relating to a QgsAtlasComposition.
void assignFreeId()
Sets mId to a number not yet used in the composition.
void statusMsgChanged(const QString &message)
Is emitted when the composition has an updated status bar message for the composer window...
void setOutputFileName(const QString &fileName)
QString field() const
Get the field which this QgsDataDefined represents.
QString attribute(const QString &name, const QString &defValue) const
virtual void beginItemCommand(const QString &text)
QPointF snapPointToGrid(QPointF scenePoint) const
Snaps a scene coordinate point to grid.
void computeWorldFileParameters(double &a, double &b, double &c, double &d, double &e, double &f) const
Compute world file parameters.
void setResizeToContentsMargins(double marginTop, double marginRight, double marginBottom, double marginLeft)
Sets the resize to contents margins.
double yMaximum() const
Get the y maximum value (top side of rectangle)
GridStyle
Style to draw the snapping grid.
QgsFields fields() const
Returns the list of fields of this layer.
QList< QGraphicsItem * > items() const
void alignSelectedItemsTop()
void rebuildZList()
Rebuilds the z-order list, based on the current stacking of items in the composition.
QString toString(int indent) const
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.
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.
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...
const_iterator constBegin() const
const T & at(int i) const
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 setBackgroundBrush(const QBrush &brush)
void setSelectedItem(QgsComposerItem *item)
Clears any selected items and sets an item as the current selection.
void setPagesVisible(bool visible)
Sets whether the page items should be visible in the composition.
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.
static QDomElement saveSymbol(const QString &symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
bool enabled() const
Returns whether the atlas generation is enabled.
void setSceneRect(const QRectF &rect)
QgsExpression * expression()
void updateBounds()
Updates the scene bounds of the composition.
Container of fields for a vector layer.
A container for grouping several QgsComposerItems.
void resizeToContentsMargins(double &marginTop, double &marginRight, double &marginBottom, double &marginLeft) const
Returns the resize to contents margins.
void sendItemAddedSignal(QgsComposerItem *item)
Casts object to the proper subclass type and calls corresponding itemAdded signal.
QgsFeature feature() const
Returns the current atlas feature.
virtual void setSelected(bool s)
Set selected, selected item should be highlighted.
void savePreviousState()
Saves current item state as previous state.
const QgsComposerItem * getComposerItemByUuid(const QString &theUuid) const
Returns a composer item given its unique identifier.
const_iterator constFind(const Key &key) const
A composer command that merges together with other commands having the same context (=id)...
QDomElement documentElement() const
bool moveItemToBottom(QgsComposerItem *item)
void setCreateUndoCommands(bool enabled)
Sets whether undo commands should be created for interactions with the multiframe.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the composition.
const_iterator insert(const T &value)
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.
QRectF mapRectToScene(const QRectF &rect) const
void composerScaleBarAdded(QgsComposerScaleBar *scalebar)
Is emitted when new composer scale bar has been added.
void setDirty(bool b)
Set project as dirty (modified).
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 toDouble(bool *ok) const
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 setPaperSize(double width, double height, bool keepRelativeItemPosition=true)
Changes size of paper item.
void setStatusMessage(const QString &message)
Sets the status bar message for the composer window.
QString tr(const char *sourceText, const char *disambiguation, int n)
void remove(const QString &key)
Remove a key (entry) from the store.
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.
void adjust(qreal dx1, qreal dy1, qreal dx2, qreal dy2)
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.
void update(const QRectF &rect)
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.
double x() const
Get the x value of the point.
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.
QRectF pageItemBounds(int pageNumber, bool visibleOnly=false) const
Returns the bounding box of the items contained on a specified page.
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 setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the composition.
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.
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
QDomElement toElement() const
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)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Return value for the given key. If the key is not stored, default value will be used.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Reads the properties specific to an attribute table from xml.
void setUseExpression(bool use)
Controls if the field or the expression part is active.
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.
QString number(int n, int base)
void refreshItemsTriggered()
Is emitted when item in the composition must be refreshed.
bool beginRender()
Begins the rendering.
void setValue(const QString &key, const QVariant &value)
Add an entry to the store. If the entry with the keys exists already, it will be overwritten.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
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.
QVariant property(const char *name) const
int toInt(bool *ok) const
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
void removeItem(QGraphicsItem *item)
void cancelCommand()
Deletes current command.
void fill(uint pixelValue)
void setSnapGridOffsetX(const double offset)
#define QgsDebugMsgLevel(str, level)
bool containsChange() const
Returns true if previous state and after state are valid and different.
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 setAttribute(const QString &name, const QString &value)
void setField(const QString &field)
Set the field name which this QgsDataDefined represents.
void clear()
Clears all items from z-order list and resets the model.
QList< QGraphicsView * > views() const
void removeSnapLine(QGraphicsLineItem *line)
Remove custom snap line (and delete the object)
void addItem(QgsComposerItem *item) override
Adds an item to the group.
int toInt(bool *ok, int base) const
void alignSelectedItemsRight()
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QDomNodeList elementsByTagName(const QString &tagname) const
QStringList keys() const
Return list of stored keys.
Abstract base class for composer items with the ability to distribute the content to several frames (...
void resizePageToContents(double marginTop=0.0, double marginRight=0.0, double marginBottom=0.0, double marginLeft=0.0)
Resizes the composition page to fit the current contents of the composition.
int removeAll(const T &value)
const_iterator constEnd() const
void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties, const QgsExpressionContext *context=nullptr)
Refreshes a data defined property for the composition by reevaluating the property's value and redraw...
void setLine(const QLineF &line)
void addComposerTableFrame(QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame)
Adds composer tablev2 frame and advises composer to create a widget for it (through signal) ...
QPaintDevice * device() const
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 setWidthF(qreal width)
void removeComposerItem(QgsComposerItem *item, const bool createCommand=true, const bool removeGroupItems=true)
Remove item from the graphics scene.
QRectF compositionBounds(bool ignorePages=false, double margin=0.0) const
Calculates the bounds of all non-gui items in the composition.
const_iterator constEnd() const
void removeCustomProperty(const QString &key)
Remove a custom property from the composition.
bool loadFromTemplate(const QDomDocument &doc, QMap< QString, QString > *substitutionMap=nullptr, bool addUndoCommands=false, const bool clearComposition=true)
Load a template document.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets state from Dom document.
QRectF united(const QRectF &rectangle) const
void setPaperSize(PaperSize newPaperSize)
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.
void setColor(const QColor &color)
QImage printPageAsRaster(int page, QSize imageSize=QSize(), int dpi=0)
Renders a composer page to an image.
QStringList customProperties() const
Return list of keys stored in custom properties for composition.
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...
virtual QPaintEngine * paintEngine() const
void setPen(const QPen &pen)
const QgsComposerItem * getComposerItemById(const QString &theId) const
Returns a composer item given its text identifier.
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.
A composer command class for grouping / ungrouping composer items.
bool useExpression() const
Returns if the field or the expression part is active.
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.
QgsExpressionContext * createExpressionContext() const
Creates an expression context relating to the compositions's current state.
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 setFullPage(bool fp)
PreviewMode previewMode() const
virtual QgsFillSymbolV2 * clone() const override
void setLine(qreal x1, qreal y1, qreal x2, qreal y2)
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 setTopLeft(const QPointF &position)
void updateSettings()
Refreshes the composition when composer related options change.
void saveAfterState()
Saves current item state as after state.
const_iterator constBegin() const
static bool decodePresetPaperSize(const QString &presetString, double &width, double &height)
Decodes a string representing a preset page size.
bool setAtlasMode(const QgsComposition::AtlasMode mode)
Sets the current atlas mode of the composition.
int pageNumberForPoint(QPointF position) const
Returns the page number corresponding to a point in the composition.
void setPositionLock(const bool lock)
Locks / unlocks the item position for mouse drags.
void setOrientation(Orientation orientation)
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.
const Key key(const T &value) const
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.
QString & replace(int position, int n, QChar after)
void setGridStyle(const GridStyle s)
A composer command class for adding / removing composer items.
void selectNextByZOrder(const ZValueDirection direction)
QVariant value(const QString &key, const QVariant &defaultValue) const
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.
void drawImage(const QRectF &target, const QImage &image, const QRectF &source, QFlags< Qt::ImageConversionFlag > flags)
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.
bool remove(const T &value)
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)
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Write store contents to XML.
virtual void endItemCommand()
void readXMLMapSettings(const QDomElement &elem, const QDomDocument &doc)
Reads old (pre 2.2) map related atlas settings from xml.
void raiseSelectedItems()
QPointF positionOnPage(QPointF position) const
Returns the position within a page of a point in the composition.
Q_DECL_DEPRECATED bool prepareExpression(QgsVectorLayer *layer)
Prepares the expression using a vector layer.
bool expressionIsPrepared() const
Returns whether the data defined object's expression is prepared.
void addComposerHtmlFrame(QgsComposerHtml *html, QgsComposerFrame *frame)
Adds composer html frame and advises composer to create a widget for it (through signal) ...
QgsComposerItem * composerItemAt(QPointF position, const bool ignoreLocked=false) const
Returns the topmost composer item at a specified position.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
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
QDomElement firstChildElement(const QString &tagName) const
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 update(qreal x, qreal y, qreal w, qreal h)
void renderRect(QPainter *p, const QRectF &rect)
Renders a portion of the composition to a paint device.
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.
int page() const
Gets the page the item is currently on.
void selectedItemChanged(QgsComposerItem *selected)
Is emitted when selected item changed.
void renderPage(QPainter *p, int page)
Renders a full page to a paint device.
void setVisible(bool visible)
double y() const
Get the y value of the point.
QImage renderRectAsRaster(const QRectF &rect, QSize imageSize=QSize(), int dpi=0)
Renders a portion of the composition to an image.
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()
double toDouble(bool *ok) const
void composerHtmlFrameAdded(QgsComposerHtml *html, QgsComposerFrame *frame)
Is emitted when a new composer html has been added to the view.
iterator insert(const Key &key, const T &value)
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...
void removeAttribute(const QString &name)
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.
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.
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
void setBrush(const QBrush &brush)
friend class QgsComposerModel
bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false) override
Reads multiframe state information from a DOM element.
const_iterator constEnd() const
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)
QDomElement createElement(const QString &tagName)
void composerItems(QList< T * > &itemList)
Return composer items of a specific type.
const_iterator constBegin() const
void printResolutionChanged()
Is emitted when the compositions print resolution changes.
void setColorMode(ColorMode newColorMode)
void addItem(QGraphicsItem *item)
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)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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.
bool begin(QPaintDevice *device)
void setBottomRight(const QPointF &position)
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.
const QgsRectangle * currentMapExtent() const
Returns a pointer to the current map extent, which is either the original user specified extent or th...
QString evalErrorString() const
Returns evaluation error.
void setExpressionString(const QString &expr)
Sets the expression for this QgsDataDefined.
iterator find(const Key &key)
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 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)
static QgsComposition::PaperOrientation decodePaperOrientation(const QString &orientationString, bool &ok)
Decodes a string representing a paper orientation.
void push(QUndoCommand *cmd)
double height() const
Height of the rectangle.
virtual int type() const override
Return correct graphics item type.
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
QDomNode at(int index) const
void setSnapGridOffsetY(const double offset)
const T value(const Key &key) const
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.
static QgsExpressionContextScope * compositionScope(const QgsComposition *composition)
Creates a new scope which contains variables and functions relating to a QgsComposition.
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)