QGIS API Documentation  2.99.0-Master (9fdd060)
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 
53 class GUI_EXPORT QgsComposerView: public QGraphicsView
54 {
55 
56 #ifdef SIP_RUN
58  if ( sipCpp->inherits( "QgsComposerView" ) )
59  sipType = sipType_QgsComposerView;
60  else
61  sipType = NULL;
62  SIP_END
63 #endif
64  Q_OBJECT
65 
66  public:
67 
69  enum Tool
70  {
71  Select = 0, // Select/Move item
72  AddArrow, // add arrow
74  AddMap, // add new map
75  AddLegend, // add vector legend
76  AddLabel, // add label
77  AddScalebar, // add scalebar
78  AddPicture, // add raster/vector picture
84  AddTable, // add attribute table
86  MoveItemContent, // move content of item (e.g. content of map)
88  Pan,
89  Zoom
90  };
91 
93  {
95  ClipboardModeCopy
96  };
97 
98  enum PasteMode
99  {
102  PasteModeInPlace
103  };
104 
106  {
109  ActiveUntilMouseRelease
110  };
111 
112  QgsComposerView( QWidget *parent SIP_TRANSFERTHIS = nullptr, const char *name = nullptr, Qt::WindowFlags f = 0 );
113 
115  void groupItems();
116 
118  void ungroupItems();
119 
121  void copyItems( ClipboardMode mode );
122 
124  void pasteItems( PasteMode mode );
125 
127  void deleteSelectedItems();
128 
130  void selectAll();
131 
133  void selectNone();
134 
136  void selectInvert();
137 
138  QgsComposerView::Tool currentTool() const {return mCurrentTool;}
139  void setCurrentTool( QgsComposerView::Tool t );
140 
145  void setComposition( QgsComposition *c SIP_KEEPREFERENCE );
146 
148  QgsComposition *composition();
149 
151  QMainWindow *composerWindow();
152 
153  void setPaintingEnabled( bool enabled ) { mPaintingEnabled = enabled; }
154  bool paintingEnabled() const { return mPaintingEnabled; }
155 
157  void updateRulers();
158 
159  void setHorizontalRuler( QgsComposerRuler *r ) { mHorizontalRuler = r; }
160  void setVerticalRuler( QgsComposerRuler *r ) { mVerticalRuler = r; }
161 
163  void setZoomLevel( double zoomLevel );
164 
171  void scaleSafe( double scale );
172 
179  void setPreviewModeEnabled( bool enabled );
180 
188  void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
189 
196  void setMapCanvas( QgsMapCanvas *canvas );
197 
203  QgsMapCanvas *mapCanvas() const;
204 
205  protected:
206  void mousePressEvent( QMouseEvent * ) override;
207  void mouseReleaseEvent( QMouseEvent * ) override;
208  void mouseMoveEvent( QMouseEvent * ) override;
209  void mouseDoubleClickEvent( QMouseEvent *e ) override;
210 
211  void keyPressEvent( QKeyEvent *e ) override;
212  void keyReleaseEvent( QKeyEvent *e ) override;
213 
214  void wheelEvent( QWheelEvent *event ) override;
215 
216  void paintEvent( QPaintEvent *event ) override;
217 
218  void hideEvent( QHideEvent *e ) override;
219  void showEvent( QShowEvent *e ) override;
220 
221  void resizeEvent( QResizeEvent *event ) override;
222  void scrollContentsBy( int dx, int dy ) override;
223 
224  private:
226  QgsComposerView::Tool mCurrentTool = Select;
228  QgsComposerView::Tool mPreviousTool = Select;
229 
231  QGraphicsRectItem *mRubberBandItem = nullptr;
233  QGraphicsLineItem *mRubberBandLineItem = nullptr;
235  QgsComposerItem *mMoveContentItem = nullptr;
237  QPointF mMoveContentStartPos;
239  QPointF mRubberBandStartPos;
240 
242  bool mMarqueeSelect = false;
244  bool mMarqueeZoom = false;
247 
248  bool mPaintingEnabled = true;
249 
250  QgsComposerRuler *mHorizontalRuler = nullptr;
251  QgsComposerRuler *mVerticalRuler = nullptr;
252 
253  QgsMapCanvas *mCanvas = nullptr;
254 
256  void addShape( Tool currentTool );
257 
259  void addPolygonNode( QPointF scenePoint );
260  void movePolygonNode( QPointF scenePoint, bool constrainAngle );
261  void displayNodes( const bool display = true );
262  void setSelectedNode( QgsComposerNodesItem *shape, const int index );
263  void deselectNode();
264 
265  float mMoveContentSearchRadius = 25;
266  QgsComposerNodesItem *mNodesItem = nullptr;
267  int mNodesItemIndex = -1;
268  std::unique_ptr<QGraphicsPolygonItem> mPolygonItem;
269  std::unique_ptr<QGraphicsPathItem> mPolylineItem;
270 
272  bool mToolPanning = false;
274  bool mMousePanning = false;
276  bool mKeyPanning = false;
277 
279  bool mMovingItemContent = false;
280 
281  QPoint mMouseLastXY;
282  QPoint mMouseCurrentXY;
283  QPoint mMousePressStartPos;
284 
285  QgsPreviewEffect *mPreviewEffect = nullptr;
286 
288  QCursor defaultCursorForTool( Tool currentTool );
289 
291  void wheelZoom( QWheelEvent *event );
293  void updateRubberBandRect( QPointF &pos, const bool constrainSquare = false, const bool fromCenter = false );
295  void updateRubberBandLine( QPointF pos, const bool constrainAngles = false );
297  void removeRubberBand();
298 
300  void startMarqueeSelect( QPointF &scenePoint );
302  void endMarqueeSelect( QMouseEvent *e );
304  void startMarqueeZoom( QPointF &scenePoint );
306  void endMarqueeZoom( QMouseEvent *e );
307 
308  //void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );
309 
310  signals:
312  void selectedItemChanged( QgsComposerItem *selected );
314  void itemRemoved( QgsComposerItem * );
315 
319  void actionFinished();
321  void cursorPosChanged( QPointF );
323  void zoomLevelChanged();
324 
326  void composerViewShow( QgsComposerView * );
328  void composerViewHide( QgsComposerView * );
329 
331  void compositionSet( QgsComposition * );
332 };
333 
334 #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:46
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:74
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:175
Widget to display the composer items.
#define SIP_KEEPREFERENCE
Definition: qgis_sip.h:79
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:165
A label that can be placed onto a map composition.
QgsComposerView::Tool currentTool() const
A legend that can be placed onto a map composition.