QGIS API Documentation  2.99.0-Master (90ae728)
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 #include "qgis_gui.h"
24 #include <memory>
25 
26 class QDomDocument;
27 class QDomElement;
28 class QKeyEvent;
29 class QMainWindow;
30 class QMouseEvent;
31 class QgsComposition;
32 class QgsComposerArrow;
33 class QgsComposerItem;
34 class QgsComposerLabel;
35 class QgsComposerLegend;
36 class QgsComposerMap;
37 class QgsComposerPicture;
38 class QgsComposerRuler;
40 class QgsComposerShape;
43 class QgsMapCanvas;
44 
51 class GUI_EXPORT QgsComposerView: public QGraphicsView
52 {
53  Q_OBJECT
54 
55  public:
56 
58  enum Tool
59  {
60  Select = 0, // Select/Move item
61  AddArrow, // add arrow
63  AddMap, // add new map
64  AddLegend, // add vector legend
65  AddLabel, // add label
66  AddScalebar, // add scalebar
67  AddPicture, // add raster/vector picture
73  AddTable, // add attribute table
75  MoveItemContent, // move content of item (e.g. content of map)
77  Pan,
78  Zoom
79  };
80 
82  {
84  ClipboardModeCopy
85  };
86 
87  enum PasteMode
88  {
91  PasteModeInPlace
92  };
93 
95  {
98  ActiveUntilMouseRelease
99  };
100 
101  QgsComposerView( QWidget* parent = nullptr, const char* name = nullptr, Qt::WindowFlags f = 0 );
102 
104  void groupItems();
105 
107  void ungroupItems();
108 
110  void copyItems( ClipboardMode mode );
111 
113  void pasteItems( PasteMode mode );
114 
116  void deleteSelectedItems();
117 
119  void selectAll();
120 
122  void selectNone();
123 
125  void selectInvert();
126 
127  QgsComposerView::Tool currentTool() const {return mCurrentTool;}
128  void setCurrentTool( QgsComposerView::Tool t );
129 
133  void setComposition( QgsComposition* c );
134 
136  QgsComposition* composition();
137 
139  QMainWindow* composerWindow();
140 
141  void setPaintingEnabled( bool enabled ) { mPaintingEnabled = enabled; }
142  bool paintingEnabled() const { return mPaintingEnabled; }
143 
145  void updateRulers();
146 
147  void setHorizontalRuler( QgsComposerRuler* r ) { mHorizontalRuler = r; }
148  void setVerticalRuler( QgsComposerRuler* r ) { mVerticalRuler = r; }
149 
151  void setZoomLevel( double zoomLevel );
152 
158  void scaleSafe( double scale );
159 
165  void setPreviewModeEnabled( bool enabled );
166 
173  void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
174 
180  void setMapCanvas( QgsMapCanvas* canvas );
181 
187  QgsMapCanvas* mapCanvas() const;
188 
189  protected:
190  void mousePressEvent( QMouseEvent* ) override;
191  void mouseReleaseEvent( QMouseEvent* ) override;
192  void mouseMoveEvent( QMouseEvent* ) override;
193  void mouseDoubleClickEvent( QMouseEvent* e ) override;
194 
195  void keyPressEvent( QKeyEvent * e ) override;
196  void keyReleaseEvent( QKeyEvent * e ) override;
197 
198  void wheelEvent( QWheelEvent* event ) override;
199 
200  void paintEvent( QPaintEvent* event ) override;
201 
202  void hideEvent( QHideEvent* e ) override;
203  void showEvent( QShowEvent* e ) override;
204 
205  void resizeEvent( QResizeEvent* event ) override;
206  void scrollContentsBy( int dx, int dy ) override;
207 
208  private:
210  QgsComposerView::Tool mCurrentTool;
212  QgsComposerView::Tool mPreviousTool;
213 
215  QGraphicsRectItem* mRubberBandItem = nullptr;
217  QGraphicsLineItem* mRubberBandLineItem = nullptr;
219  QgsComposerItem* mMoveContentItem = nullptr;
221  QPointF mMoveContentStartPos;
223  QPointF mRubberBandStartPos;
224 
226  bool mMarqueeSelect;
228  bool mMarqueeZoom;
230  QgsComposerView::ToolStatus mTemporaryZoomStatus;
231 
232  bool mPaintingEnabled;
233 
234  QgsComposerRuler* mHorizontalRuler = nullptr;
235  QgsComposerRuler* mVerticalRuler = nullptr;
236 
237  QgsMapCanvas* mCanvas = nullptr;
238 
240  void addShape( Tool currentTool );
241 
243  void addPolygonNode( QPointF scenePoint );
244  void movePolygonNode( QPointF scenePoint, bool constrainAngle );
245  void displayNodes( const bool display = true );
246  void setSelectedNode( QgsComposerNodesItem *shape, const int index );
247  void deselectNode();
248 
249  float mMoveContentSearchRadius;
250  QgsComposerNodesItem* mNodesItem = nullptr;
251  int mNodesItemIndex;
252  std::unique_ptr<QGraphicsPolygonItem> mPolygonItem;
253  std::unique_ptr<QGraphicsPathItem> mPolylineItem;
254 
256  bool mToolPanning;
258  bool mMousePanning;
260  bool mKeyPanning;
261 
263  bool mMovingItemContent;
264 
265  QPoint mMouseLastXY;
266  QPoint mMouseCurrentXY;
267  QPoint mMousePressStartPos;
268 
269  QgsPreviewEffect* mPreviewEffect = nullptr;
270 
272  QCursor defaultCursorForTool( Tool currentTool );
273 
275  void wheelZoom( QWheelEvent * event );
277  void updateRubberBandRect( QPointF & pos, const bool constrainSquare = false, const bool fromCenter = false );
279  void updateRubberBandLine( QPointF pos, const bool constrainAngles = false );
281  void removeRubberBand();
282 
284  void startMarqueeSelect( QPointF & scenePoint );
286  void endMarqueeSelect( QMouseEvent* e );
288  void startMarqueeZoom( QPointF & scenePoint );
290  void endMarqueeZoom( QMouseEvent* e );
291 
292  //void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );
293 
294  signals:
296  void selectedItemChanged( QgsComposerItem* selected );
298  void itemRemoved( QgsComposerItem* );
299 
302  void actionFinished();
304  void cursorPosChanged( QPointF );
306  void zoomLevelChanged();
307 
309  void composerViewShow( QgsComposerView* );
311  void composerViewHide( QgsComposerView* );
312 
314  void compositionSet( QgsComposition* );
315 };
316 
317 #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.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:72
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.