48 #include <QDomDocument> 49 #include <QDomElement> 50 #include <QGraphicsRectItem> 51 #include <QGraphicsView> 61 , mMapRenderer( mapRenderer )
62 , mMapSettings( mapRenderer->mapSettings() )
63 , mAtlasComposition( this )
70 , mMapRenderer( nullptr )
71 , mMapSettings( mapSettings )
72 , mAtlasComposition( this )
83 mSpaceBetweenPages = 10;
84 mPageStyleSymbol =
nullptr;
85 mPrintAsRaster =
false;
86 mGenerateWorldFile =
false;
87 mWorldFileMap =
nullptr;
88 mUseAdvancedEffects =
true;
92 mSnapGridResolution = 0;
95 mAlignmentSnap =
true;
96 mGuidesVisible =
true;
99 mBoundingBoxesVisible =
true;
100 mSelectionHandles =
nullptr;
101 mActiveItemCommand =
nullptr;
102 mActiveMultiFrameCommand =
nullptr;
104 mPreventCursorChange =
false;
105 mItemsModel =
nullptr;
108 mResizeToContentsMarginTop = 0;
109 mResizeToContentsMarginRight = 0;
110 mResizeToContentsMarginBottom = 0;
111 mResizeToContentsMarginLeft = 0;
128 connect( &mAtlasComposition, SIGNAL( toggled(
bool ) ),
this, SLOT( prepareAllDataDefinedExpressions() ) );
129 connect( &mAtlasComposition, SIGNAL( coverageLayerChanged(
QgsVectorLayer* ) ),
this, SLOT( prepareAllDataDefinedExpressions() ) );
132 createDefaultPageStyleSymbol();
141 mSelectionHandles->
hide();
144 mPrintResolution = 300;
194 deleteAndRemoveMultiFrames();
200 qDeleteAll( itemList );
203 qDeleteAll( mDataDefinedProperties );
204 mDataDefinedProperties.
clear();
211 delete mActiveItemCommand;
212 delete mActiveMultiFrameCommand;
213 delete mPageStyleSymbol;
217 void QgsComposition::loadDefaults()
220 mSnapGridResolution = settings.
value(
"/Composer/defaultSnapGridResolution", 10.0 ).
toDouble();
221 mSnapGridOffsetX = settings.
value(
"/Composer/defaultSnapGridOffsetX", 0 ).
toDouble();
222 mSnapGridOffsetY = settings.
value(
"/Composer/defaultSnapGridOffsetY", 0 ).
toDouble();
223 mSnapTolerance = settings.
value(
"/Composer/defaultSnapTolerancePixels", 5 ).
toInt();
238 for ( ; mapIt != maps.
end(); ++mapIt )
241 ( *mapIt )->update();
264 for ( ; itemIter != selectedItemList.
end(); ++itemIter )
281 evalContext = scopedContext.
data();
293 refreshPageSize( evalContext );
305 for ( ; itemIt != itemList.
end(); ++itemIt )
309 if (( composerItem && ( !paperItem || !ignorePages ) ) )
313 bounds = bounds.
united(( *itemIt )->sceneBoundingRect() );
315 bounds = ( *itemIt )->sceneBoundingRect();
319 if ( bounds.
isValid() && margin > 0.0 )
322 bounds.
adjust( -mPageWidth * margin, -mPageWidth * margin, mPageWidth * margin, mPageWidth * margin );
336 for ( ; itemIt != itemList.
end(); ++itemIt )
340 if ( composerItem && !paperItem &&
itemPageNumber( composerItem ) == pageNumber )
342 if ( visibleOnly && !composerItem->
isVisible() )
347 bounds = bounds.
united(( *itemIt )->sceneBoundingRect() );
349 bounds = ( *itemIt )->sceneBoundingRect();
363 if ( keepRelativeItemPosition )
368 for ( ; itemIt != itemList.
end(); ++itemIt )
382 for ( ; guideIt != guides->
end(); ++guideIt )
384 QLineF line = ( *guideIt )->line();
388 ( *guideIt )->
setLine( line.
x1(), 0, line.
x1(), totalHeight );
393 if ( keepRelativeItemPosition )
399 ( *guideIt )->setLine( 0, newY, width, newY );
404 ( *guideIt )->setLine( 0, line.
y1(),
width, line.
y1() );
412 for (
int i = 0; i < mPages.
size(); ++i )
414 mPages.
at( i )->setSceneRect(
QRectF( 0, currentY, width, height ) );
415 currentY += ( height + mSpaceBetweenPages );
438 double newWidth = bounds.
width() + marginLeft + marginRight;
439 double newHeight = bounds.
height() + marginTop + marginBottom;
443 double diffX = marginLeft - bounds.
left();
444 double diffY = marginTop - bounds.
top();
455 composerItem->
move( diffX, diffY );
466 guide->
setLine( line.
x1() + diffX, 0, line.
x1() + diffX, newHeight );
471 guide->
setLine( 0, line.
y1() + diffY, newWidth, line.
y1() + diffY );
478 mResizeToContentsMarginTop = marginTop;
479 mResizeToContentsMarginRight = marginRight;
480 mResizeToContentsMarginBottom = marginBottom;
481 mResizeToContentsMarginLeft = marginLeft;
486 marginTop = mResizeToContentsMarginTop;
487 marginRight = mResizeToContentsMarginRight;
488 marginBottom = mResizeToContentsMarginBottom;
489 marginLeft = mResizeToContentsMarginLeft;
495 int desiredPages =
pages;
503 int pagesD = exprVal.
toInt( &ok );
507 desiredPages = pagesD;
511 int diff = desiredPages - currentPages;
514 for (
int i = 0; i < diff; ++i )
522 for (
int i = 0; i < diff; ++i )
524 delete mPages.
last();
532 double totalHeight = ( mPageHeight +
spaceBetweenPages() ) * ( pages - 1 ) + mPageHeight;
533 for ( ; guideIt != guides->
end(); ++guideIt )
535 QLineF line = ( *guideIt )->line();
539 ( *guideIt )->
setLine( line.
x1(), 0, line.
x1(), totalHeight );
551 return mPages.
size();
563 for ( ; itemIt != items.
constEnd(); ++itemIt )
579 if ( page >
numPages() || page < 1 )
590 for ( ; frameIt != frames.
constEnd(); ++frameIt )
592 if (( *frameIt )->hidePageIfEmpty() && ( *frameIt )->isEmpty() )
603 delete mPageStyleSymbol;
608 void QgsComposition::createDefaultPageStyleSymbol()
610 delete mPageStyleSymbol;
612 properties.
insert(
"color",
"white" );
613 properties.
insert(
"style",
"solid" );
614 properties.
insert(
"style_border",
"no" );
615 properties.
insert(
"joinstyle",
"miter" );
639 pageNumber = pageNumber < 1 ? 1 : pageNumber;
640 pageNumber = pageNumber > mPages.
size() ? mPages.
size() : pageNumber;
658 itemList =
items( position, Qt::IntersectsItemShape, Qt::DescendingOrder );
661 bool foundBelowItem =
false;
662 for ( ; itemIt != itemList.
end(); ++itemIt )
666 if ( composerItem && !paperItem )
670 if (( ! belowItem || foundBelowItem ) && ( !ignoreLocked || !composerItem->
positionLock() ) )
676 if ( composerItem == belowItem )
679 foundBelowItem =
true;
704 for ( ; itemIter != graphicsItemList.
end(); ++itemIter )
707 if ( composerItem && ( includeLockedItems || !composerItem->
positionLock() ) )
709 composerItemList.
push_back( composerItem );
713 return composerItemList;
722 for ( ; itemIt != itemList.
end(); ++itemIt )
738 for ( ; itemIt != itemList.
end(); ++itemIt )
743 if ( composerMap->
id() == id )
775 for ( ; itemIt != itemList.
end(); ++itemIt )
780 if ( mypItem->
id() == theId )
795 if ( inAllComposers )
797 composers = QgisApp::instance()->printComposers();
805 for ( ; it != composers.
constEnd(); ++it )
809 for ( ; itemIt != itemList.
end(); ++itemIt )
814 if ( mypItem->
uuid() == theUuid )
830 for ( ; itemIt != itemList.
end(); ++itemIt )
835 if ( mypItem->
uuid() == theUuid )
847 mPrintResolution = dpi;
854 mUseAdvancedEffects = effectsEnabled;
859 for ( ; itemIt != itemList.
constEnd(); ++itemIt )
881 if ( composerElem.
isNull() )
915 compositionElem.
setAttribute(
"showPages", mPagesVisible );
919 for ( ; snapLineIt != mSnapLines.
constEnd(); ++snapLineIt )
922 QLineF line = ( *snapLineIt )->line();
930 compositionElem.
setAttribute(
"printResolution", mPrintResolution );
931 compositionElem.
setAttribute(
"printAsRaster", mPrintAsRaster );
933 compositionElem.
setAttribute(
"generateWorldFile", mGenerateWorldFile ? 1 : 0 );
934 if ( mGenerateWorldFile && mWorldFileMap )
936 compositionElem.
setAttribute(
"worldFileMap", mWorldFileMap->
id() );
939 compositionElem.
setAttribute(
"alignmentSnap", mAlignmentSnap ? 1 : 0 );
940 compositionElem.
setAttribute(
"guidesVisible", mGuidesVisible ? 1 : 0 );
941 compositionElem.
setAttribute(
"smartGuides", mSmartGuides ? 1 : 0 );
942 compositionElem.
setAttribute(
"snapTolerancePixels", mSnapTolerance );
944 compositionElem.
setAttribute(
"resizeToContentsMarginTop", mResizeToContentsMarginTop );
945 compositionElem.
setAttribute(
"resizeToContentsMarginRight", mResizeToContentsMarginRight );
946 compositionElem.
setAttribute(
"resizeToContentsMarginBottom", mResizeToContentsMarginBottom );
947 compositionElem.
setAttribute(
"resizeToContentsMarginLeft", mResizeToContentsMarginLeft );
952 for ( ; itemIt != itemList.
constEnd(); ++itemIt )
959 composerItem->
writeXML( compositionElem, doc );
966 for ( ; multiFrameIt != mMultiFrames.
constEnd(); ++multiFrameIt )
968 ( *multiFrameIt )->writeXML( compositionElem, doc );
976 mCustomProperties.
writeXml( compositionElem, doc );
984 if ( compositionElem.
isNull() )
990 bool widthConversionOk, heightConversionOk;
991 mPageWidth = compositionElem.
attribute(
"paperWidth" ).
toDouble( &widthConversionOk );
992 mPageHeight = compositionElem.
attribute(
"paperHeight" ).
toDouble( &heightConversionOk );
997 if ( !pageStyleSymbolElem.
isNull() )
999 delete mPageStyleSymbol;
1000 mPageStyleSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( pageStyleSymbolElem );
1003 if ( widthConversionOk && heightConversionOk )
1006 for (
int i = 0; i <
numPages; ++i )
1013 mSnapToGrid = compositionElem.
attribute(
"snapping",
"0" ).
toInt() == 0 ?
false :
true;
1014 mGridVisible = compositionElem.
attribute(
"gridVisible",
"0" ).
toInt() == 0 ?
false :
true;
1016 mSnapGridResolution = compositionElem.
attribute(
"snapGridResolution" ).
toDouble();
1020 mAlignmentSnap = compositionElem.
attribute(
"alignmentSnap",
"1" ).
toInt() == 0 ?
false :
true;
1021 mGuidesVisible = compositionElem.
attribute(
"guidesVisible",
"1" ).
toInt() == 0 ?
false :
true;
1022 mSmartGuides = compositionElem.
attribute(
"smartGuides",
"1" ).
toInt() == 0 ?
false :
true;
1023 mSnapTolerance = compositionElem.
attribute(
"snapTolerancePixels",
"10" ).
toInt();
1025 mResizeToContentsMarginTop = compositionElem.
attribute(
"resizeToContentsMarginTop",
"0" ).
toDouble();
1026 mResizeToContentsMarginRight = compositionElem.
attribute(
"resizeToContentsMarginRight",
"0" ).
toDouble();
1027 mResizeToContentsMarginBottom = compositionElem.
attribute(
"resizeToContentsMarginBottom",
"0" ).
toDouble();
1028 mResizeToContentsMarginLeft = compositionElem.
attribute(
"resizeToContentsMarginLeft",
"0" ).
toDouble();
1032 for (
int i = 0; i < snapLineNodes.
size(); ++i )
1040 snapItem->
setLine( x1, y1, x2, y2 );
1043 mPagesVisible = ( compositionElem.
attribute(
"showPages",
"1" ) !=
"0" );
1044 mPrintAsRaster = compositionElem.
attribute(
"printAsRaster" ).
toInt();
1045 mPrintResolution = compositionElem.
attribute(
"printResolution",
"300" ).
toInt();
1047 mGenerateWorldFile = compositionElem.
attribute(
"generateWorldFile",
"0" ).
toInt() == 1 ?
true :
false;
1053 mCustomProperties.
readXml( compositionElem );
1064 if ( clearComposition )
1066 deleteAndRemoveMultiFrames();
1071 for ( ; itemIter != itemList.
end(); ++itemIter )
1075 if ( cItem && !pItem )
1082 mItemsModel->
clear();
1085 mUndoStack->
clear();
1089 if ( substitutionMap )
1093 for ( ; sIt != substitutionMap->
constEnd(); ++sIt )
1095 xmlString = xmlString.
replace(
'[' + sIt.
key() +
']', encodeStringForXML( sIt.
value() ) );
1099 int errorLine, errorColumn;
1100 if ( !importDoc.
setContent( xmlString, &errorMsg, &errorLine, &errorColumn ) )
1112 if ( clearComposition )
1115 if ( compositionElem.
isNull() )
1120 bool ok =
readXML( compositionElem, importDoc );
1133 for (
int i = 0; i < composerItemsNodes.
count(); ++i )
1135 QDomNode composerItemNode = composerItemsNodes.
at( i );
1148 if ( clearComposition )
1160 for (
int i = 0; i < composerItemList.
size(); ++i )
1171 minX = qMin( minX, x );
1172 minY = qMin( minY, y );
1185 bool addUndoCommands,
QPointF* pos,
bool pasteInPlace )
1187 QPointF* pasteInPlacePt =
nullptr;
1201 QPointF minItemPos = minPointFromXml( elem );
1204 pasteShiftPos = *pos - minItemPos;
1211 pasteInPlacePt =
new QPointF( 0,
pageNumberAt( *pos ) * ( mPageHeight + mSpaceBetweenPages ) );
1215 for (
int i = 0; i < composerLabelList.
size(); ++i )
1219 newLabel->
readXML( currentComposerLabelElem, doc );
1222 if ( pasteInPlacePt )
1225 newLabel->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1229 newLabel->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1232 lastPastedItem = newLabel;
1236 if ( addUndoCommands )
1243 for (
int i = 0; i < composerMapList.
size(); ++i )
1248 if ( mapsToRestore )
1253 newMap->
readXML( currentComposerMapElem, doc );
1256 if ( mapsToRestore )
1269 newMap->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1273 newMap->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1276 lastPastedItem = newMap;
1279 if ( addUndoCommands )
1294 for ( ; overviewIt != overviews.
end(); ++overviewIt )
1296 ( *overviewIt )->connectSignals();
1303 for (
int i = 0; i < composerArrowList.
size(); ++i )
1307 newArrow->
readXML( currentComposerArrowElem, doc );
1313 newArrow->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1317 newArrow->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1320 lastPastedItem = newArrow;
1324 if ( addUndoCommands )
1331 for (
int i = 0; i < composerScaleBarList.
size(); ++i )
1335 newScaleBar->
readXML( currentComposerScaleBarElem, doc );
1341 newScaleBar->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1345 newScaleBar->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1348 lastPastedItem = newScaleBar;
1352 if ( addUndoCommands )
1359 for (
int i = 0; i < composerShapeList.
size(); ++i )
1363 newShape->
readXML( currentComposerShapeElem, doc );
1371 newShape->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1375 newShape->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1378 lastPastedItem = newShape;
1382 if ( addUndoCommands )
1389 for (
int i = 0; i < composerPictureList.
size(); ++i )
1393 newPicture->
readXML( currentComposerPictureElem, doc );
1399 newPicture->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1403 newPicture->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1406 lastPastedItem = newPicture;
1410 if ( addUndoCommands )
1417 for (
int i = 0; i < composerLegendList.
size(); ++i )
1421 newLegend->
readXML( currentComposerLegendElem, doc );
1427 newLegend->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1431 newLegend->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1434 lastPastedItem = newLegend;
1438 if ( addUndoCommands )
1445 for (
int i = 0; i < composerTableList.
size(); ++i )
1449 newTable->
readXML( currentComposerTableElem, doc );
1455 newTable->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1459 newTable->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1462 lastPastedItem = newTable;
1466 if ( addUndoCommands )
1474 for (
int i = 0; i < composerHtmlList.
size(); ++i )
1478 newHtml->
readXML( currentHtmlElem, doc );
1491 for (
int i = 0; i < composerAttributeTableV2List.
size(); ++i )
1495 newTable->
readXML( currentTableElem, doc );
1512 for (
int i = 0; i < groupList.
size(); ++i )
1516 newGroup->
readXML( groupElem, doc );
1525 if ( lastPastedItem )
1530 delete pasteInPlacePt;
1531 pasteInPlacePt =
nullptr;
1561 bool itemsRaised =
false;
1562 for ( ; it != selectedItems.
end(); ++it )
1564 itemsRaised = itemsRaised |
raiseItem( *it );
1598 if ( !selectedItems.
isEmpty() )
1600 previousSelectedItem = selectedItems.
at( 0 );
1603 if ( !previousSelectedItem )
1610 switch ( direction )
1620 if ( !selectedItem )
1635 bool itemsLowered =
false;
1636 for ( ; it != selectedItems.
end(); ++it )
1638 itemsLowered = itemsLowered |
lowerItem( *it );
1641 if ( !itemsLowered )
1662 bool itemsRaised =
false;
1663 for ( ; it != selectedItems.
end(); ++it )
1689 bool itemsLowered =
false;
1690 for ( ; it != selectedItems.
end(); ++it )
1695 if ( !itemsLowered )
1715 if ( selectedItems.
size() < 2 )
1721 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1726 double minXCoordinate = selectedItemBBox.
left();
1731 for ( ; align_it != selectedItems.
end(); ++align_it )
1735 ( *align_it )->setPos( minXCoordinate, ( *align_it )->pos().y() );
1738 mUndoStack->
push( parentCommand );
1745 if ( selectedItems.
size() < 2 )
1751 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1756 double averageXCoord = ( selectedItemBBox.
left() + selectedItemBBox.
right() ) / 2.0;
1761 for ( ; align_it != selectedItems.
end(); ++align_it )
1765 ( *align_it )->setPos( averageXCoord - ( *align_it )->rect().width() / 2.0, ( *align_it )->pos().y() );
1768 mUndoStack->
push( parentCommand );
1775 if ( selectedItems.
size() < 2 )
1781 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1786 double maxXCoordinate = selectedItemBBox.
right();
1791 for ( ; align_it != selectedItems.
end(); ++align_it )
1795 ( *align_it )->setPos( maxXCoordinate - ( *align_it )->rect().width(), ( *align_it )->pos().y() );
1798 mUndoStack->
push( parentCommand );
1805 if ( selectedItems.
size() < 2 )
1811 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1816 double minYCoordinate = selectedItemBBox.
top();
1820 for ( ; align_it != selectedItems.
end(); ++align_it )
1824 ( *align_it )->setPos(( *align_it )->pos().x(), minYCoordinate );
1827 mUndoStack->
push( parentCommand );
1834 if ( selectedItems.
size() < 2 )
1840 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1845 double averageYCoord = ( selectedItemBBox.
top() + selectedItemBBox.
bottom() ) / 2.0;
1848 for ( ; align_it != selectedItems.
end(); ++align_it )
1852 ( *align_it )->setPos(( *align_it )->pos().x(), averageYCoord - ( *align_it )->rect().height() / 2 );
1855 mUndoStack->
push( parentCommand );
1862 if ( selectedItems.
size() < 2 )
1868 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1873 double maxYCoord = selectedItemBBox.
bottom();
1876 for ( ; align_it != selectedItems.
end(); ++align_it )
1880 ( *align_it )->setPos(( *align_it )->pos().x(), maxYCoord - ( *align_it )->rect().height() );
1883 mUndoStack->
push( parentCommand );
1892 for ( ; itemIter != selectionList.
end(); ++itemIter )
1896 ( *itemIter )->setPositionLock(
true );
1901 mUndoStack->
push( parentCommand );
1916 for ( ; itemIt != itemList.
end(); ++itemIt )
1930 mUndoStack->
push( parentCommand );
1936 if ( items.
size() < 2 )
1945 for ( ; itemIter != items.
end(); ++itemIter )
1947 itemGroup->
addItem( *itemIter );
1959 return ungroupedItems;
1964 for ( ; itemIt != groupedItems.
end(); ++itemIt )
1966 ungroupedItems << ( *itemIt );
1975 return ungroupedItems;
1978 void QgsComposition::updateZValues(
const bool addUndoCommands )
1985 if ( addUndoCommands )
1987 parentCommand =
new QUndoCommand(
tr(
"Item z-order changed" ) );
1995 if ( addUndoCommands )
2001 if ( addUndoCommands )
2008 if ( addUndoCommands )
2010 mUndoStack->
push( parentCommand );
2022 updateZValues(
false );
2027 if ( !mSnapToGrid || mSnapGridResolution <= 0 || !graphicsView() )
2033 int pageNr =
static_cast< int >( scenePoint.
y() / ( mPageHeight + mSpaceBetweenPages ) );
2034 double yOffset = pageNr * ( mPageHeight + mSpaceBetweenPages );
2035 double yPage = scenePoint.
y() - yOffset;
2038 int xRatio =
static_cast< int >(( scenePoint.
x() - mSnapGridOffsetX ) / mSnapGridResolution + 0.5 );
2039 int yRatio =
static_cast< int >(( yPage - mSnapGridOffsetY ) / mSnapGridResolution + 0.5 );
2041 double xSnapped = xRatio * mSnapGridResolution + mSnapGridOffsetX;
2042 double ySnapped = yRatio * mSnapGridResolution + mSnapGridOffsetY + yOffset;
2045 double viewScaleFactor = graphicsView()->
transform().
m11();
2046 double alignThreshold = mSnapTolerance / viewScaleFactor;
2048 if ( fabs( xSnapped - scenePoint.
x() ) > alignThreshold )
2051 xSnapped = scenePoint.
x();
2053 if ( fabs( ySnapped - scenePoint.
y() ) > alignThreshold )
2056 ySnapped = scenePoint.
y();
2059 return QPointF( xSnapped, ySnapped );
2065 QPen linePen( Qt::SolidLine );
2097 mGuidesVisible = visible;
2106 mPagesVisible = visible;
2113 double minSqrDist = DBL_MAX;
2115 double currentXCoord = 0;
2116 double currentYCoord = 0;
2117 double currentSqrDist = 0;
2118 double sqrTolerance = tolerance * tolerance;
2120 snappedItems.clear();
2123 for ( ; it != mSnapLines.
constEnd(); ++it )
2125 bool itemHorizontal =
qgsDoubleNear(( *it )->line().y2() - ( *it )->line().y1(), 0 );
2126 if ( horizontal && itemHorizontal )
2128 currentYCoord = ( *it )->line().y1();
2129 currentSqrDist = ( y - currentYCoord ) * ( y - currentYCoord );
2131 else if ( !horizontal && !itemHorizontal )
2133 currentXCoord = ( *it )->line().x1();
2134 currentSqrDist = ( x - currentXCoord ) * ( x - currentXCoord );
2141 if ( currentSqrDist < minSqrDist && currentSqrDist < sqrTolerance )
2144 minSqrDist = currentSqrDist;
2148 double itemTolerance = 0.0000001;
2154 for ( ; itemIt != itemList.
end(); ++itemIt )
2198 int QgsComposition::boundingRectOfSelectedItems(
QRectF& bRect )
2201 if ( selectedItems.
size() < 1 )
2208 double minX = currentItem->
pos().
x();
2209 double minY = currentItem->
pos().
y();
2210 double maxX = minX + currentItem->
rect().
width();
2211 double maxY = minY + currentItem->
rect().
height();
2213 double currentMinX, currentMinY, currentMaxX, currentMaxY;
2215 for (
int i = 1; i < selectedItems.
size(); ++i )
2217 currentItem = selectedItems.
at( i );
2218 currentMinX = currentItem->
pos().
x();
2219 currentMinY = currentItem->
pos().
y();
2220 currentMaxX = currentMinX + currentItem->
rect().
width();
2221 currentMaxY = currentMinY + currentItem->
rect().
height();
2223 if ( currentMinX < minX )
2225 if ( currentMaxX > maxX )
2227 if ( currentMinY < minY )
2229 if ( currentMaxY > maxY )
2252 mSnapGridResolution = r;
2258 mSnapGridOffsetX = offset;
2264 mSnapGridOffsetY = offset;
2284 mBoundingBoxesVisible = boundsVisible;
2286 if ( mSelectionHandles )
2288 mSelectionHandles->
update();
2300 void QgsComposition::loadSettings()
2306 gridStyleString = s.
value(
"/Composer/gridStyle",
"Dots" ).
toString();
2308 int gridRed, gridGreen, gridBlue, gridAlpha;
2309 gridRed = s.
value(
"/Composer/gridRed", 190 ).
toInt();
2310 gridGreen = s.
value(
"/Composer/gridGreen", 190 ).
toInt();
2311 gridBlue = s.
value(
"/Composer/gridBlue", 190 ).
toInt();
2312 gridAlpha = s.
value(
"/Composer/gridAlpha", 100 ).
toInt();
2313 QColor gridColor =
QColor( gridRed, gridGreen, gridBlue, gridAlpha );
2318 if ( gridStyleString ==
"Dots" )
2322 else if ( gridStyleString ==
"Crosses" )
2334 delete mActiveItemCommand;
2337 mActiveItemCommand =
nullptr;
2354 if ( mActiveItemCommand )
2359 mUndoStack->
push( mActiveItemCommand );
2364 delete mActiveItemCommand;
2366 mActiveItemCommand =
nullptr;
2372 delete mActiveItemCommand;
2373 mActiveItemCommand =
nullptr;
2378 delete mActiveMultiFrameCommand;
2382 mActiveMultiFrameCommand =
nullptr;
2399 if ( mActiveMultiFrameCommand )
2404 mUndoStack->
push( mActiveMultiFrameCommand );
2409 delete mActiveMultiFrameCommand;
2411 mActiveMultiFrameCommand =
nullptr;
2417 delete mActiveMultiFrameCommand;
2418 mActiveMultiFrameCommand =
nullptr;
2423 mMultiFrames.
insert( multiFrame );
2430 mMultiFrames.
remove( multiFrame );
2458 if ( setDefaultPreviewStyle )
2555 if ( itemGroup && removeGroupItems )
2562 for ( ; it != groupedItems.
end(); ++it )
2565 connectAddRemoveCommandSignals( subcommand );
2577 if ( createCommand )
2598 if ( frameItem && multiFrame )
2603 if ( createCommand )
2606 multiFrame,
this,
tr(
"Multiframe removed" ) );
2624 connectAddRemoveCommandSignals( c );
2720 void QgsComposition::updatePaperItems()
2728 void QgsComposition::addPaperItem()
2732 double currentY = paperHeight * mPages.
size() + mPages.
size() * mSpaceBetweenPages;
2740 void QgsComposition::removePaperItems()
2742 qDeleteAll( mPages );
2746 void QgsComposition::deleteAndRemoveMultiFrames()
2748 qDeleteAll( mMultiFrames );
2749 mMultiFrames.
clear();
2780 return print( printer );
2785 if ( ddPageSizeActive() )
2799 bool pageExported =
false;
2800 if ( mPrintAsRaster )
2802 for (
int i = fromPage; i <= toPage; ++i )
2808 if (( pageExported && i > fromPage ) || startNewPage )
2817 p.
drawImage( targetArea, image, targetArea );
2819 pageExported =
true;
2823 if ( !mPrintAsRaster )
2825 for (
int i = fromPage; i <= toPage; ++i )
2831 if (( pageExported && i > fromPage ) || startNewPage )
2836 pageExported =
true;
2850 if ( evaluateDDPageSize && ddPageSizeActive() )
2865 bool ready = p.
begin( &printer );
2878 int resolution = mPrintResolution;
2883 resolution = ( imageSize.
width() / mPageWidth
2884 + imageSize.
height() / mPageHeight ) / 2.0 * 25.4;
2893 :
static_cast< int >( resolution * mPageWidth / 25.4 );
2895 :
static_cast< int >( resolution * mPageHeight / 25.4 );
2897 QImage image(
QSize( width, height ), QImage::Format_ARGB32 );
2912 int resolution = mPrintResolution;
2917 resolution = ( imageSize.
width() / rect.
width()
2927 :
static_cast< int >( resolution * rect.
width() / 25.4 );
2929 :
static_cast< int >( resolution * rect.
height() / 25.4 );
2931 QImage image(
QSize( width, height ), QImage::Format_ARGB32 );
2936 image.
fill( Qt::transparent );
2946 if ( mPages.
size() <= page )
2980 mPlotStyle = savedPlotStyle;
2986 modifiedStr.
replace(
'&',
"&" );
2987 modifiedStr.
replace(
'\"',
""" );
2988 modifiedStr.
replace(
'\'',
"'" );
2989 modifiedStr.
replace(
'<',
"<" );
2990 modifiedStr.
replace(
'>',
">" );
3000 return viewList.
at( 0 );
3009 if ( !mWorldFileMap )
3014 int pageNumber = mWorldFileMap->
page() - 1;
3015 double pageY = pageNumber * ( mPageHeight + mSpaceBetweenPages );
3016 QRectF pageRect( 0, pageY, mPageWidth, mPageHeight );
3024 if ( !mWorldFileMap )
3029 double destinationHeight = exportRegion.
height();
3030 double destinationWidth = exportRegion.
width();
3037 double xRatio = mapExtent.
width() / mapItemSceneRect.
width();
3038 double yRatio = mapExtent.
height() / mapItemSceneRect.
height();
3040 double xCenter = mapExtent.
center().
x();
3041 double yCenter = mapExtent.
center().
y();
3046 mapItemPos.
rx() -= exportRegion.
left();
3047 mapItemPos.
ry() -= exportRegion.
top();
3049 double xmin = mapExtent.
xMinimum() - mapItemPos.
x() * xRatio;
3050 double ymax = mapExtent.
yMaximum() + mapItemPos.
y() * yRatio;
3051 QgsRectangle paperExtent( xmin, ymax - destinationHeight * yRatio, xmin + destinationWidth * xRatio, ymax );
3053 double X0 = paperExtent.
xMinimum();
3054 double Y0 = paperExtent.
yMinimum();
3056 int widthPx =
static_cast< int >(
printResolution() * destinationWidth / 25.4 );
3057 int heightPx =
static_cast< int >(
printResolution() * destinationHeight / 25.4 );
3059 double Ww = paperExtent.
width() / widthPx;
3060 double Hh = paperExtent.
height() / heightPx;
3069 s[5] = Y0 + paperExtent.
height();
3073 r[0] = cos( alpha );
3074 r[1] = -sin( alpha );
3075 r[2] = xCenter * ( 1 - cos( alpha ) ) + yCenter * sin( alpha );
3076 r[3] = sin( alpha );
3077 r[4] = cos( alpha );
3078 r[5] = - xCenter * sin( alpha ) + yCenter * ( 1 - cos( alpha ) );
3081 a = r[0] * s[0] + r[1] * s[3];
3082 b = r[0] * s[1] + r[1] * s[4];
3083 c = r[0] * s[2] + r[1] * s[5] + r[2];
3084 d = r[3] * s[0] + r[4] * s[3];
3085 e = r[3] * s[1] + r[4] * s[4];
3086 f = r[3] * s[2] + r[4] * s[5] + r[5];
3099 bool atlasHasFeatures = mAtlasComposition.
beginRender();
3100 if ( ! atlasHasFeatures )
3112 bool QgsComposition::ddPageSizeActive()
const 3128 evalContext = scopedContext.
data();
3131 double pageWidth = mPageWidth;
3132 double pageHeight = mPageHeight;
3145 pageHeight = heightD;
3153 double widthD = exprVal.
toDouble( &ok );
3163 double heightD = exprVal.
toDouble( &ok );
3167 pageHeight = heightD;
3180 double heightD, widthD;
3183 heightD = qMax( pageHeight, pageWidth );
3184 widthD = qMin( pageHeight, pageWidth );
3188 heightD = qMin( pageHeight, pageWidth );
3189 widthD = qMax( pageHeight, pageWidth );
3192 pageHeight = heightD;
3209 if ( it != mDataDefinedProperties.
constEnd() )
3226 bool defaultVals = ( !active && !useExpression && expression.
isEmpty() && field.
isEmpty() );
3228 if ( mDataDefinedProperties.
contains( property ) )
3231 if ( it != mDataDefinedProperties.
constEnd() )
3240 else if ( !defaultVals )
3243 mDataDefinedProperties.
insert( property, dd );
3249 mCustomProperties.
setValue( key, value );
3254 return mCustomProperties.
value( key, defaultValue );
3259 mCustomProperties.
remove( key );
3264 return mCustomProperties.
keys();
3278 expressionValue.
clear();
3283 bool useFeature =
false;
3284 if ( mAtlasComposition.
enabled() )
3289 layerFields = atlasLayer->
fields();
3294 currentFeature = mAtlasComposition.
feature();
3299 QVariant result = dataDefinedValue(
property, useFeature ? ¤tFeature :
nullptr, layerFields, context, dataDefinedProperties );
3303 expressionValue = result;
3325 if ( it != dataDefinedProperties->
constEnd() )
3354 if ( it != dataDefinedProperties->
constEnd() )
3375 prepareDataDefinedExpression( dd, dataDefinedProperties, context );
3382 result = expr->
evaluate( &context );
3389 else if ( !useExpression && !field.
isEmpty() )
3417 for ( ; it != dataDefinedProperties->
constEnd(); ++it )
3419 it.
value()->prepareExpression( context );
3430 if ( mAtlasComposition.
enabled() )
3437 void QgsComposition::prepareAllDataDefinedExpressions()
3440 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.
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 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.
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)