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 );
1067 if ( clearComposition )
1069 deleteAndRemoveMultiFrames();
1074 for ( ; itemIter != itemList.
end(); ++itemIter )
1078 if ( cItem && !pItem )
1085 mItemsModel->
clear();
1088 mUndoStack->
clear();
1092 if ( substitutionMap )
1096 for ( ; sIt != substitutionMap->
constEnd(); ++sIt )
1098 xmlString = xmlString.
replace(
'[' + sIt.
key() +
']', encodeStringForXML( sIt.
value() ) );
1102 int errorLine, errorColumn;
1103 if ( !importDoc.
setContent( xmlString, &errorMsg, &errorLine, &errorColumn ) )
1115 if ( clearComposition )
1118 if ( compositionElem.
isNull() )
1123 bool ok =
readXML( compositionElem, importDoc );
1136 for (
int i = 0; i < composerItemsNodes.
count(); ++i )
1138 QDomNode composerItemNode = composerItemsNodes.
at( i );
1151 if ( clearComposition )
1163 for (
int i = 0; i < composerItemList.
size(); ++i )
1174 minX = qMin( minX, x );
1175 minY = qMin( minY, y );
1188 bool addUndoCommands,
QPointF* pos,
bool pasteInPlace )
1190 QPointF* pasteInPlacePt =
nullptr;
1204 QPointF minItemPos = minPointFromXml( elem );
1207 pasteShiftPos = *pos - minItemPos;
1214 pasteInPlacePt =
new QPointF( 0,
pageNumberAt( *pos ) * ( mPageHeight + mSpaceBetweenPages ) );
1218 for (
int i = 0; i < composerLabelList.
size(); ++i )
1222 newLabel->
readXML( currentComposerLabelElem, doc );
1225 if ( pasteInPlacePt )
1228 newLabel->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1232 newLabel->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1235 lastPastedItem = newLabel;
1239 if ( addUndoCommands )
1246 for (
int i = 0; i < composerMapList.
size(); ++i )
1251 if ( mapsToRestore )
1256 newMap->
readXML( currentComposerMapElem, doc );
1259 if ( mapsToRestore )
1272 newMap->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1276 newMap->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1279 lastPastedItem = newMap;
1282 if ( addUndoCommands )
1297 for ( ; overviewIt != overviews.
end(); ++overviewIt )
1299 ( *overviewIt )->connectSignals();
1306 for (
int i = 0; i < composerArrowList.
size(); ++i )
1310 newArrow->
readXML( currentComposerArrowElem, doc );
1316 newArrow->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1320 newArrow->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1323 lastPastedItem = newArrow;
1327 if ( addUndoCommands )
1334 for (
int i = 0; i < composerScaleBarList.
size(); ++i )
1338 newScaleBar->
readXML( currentComposerScaleBarElem, doc );
1344 newScaleBar->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1348 newScaleBar->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1351 lastPastedItem = newScaleBar;
1355 if ( addUndoCommands )
1362 for (
int i = 0; i < composerShapeList.
size(); ++i )
1366 newShape->
readXML( currentComposerShapeElem, doc );
1374 newShape->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1378 newShape->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1381 lastPastedItem = newShape;
1385 if ( addUndoCommands )
1392 for (
int i = 0; i < composerPictureList.
size(); ++i )
1396 newPicture->
readXML( currentComposerPictureElem, doc );
1402 newPicture->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1406 newPicture->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1409 lastPastedItem = newPicture;
1413 if ( addUndoCommands )
1420 for (
int i = 0; i < composerLegendList.
size(); ++i )
1424 newLegend->
readXML( currentComposerLegendElem, doc );
1430 newLegend->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1434 newLegend->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1437 lastPastedItem = newLegend;
1441 if ( addUndoCommands )
1448 for (
int i = 0; i < composerTableList.
size(); ++i )
1452 newTable->
readXML( currentComposerTableElem, doc );
1458 newTable->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1462 newTable->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1465 lastPastedItem = newTable;
1469 if ( addUndoCommands )
1477 for (
int i = 0; i < composerHtmlList.
size(); ++i )
1481 newHtml->
readXML( currentHtmlElem, doc );
1494 for (
int i = 0; i < composerAttributeTableV2List.
size(); ++i )
1498 newTable->
readXML( currentTableElem, doc );
1515 for (
int i = 0; i < groupList.
size(); ++i )
1519 newGroup->
readXML( groupElem, doc );
1521 if ( addUndoCommands )
1532 if ( lastPastedItem )
1537 delete pasteInPlacePt;
1538 pasteInPlacePt =
nullptr;
1568 bool itemsRaised =
false;
1569 for ( ; it != selectedItems.
end(); ++it )
1571 itemsRaised = itemsRaised |
raiseItem( *it );
1605 if ( !selectedItems.
isEmpty() )
1607 previousSelectedItem = selectedItems.
at( 0 );
1610 if ( !previousSelectedItem )
1617 switch ( direction )
1627 if ( !selectedItem )
1642 bool itemsLowered =
false;
1643 for ( ; it != selectedItems.
end(); ++it )
1645 itemsLowered = itemsLowered |
lowerItem( *it );
1648 if ( !itemsLowered )
1669 bool itemsRaised =
false;
1670 for ( ; it != selectedItems.
end(); ++it )
1696 bool itemsLowered =
false;
1697 for ( ; it != selectedItems.
end(); ++it )
1702 if ( !itemsLowered )
1722 if ( selectedItems.
size() < 2 )
1728 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1733 double minXCoordinate = selectedItemBBox.
left();
1738 for ( ; align_it != selectedItems.
end(); ++align_it )
1742 ( *align_it )->setPos( minXCoordinate, ( *align_it )->pos().y() );
1745 mUndoStack->
push( parentCommand );
1752 if ( selectedItems.
size() < 2 )
1758 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1763 double averageXCoord = ( selectedItemBBox.
left() + selectedItemBBox.
right() ) / 2.0;
1768 for ( ; align_it != selectedItems.
end(); ++align_it )
1772 ( *align_it )->setPos( averageXCoord - ( *align_it )->rect().width() / 2.0, ( *align_it )->pos().y() );
1775 mUndoStack->
push( parentCommand );
1782 if ( selectedItems.
size() < 2 )
1788 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1793 double maxXCoordinate = selectedItemBBox.
right();
1798 for ( ; align_it != selectedItems.
end(); ++align_it )
1802 ( *align_it )->setPos( maxXCoordinate - ( *align_it )->rect().width(), ( *align_it )->pos().y() );
1805 mUndoStack->
push( parentCommand );
1812 if ( selectedItems.
size() < 2 )
1818 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1823 double minYCoordinate = selectedItemBBox.
top();
1827 for ( ; align_it != selectedItems.
end(); ++align_it )
1831 ( *align_it )->setPos(( *align_it )->pos().x(), minYCoordinate );
1834 mUndoStack->
push( parentCommand );
1841 if ( selectedItems.
size() < 2 )
1847 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1852 double averageYCoord = ( selectedItemBBox.
top() + selectedItemBBox.
bottom() ) / 2.0;
1855 for ( ; align_it != selectedItems.
end(); ++align_it )
1859 ( *align_it )->setPos(( *align_it )->pos().x(), averageYCoord - ( *align_it )->rect().height() / 2 );
1862 mUndoStack->
push( parentCommand );
1869 if ( selectedItems.
size() < 2 )
1875 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1880 double maxYCoord = selectedItemBBox.
bottom();
1883 for ( ; align_it != selectedItems.
end(); ++align_it )
1887 ( *align_it )->setPos(( *align_it )->pos().x(), maxYCoord - ( *align_it )->rect().height() );
1890 mUndoStack->
push( parentCommand );
1899 for ( ; itemIter != selectionList.
end(); ++itemIter )
1903 ( *itemIter )->setPositionLock(
true );
1908 mUndoStack->
push( parentCommand );
1923 for ( ; itemIt != itemList.
end(); ++itemIt )
1937 mUndoStack->
push( parentCommand );
1943 if ( items.
size() < 2 )
1953 for ( ; itemIter != items.
end(); ++itemIter )
1955 itemGroup->
addItem( *itemIter );
1980 return ungroupedItems;
1996 for ( ; itemIt != groupedItems.
end(); ++itemIt )
1998 ungroupedItems << ( *itemIt );
2006 return ungroupedItems;
2009 void QgsComposition::updateZValues(
const bool addUndoCommands )
2016 if ( addUndoCommands )
2018 parentCommand =
new QUndoCommand(
tr(
"Item z-order changed" ) );
2026 if ( addUndoCommands )
2032 if ( addUndoCommands )
2039 if ( addUndoCommands )
2041 mUndoStack->
push( parentCommand );
2053 updateZValues(
false );
2058 if ( !mSnapToGrid || mSnapGridResolution <= 0 || !graphicsView() )
2064 int pageNr =
static_cast< int >( scenePoint.
y() / ( mPageHeight + mSpaceBetweenPages ) );
2065 double yOffset = pageNr * ( mPageHeight + mSpaceBetweenPages );
2066 double yPage = scenePoint.
y() - yOffset;
2069 int xRatio =
static_cast< int >(( scenePoint.
x() - mSnapGridOffsetX ) / mSnapGridResolution + 0.5 );
2070 int yRatio =
static_cast< int >(( yPage - mSnapGridOffsetY ) / mSnapGridResolution + 0.5 );
2072 double xSnapped = xRatio * mSnapGridResolution + mSnapGridOffsetX;
2073 double ySnapped = yRatio * mSnapGridResolution + mSnapGridOffsetY + yOffset;
2076 double viewScaleFactor = graphicsView()->
transform().
m11();
2077 double alignThreshold = mSnapTolerance / viewScaleFactor;
2079 if ( fabs( xSnapped - scenePoint.
x() ) > alignThreshold )
2082 xSnapped = scenePoint.
x();
2084 if ( fabs( ySnapped - scenePoint.
y() ) > alignThreshold )
2087 ySnapped = scenePoint.
y();
2090 return QPointF( xSnapped, ySnapped );
2096 QPen linePen( Qt::SolidLine );
2128 mGuidesVisible = visible;
2137 mPagesVisible = visible;
2144 double minSqrDist = DBL_MAX;
2146 double currentXCoord = 0;
2147 double currentYCoord = 0;
2148 double currentSqrDist = 0;
2149 double sqrTolerance = tolerance * tolerance;
2151 snappedItems.clear();
2154 for ( ; it != mSnapLines.
constEnd(); ++it )
2156 bool itemHorizontal =
qgsDoubleNear(( *it )->line().y2() - ( *it )->line().y1(), 0 );
2157 if ( horizontal && itemHorizontal )
2159 currentYCoord = ( *it )->line().y1();
2160 currentSqrDist = ( y - currentYCoord ) * ( y - currentYCoord );
2162 else if ( !horizontal && !itemHorizontal )
2164 currentXCoord = ( *it )->line().x1();
2165 currentSqrDist = ( x - currentXCoord ) * ( x - currentXCoord );
2172 if ( currentSqrDist < minSqrDist && currentSqrDist < sqrTolerance )
2175 minSqrDist = currentSqrDist;
2179 double itemTolerance = 0.0000001;
2185 for ( ; itemIt != itemList.
end(); ++itemIt )
2229 int QgsComposition::boundingRectOfSelectedItems(
QRectF& bRect )
2232 if ( selectedItems.
size() < 1 )
2239 double minX = currentItem->
pos().
x();
2240 double minY = currentItem->
pos().
y();
2241 double maxX = minX + currentItem->
rect().
width();
2242 double maxY = minY + currentItem->
rect().
height();
2244 double currentMinX, currentMinY, currentMaxX, currentMaxY;
2246 for (
int i = 1; i < selectedItems.
size(); ++i )
2248 currentItem = selectedItems.
at( i );
2249 currentMinX = currentItem->
pos().
x();
2250 currentMinY = currentItem->
pos().
y();
2251 currentMaxX = currentMinX + currentItem->
rect().
width();
2252 currentMaxY = currentMinY + currentItem->
rect().
height();
2254 if ( currentMinX < minX )
2256 if ( currentMaxX > maxX )
2258 if ( currentMinY < minY )
2260 if ( currentMaxY > maxY )
2283 mSnapGridResolution = r;
2289 mSnapGridOffsetX = offset;
2295 mSnapGridOffsetY = offset;
2315 mBoundingBoxesVisible = boundsVisible;
2317 if ( mSelectionHandles )
2319 mSelectionHandles->
update();
2331 void QgsComposition::loadSettings()
2337 gridStyleString = s.
value(
"/Composer/gridStyle",
"Dots" ).
toString();
2339 int gridRed, gridGreen, gridBlue, gridAlpha;
2340 gridRed = s.
value(
"/Composer/gridRed", 190 ).
toInt();
2341 gridGreen = s.
value(
"/Composer/gridGreen", 190 ).
toInt();
2342 gridBlue = s.
value(
"/Composer/gridBlue", 190 ).
toInt();
2343 gridAlpha = s.
value(
"/Composer/gridAlpha", 100 ).
toInt();
2344 QColor gridColor =
QColor( gridRed, gridGreen, gridBlue, gridAlpha );
2349 if ( gridStyleString ==
"Dots" )
2353 else if ( gridStyleString ==
"Crosses" )
2365 delete mActiveItemCommand;
2368 mActiveItemCommand =
nullptr;
2385 if ( mActiveItemCommand )
2390 mUndoStack->
push( mActiveItemCommand );
2395 delete mActiveItemCommand;
2397 mActiveItemCommand =
nullptr;
2403 delete mActiveItemCommand;
2404 mActiveItemCommand =
nullptr;
2409 delete mActiveMultiFrameCommand;
2413 mActiveMultiFrameCommand =
nullptr;
2430 if ( mActiveMultiFrameCommand )
2435 mUndoStack->
push( mActiveMultiFrameCommand );
2440 delete mActiveMultiFrameCommand;
2442 mActiveMultiFrameCommand =
nullptr;
2448 delete mActiveMultiFrameCommand;
2449 mActiveMultiFrameCommand =
nullptr;
2454 mMultiFrames.
insert( multiFrame );
2461 mMultiFrames.
remove( multiFrame );
2489 if ( setDefaultPreviewStyle )
2587 QgsDebugMsg(
QString(
"removeComposerItem called, createCommand:%1 removeGroupItems:%2" )
2588 .arg( createCommand ).arg( removeGroupItems ) );
2591 if ( itemGroup && removeGroupItems )
2598 tr(
"Remove item group" ) );
2599 connectAddRemoveCommandSignals( parentCommand );
2605 for ( ; it != groupedItems.
end(); ++it )
2610 connectAddRemoveCommandSignals( subcommand );
2620 if ( createCommand )
2635 if ( frameItem && multiFrame )
2640 if ( createCommand )
2643 multiFrame,
this,
tr(
"Multiframe removed" ) );
2661 connectAddRemoveCommandSignals( c );
2762 void QgsComposition::updatePaperItems()
2770 void QgsComposition::addPaperItem()
2774 double currentY = paperHeight * mPages.
size() + mPages.
size() * mSpaceBetweenPages;
2782 void QgsComposition::removePaperItems()
2784 qDeleteAll( mPages );
2788 void QgsComposition::deleteAndRemoveMultiFrames()
2790 qDeleteAll( mMultiFrames );
2791 mMultiFrames.
clear();
2822 return print( printer );
2827 if ( ddPageSizeActive() )
2841 bool pageExported =
false;
2842 if ( mPrintAsRaster )
2844 for (
int i = fromPage; i <= toPage; ++i )
2850 if (( pageExported && i > fromPage ) || startNewPage )
2859 p.
drawImage( targetArea, image, targetArea );
2861 pageExported =
true;
2865 if ( !mPrintAsRaster )
2867 for (
int i = fromPage; i <= toPage; ++i )
2873 if (( pageExported && i > fromPage ) || startNewPage )
2878 pageExported =
true;
2892 if ( evaluateDDPageSize && ddPageSizeActive() )
2907 bool ready = p.
begin( &printer );
2920 int resolution = mPrintResolution;
2925 resolution = ( imageSize.
width() / mPageWidth
2926 + imageSize.
height() / mPageHeight ) / 2.0 * 25.4;
2935 :
static_cast< int >( resolution * mPageWidth / 25.4 );
2937 :
static_cast< int >( resolution * mPageHeight / 25.4 );
2939 QImage image(
QSize( width, height ), QImage::Format_ARGB32 );
2954 int resolution = mPrintResolution;
2959 resolution = ( imageSize.
width() / rect.
width()
2969 :
static_cast< int >( resolution * rect.
width() / 25.4 );
2971 :
static_cast< int >( resolution * rect.
height() / 25.4 );
2973 QImage image(
QSize( width, height ), QImage::Format_ARGB32 );
2978 image.
fill( Qt::transparent );
2988 if ( mPages.
size() <= page )
3022 mPlotStyle = savedPlotStyle;
3028 modifiedStr.
replace(
'&',
"&" );
3029 modifiedStr.
replace(
'\"',
""" );
3030 modifiedStr.
replace(
'\'',
"'" );
3031 modifiedStr.
replace(
'<',
"<" );
3032 modifiedStr.
replace(
'>',
">" );
3042 return viewList.
at( 0 );
3051 if ( !mWorldFileMap )
3056 int pageNumber = mWorldFileMap->
page() - 1;
3057 double pageY = pageNumber * ( mPageHeight + mSpaceBetweenPages );
3058 QRectF pageRect( 0, pageY, mPageWidth, mPageHeight );
3066 if ( !mWorldFileMap )
3071 double destinationHeight = exportRegion.
height();
3072 double destinationWidth = exportRegion.
width();
3079 double xRatio = mapExtent.
width() / mapItemSceneRect.
width();
3080 double yRatio = mapExtent.
height() / mapItemSceneRect.
height();
3082 double xCenter = mapExtent.
center().
x();
3083 double yCenter = mapExtent.
center().
y();
3088 mapItemPos.
rx() -= exportRegion.
left();
3089 mapItemPos.
ry() -= exportRegion.
top();
3091 double xmin = mapExtent.
xMinimum() - mapItemPos.
x() * xRatio;
3092 double ymax = mapExtent.
yMaximum() + mapItemPos.
y() * yRatio;
3093 QgsRectangle paperExtent( xmin, ymax - destinationHeight * yRatio, xmin + destinationWidth * xRatio, ymax );
3095 double X0 = paperExtent.
xMinimum();
3096 double Y0 = paperExtent.
yMinimum();
3098 int widthPx =
static_cast< int >(
printResolution() * destinationWidth / 25.4 );
3099 int heightPx =
static_cast< int >(
printResolution() * destinationHeight / 25.4 );
3101 double Ww = paperExtent.
width() / widthPx;
3102 double Hh = paperExtent.
height() / heightPx;
3111 s[5] = Y0 + paperExtent.
height();
3115 r[0] = cos( alpha );
3116 r[1] = -sin( alpha );
3117 r[2] = xCenter * ( 1 - cos( alpha ) ) + yCenter * sin( alpha );
3118 r[3] = sin( alpha );
3119 r[4] = cos( alpha );
3120 r[5] = - xCenter * sin( alpha ) + yCenter * ( 1 - cos( alpha ) );
3123 a = r[0] * s[0] + r[1] * s[3];
3124 b = r[0] * s[1] + r[1] * s[4];
3125 c = r[0] * s[2] + r[1] * s[5] + r[2];
3126 d = r[3] * s[0] + r[4] * s[3];
3127 e = r[3] * s[1] + r[4] * s[4];
3128 f = r[3] * s[2] + r[4] * s[5] + r[5];
3141 bool atlasHasFeatures = mAtlasComposition.
beginRender();
3142 if ( ! atlasHasFeatures )
3154 bool QgsComposition::ddPageSizeActive()
const 3170 evalContext = scopedContext.
data();
3173 double pageWidth = mPageWidth;
3174 double pageHeight = mPageHeight;
3187 pageHeight = heightD;
3195 double widthD = exprVal.
toDouble( &ok );
3205 double heightD = exprVal.
toDouble( &ok );
3209 pageHeight = heightD;
3222 double heightD, widthD;
3225 heightD = qMax( pageHeight, pageWidth );
3226 widthD = qMin( pageHeight, pageWidth );
3230 heightD = qMin( pageHeight, pageWidth );
3231 widthD = qMax( pageHeight, pageWidth );
3234 pageHeight = heightD;
3251 if ( it != mDataDefinedProperties.
constEnd() )
3268 bool defaultVals = ( !active && !useExpression && expression.
isEmpty() && field.
isEmpty() );
3270 if ( mDataDefinedProperties.
contains( property ) )
3273 if ( it != mDataDefinedProperties.
constEnd() )
3282 else if ( !defaultVals )
3285 mDataDefinedProperties.
insert( property, dd );
3291 mCustomProperties.
setValue( key, value );
3299 return mCustomProperties.
value( key, defaultValue );
3304 mCustomProperties.
remove( key );
3309 return mCustomProperties.
keys();
3323 expressionValue.
clear();
3328 bool useFeature =
false;
3329 if ( mAtlasComposition.
enabled() )
3334 layerFields = atlasLayer->
fields();
3339 currentFeature = mAtlasComposition.
feature();
3344 QVariant result = dataDefinedValue(
property, useFeature ? ¤tFeature :
nullptr, layerFields, context, dataDefinedProperties );
3348 expressionValue = result;
3370 if ( it != dataDefinedProperties->
constEnd() )
3399 if ( it != dataDefinedProperties->
constEnd() )
3420 prepareDataDefinedExpression( dd, dataDefinedProperties, context );
3427 result = expr->
evaluate( &context );
3434 else if ( !useExpression && !field.
isEmpty() )
3462 for ( ; it != dataDefinedProperties->
constEnd(); ++it )
3464 it.
value()->prepareExpression( context );
3475 if ( mAtlasComposition.
enabled() )
3482 void QgsComposition::prepareAllDataDefinedExpressions()
3485 prepareDataDefinedExpression(
nullptr, &mDataDefinedProperties, *context.
data() );
void lowerSelectedItems()
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.
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)
QgsComposerItemGroup * groupItems(QList< QgsComposerItem *> items)
Creates a new group from a list of composer items and adds it to the composition. ...
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets state from Dom document.
A rectangle specified with double values.
void setDotsPerMeterX(int x)
void setDotsPerMeterY(int y)
bool writeXML(QDomElement &composerElem, QDomDocument &doc)
Writes settings to xml (paper dimension)
QgsPoint center() const
Center point of the rectangle.
void setAllUnselected()
Clears any selected items in the composition.
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets state from Dom document.
void composerItems(QList< T *> &itemList)
Return composer items of a specific type.
bool containsChange() const
Returns true if previous state and after state are valid and different.
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'...
bool shouldExportPage(const int page) const
Returns whether a specified page number should be included in exports of the composition.
void render(QPainter *painter, const QRectF &target, const QRectF &source, Qt::AspectRatioMode aspectRatioMode)
void setResolution(int dpi)
QgsExpressionContext * createExpressionContext() const
Creates an expression context relating to the compositions's current state.
QRectF pageItemBounds(int pageNumber, bool visibleOnly=false) const
Returns the bounding box of the items contained on a specified page.
int itemPageNumber(const QgsComposerItem *) const
Returns on which page number (0-based) is displayed an item.
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.
bool expressionIsPrepared() const
Returns whether the data defined object's expression is prepared.
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 attribute(const QString &name, const QString &defValue) const
virtual void beginItemCommand(const QString &text)
void setResizeToContentsMargins(double marginTop, double marginRight, double marginBottom, double marginLeft)
Sets the resize to contents margins.
GridStyle
Style to draw the snapping grid.
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.
int pageNumberForPoint(QPointF position) const
Returns the page number corresponding to a point in the composition.
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.
int printResolution() const
static QgsFillSymbolV2 * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
void cache()
Create cache image.
const_iterator constBegin() const
bool pageIsEmpty(const int page) const
Returns whether a page is empty, ie, it contains no items except for the background paper item...
const T & at(int i) const
static void readDataDefinedPropertyMap(const QDomElement &itemElem, QMap< QgsComposerObject::DataDefinedProperty, QString > *dataDefinedNames, QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined * > *dataDefinedProperties)
Reads all data defined properties from xml.
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...
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the composition.
void removeItemFromZList(QgsComposerItem *item)
Removes item from z list.
static QDomElement saveSymbol(const QString &symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
QString evalErrorString() const
Returns evaluation error.
void setSceneRect(const QRectF &rect)
QgsExpression * expression()
int id() const
Get identification number.
int numPages() const
Returns the number of pages in the composition.
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.
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.
virtual void setSelected(bool s)
Set selected, selected item should be highlighted.
void savePreviousState()
Saves current item state as previous state.
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.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Write store contents to XML.
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
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)
QList< const QgsComposerMap * > composerMapItems() const
Returns pointers to all composer maps in the scene.
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.
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()
A table that displays attributes from a vector layer.
DataDefinedProperty
Data defined properties for different item types.
void variablesChanged()
Emitted whenever the expression variables stored in the composition have been changed.
void endRender()
Ends the rendering.
double y() const
Get the y value of the point.
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 useExpression() const
Returns if the field or the expression part is active.
QgsFields fields() const
Returns the list of fields of this layer.
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.
const QgsComposerItem * getComposerItemById(const QString &theId) const
Returns a composer item given its text identifier.
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...
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.
void setGridPen(const QPen &p)
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.
int page() const
Gets the page the item is currently on.
const QgsComposerItem * getComposerItemByUuid(const QString &theUuid) const
Returns a composer item given its unique identifier.
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.
QgsComposerItem * getComposerItemAbove(QgsComposerItem *item) const
Finds the next composer item above an item.
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.
QgsComposerItem * getComposerItemBelow(QgsComposerItem *item) const
Finds the next composer item below an item.
QVariant property(const char *name) const
int toInt(bool *ok) const
void removeItem(QGraphicsItem *item)
void cancelCommand()
Deletes current command.
void fill(uint pixelValue)
int pageNumberAt(QPointF position) const
Returns the page number (0-based) given a coordinate.
void setSnapGridOffsetX(const double offset)
#define QgsDebugMsgLevel(str, level)
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...
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.
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)
double width() const
Width of the rectangle.
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
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)
bool containsChange() const
Returns true if previous state and after state are valid and different.
void addComposerTableFrame(QgsComposerAttributeTableV2 *table, QgsComposerFrame *frame)
Adds composer tablev2 frame and advises composer to create a widget for it (through signal) ...
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QRectF compositionBounds(bool ignorePages=false, double margin=0.0) const
Calculates the bounds of all non-gui items in the composition.
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.
const_iterator constEnd() const
void removeCustomProperty(const QString &key)
Remove a custom property from the composition.
QString uuid() const
Get item identification name.
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.
void setColor(const QColor &color)
bool isDrawing() const
True if a draw is already in progress.
QImage printPageAsRaster(int page, QSize imageSize=QSize(), int dpi=0)
Renders a composer page to an image.
A composer command that merges together with other commands having the same context (=id) for multi f...
void setSnapGridResolution(const double r)
QStringList customProperties() const
Return list of keys stored in custom properties for composition.
QStringList keys() const
Return list of stored keys.
virtual QPaintEngine * paintEngine() const
void setPen(const QPen &pen)
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
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.
QgsComposerItem * composerItemAt(QPointF position, const bool ignoreLocked=false) const
Returns the topmost composer item at a specified position.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets state from Dom document.
void refreshItems()
Forces items in the composition to refresh.
void setUpdatesEnabled(bool enabled)
Sets whether updates to the composer map are enabled.
QPointF positionOnPage(QPointF position) const
Returns the position within a page of a point in the composition.
void setFullPage(bool fp)
virtual QgsFillSymbolV2 * clone() const override
void composerItemsOnPage(QList< T *> &itemList, const int pageNumber) const
Return composer items of a specific type on a specified page.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
void setLine(qreal x1, qreal y1, qreal x2, qreal y2)
void removeItem(QgsComposerItem *item)
Removes an item from the z-order list.
void resizeToContentsMargins(double &marginTop, double &marginRight, double &marginBottom, double &marginLeft) const
Returns the resize to contents margins.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets state from Dom document.
void setTopLeft(const QPointF &position)
QString field() const
Get the field which this QgsDataDefined represents.
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.
QgsComposerItem * getComposerItemAbove(QgsComposerItem *item) const
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 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...
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
int indexFromName(const QString &name) const
Look up field's index from name. Returns -1 on error.
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)
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)
virtual void endItemCommand()
void readXMLMapSettings(const QDomElement &elem, const QDomDocument &doc)
Reads old (pre 2.2) map related atlas settings from xml.
void raiseSelectedItems()
PreviewMode previewMode() const
int frameCount() const
Returns the number of frames associated with this multiframe.
QList< QgsComposerMapOverview *> asList() const
Returns a list of QgsComposerMapOverviews contained by the stack.
Q_DECL_DEPRECATED bool prepareExpression(QgsVectorLayer *layer)
Prepares the expression using a vector layer.
void addComposerHtmlFrame(QgsComposerHtml *html, QgsComposerFrame *frame)
Adds composer html frame and advises composer to create a widget for it (through signal) ...
QgsComposerMultiFrame * multiFrame() const
Returns the parent multiframe for the frame.
QPointF snapPointToGrid(QPointF scenePoint) const
Snaps a scene coordinate point to grid.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
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()
static double pointsToMM(const double pointSize)
Returns the size in mm corresponding to a font point size.
double xMinimum() const
Get the x minimum value (left side of rectangle)
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)
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.
double paperHeight() const
Height of paper item.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
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 yMaximum() const
Get the y maximum value (top side of rectangle)
double toDouble(bool *ok) const
double paperWidth() const
Width of paper item.
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...
int zOrderListSize() const
Returns the size of the z-order list, which includes items which may have been removed from the compo...
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.
QgsFeature feature() const
Returns the current atlas feature.
Q_DECL_DEPRECATED double pointFontSize(int pixelSize) const
Does the inverse calculation and returns points for mm.
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
QGraphicsLineItem * addSnapLine()
Add a custom snap line (can be horizontal or vertical)
QDomElement createElement(const QString &tagName)
bool positionLock() const
Returns whether position lock for mouse drags is enabled returns true if item is locked for mouse mov...
const_iterator constBegin() const
void printResolutionChanged()
Is emitted when the compositions print resolution changes.
void setColorMode(ColorMode newColorMode)
double mapRotation(QgsComposerObject::PropertyValueType valueType=QgsComposerObject::EvaluatedValue) const
Returns the rotation used for drawing the map within the composer item.
void addItem(QGraphicsItem *item)
void setPreviewMode(PreviewMode m)
bool raiseItem(QgsComposerItem *item)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setSnapToGridEnabled(const bool b)
bool reorderItemToTop(QgsComposerItem *item)
Moves an item to the top of the z-order list.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
Represents a vector layer which manages a vector based data sets.
bool begin(QPaintDevice *device)
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
void setBottomRight(const QPointF &position)
void move(double dx, double dy)
Moves item in canvas coordinates.
Q_DECL_DEPRECATED int pixelFontSize(double pointSize) const
Returns the mm font size for a font that has point size set.
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) ...
void computeWorldFileParameters(double &a, double &b, double &c, double &d, double &e, double &f) const
Compute world file parameters.
void addMultiFrame(QgsComposerMultiFrame *multiFrame)
Adds multiframe.
void addItemAtTop(QgsComposerItem *item)
Adds an item to the top of the composition z stack.
void setExpressionString(const QString &expr)
Sets the expression for this QgsDataDefined.
QString id() const
Get item's id (which is not necessarly unique)
const QgsRectangle * currentMapExtent() const
Returns a pointer to the current map extent, which is either the original user specified extent or th...
iterator find(const Key &key)
bool lowerItem(QgsComposerItem *item)
QgsComposerItem * getComposerItemBelow(QgsComposerItem *item) const
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)
double spaceBetweenPages() const
Returns the vertical space between pages in a composer view.
double x() const
Get the x value of the point.
bool enabled() const
Returns whether the atlas generation is enabled.
void addComposerLegend(QgsComposerLegend *legend)
Adds legend to the graphics scene and advices composer to create a widget for it (through signal) ...
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.