QGIS API Documentation  2.99.0-Master (7fe5405)
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 
25 class QDomDocument;
26 class QDomElement;
27 class QKeyEvent;
28 class QMainWindow;
29 class QMouseEvent;
30 class QgsComposition;
31 class QgsComposerArrow;
32 class QgsComposerItem;
33 class QgsComposerLabel;
34 class QgsComposerLegend;
35 class QgsComposerMap;
36 class QgsComposerPicture;
37 class QgsComposerRuler;
39 class QgsComposerShape;
42 class QgsMapCanvas;
43 
50 class GUI_EXPORT QgsComposerView: public QGraphicsView
51 {
52  Q_OBJECT
53 
54  public:
55 
57  enum Tool
58  {
59  Select = 0, // Select/Move item
60  AddArrow, // add arrow
62  AddMap, // add new map
63  AddLegend, // add vector legend
64  AddLabel, // add label
65  AddScalebar, // add scalebar
66  AddPicture, // add raster/vector picture
72  AddTable, // add attribute table
74  MoveItemContent, // move content of item (e.g. content of map)
76  Pan,
77  Zoom
78  };
79 
81  {
83  ClipboardModeCopy
84  };
85 
86  enum PasteMode
87  {
90  PasteModeInPlace
91  };
92 
94  {
97  ActiveUntilMouseRelease
98  };
99 
100  QgsComposerView( QWidget* parent = nullptr, const char* name = nullptr, Qt::WindowFlags f = 0 );
101 
103  void groupItems();
104 
106  void ungroupItems();
107 
109  void copyItems( ClipboardMode mode );
110 
112  void pasteItems( PasteMode mode );
113 
115  void deleteSelectedItems();
116 
118  void selectAll();
119 
121  void selectNone();
122 
124  void selectInvert();
125 
126  QgsComposerView::Tool currentTool() const {return mCurrentTool;}
127  void setCurrentTool( QgsComposerView::Tool t );
128 
132  void setComposition( QgsComposition* c );
133 
135  QgsComposition* composition();
136 
138  QMainWindow* composerWindow();
139 
140  void setPaintingEnabled( bool enabled ) { mPaintingEnabled = enabled; }
141  bool paintingEnabled() const { return mPaintingEnabled; }
142 
144  void updateRulers();
145 
146  void setHorizontalRuler( QgsComposerRuler* r ) { mHorizontalRuler = r; }
147  void setVerticalRuler( QgsComposerRuler* r ) { mVerticalRuler = r; }
148 
150  void setZoomLevel( double zoomLevel );
151 
157  void scaleSafe( double scale );
158 
164  void setPreviewModeEnabled( bool enabled );
165 
172  void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
173 
179  void setMapCanvas( QgsMapCanvas* canvas );
180 
186  QgsMapCanvas* mapCanvas() const;
187 
188  protected:
189  void mousePressEvent( QMouseEvent* ) override;
190  void mouseReleaseEvent( QMouseEvent* ) override;
191  void mouseMoveEvent( QMouseEvent* ) override;
192  void mouseDoubleClickEvent( QMouseEvent* e ) override;
193 
194  void keyPressEvent( QKeyEvent * e ) override;
195  void keyReleaseEvent( QKeyEvent * e ) override;
196 
197  void wheelEvent( QWheelEvent* event ) override;
198 
199  void paintEvent( QPaintEvent* event ) override;
200 
201  void hideEvent( QHideEvent* e ) override;
202  void showEvent( QShowEvent* e ) override;
203 
204  void resizeEvent( QResizeEvent* event ) override;
205  void scrollContentsBy( int dx, int dy ) override;
206 
207  private:
209  QgsComposerView::Tool mCurrentTool;
211  QgsComposerView::Tool mPreviousTool;
212 
214  QGraphicsRectItem* mRubberBandItem;
216  QGraphicsLineItem* mRubberBandLineItem;
218  QgsComposerItem* mMoveContentItem;
220  QPointF mMoveContentStartPos;
222  QPointF mRubberBandStartPos;
223 
225  bool mMarqueeSelect;
227  bool mMarqueeZoom;
229  QgsComposerView::ToolStatus mTemporaryZoomStatus;
230 
231  bool mPaintingEnabled;
232 
233  QgsComposerRuler* mHorizontalRuler;
234  QgsComposerRuler* mVerticalRuler;
235 
236  QgsMapCanvas* mCanvas = nullptr;
237 
239  void addShape( Tool currentTool );
240 
242  void addPolygonNode( QPointF scenePoint );
243  void movePolygonNode( QPointF scenePoint );
244  void displayNodes( const bool display = true );
245  void setSelectedNode( QgsComposerNodesItem *shape, const int index );
246  void deselectNode();
247 
248  float mMoveContentSearchRadius;
249  QgsComposerNodesItem* mNodesItem;
250  int mNodesItemIndex;
251  QScopedPointer<QGraphicsPolygonItem> mPolygonItem;
252  QScopedPointer<QGraphicsPathItem> mPolylineItem;
253 
255  bool mToolPanning;
257  bool mMousePanning;
259  bool mKeyPanning;
260 
262  bool mMovingItemContent;
263 
264  QPoint mMouseLastXY;
265  QPoint mMouseCurrentXY;
266  QPoint mMousePressStartPos;
267 
268  QgsPreviewEffect* mPreviewEffect;
269 
271  QCursor defaultCursorForTool( Tool currentTool );
272 
274  void wheelZoom( QWheelEvent * event );
276  void updateRubberBandRect( QPointF & pos, const bool constrainSquare = false, const bool fromCenter = false );
278  void updateRubberBandLine( QPointF pos, const bool constrainAngles = false );
280  void removeRubberBand();
281 
283  void startMarqueeSelect( QPointF & scenePoint );
285  void endMarqueeSelect( QMouseEvent* e );
287  void startMarqueeZoom( QPointF & scenePoint );
289  void endMarqueeZoom( QMouseEvent* e );
290 
291  //void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );
292 
293  signals:
295  void selectedItemChanged( QgsComposerItem* selected );
297  void itemRemoved( QgsComposerItem* );
298 
301  void actionFinished();
303  void cursorPosChanged( QPointF );
305  void zoomLevelChanged();
306 
308  void composerViewShow( QgsComposerView* );
310  void composerViewHide( QgsComposerView* );
311 
313  void compositionSet( QgsComposition* );
314 };
315 
316 #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: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, ...)
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.