QGIS API Documentation  2.17.0-Master (eef6f05)
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>
22 #include "qgsprevieweffect.h" // for QgsPreviewEffect::PreviewMode
23 #include <QGraphicsPolygonItem>
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 
49 class GUI_EXPORT QgsComposerView: public QGraphicsView
50 {
51  Q_OBJECT
52 
53  public:
54 
56  enum Tool
57  {
58  Select = 0, // Select/Move item
59  AddArrow, // add arrow
61  AddMap, // add new map
62  AddLegend, // add vector legend
63  AddLabel, // add label
64  AddScalebar, // add scalebar
65  AddPicture, // add raster/vector picture
71  AddTable, // add attribute table
73  MoveItemContent, // move content of item (e.g. content of map)
75  Pan,
76  Zoom
77  };
78 
80  {
82  ClipboardModeCopy
83  };
84 
85  enum PasteMode
86  {
89  PasteModeInPlace
90  };
91 
93  {
96  ActiveUntilMouseRelease
97  };
98 
99  QgsComposerView( QWidget* parent = nullptr, const char* name = nullptr, const Qt::WindowFlags& f = nullptr );
100 
102  void groupItems();
103 
105  void ungroupItems();
106 
108  void copyItems( ClipboardMode mode );
109 
111  void pasteItems( PasteMode mode );
112 
114  void deleteSelectedItems();
115 
117  void selectAll();
118 
120  void selectNone();
121 
123  void selectInvert();
124 
125  QgsComposerView::Tool currentTool() const {return mCurrentTool;}
126  void setCurrentTool( QgsComposerView::Tool t );
127 
131  void setComposition( QgsComposition* c );
132 
134  QgsComposition* composition();
135 
137  QMainWindow* composerWindow();
138 
139  void setPaintingEnabled( bool enabled ) { mPaintingEnabled = enabled; }
140  bool paintingEnabled() const { return mPaintingEnabled; }
141 
143  void updateRulers();
144 
145  void setHorizontalRuler( QgsComposerRuler* r ) { mHorizontalRuler = r; }
146  void setVerticalRuler( QgsComposerRuler* r ) { mVerticalRuler = r; }
147 
149  void setZoomLevel( double zoomLevel );
150 
156  void scaleSafe( double scale );
157 
163  void setPreviewModeEnabled( bool enabled );
170  void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
171 
172  protected:
173  void mousePressEvent( QMouseEvent* ) override;
174  void mouseReleaseEvent( QMouseEvent* ) override;
175  void mouseMoveEvent( QMouseEvent* ) override;
176  void mouseDoubleClickEvent( QMouseEvent* e ) override;
177 
178  void keyPressEvent( QKeyEvent * e ) override;
179  void keyReleaseEvent( QKeyEvent * e ) override;
180 
181  void wheelEvent( QWheelEvent* event ) override;
182 
183  void paintEvent( QPaintEvent* event ) override;
184 
185  void hideEvent( QHideEvent* e ) override;
186  void showEvent( QShowEvent* e ) override;
187 
188  void resizeEvent( QResizeEvent* event ) override;
189  void scrollContentsBy( int dx, int dy ) override;
190 
191  private:
193  QgsComposerView::Tool mCurrentTool;
195  QgsComposerView::Tool mPreviousTool;
196 
198  QGraphicsRectItem* mRubberBandItem;
200  QGraphicsLineItem* mRubberBandLineItem;
202  QgsComposerItem* mMoveContentItem;
204  QPointF mMoveContentStartPos;
206  QPointF mRubberBandStartPos;
207 
209  bool mMarqueeSelect;
211  bool mMarqueeZoom;
213  QgsComposerView::ToolStatus mTemporaryZoomStatus;
214 
215  bool mPaintingEnabled;
216 
217  QgsComposerRuler* mHorizontalRuler;
218  QgsComposerRuler* mVerticalRuler;
219 
221  void addShape( Tool currentTool );
222 
224  void addPolygonNode( const QPointF & scenePoint );
225  void movePolygonNode( const QPointF & scenePoint );
226  void displayNodes( const bool display = true );
227  void setSelectedNode( QgsComposerNodesItem *shape, const int index );
228  void unselectNode();
229 
230  float mMoveContentSearchRadius;
231  QgsComposerNodesItem* mNodesItem;
232  int mNodesItemIndex;
234  QScopedPointer<QGraphicsPathItem> mPolylineItem;
235 
237  bool mToolPanning;
239  bool mMousePanning;
241  bool mKeyPanning;
242 
244  bool mMovingItemContent;
245 
246  QPoint mMouseLastXY;
247  QPoint mMouseCurrentXY;
248  QPoint mMousePressStartPos;
249 
250  QgsPreviewEffect* mPreviewEffect;
251 
253  QCursor defaultCursorForTool( Tool currentTool );
254 
256  void wheelZoom( QWheelEvent * event );
258  void updateRubberBandRect( QPointF & pos, const bool constrainSquare = false, const bool fromCenter = false );
260  void updateRubberBandLine( QPointF pos, const bool constrainAngles = false );
262  void removeRubberBand();
263 
265  void startMarqueeSelect( QPointF & scenePoint );
267  void endMarqueeSelect( QMouseEvent* e );
269  void startMarqueeZoom( QPointF & scenePoint );
271  void endMarqueeZoom( QMouseEvent* e );
272 
273  //void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );
274 
275  signals:
277  void selectedItemChanged( QgsComposerItem* selected );
279  void itemRemoved( QgsComposerItem* );
282  void actionFinished();
284  void cursorPosChanged( QPointF );
286  void zoomLevelChanged();
287 
289  void composerViewShow( QgsComposerView* );
291  void composerViewHide( QgsComposerView* );
292 
294  void compositionSet( QgsComposition* );
295 };
296 
297 #endif
virtual void mouseMoveEvent(QMouseEvent *event)
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
virtual void keyReleaseEvent(QKeyEvent *event)
An item that draws an arrow between two points.
virtual void showEvent(QShowEvent *event)
void setPaintingEnabled(bool enabled)
A item that forms part of a map composition.
virtual void mouseReleaseEvent(QMouseEvent *event)
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, ...)
virtual void hideEvent(QHideEvent *event)
Widget to display the composer items.
virtual void keyPressEvent(QKeyEvent *event)
Graphics scene for map printing.
Object representing map window.
virtual void mousePressEvent(QMouseEvent *event)
Tool
Current tool.
A class to show paper scale and the current cursor position.
virtual void paintEvent(QPaintEvent *event)
A composer items that draws common shapes (ellipse, triangle, rectangle)
void setHorizontalRuler(QgsComposerRuler *r)
A label that can be placed onto a map composition.
typedef WindowFlags
QgsComposerView::Tool currentTool() const
virtual void mouseDoubleClickEvent(QMouseEvent *event)
A legend that can be placed onto a map composition.
virtual void wheelEvent(QWheelEvent *event)
virtual void scrollContentsBy(int dx, int dy)
virtual void resizeEvent(QResizeEvent *event)