16 #ifndef QGSCOMPOSITION_H
17 #define QGSCOMPOSITION_H
22 #include <QDomDocument>
23 #include <QGraphicsScene>
24 #include <QLinkedList>
40 class QGraphicsRectItem;
89 void setPaperSize(
double width,
double height );
92 double paperHeight()
const;
95 double paperWidth()
const;
100 void setNumPages(
int pages );
102 int numPages()
const;
104 void setSnapToGridEnabled(
bool b );
107 void setSnapGridResolution(
double r );
110 void setSnapGridOffsetX(
double offset );
113 void setSnapGridOffsetY(
double offset );
116 void setGridPen(
const QPen& p );
117 const QPen&
gridPen()
const {
return mGridPen;}
119 void setGridStyle( GridStyle s );
135 int pageNumberAt(
const QPointF& position )
const;
140 QList<QgsComposerItem*> selectedComposerItems();
145 QList<const QgsComposerMap*> composerMapItems()
const;
150 template<
class T>
void composerItems( QList<T*>& itemList );
190 void setUseAdvancedEffects(
bool effectsEnabled );
193 void setSelectionTolerance(
double tol );
204 int pixelFontSize(
double pointSize )
const;
207 double pointFontSize(
int pixelSize )
const;
210 bool writeXML( QDomElement& composerElem, QDomDocument& doc );
213 bool readXML(
const QDomElement& compositionElem,
const QDomDocument& doc );
220 bool loadFromTemplate(
const QDomDocument& doc, QMap<QString, QString>* substitutionMap = 0,
bool addUndoCommands =
false );
231 void addItemsFromXML(
const QDomElement& elem,
const QDomDocument& doc, QMap< QgsComposerMap*, int >* mapsToRestore = 0,
232 bool addUndoCommands =
false, QPointF* pos = 0,
bool pasteInPlace =
false );
240 void raiseSelectedItems();
242 void lowerSelectedItems();
244 void moveSelectedItemsToTop();
246 void moveSelectedItemsToBottom();
250 void alignSelectedItemsLeft();
251 void alignSelectedItemsHCenter();
252 void alignSelectedItemsRight();
253 void alignSelectedItemsTop();
254 void alignSelectedItemsVCenter();
255 void alignSelectedItemsBottom();
262 QPointF snapPointToGrid(
const QPointF& scenePoint )
const;
271 QPointF alignItem(
const QgsComposerItem* item,
double& alignX,
double& alignY,
double dx = 0,
double dy = 0 );
279 QPointF alignPos(
const QPointF& pos,
const QgsComposerItem* excludeItem,
double& alignX,
double& alignY );
282 QGraphicsLineItem* addSnapLine();
284 void removeSnapLine( QGraphicsLineItem* line );
288 QGraphicsLineItem* nearestSnapLine(
bool horizontal,
double x,
double y,
double tolerance, QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode > >& snappedItems );
290 void setSnapLinesVisible(
bool visible );
301 void cancelCommand();
304 void endMultiFrameCommand();
316 void addComposerMap(
QgsComposerMap* map,
bool setDefaultPreviewStyle =
true );
331 void removeComposerItem(
QgsComposerItem* item,
bool createCommand =
true );
340 void beginPrint( QPrinter& printer );
342 void beginPrintAsPDF( QPrinter& printer,
const QString&
file );
344 void doPrint( QPrinter& printer, QPainter& painter );
347 void print( QPrinter &printer );
350 void exportAsPDF(
const QString&
file );
354 QImage printPageAsRaster(
int page );
358 void renderPage( QPainter* p,
int page );
419 void updateZValues();
423 int boundingRectOfSelectedItems( QRectF& bRect );
430 void updatePaperItems();
432 void removePaperItems();
433 void deleteAndRemoveMultiFrames();
435 static QString encodeStringForXML(
const QString& str );
438 void collectAlignCoordinates( QMap< double, const QgsComposerItem* >& alignCoordsX,
439 QMap< double, const QgsComposerItem* >& alignCoordsY,
const QgsComposerItem* excludeItem );
441 void checkNearestItem(
double checkCoord,
const QMap< double, const QgsComposerItem* >& alignCoords,
double& smallestDiff,
442 double itemCoordOffset,
double& itemCoord,
double& alignCoord )
const;
446 static bool nearestItem(
const QMap< double, const QgsComposerItem* >& coords,
double value,
double& nearestValue );
449 void paperSizeChanged();
450 void nPagesChanged();
479 QList<QGraphicsItem *> graphicsItemList = items();
480 QList<QGraphicsItem *>::iterator itemIt = graphicsItemList.begin();
481 for ( ; itemIt != graphicsItemList.end(); ++itemIt )
483 T* item =
dynamic_cast<T*
>( *itemIt );
486 itemList.push_back( item );