QGIS API Documentation  2.15.0-Master (13f053b)
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 setPreviewModeEnabled( bool enabled );
163  void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
164 
165  protected:
166  void mousePressEvent( QMouseEvent* ) override;
167  void mouseReleaseEvent( QMouseEvent* ) override;
168  void mouseMoveEvent( QMouseEvent* ) override;
169  void mouseDoubleClickEvent( QMouseEvent* e ) override;
170 
171  void keyPressEvent( QKeyEvent * e ) override;
172  void keyReleaseEvent( QKeyEvent * e ) override;
173 
174  void wheelEvent( QWheelEvent* event ) override;
175 
176  void paintEvent( QPaintEvent* event ) override;
177 
178  void hideEvent( QHideEvent* e ) override;
179  void showEvent( QShowEvent* e ) override;
180 
181  void resizeEvent( QResizeEvent* event ) override;
182  void scrollContentsBy( int dx, int dy ) override;
183 
184  private:
186  QgsComposerView::Tool mCurrentTool;
188  QgsComposerView::Tool mPreviousTool;
189 
191  QGraphicsRectItem* mRubberBandItem;
193  QGraphicsLineItem* mRubberBandLineItem;
195  QgsComposerItem* mMoveContentItem;
197  QPointF mMoveContentStartPos;
199  QPointF mRubberBandStartPos;
200 
202  bool mMarqueeSelect;
204  bool mMarqueeZoom;
206  QgsComposerView::ToolStatus mTemporaryZoomStatus;
207 
208  bool mPaintingEnabled;
209 
210  QgsComposerRuler* mHorizontalRuler;
211  QgsComposerRuler* mVerticalRuler;
212 
214  void addShape( Tool currentTool );
215 
217  void addPolygonNode( const QPointF & scenePoint );
218  void movePolygonNode( const QPointF & scenePoint );
219  void displayNodes( const bool display = true );
220  void setSelectedNode( QgsComposerNodesItem *shape, const int index );
221  void unselectNode();
222 
223  float mMoveContentSearchRadius;
224  QgsComposerNodesItem* mNodesItem;
225  int mNodesItemIndex;
227  QScopedPointer<QGraphicsPathItem> mPolylineItem;
228 
230  bool mToolPanning;
232  bool mMousePanning;
234  bool mKeyPanning;
235 
237  bool mMovingItemContent;
238 
239  QPoint mMouseLastXY;
240  QPoint mMouseCurrentXY;
241  QPoint mMousePressStartPos;
242 
243  QgsPreviewEffect* mPreviewEffect;
244 
246  QCursor defaultCursorForTool( Tool currentTool );
247 
249  void wheelZoom( QWheelEvent * event );
251  void updateRubberBandRect( QPointF & pos, const bool constrainSquare = false, const bool fromCenter = false );
253  void updateRubberBandLine( QPointF pos, const bool constrainAngles = false );
255  void removeRubberBand();
256 
258  void startMarqueeSelect( QPointF & scenePoint );
260  void endMarqueeSelect( QMouseEvent* e );
262  void startMarqueeZoom( QPointF & scenePoint );
264  void endMarqueeZoom( QMouseEvent* e );
265 
266  //void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );
267 
268  signals:
270  void selectedItemChanged( QgsComposerItem* selected );
272  void itemRemoved( QgsComposerItem* );
275  void actionFinished();
277  void cursorPosChanged( QPointF );
279  void zoomLevelChanged();
280 
282  void composerViewShow( QgsComposerView* );
284  void composerViewHide( QgsComposerView* );
285 
287  void compositionSet( QgsComposition* );
288 };
289 
290 #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
virtual void keyReleaseEvent(QKeyEvent *event)
An item that draws an arrow between to 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)
bool paintingEnabled() const
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
virtual void mouseDoubleClickEvent(QMouseEvent *event)
A legend that can be placed onto a map composition.
virtual void wheelEvent(QWheelEvent *event)
QgsComposerView::Tool currentTool() const
virtual void scrollContentsBy(int dx, int dy)
virtual void resizeEvent(QResizeEvent *event)