QGIS API Documentation  2.99.0-Master (69af2f5)
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 "qgis.h"
22 #include "qgsprevieweffect.h" // for QgsPreviewEffect::PreviewMode
23 #include <QGraphicsPolygonItem>
24 #include "qgis_gui.h"
25 #include <memory>
26 
27 class QDomDocument;
28 class QDomElement;
29 class QKeyEvent;
30 class QMainWindow;
31 class QMouseEvent;
32 class QgsComposition;
33 class QgsComposerArrow;
34 class QgsComposerItem;
35 class QgsComposerLabel;
36 class QgsComposerLegend;
37 class QgsComposerMap;
38 class QgsComposerPicture;
39 class QgsComposerRuler;
41 class QgsComposerShape;
44 class QgsMapCanvas;
45 
52 class GUI_EXPORT QgsComposerView: public QGraphicsView
53 {
54 
55 #ifdef SIP_RUN
57  if ( sipCpp->inherits( "QgsComposerView" ) )
58  sipType = sipType_QgsComposerView;
59  else
60  sipType = NULL;
61  SIP_END
62 #endif
63  Q_OBJECT
64 
65  public:
66 
68  enum Tool
69  {
70  Select = 0, // Select/Move item
71  AddArrow, // add arrow
73  AddMap, // add new map
74  AddLegend, // add vector legend
75  AddLabel, // add label
76  AddScalebar, // add scalebar
77  AddPicture, // add raster/vector picture
83  AddTable, // add attribute table
85  MoveItemContent, // move content of item (e.g. content of map)
87  Pan,
88  Zoom
89  };
90 
92  {
94  ClipboardModeCopy
95  };
96 
97  enum PasteMode
98  {
101  PasteModeInPlace
102  };
103 
105  {
108  ActiveUntilMouseRelease
109  };
110 
111  QgsComposerView( QWidget *parent SIP_TRANSFERTHIS = nullptr, const char *name = nullptr, Qt::WindowFlags f = 0 );
112 
114  void groupItems();
115 
117  void ungroupItems();
118 
120  void copyItems( ClipboardMode mode );
121 
123  void pasteItems( PasteMode mode );
124 
126  void deleteSelectedItems();
127 
129  void selectAll();
130 
132  void selectNone();
133 
135  void selectInvert();
136 
137  QgsComposerView::Tool currentTool() const {return mCurrentTool;}
138  void setCurrentTool( QgsComposerView::Tool t );
139 
143  void setComposition( QgsComposition *c SIP_KEEPREFERENCE );
144 
146  QgsComposition *composition();
147 
149  QMainWindow *composerWindow();
150 
151  void setPaintingEnabled( bool enabled ) { mPaintingEnabled = enabled; }
152  bool paintingEnabled() const { return mPaintingEnabled; }
153 
155  void updateRulers();
156 
157  void setHorizontalRuler( QgsComposerRuler *r ) { mHorizontalRuler = r; }
158  void setVerticalRuler( QgsComposerRuler *r ) { mVerticalRuler = r; }
159 
161  void setZoomLevel( double zoomLevel );
162 
168  void scaleSafe( double scale );
169 
175  void setPreviewModeEnabled( bool enabled );
176 
183  void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
184 
190  void setMapCanvas( QgsMapCanvas *canvas );
191 
197  QgsMapCanvas *mapCanvas() const;
198 
199  protected:
200  void mousePressEvent( QMouseEvent * ) override;
201  void mouseReleaseEvent( QMouseEvent * ) override;
202  void mouseMoveEvent( QMouseEvent * ) override;
203  void mouseDoubleClickEvent( QMouseEvent *e ) override;
204 
205  void keyPressEvent( QKeyEvent *e ) override;
206  void keyReleaseEvent( QKeyEvent *e ) override;
207 
208  void wheelEvent( QWheelEvent *event ) override;
209 
210  void paintEvent( QPaintEvent *event ) override;
211 
212  void hideEvent( QHideEvent *e ) override;
213  void showEvent( QShowEvent *e ) override;
214 
215  void resizeEvent( QResizeEvent *event ) override;
216  void scrollContentsBy( int dx, int dy ) override;
217 
218  private:
220  QgsComposerView::Tool mCurrentTool;
222  QgsComposerView::Tool mPreviousTool;
223 
225  QGraphicsRectItem *mRubberBandItem = nullptr;
227  QGraphicsLineItem *mRubberBandLineItem = nullptr;
229  QgsComposerItem *mMoveContentItem = nullptr;
231  QPointF mMoveContentStartPos;
233  QPointF mRubberBandStartPos;
234 
236  bool mMarqueeSelect;
238  bool mMarqueeZoom;
240  QgsComposerView::ToolStatus mTemporaryZoomStatus;
241 
242  bool mPaintingEnabled;
243 
244  QgsComposerRuler *mHorizontalRuler = nullptr;
245  QgsComposerRuler *mVerticalRuler = nullptr;
246 
247  QgsMapCanvas *mCanvas = nullptr;
248 
250  void addShape( Tool currentTool );
251 
253  void addPolygonNode( QPointF scenePoint );
254  void movePolygonNode( QPointF scenePoint, bool constrainAngle );
255  void displayNodes( const bool display = true );
256  void setSelectedNode( QgsComposerNodesItem *shape, const int index );
257  void deselectNode();
258 
259  float mMoveContentSearchRadius;
260  QgsComposerNodesItem *mNodesItem = nullptr;
261  int mNodesItemIndex;
262  std::unique_ptr<QGraphicsPolygonItem> mPolygonItem;
263  std::unique_ptr<QGraphicsPathItem> mPolylineItem;
264 
266  bool mToolPanning;
268  bool mMousePanning;
270  bool mKeyPanning;
271 
273  bool mMovingItemContent;
274 
275  QPoint mMouseLastXY;
276  QPoint mMouseCurrentXY;
277  QPoint mMousePressStartPos;
278 
279  QgsPreviewEffect *mPreviewEffect = nullptr;
280 
282  QCursor defaultCursorForTool( Tool currentTool );
283 
285  void wheelZoom( QWheelEvent *event );
287  void updateRubberBandRect( QPointF &pos, const bool constrainSquare = false, const bool fromCenter = false );
289  void updateRubberBandLine( QPointF pos, const bool constrainAngles = false );
291  void removeRubberBand();
292 
294  void startMarqueeSelect( QPointF &scenePoint );
296  void endMarqueeSelect( QMouseEvent *e );
298  void startMarqueeZoom( QPointF &scenePoint );
300  void endMarqueeZoom( QMouseEvent *e );
301 
302  //void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );
303 
304  signals:
306  void selectedItemChanged( QgsComposerItem *selected );
308  void itemRemoved( QgsComposerItem * );
309 
312  void actionFinished();
314  void cursorPosChanged( QPointF );
316  void zoomLevelChanged();
317 
319  void composerViewShow( QgsComposerView * );
321  void composerViewHide( QgsComposerView * );
322 
324  void compositionSet( QgsComposition * );
325 };
326 
327 #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.
bool paintingEnabled() const
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:34
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:73
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, ...)
#define SIP_END
Definition: qgis_sip.h:163
Widget to display the composer items.
#define SIP_KEEPREFERENCE
Definition: qgis_sip.h:67
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)
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:153
A label that can be placed onto a map composition.
QgsComposerView::Tool currentTool() const
A legend that can be placed onto a map composition.