Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgscomposition.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposition.h
3  -------------------
4  begin : January 2005
5  copyright : (C) 2005 by Radim Blazek
6  email : blazek@itc.it
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSCOMPOSITION_H
17 #define QGSCOMPOSITION_H
18 
19 #include <QDomDocument>
20 #include <QGraphicsScene>
21 #include <QLinkedList>
22 #include <QUndoStack>
23 
24 #include "qgscomposeritemcommand.h"
25 
26 class QgsComposerItem;
27 class QgsComposerMap;
28 class QgsPaperItem;
29 class QGraphicsRectItem;
30 class QgsMapRenderer;
31 
32 class QDomElement;
33 
40 class CORE_EXPORT QgsComposition: public QGraphicsScene
41 {
42  Q_OBJECT
43  public:
44 
46  enum PlotStyle
47  {
48  Preview = 0, // Use cache etc
49  Print, // Render well
50  Postscript // Fonts need different scaling!
51  };
52 
54  enum GridStyle
55  {
58  Crosses
59  };
60 
61  QgsComposition( QgsMapRenderer* mapRenderer );
62  ~QgsComposition();
63 
65  void setPaperSize( double width, double height );
66 
68  double paperHeight() const;
69 
71  double paperWidth() const;
72 
73  void setSnapToGridEnabled( bool b );
74  bool snapToGridEnabled() const {return mSnapToGrid;}
75 
76  void setSnapGridResolution( double r );
77  double snapGridResolution() const {return mSnapGridResolution;}
78 
79  void setSnapGridOffsetX( double offset );
80  double snapGridOffsetX() const {return mSnapGridOffsetX;}
81 
82  void setSnapGridOffsetY( double offset );
83  double snapGridOffsetY() const {return mSnapGridOffsetY;}
84 
85  void setGridPen( const QPen& p );
86  const QPen& gridPen() const {return mGridPen;}
87 
88  void setGridStyle( GridStyle s );
89  GridStyle gridStyle() const {return mGridStyle;}
90 
92  QUndoStack* undoStack() { return &mUndoStack; }
93 
95  QgsComposerItem* composerItemAt( const QPointF & position );
96 
97  QList<QgsComposerItem*> selectedComposerItems();
98 
100  QList<const QgsComposerMap*> composerMapItems() const;
101 
104  const QgsComposerMap* getComposerMapById( int id ) const;
105 
106  int printResolution() const {return mPrintResolution;}
107  void setPrintResolution( int dpi ) {mPrintResolution = dpi;}
108 
109  bool printAsRaster() const {return mPrintAsRaster;}
110  void setPrintAsRaster( bool enabled ) { mPrintAsRaster = enabled; }
111 
113  QgsMapRenderer* mapRenderer() {return mMapRenderer;}
114 
115  QgsComposition::PlotStyle plotStyle() const {return mPlotStyle;}
116  void setPlotStyle( QgsComposition::PlotStyle style ) {mPlotStyle = style;}
117 
121  int pixelFontSize( double pointSize ) const;
122 
124  double pointFontSize( int pixelSize ) const;
125 
127  bool writeXML( QDomElement& composerElem, QDomDocument& doc );
128 
130  bool readXML( const QDomElement& compositionElem, const QDomDocument& doc );
131 
133  void addItemToZList( QgsComposerItem* item );
135  void removeItemFromZList( QgsComposerItem* item );
136 
137  //functions to move selected items in hierarchy
138  void raiseSelectedItems();
139  void raiseItem( QgsComposerItem* item );
140  void lowerSelectedItems();
141  void lowerItem( QgsComposerItem* item );
142  void moveSelectedItemsToTop();
143  void moveItemToTop( QgsComposerItem* item );
144  void moveSelectedItemsToBottom();
145  void moveItemToBottom( QgsComposerItem* item );
146 
147  //functions to align selected items
148  void alignSelectedItemsLeft();
149  void alignSelectedItemsHCenter();
150  void alignSelectedItemsRight();
151  void alignSelectedItemsTop();
152  void alignSelectedItemsVCenter();
153  void alignSelectedItemsBottom();
154 
157  void sortZList();
158 
160  QPointF snapPointToGrid( const QPointF& scenePoint ) const;
161 
166  void beginCommand( QgsComposerItem* item, const QString& commandText, QgsComposerMergeCommand::Context c = QgsComposerMergeCommand::Unknown );
167 
169  void endCommand();
171  void cancelCommand();
172 
173 
174  private:
179 
181  QLinkedList<QgsComposerItem*> mItemZList;
182 
185 
188 
194  QPen mGridPen;
196 
197  QUndoStack mUndoStack;
198 
200 
201  QgsComposition(); //default constructor is forbidden
202 
204  void updateZValues();
205 
208  int boundingRectOfSelectedItems( QRectF& bRect );
209 
210  void loadGridAppearanceSettings();
211  void saveGridAppearanceSettings();
212 
213  signals:
214  void paperSizeChanged();
215 };
216 
217 #endif
218 
219 
220