QGIS API Documentation  2.99.0-Master (8ec3eaf)
qgscomposerview.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerview.h
3  -------------------
4  begin : January 2005
5  copyright : (C) 2005 by Radim Blazek
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #ifndef QGSCOMPOSERVIEW_H
18 #define QGSCOMPOSERVIEW_H
19 
20 #include <QGraphicsView>
21 #include "qgsprevieweffect.h" // for QgsPreviewEffect::PreviewMode
22 #include <QGraphicsPolygonItem>
23 
24 class QDomDocument;
25 class QDomElement;
26 class QKeyEvent;
27 class QMainWindow;
28 class QMouseEvent;
29 class QgsComposition;
30 class QgsComposerArrow;
31 class QgsComposerItem;
32 class QgsComposerLabel;
33 class QgsComposerLegend;
34 class QgsComposerMap;
35 class QgsComposerPicture;
36 class QgsComposerRuler;
38 class QgsComposerShape;
41 
48 class GUI_EXPORT QgsComposerView: public QGraphicsView
49 {
50  Q_OBJECT
51 
52  public:
53 
55  enum Tool
56  {
57  Select = 0, // Select/Move item
58  AddArrow, // add arrow
60  AddMap, // add new map
61  AddLegend, // add vector legend
62  AddLabel, // add label
63  AddScalebar, // add scalebar
64  AddPicture, // add raster/vector picture
70  AddTable, // add attribute table
72  MoveItemContent, // move content of item (e.g. content of map)
74  Pan,
75  Zoom
76  };
77 
79  {
81  ClipboardModeCopy
82  };
83 
84  enum PasteMode
85  {
88  PasteModeInPlace
89  };
90 
92  {
95  ActiveUntilMouseRelease
96  };
97 
98  QgsComposerView( QWidget* parent = nullptr, const char* name = nullptr, Qt::WindowFlags f = 0 );
99 
101  void groupItems();
102 
104  void ungroupItems();
105 
107  void copyItems( ClipboardMode mode );
108 
110  void pasteItems( PasteMode mode );
111 
113  void deleteSelectedItems();
114 
116  void selectAll();
117 
119  void selectNone();
120 
122  void selectInvert();
123 
124  QgsComposerView::Tool currentTool() const {return mCurrentTool;}
125  void setCurrentTool( QgsComposerView::Tool t );
126 
130  void setComposition( QgsComposition* c );
131 
133  QgsComposition* composition();
134 
136  QMainWindow* composerWindow();
137 
138  void setPaintingEnabled( bool enabled ) { mPaintingEnabled = enabled; }
139  bool paintingEnabled() const { return mPaintingEnabled; }
140 
142  void updateRulers();
143 
144  void setHorizontalRuler( QgsComposerRuler* r ) { mHorizontalRuler = r; }
145  void setVerticalRuler( QgsComposerRuler* r ) { mVerticalRuler = r; }
146 
148  void setZoomLevel( double zoomLevel );
149 
155  void scaleSafe( double scale );
156 
162  void setPreviewModeEnabled( bool enabled );
163 
170  void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
171 
172  protected:
173  void mousePressEvent( QMouseEvent* ) override;
174  void mouseReleaseEvent( QMouseEvent* ) override;
175  void mouseMoveEvent( QMouseEvent* ) override;
176  void mouseDoubleClickEvent( QMouseEvent* e ) override;
177 
178  void keyPressEvent( QKeyEvent * e ) override;
179  void keyReleaseEvent( QKeyEvent * e ) override;
180 
181  void wheelEvent( QWheelEvent* event ) override;
182 
183  void paintEvent( QPaintEvent* event ) override;
184 
185  void hideEvent( QHideEvent* e ) override;
186  void showEvent( QShowEvent* e ) override;
187 
188  void resizeEvent( QResizeEvent* event ) override;
189  void scrollContentsBy( int dx, int dy ) override;
190 
191  private:
193  QgsComposerView::Tool mCurrentTool;
195  QgsComposerView::Tool mPreviousTool;
196 
198  QGraphicsRectItem* mRubberBandItem;
200  QGraphicsLineItem* mRubberBandLineItem;
202  QgsComposerItem* mMoveContentItem;
204  QPointF mMoveContentStartPos;
206  QPointF mRubberBandStartPos;
207 
209  bool mMarqueeSelect;
211  bool mMarqueeZoom;
213  QgsComposerView::ToolStatus mTemporaryZoomStatus;
214 
215  bool mPaintingEnabled;
216 
217  QgsComposerRuler* mHorizontalRuler;
218  QgsComposerRuler* mVerticalRuler;
219 
221  void addShape( Tool currentTool );
222 
224  void addPolygonNode( QPointF scenePoint );
225  void movePolygonNode( QPointF scenePoint );
226  void displayNodes( const bool display = true );
227  void setSelectedNode( QgsComposerNodesItem *shape, const int index );
228  void unselectNode();
229 
230  float mMoveContentSearchRadius;
231  QgsComposerNodesItem* mNodesItem;
232  int mNodesItemIndex;
233  QScopedPointer<QGraphicsPolygonItem> mPolygonItem;
234  QScopedPointer<QGraphicsPathItem> mPolylineItem;
235 
237  bool mToolPanning;
239  bool mMousePanning;
241  bool mKeyPanning;
242 
244  bool mMovingItemContent;
245 
246  QPoint mMouseLastXY;
247  QPoint mMouseCurrentXY;
248  QPoint mMousePressStartPos;
249 
250  QgsPreviewEffect* mPreviewEffect;
251 
253  QCursor defaultCursorForTool( Tool currentTool );
254 
256  void wheelZoom( QWheelEvent * event );
258  void updateRubberBandRect( QPointF & pos, const bool constrainSquare = false, const bool fromCenter = false );
260  void updateRubberBandLine( QPointF pos, const bool constrainAngles = false );
262  void removeRubberBand();
263 
265  void startMarqueeSelect( QPointF & scenePoint );
267  void endMarqueeSelect( QMouseEvent* e );
269  void startMarqueeZoom( QPointF & scenePoint );
271  void endMarqueeZoom( QMouseEvent* e );
272 
273  //void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );
274 
275  signals:
277  void selectedItemChanged( QgsComposerItem* selected );
279  void itemRemoved( QgsComposerItem* );
280 
283  void actionFinished();
285  void cursorPosChanged( QPointF );
287  void zoomLevelChanged();
288 
290  void composerViewShow( QgsComposerView* );
292  void composerViewHide( QgsComposerView* );
293 
295  void compositionSet( QgsComposition* );
296 };
297 
298 #endif
An abstract composer item that provides generic methods for nodes based shapes such as polygon or pol...
A scale bar item that can be added to a map composition.
static unsigned index
bool paintingEnabled() const
An item that draws an arrow between two points.
void setPaintingEnabled(bool enabled)
A item that forms part of a map composition.
A table that displays attributes from a vector layer.
void setVerticalRuler(QgsComposerRuler *r)
A graphics effect which can be applied to a widget to simulate various printing and color blindness m...
A composer class that displays svg files or raster format (jpg, png, ...)
Widget to display the composer items.
Graphics scene for map printing.
Object representing map window.
Tool
Current tool.
A class to show paper scale and the current cursor position.
A composer items that draws common shapes (ellipse, triangle, rectangle)
void setHorizontalRuler(QgsComposerRuler *r)
A label that can be placed onto a map composition.
QgsComposerView::Tool currentTool() const
A legend that can be placed onto a map composition.