QGIS API Documentation  2.99.0-Master (d55fa22)
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  Q_OBJECT
55 
56  public:
57 
59  enum Tool
60  {
61  Select = 0, // Select/Move item
62  AddArrow, // add arrow
64  AddMap, // add new map
65  AddLegend, // add vector legend
66  AddLabel, // add label
67  AddScalebar, // add scalebar
68  AddPicture, // add raster/vector picture
74  AddTable, // add attribute table
76  MoveItemContent, // move content of item (e.g. content of map)
78  Pan,
79  Zoom
80  };
81 
83  {
85  ClipboardModeCopy
86  };
87 
88  enum PasteMode
89  {
92  PasteModeInPlace
93  };
94 
96  {
99  ActiveUntilMouseRelease
100  };
101 
102  QgsComposerView( QWidget *parent = nullptr, const char *name = nullptr, Qt::WindowFlags f = 0 );
103 
105  void groupItems();
106 
108  void ungroupItems();
109 
111  void copyItems( ClipboardMode mode );
112 
114  void pasteItems( PasteMode mode );
115 
117  void deleteSelectedItems();
118 
120  void selectAll();
121 
123  void selectNone();
124 
126  void selectInvert();
127 
128  QgsComposerView::Tool currentTool() const {return mCurrentTool;}
129  void setCurrentTool( QgsComposerView::Tool t );
130 
134  void setComposition( QgsComposition *c SIP_KEEPREFERENCE );
135 
137  QgsComposition *composition();
138 
140  QMainWindow *composerWindow();
141 
142  void setPaintingEnabled( bool enabled ) { mPaintingEnabled = enabled; }
143  bool paintingEnabled() const { return mPaintingEnabled; }
144 
146  void updateRulers();
147 
148  void setHorizontalRuler( QgsComposerRuler *r ) { mHorizontalRuler = r; }
149  void setVerticalRuler( QgsComposerRuler *r ) { mVerticalRuler = r; }
150 
152  void setZoomLevel( double zoomLevel );
153 
159  void scaleSafe( double scale );
160 
166  void setPreviewModeEnabled( bool enabled );
167 
174  void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
175 
181  void setMapCanvas( QgsMapCanvas *canvas );
182 
188  QgsMapCanvas *mapCanvas() const;
189 
190  protected:
191  void mousePressEvent( QMouseEvent * ) override;
192  void mouseReleaseEvent( QMouseEvent * ) override;
193  void mouseMoveEvent( QMouseEvent * ) override;
194  void mouseDoubleClickEvent( QMouseEvent *e ) override;
195 
196  void keyPressEvent( QKeyEvent *e ) override;
197  void keyReleaseEvent( QKeyEvent *e ) override;
198 
199  void wheelEvent( QWheelEvent *event ) override;
200 
201  void paintEvent( QPaintEvent *event ) override;
202 
203  void hideEvent( QHideEvent *e ) override;
204  void showEvent( QShowEvent *e ) override;
205 
206  void resizeEvent( QResizeEvent *event ) override;
207  void scrollContentsBy( int dx, int dy ) override;
208 
209  private:
211  QgsComposerView::Tool mCurrentTool;
213  QgsComposerView::Tool mPreviousTool;
214 
216  QGraphicsRectItem *mRubberBandItem = nullptr;
218  QGraphicsLineItem *mRubberBandLineItem = nullptr;
220  QgsComposerItem *mMoveContentItem = nullptr;
222  QPointF mMoveContentStartPos;
224  QPointF mRubberBandStartPos;
225 
227  bool mMarqueeSelect;
229  bool mMarqueeZoom;
231  QgsComposerView::ToolStatus mTemporaryZoomStatus;
232 
233  bool mPaintingEnabled;
234 
235  QgsComposerRuler *mHorizontalRuler = nullptr;
236  QgsComposerRuler *mVerticalRuler = nullptr;
237 
238  QgsMapCanvas *mCanvas = nullptr;
239 
241  void addShape( Tool currentTool );
242 
244  void addPolygonNode( QPointF scenePoint );
245  void movePolygonNode( QPointF scenePoint, bool constrainAngle );
246  void displayNodes( const bool display = true );
247  void setSelectedNode( QgsComposerNodesItem *shape, const int index );
248  void deselectNode();
249 
250  float mMoveContentSearchRadius;
251  QgsComposerNodesItem *mNodesItem = nullptr;
252  int mNodesItemIndex;
253  std::unique_ptr<QGraphicsPolygonItem> mPolygonItem;
254  std::unique_ptr<QGraphicsPathItem> mPolylineItem;
255 
257  bool mToolPanning;
259  bool mMousePanning;
261  bool mKeyPanning;
262 
264  bool mMovingItemContent;
265 
266  QPoint mMouseLastXY;
267  QPoint mMouseCurrentXY;
268  QPoint mMousePressStartPos;
269 
270  QgsPreviewEffect *mPreviewEffect = nullptr;
271 
273  QCursor defaultCursorForTool( Tool currentTool );
274 
276  void wheelZoom( QWheelEvent *event );
278  void updateRubberBandRect( QPointF &pos, const bool constrainSquare = false, const bool fromCenter = false );
280  void updateRubberBandLine( QPointF pos, const bool constrainAngles = false );
282  void removeRubberBand();
283 
285  void startMarqueeSelect( QPointF &scenePoint );
287  void endMarqueeSelect( QMouseEvent *e );
289  void startMarqueeZoom( QPointF &scenePoint );
291  void endMarqueeZoom( QMouseEvent *e );
292 
293  //void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );
294 
295  signals:
297  void selectedItemChanged( QgsComposerItem *selected );
299  void itemRemoved( QgsComposerItem * );
300 
303  void actionFinished();
305  void cursorPosChanged( QPointF );
307  void zoomLevelChanged();
308 
310  void composerViewShow( QgsComposerView * );
312  void composerViewHide( QgsComposerView * );
313 
315  void compositionSet( QgsComposition * );
316 };
317 
318 #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
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, ...)
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)
A label that can be placed onto a map composition.
QgsComposerView::Tool currentTool() const
A legend that can be placed onto a map composition.