51 #include <QDomDocument> 52 #include <QDomElement> 53 #include <QGraphicsRectItem> 54 #include <QGraphicsView> 66 , mMapRenderer( mapRenderer )
67 , mMapSettings( mapRenderer->mapSettings() )
68 , mAtlasComposition( this )
75 , mMapRenderer( nullptr )
76 , mMapSettings( mapSettings )
77 , mAtlasComposition( this )
88 mSpaceBetweenPages = 10;
89 mPageStyleSymbol =
nullptr;
90 mPrintAsRaster =
false;
91 mGenerateWorldFile =
false;
92 mUseAdvancedEffects =
true;
96 mSnapGridResolution = 0;
99 mAlignmentSnap =
true;
100 mGuidesVisible =
true;
103 mBoundingBoxesVisible =
true;
104 mSelectionHandles =
nullptr;
105 mActiveItemCommand =
nullptr;
106 mActiveMultiFrameCommand =
nullptr;
108 mPreventCursorChange =
false;
109 mItemsModel =
nullptr;
112 mResizeToContentsMarginTop = 0;
113 mResizeToContentsMarginRight = 0;
114 mResizeToContentsMarginBottom = 0;
115 mResizeToContentsMarginLeft = 0;
132 connect( &mAtlasComposition, SIGNAL( toggled(
bool ) ),
this, SLOT( prepareAllDataDefinedExpressions() ) );
133 connect( &mAtlasComposition, SIGNAL( coverageLayerChanged(
QgsVectorLayer* ) ),
this, SLOT( prepareAllDataDefinedExpressions() ) );
136 createDefaultPageStyleSymbol();
145 mSelectionHandles->
hide();
148 mPrintResolution = 300;
197 deleteAndRemoveMultiFrames();
203 qDeleteAll( itemList );
206 qDeleteAll( mDataDefinedProperties );
207 mDataDefinedProperties.
clear();
214 delete mActiveItemCommand;
215 delete mActiveMultiFrameCommand;
216 delete mPageStyleSymbol;
220 void QgsComposition::loadDefaults()
223 mSnapGridResolution = settings.
value(
"/Composer/defaultSnapGridResolution", 10.0 ).
toDouble();
224 mSnapGridOffsetX = settings.
value(
"/Composer/defaultSnapGridOffsetX", 0 ).
toDouble();
225 mSnapGridOffsetY = settings.
value(
"/Composer/defaultSnapGridOffsetY", 0 ).
toDouble();
226 mSnapTolerance = settings.
value(
"/Composer/defaultSnapTolerancePixels", 5 ).
toInt();
241 for ( ; mapIt != maps.
end(); ++mapIt )
244 ( *mapIt )->update();
267 for ( ; itemIter != selectedItemList.
end(); ++itemIter )
284 evalContext = scopedContext.
data();
296 refreshPageSize( evalContext );
308 for ( ; itemIt != itemList.
end(); ++itemIt )
312 if (( composerItem && ( !paperItem || !ignorePages ) ) )
316 bounds = bounds.
united(( *itemIt )->sceneBoundingRect() );
318 bounds = ( *itemIt )->sceneBoundingRect();
322 if ( bounds.
isValid() && margin > 0.0 )
325 bounds.
adjust( -mPageWidth * margin, -mPageWidth * margin, mPageWidth * margin, mPageWidth * margin );
339 for ( ; itemIt != itemList.
end(); ++itemIt )
343 if ( composerItem && !paperItem &&
itemPageNumber( composerItem ) == pageNumber )
345 if ( visibleOnly && !composerItem->
isVisible() )
350 bounds = bounds.
united(( *itemIt )->sceneBoundingRect() );
352 bounds = ( *itemIt )->sceneBoundingRect();
366 if ( keepRelativeItemPosition )
371 for ( ; itemIt != itemList.
end(); ++itemIt )
385 for ( ; guideIt != guides->
end(); ++guideIt )
387 QLineF line = ( *guideIt )->line();
391 ( *guideIt )->
setLine( line.
x1(), 0, line.
x1(), totalHeight );
396 if ( keepRelativeItemPosition )
402 ( *guideIt )->setLine( 0, newY, width, newY );
407 ( *guideIt )->setLine( 0, line.
y1(),
width, line.
y1() );
415 for (
int i = 0; i < mPages.
size(); ++i )
417 mPages.
at( i )->setSceneRect(
QRectF( 0, currentY, width, height ) );
418 currentY += ( height + mSpaceBetweenPages );
441 double newWidth = bounds.
width() + marginLeft + marginRight;
442 double newHeight = bounds.
height() + marginTop + marginBottom;
446 double diffX = marginLeft - bounds.
left();
447 double diffY = marginTop - bounds.
top();
458 composerItem->
move( diffX, diffY );
469 guide->
setLine( line.
x1() + diffX, 0, line.
x1() + diffX, newHeight );
474 guide->
setLine( 0, line.
y1() + diffY, newWidth, line.
y1() + diffY );
481 mResizeToContentsMarginTop = marginTop;
482 mResizeToContentsMarginRight = marginRight;
483 mResizeToContentsMarginBottom = marginBottom;
484 mResizeToContentsMarginLeft = marginLeft;
489 marginTop = mResizeToContentsMarginTop;
490 marginRight = mResizeToContentsMarginRight;
491 marginBottom = mResizeToContentsMarginBottom;
492 marginLeft = mResizeToContentsMarginLeft;
498 int desiredPages =
pages;
506 int pagesD = exprVal.
toInt( &ok );
510 desiredPages = pagesD;
514 int diff = desiredPages - currentPages;
517 for (
int i = 0; i < diff; ++i )
525 for (
int i = 0; i < diff; ++i )
527 delete mPages.
last();
535 double totalHeight = ( mPageHeight +
spaceBetweenPages() ) * ( pages - 1 ) + mPageHeight;
536 for ( ; guideIt != guides->
end(); ++guideIt )
538 QLineF line = ( *guideIt )->line();
542 ( *guideIt )->
setLine( line.
x1(), 0, line.
x1(), totalHeight );
554 return mPages.
size();
566 for ( ; itemIt != items.
constEnd(); ++itemIt )
582 if ( page >
numPages() || page < 1 )
593 for ( ; frameIt != frames.
constEnd(); ++frameIt )
595 if (( *frameIt )->hidePageIfEmpty() && ( *frameIt )->isEmpty() )
606 delete mPageStyleSymbol;
611 void QgsComposition::createDefaultPageStyleSymbol()
613 delete mPageStyleSymbol;
615 properties.
insert(
"color",
"white" );
616 properties.
insert(
"style",
"solid" );
617 properties.
insert(
"style_border",
"no" );
618 properties.
insert(
"joinstyle",
"miter" );
642 pageNumber = pageNumber < 1 ? 1 : pageNumber;
643 pageNumber = pageNumber > mPages.
size() ? mPages.
size() : pageNumber;
661 itemList =
items( position, Qt::IntersectsItemShape, Qt::DescendingOrder );
664 bool foundBelowItem =
false;
665 for ( ; itemIt != itemList.
end(); ++itemIt )
669 if ( composerItem && !paperItem )
673 if (( ! belowItem || foundBelowItem ) && ( !ignoreLocked || !composerItem->
positionLock() ) )
679 if ( composerItem == belowItem )
682 foundBelowItem =
true;
707 for ( ; itemIter != graphicsItemList.
end(); ++itemIter )
710 if ( composerItem && ( includeLockedItems || !composerItem->
positionLock() ) )
712 composerItemList.
push_back( composerItem );
716 return composerItemList;
725 for ( ; itemIt != itemList.
end(); ++itemIt )
741 for ( ; itemIt != itemList.
end(); ++itemIt )
746 if ( composerMap->
id() == id )
778 for ( ; itemIt != itemList.
end(); ++itemIt )
783 if ( mypItem->
id() == theId )
798 if ( inAllComposers )
800 composers = QgisApp::instance()->printComposers();
808 for ( ; it != composers.
constEnd(); ++it )
812 for ( ; itemIt != itemList.
end(); ++itemIt )
817 if ( mypItem->
uuid() == theUuid )
833 for ( ; itemIt != itemList.
end(); ++itemIt )
838 if ( mypItem->
uuid() == theUuid )
850 mPrintResolution = dpi;
868 mUseAdvancedEffects = effectsEnabled;
873 for ( ; itemIt != itemList.
constEnd(); ++itemIt )
895 if ( composerElem.
isNull() )
929 compositionElem.
setAttribute(
"showPages", mPagesVisible );
933 for ( ; snapLineIt != mSnapLines.
constEnd(); ++snapLineIt )
936 QLineF line = ( *snapLineIt )->line();
944 compositionElem.
setAttribute(
"printResolution", mPrintResolution );
945 compositionElem.
setAttribute(
"printAsRaster", mPrintAsRaster );
947 compositionElem.
setAttribute(
"generateWorldFile", mGenerateWorldFile ? 1 : 0 );
948 compositionElem.
setAttribute(
"worldFileMap", mWorldFileMapId );
950 compositionElem.
setAttribute(
"alignmentSnap", mAlignmentSnap ? 1 : 0 );
951 compositionElem.
setAttribute(
"guidesVisible", mGuidesVisible ? 1 : 0 );
952 compositionElem.
setAttribute(
"smartGuides", mSmartGuides ? 1 : 0 );
953 compositionElem.
setAttribute(
"snapTolerancePixels", mSnapTolerance );
955 compositionElem.
setAttribute(
"resizeToContentsMarginTop", mResizeToContentsMarginTop );
956 compositionElem.
setAttribute(
"resizeToContentsMarginRight", mResizeToContentsMarginRight );
957 compositionElem.
setAttribute(
"resizeToContentsMarginBottom", mResizeToContentsMarginBottom );
958 compositionElem.
setAttribute(
"resizeToContentsMarginLeft", mResizeToContentsMarginLeft );
963 for ( ; itemIt != itemList.
constEnd(); ++itemIt )
970 composerItem->
writeXML( compositionElem, doc );
977 for ( ; multiFrameIt != mMultiFrames.
constEnd(); ++multiFrameIt )
979 ( *multiFrameIt )->writeXML( compositionElem, doc );
987 mCustomProperties.
writeXml( compositionElem, doc );
995 if ( compositionElem.
isNull() )
1001 bool widthConversionOk, heightConversionOk;
1002 mPageWidth = compositionElem.
attribute(
"paperWidth" ).
toDouble( &widthConversionOk );
1003 mPageHeight = compositionElem.
attribute(
"paperHeight" ).
toDouble( &heightConversionOk );
1008 if ( !pageStyleSymbolElem.
isNull() )
1010 delete mPageStyleSymbol;
1011 mPageStyleSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( pageStyleSymbolElem );
1014 if ( widthConversionOk && heightConversionOk )
1017 for (
int i = 0; i <
numPages; ++i )
1024 mSnapToGrid = compositionElem.
attribute(
"snapping",
"0" ).
toInt() == 0 ? false :
true;
1025 mGridVisible = compositionElem.
attribute(
"gridVisible",
"0" ).
toInt() == 0 ? false :
true;
1027 mSnapGridResolution = compositionElem.
attribute(
"snapGridResolution" ).
toDouble();
1031 mAlignmentSnap = compositionElem.
attribute(
"alignmentSnap",
"1" ).
toInt() == 0 ? false :
true;
1032 mGuidesVisible = compositionElem.
attribute(
"guidesVisible",
"1" ).
toInt() == 0 ? false :
true;
1033 mSmartGuides = compositionElem.
attribute(
"smartGuides",
"1" ).
toInt() == 0 ? false :
true;
1034 mSnapTolerance = compositionElem.
attribute(
"snapTolerancePixels",
"10" ).
toInt();
1036 mResizeToContentsMarginTop = compositionElem.
attribute(
"resizeToContentsMarginTop",
"0" ).
toDouble();
1037 mResizeToContentsMarginRight = compositionElem.
attribute(
"resizeToContentsMarginRight",
"0" ).
toDouble();
1038 mResizeToContentsMarginBottom = compositionElem.
attribute(
"resizeToContentsMarginBottom",
"0" ).
toDouble();
1039 mResizeToContentsMarginLeft = compositionElem.
attribute(
"resizeToContentsMarginLeft",
"0" ).
toDouble();
1043 for (
int i = 0; i < snapLineNodes.
size(); ++i )
1051 snapItem->
setLine( x1, y1, x2, y2 );
1054 mPagesVisible = ( compositionElem.
attribute(
"showPages",
"1" ) !=
"0" );
1055 mPrintAsRaster = compositionElem.
attribute(
"printAsRaster" ).
toInt();
1056 mPrintResolution = compositionElem.
attribute(
"printResolution",
"300" ).
toInt();
1058 mGenerateWorldFile = compositionElem.
attribute(
"generateWorldFile",
"0" ).
toInt() == 1 ? true :
false;
1059 mWorldFileMapId = compositionElem.
attribute(
"worldFileMap" );
1065 mCustomProperties.
readXml( compositionElem );
1078 if ( clearComposition )
1080 deleteAndRemoveMultiFrames();
1085 for ( ; itemIter != itemList.
end(); ++itemIter )
1089 if ( cItem && !pItem )
1096 mItemsModel->
clear();
1099 mUndoStack->
clear();
1103 if ( substitutionMap )
1107 for ( ; sIt != substitutionMap->
constEnd(); ++sIt )
1109 xmlString = xmlString.
replace(
'[' + sIt.
key() +
']', encodeStringForXML( sIt.
value() ) );
1113 int errorLine, errorColumn;
1114 if ( !importDoc.
setContent( xmlString, &errorMsg, &errorLine, &errorColumn ) )
1126 if ( clearComposition )
1129 if ( compositionElem.
isNull() )
1134 bool ok =
readXML( compositionElem, importDoc );
1147 for (
int i = 0; i < composerItemsNodes.
count(); ++i )
1149 QDomNode composerItemNode = composerItemsNodes.
at( i );
1162 if ( clearComposition )
1174 for (
int i = 0; i < composerItemList.
size(); ++i )
1185 minX = qMin( minX, x );
1186 minY = qMin( minY, y );
1199 bool addUndoCommands,
QPointF* pos,
bool pasteInPlace )
1201 QPointF* pasteInPlacePt =
nullptr;
1215 QPointF minItemPos = minPointFromXml( elem );
1218 pasteShiftPos = *pos - minItemPos;
1225 pasteInPlacePt =
new QPointF( 0,
pageNumberAt( *pos ) * ( mPageHeight + mSpaceBetweenPages ) );
1229 for (
int i = 0; i < composerLabelList.
size(); ++i )
1233 newLabel->
readXML( currentComposerLabelElem, doc );
1236 if ( pasteInPlacePt )
1239 newLabel->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1243 newLabel->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1246 lastPastedItem = newLabel;
1250 if ( addUndoCommands )
1257 for (
int i = 0; i < composerMapList.
size(); ++i )
1262 if ( mapsToRestore )
1267 newMap->
readXML( currentComposerMapElem, doc );
1270 if ( mapsToRestore )
1283 newMap->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1287 newMap->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1290 lastPastedItem = newMap;
1293 if ( addUndoCommands )
1308 for ( ; overviewIt != overviews.
end(); ++overviewIt )
1310 ( *overviewIt )->connectSignals();
1317 for (
int i = 0; i < composerArrowList.
size(); ++i )
1321 newArrow->
readXML( currentComposerArrowElem, doc );
1327 newArrow->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1331 newArrow->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1334 lastPastedItem = newArrow;
1338 if ( addUndoCommands )
1345 for (
int i = 0; i < composerScaleBarList.
size(); ++i )
1349 newScaleBar->
readXML( currentComposerScaleBarElem, doc );
1355 newScaleBar->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1359 newScaleBar->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1362 lastPastedItem = newScaleBar;
1366 if ( addUndoCommands )
1373 for (
int i = 0; i < composerShapeList.
size(); ++i )
1377 newShape->
readXML( currentComposerShapeElem, doc );
1385 newShape->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1389 newShape->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1392 lastPastedItem = newShape;
1396 if ( addUndoCommands )
1404 for (
int i = 0; i < composerPolygonList.
size(); ++i )
1408 newPolygon->
readXML( currentComposerPolygonElem, doc );
1415 newPolygon->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1419 newPolygon->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1422 lastPastedItem = newPolygon;
1427 if ( addUndoCommands )
1435 for (
int i = 0; i < addComposerPolylineList.
size(); ++i )
1439 newPolyline->
readXML( currentComposerPolylineElem, doc );
1446 newPolyline->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1450 newPolyline->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1453 lastPastedItem = newPolyline;
1458 if ( addUndoCommands )
1466 for (
int i = 0; i < composerPictureList.
size(); ++i )
1470 newPicture->
readXML( currentComposerPictureElem, doc );
1476 newPicture->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1480 newPicture->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1483 lastPastedItem = newPicture;
1487 if ( addUndoCommands )
1494 for (
int i = 0; i < composerLegendList.
size(); ++i )
1498 newLegend->
readXML( currentComposerLegendElem, doc );
1504 newLegend->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1508 newLegend->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1511 lastPastedItem = newLegend;
1515 if ( addUndoCommands )
1522 for (
int i = 0; i < composerTableList.
size(); ++i )
1526 newTable->
readXML( currentComposerTableElem, doc );
1532 newTable->
move( pasteInPlacePt->
x(), pasteInPlacePt->
y() );
1536 newTable->
move( pasteShiftPos.
x(), pasteShiftPos.
y() );
1539 lastPastedItem = newTable;
1543 if ( addUndoCommands )
1551 for (
int i = 0; i < composerHtmlList.
size(); ++i )
1555 newHtml->
readXML( currentHtmlElem, doc );
1568 for (
int i = 0; i < composerAttributeTableV2List.
size(); ++i )
1572 newTable->
readXML( currentTableElem, doc );
1589 for (
int i = 0; i < groupList.
size(); ++i )
1593 newGroup->
readXML( groupElem, doc );
1595 if ( addUndoCommands )
1606 if ( lastPastedItem )
1611 delete pasteInPlacePt;
1612 pasteInPlacePt =
nullptr;
1642 bool itemsRaised =
false;
1643 for ( ; it != selectedItems.
end(); ++it )
1645 itemsRaised = itemsRaised |
raiseItem( *it );
1679 if ( !selectedItems.
isEmpty() )
1681 previousSelectedItem = selectedItems.
at( 0 );
1684 if ( !previousSelectedItem )
1691 switch ( direction )
1701 if ( !selectedItem )
1716 bool itemsLowered =
false;
1717 for ( ; it != selectedItems.
end(); ++it )
1719 itemsLowered = itemsLowered |
lowerItem( *it );
1722 if ( !itemsLowered )
1743 bool itemsRaised =
false;
1744 for ( ; it != selectedItems.
end(); ++it )
1770 bool itemsLowered =
false;
1771 for ( ; it != selectedItems.
end(); ++it )
1776 if ( !itemsLowered )
1796 if ( selectedItems.
size() < 2 )
1802 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1807 double minXCoordinate = selectedItemBBox.
left();
1812 for ( ; align_it != selectedItems.
end(); ++align_it )
1816 ( *align_it )->setPos( minXCoordinate, ( *align_it )->pos().y() );
1819 mUndoStack->
push( parentCommand );
1826 if ( selectedItems.
size() < 2 )
1832 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1837 double averageXCoord = ( selectedItemBBox.
left() + selectedItemBBox.
right() ) / 2.0;
1842 for ( ; align_it != selectedItems.
end(); ++align_it )
1846 ( *align_it )->setPos( averageXCoord - ( *align_it )->rect().width() / 2.0, ( *align_it )->pos().y() );
1849 mUndoStack->
push( parentCommand );
1856 if ( selectedItems.
size() < 2 )
1862 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1867 double maxXCoordinate = selectedItemBBox.
right();
1872 for ( ; align_it != selectedItems.
end(); ++align_it )
1876 ( *align_it )->setPos( maxXCoordinate - ( *align_it )->rect().width(), ( *align_it )->pos().y() );
1879 mUndoStack->
push( parentCommand );
1886 if ( selectedItems.
size() < 2 )
1892 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1897 double minYCoordinate = selectedItemBBox.
top();
1901 for ( ; align_it != selectedItems.
end(); ++align_it )
1905 ( *align_it )->setPos(( *align_it )->pos().x(), minYCoordinate );
1908 mUndoStack->
push( parentCommand );
1915 if ( selectedItems.
size() < 2 )
1921 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1926 double averageYCoord = ( selectedItemBBox.
top() + selectedItemBBox.
bottom() ) / 2.0;
1929 for ( ; align_it != selectedItems.
end(); ++align_it )
1933 ( *align_it )->setPos(( *align_it )->pos().x(), averageYCoord - ( *align_it )->rect().height() / 2 );
1936 mUndoStack->
push( parentCommand );
1943 if ( selectedItems.
size() < 2 )
1949 if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
1954 double maxYCoord = selectedItemBBox.
bottom();
1957 for ( ; align_it != selectedItems.
end(); ++align_it )
1961 ( *align_it )->setPos(( *align_it )->pos().x(), maxYCoord - ( *align_it )->rect().height() );
1964 mUndoStack->
push( parentCommand );
1973 for ( ; itemIter != selectionList.
end(); ++itemIter )
1977 ( *itemIter )->setPositionLock(
true );
1982 mUndoStack->
push( parentCommand );
1997 for ( ; itemIt != itemList.
end(); ++itemIt )
2011 mUndoStack->
push( parentCommand );
2017 if ( items.
size() < 2 )
2027 for ( ; itemIter != items.
end(); ++itemIter )
2029 itemGroup->
addItem( *itemIter );
2054 return ungroupedItems;
2070 for ( ; itemIt != groupedItems.
end(); ++itemIt )
2072 ungroupedItems << ( *itemIt );
2080 return ungroupedItems;
2083 void QgsComposition::updateZValues(
const bool addUndoCommands )
2090 if ( addUndoCommands )
2092 parentCommand =
new QUndoCommand(
tr(
"Item z-order changed" ) );
2100 if ( addUndoCommands )
2106 if ( addUndoCommands )
2113 if ( addUndoCommands )
2115 mUndoStack->
push( parentCommand );
2127 updateZValues(
false );
2132 if ( !mSnapToGrid || mSnapGridResolution <= 0 || !graphicsView() )
2138 int pageNr =
static_cast< int >( scenePoint.
y() / ( mPageHeight + mSpaceBetweenPages ) );
2139 double yOffset = pageNr * ( mPageHeight + mSpaceBetweenPages );
2140 double yPage = scenePoint.
y() - yOffset;
2143 int xRatio =
static_cast< int >(( scenePoint.
x() - mSnapGridOffsetX ) / mSnapGridResolution + 0.5 );
2144 int yRatio =
static_cast< int >(( yPage - mSnapGridOffsetY ) / mSnapGridResolution + 0.5 );
2146 double xSnapped = xRatio * mSnapGridResolution + mSnapGridOffsetX;
2147 double ySnapped = yRatio * mSnapGridResolution + mSnapGridOffsetY + yOffset;
2150 double viewScaleFactor = graphicsView()->
transform().
m11();
2151 double alignThreshold = mSnapTolerance / viewScaleFactor;
2153 if ( fabs( xSnapped - scenePoint.
x() ) > alignThreshold )
2156 xSnapped = scenePoint.
x();
2158 if ( fabs( ySnapped - scenePoint.
y() ) > alignThreshold )
2161 ySnapped = scenePoint.
y();
2164 return QPointF( xSnapped, ySnapped );
2170 QPen linePen( Qt::SolidLine );
2202 mGuidesVisible = visible;
2211 mPagesVisible = visible;
2218 double minSqrDist = DBL_MAX;
2220 double currentXCoord = 0;
2221 double currentYCoord = 0;
2222 double currentSqrDist = 0;
2223 double sqrTolerance = tolerance * tolerance;
2225 snappedItems.clear();
2228 for ( ; it != mSnapLines.
constEnd(); ++it )
2230 bool itemHorizontal =
qgsDoubleNear(( *it )->line().y2() - ( *it )->line().y1(), 0 );
2231 if ( horizontal && itemHorizontal )
2233 currentYCoord = ( *it )->line().y1();
2234 currentSqrDist = ( y - currentYCoord ) * ( y - currentYCoord );
2236 else if ( !horizontal && !itemHorizontal )
2238 currentXCoord = ( *it )->line().x1();
2239 currentSqrDist = ( x - currentXCoord ) * ( x - currentXCoord );
2246 if ( currentSqrDist < minSqrDist && currentSqrDist < sqrTolerance )
2249 minSqrDist = currentSqrDist;
2253 double itemTolerance = 0.0000001;
2259 for ( ; itemIt != itemList.
end(); ++itemIt )
2303 int QgsComposition::boundingRectOfSelectedItems(
QRectF& bRect )
2306 if ( selectedItems.
size() < 1 )
2313 double minX = currentItem->
pos().
x();
2314 double minY = currentItem->
pos().
y();
2315 double maxX = minX + currentItem->
rect().
width();
2316 double maxY = minY + currentItem->
rect().
height();
2318 double currentMinX, currentMinY, currentMaxX, currentMaxY;
2320 for (
int i = 1; i < selectedItems.
size(); ++i )
2322 currentItem = selectedItems.
at( i );
2323 currentMinX = currentItem->
pos().
x();
2324 currentMinY = currentItem->
pos().
y();
2325 currentMaxX = currentMinX + currentItem->
rect().
width();
2326 currentMaxY = currentMinY + currentItem->
rect().
height();
2328 if ( currentMinX < minX )
2330 if ( currentMaxX > maxX )
2332 if ( currentMinY < minY )
2334 if ( currentMaxY > maxY )
2357 mSnapGridResolution = r;
2363 mSnapGridOffsetX = offset;
2369 mSnapGridOffsetY = offset;
2389 mBoundingBoxesVisible = boundsVisible;
2391 if ( mSelectionHandles )
2393 mSelectionHandles->
update();
2405 void QgsComposition::loadSettings()
2411 gridStyleString = s.
value(
"/Composer/gridStyle",
"Dots" ).
toString();
2413 int gridRed, gridGreen, gridBlue, gridAlpha;
2414 gridRed = s.
value(
"/Composer/gridRed", 190 ).
toInt();
2415 gridGreen = s.
value(
"/Composer/gridGreen", 190 ).
toInt();
2416 gridBlue = s.
value(
"/Composer/gridBlue", 190 ).
toInt();
2417 gridAlpha = s.
value(
"/Composer/gridAlpha", 100 ).
toInt();
2418 QColor gridColor =
QColor( gridRed, gridGreen, gridBlue, gridAlpha );
2423 if ( gridStyleString ==
"Dots" )
2427 else if ( gridStyleString ==
"Crosses" )
2439 delete mActiveItemCommand;
2442 mActiveItemCommand =
nullptr;
2459 if ( mActiveItemCommand )
2464 mUndoStack->
push( mActiveItemCommand );
2469 delete mActiveItemCommand;
2471 mActiveItemCommand =
nullptr;
2477 delete mActiveItemCommand;
2478 mActiveItemCommand =
nullptr;
2483 delete mActiveMultiFrameCommand;
2487 mActiveMultiFrameCommand =
nullptr;
2504 if ( mActiveMultiFrameCommand )
2509 mUndoStack->
push( mActiveMultiFrameCommand );
2514 delete mActiveMultiFrameCommand;
2516 mActiveMultiFrameCommand =
nullptr;
2522 delete mActiveMultiFrameCommand;
2523 mActiveMultiFrameCommand =
nullptr;
2528 mMultiFrames.
insert( multiFrame );
2535 mMultiFrames.
remove( multiFrame );
2583 if ( setDefaultPreviewStyle )
2681 QgsDebugMsg(
QString(
"removeComposerItem called, createCommand:%1 removeGroupItems:%2" )
2682 .arg( createCommand ).arg( removeGroupItems ) );
2685 if ( itemGroup && removeGroupItems )
2692 tr(
"Remove item group" ) );
2693 connectAddRemoveCommandSignals( parentCommand );
2699 for ( ; it != groupedItems.
end(); ++it )
2704 connectAddRemoveCommandSignals( subcommand );
2714 if ( createCommand )
2729 if ( frameItem && multiFrame )
2734 if ( createCommand )
2737 multiFrame,
this,
tr(
"Multiframe removed" ) );
2755 connectAddRemoveCommandSignals( c );
2870 void QgsComposition::updatePaperItems()
2878 void QgsComposition::addPaperItem()
2882 double currentY = paperHeight * mPages.
size() + mPages.
size() * mSpaceBetweenPages;
2890 void QgsComposition::removePaperItems()
2892 qDeleteAll( mPages );
2896 void QgsComposition::deleteAndRemoveMultiFrames()
2898 qDeleteAll( mMultiFrames );
2899 mMultiFrames.
clear();
2930 return print( printer );
2934 const QRectF& exportRegion,
double dpi )
const 2939 double* t = computeGeoTransform( map, exportRegion, dpi );
2945 CPLSetConfigOption(
"GDAL_PDF_DPI",
QString::number( dpi ).toLocal8Bit().constData() );
2949 GDALSetGeoTransform( outputDS, t );
2952 GDALSetMetadataItem( outputDS,
"AUTHOR",
"me",
nullptr );
2955 GDALClose( outputDS );
2957 CPLSetConfigOption(
"GDAL_PDF_DPI",
nullptr );
2963 if ( ddPageSizeActive() )
2977 bool pageExported =
false;
2978 if ( mPrintAsRaster )
2980 for (
int i = fromPage; i <= toPage; ++i )
2986 if (( pageExported && i > fromPage ) || startNewPage )
2995 p.
drawImage( targetArea, image, targetArea );
2997 pageExported =
true;
3001 if ( !mPrintAsRaster )
3003 for (
int i = fromPage; i <= toPage; ++i )
3009 if (( pageExported && i > fromPage ) || startNewPage )
3014 pageExported =
true;
3028 if ( evaluateDDPageSize && ddPageSizeActive() )
3043 bool ready = p.
begin( &printer );
3056 int resolution = mPrintResolution;
3061 resolution = qRound(( imageSize.
width() / mPageWidth
3062 + imageSize.
height() / mPageHeight ) / 2.0 * 25.4 );
3071 :
static_cast< int >( resolution * mPageWidth / 25.4 );
3073 :
static_cast< int >( resolution * mPageHeight / 25.4 );
3075 QImage image(
QSize( width, height ), QImage::Format_ARGB32 );
3090 int resolution = mPrintResolution;
3095 resolution = qRound(( imageSize.
width() / rect.
width()
3105 :
static_cast< int >( resolution * rect.
width() / 25.4 );
3107 :
static_cast< int >( resolution * rect.
height() / 25.4 );
3109 QImage image(
QSize( width, height ), QImage::Format_ARGB32 );
3114 image.
fill( Qt::transparent );
3124 if ( mPages.
size() <= page )
3158 mPlotStyle = savedPlotStyle;
3161 double* QgsComposition::computeGeoTransform(
const QgsComposerMap* map,
const QRectF& region ,
double dpi )
const 3173 QRectF exportRegion = region;
3174 if ( !exportRegion.
isValid() )
3176 int pageNumber = map->
page() - 1;
3177 double pageY = pageNumber * ( mPageHeight + mSpaceBetweenPages );
3178 exportRegion =
QRectF( 0, pageY, mPageWidth, mPageHeight );
3185 double outputHeightMM = exportRegion.
height();
3186 double outputWidthMM = exportRegion.
width();
3190 double mapXCenter = mapExtent.
center().
x();
3191 double mapYCenter = mapExtent.
center().
y();
3193 double sinAlpha = sin( alpha );
3194 double cosAlpha = cos( alpha );
3199 mapItemPos.
rx() -= exportRegion.
left();
3200 mapItemPos.
ry() -= exportRegion.
top();
3203 double xRatio = mapExtent.
width() / mapItemSceneRect.
width();
3204 double yRatio = mapExtent.
height() / mapItemSceneRect.
height();
3205 double xmin = mapExtent.
xMinimum() - mapItemPos.
x() * xRatio;
3206 double ymax = mapExtent.
yMaximum() + mapItemPos.
y() * yRatio;
3207 QgsRectangle paperExtent( xmin, ymax - outputHeightMM * yRatio, xmin + outputWidthMM * xRatio, ymax );
3210 double X0 = paperExtent.
xMinimum();
3211 double Y0 = paperExtent.
yMaximum();
3216 double X1 = X0 - mapXCenter;
3217 double Y1 = Y0 - mapYCenter;
3218 double X2 = X1 * cosAlpha + Y1 * sinAlpha;
3219 double Y2 = -X1 * sinAlpha + Y1 * cosAlpha;
3220 X0 = X2 + mapXCenter;
3221 Y0 = Y2 + mapYCenter;
3225 int pageWidthPixels =
static_cast< int >( dpi * outputWidthMM / 25.4 );
3226 int pageHeightPixels =
static_cast< int >( dpi * outputHeightMM / 25.4 );
3227 double pixelWidthScale = paperExtent.
width() / pageWidthPixels;
3228 double pixelHeightScale = paperExtent.
height() / pageHeightPixels;
3231 double* t =
new double[6];
3233 t[1] = cosAlpha * pixelWidthScale;
3234 t[2] = -sinAlpha * pixelWidthScale;
3236 t[4] = -sinAlpha * pixelHeightScale;
3237 t[5] = -cosAlpha * pixelHeightScale;
3245 modifiedStr.
replace(
'&',
"&" );
3246 modifiedStr.
replace(
'\"',
""" );
3247 modifiedStr.
replace(
'\'',
"'" );
3248 modifiedStr.
replace(
'<',
"<" );
3249 modifiedStr.
replace(
'>',
">" );
3259 return viewList.
at( 0 );
3274 int pageNumber = map->
page() - 1;
3275 double pageY = pageNumber * ( mPageHeight + mSpaceBetweenPages );
3276 QRectF pageRect( 0, pageY, mPageWidth, mPageHeight );
3289 double destinationHeight = exportRegion.
height();
3290 double destinationWidth = exportRegion.
width();
3297 double xRatio = mapExtent.
width() / mapItemSceneRect.
width();
3298 double yRatio = mapExtent.
height() / mapItemSceneRect.
height();
3300 double xCenter = mapExtent.
center().
x();
3301 double yCenter = mapExtent.
center().
y();
3306 mapItemPos.
rx() -= exportRegion.
left();
3307 mapItemPos.
ry() -= exportRegion.
top();
3309 double xmin = mapExtent.
xMinimum() - mapItemPos.
x() * xRatio;
3310 double ymax = mapExtent.
yMaximum() + mapItemPos.
y() * yRatio;
3311 QgsRectangle paperExtent( xmin, ymax - destinationHeight * yRatio, xmin + destinationWidth * xRatio, ymax );
3313 double X0 = paperExtent.
xMinimum();
3314 double Y0 = paperExtent.
yMinimum();
3316 int widthPx =
static_cast< int >(
printResolution() * destinationWidth / 25.4 );
3317 int heightPx =
static_cast< int >(
printResolution() * destinationHeight / 25.4 );
3319 double Ww = paperExtent.
width() / widthPx;
3320 double Hh = paperExtent.
height() / heightPx;
3329 s[5] = Y0 + paperExtent.
height();
3333 r[0] = cos( alpha );
3334 r[1] = -sin( alpha );
3335 r[2] = xCenter * ( 1 - cos( alpha ) ) + yCenter * sin( alpha );
3336 r[3] = sin( alpha );
3337 r[4] = cos( alpha );
3338 r[5] = - xCenter * sin( alpha ) + yCenter * ( 1 - cos( alpha ) );
3341 a = r[0] * s[0] + r[1] * s[3];
3342 b = r[0] * s[1] + r[1] * s[4];
3343 c = r[0] * s[2] + r[1] * s[5] + r[2];
3344 d = r[3] * s[0] + r[4] * s[3];
3345 e = r[3] * s[1] + r[4] * s[4];
3346 f = r[3] * s[2] + r[4] * s[5] + r[5];
3359 bool atlasHasFeatures = mAtlasComposition.
beginRender();
3360 if ( ! atlasHasFeatures )
3372 bool QgsComposition::ddPageSizeActive()
const 3388 evalContext = scopedContext.
data();
3391 double pageWidth = mPageWidth;
3392 double pageHeight = mPageHeight;
3405 pageHeight = heightD;
3413 double widthD = exprVal.
toDouble( &ok );
3423 double heightD = exprVal.
toDouble( &ok );
3427 pageHeight = heightD;
3440 double heightD, widthD;
3443 heightD = qMax( pageHeight, pageWidth );
3444 widthD = qMin( pageHeight, pageWidth );
3448 heightD = qMin( pageHeight, pageWidth );
3449 widthD = qMax( pageHeight, pageWidth );
3452 pageHeight = heightD;
3469 if ( it != mDataDefinedProperties.
constEnd() )
3486 bool defaultVals = ( !active && !useExpression && expression.
isEmpty() && field.
isEmpty() );
3488 if ( mDataDefinedProperties.
contains( property ) )
3491 if ( it != mDataDefinedProperties.
constEnd() )
3500 else if ( !defaultVals )
3503 mDataDefinedProperties.
insert( property, dd );
3509 mCustomProperties.
setValue( key, value );
3517 return mCustomProperties.
value( key, defaultValue );
3522 mCustomProperties.
remove( key );
3527 return mCustomProperties.
keys();
3541 expressionValue.
clear();
3546 bool useFeature =
false;
3547 if ( mAtlasComposition.
enabled() )
3552 layerFields = atlasLayer->
fields();
3557 currentFeature = mAtlasComposition.
feature();
3562 QVariant result = dataDefinedValue(
property, useFeature ? ¤tFeature :
nullptr, layerFields, context, dataDefinedProperties );
3566 expressionValue = result;
3588 if ( it != dataDefinedProperties->
constEnd() )
3617 if ( it != dataDefinedProperties->
constEnd() )
3638 prepareDataDefinedExpression( dd, dataDefinedProperties, context );
3645 result = expr->
evaluate( &context );
3652 else if ( !useExpression && !field.
isEmpty() )
3680 for ( ; it != dataDefinedProperties->
constEnd(); ++it )
3682 it.
value()->prepareExpression( context );
3693 if ( mAtlasComposition.
enabled() )
3700 void QgsComposition::prepareAllDataDefinedExpressions()
3703 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.
void setDirty(bool b=true)
Flag the project as dirty (modified).
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.
Composer item for polylines.
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 two 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
QgsComposerMap * worldFileMap() const
Returns the map item which will be used to generate corresponding world files when the composition is...
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 advises 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 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)
Compare two doubles (but allow some difference)
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.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets state from Dom document.
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 advises 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 composerPolylineAdded(QgsComposerPolyline *polyline)
Is emitted when new composer polyline has been added to the view.
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
void georeferenceOutput(const QString &file, QgsComposerMap *referenceMap=nullptr, const QRectF &exportRegion=QRectF(), double dpi=-1) const
Georeferences a file (image of PDF) exported from the composition.
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...
const char * constData() const
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.
void setWorldFileMap(QgsComposerMap *map)
Sets the map item which will be used to generate corresponding world files when the composition is ex...
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.
QByteArray toLocal8Bit() const
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 composerPolygonAdded(QgsComposerPolygon *polygon)
Is emitted when new composer polygon has been added to the view.
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 addComposerPolyline(QgsComposerPolyline *polyline)
Adds a composer polyline and advises composer to create a widget for it (through signal) ...
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)
Composer item for polygons.
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()
Returns the QgsProject singleton instance.
QDomElement firstChildElement(const QString &tagName) const
void addComposerMap(QgsComposerMap *map, const bool setDefaultPreviewStyle=true)
Adds map to the graphics scene and advises 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)
QString toWkt() const
Returns a WKT representation of this CRS.
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 advises 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 advises 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 addComposerPolygon(QgsComposerPolygon *polygon)
Adds a composer polygon and advises composer to create a widget for it (through signal) ...
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 advises 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)
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
bool lowerItem(QgsComposerItem *item)
QgsComposerItem * getComposerItemBelow(QgsComposerItem *item) const
void addComposerArrow(QgsComposerArrow *arrow)
Adds an arrow item to the graphics scene and advises 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 advises 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.