QGIS API Documentation  3.9.0-Master (224899f119)
qgslayoutview.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutview.h
3  ---------------
4  Date : July 2017
5  Copyright : (C) 2017 Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
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 QGSLAYOUTVIEW_H
18 #define QGSLAYOUTVIEW_H
19 
20 #include "qgis_sip.h"
21 #include "qgsprevieweffect.h" // for QgsPreviewEffect::PreviewMode
22 #include "qgis_gui.h"
23 #include "qgslayoutitempage.h"
24 #include "qgslayoutaligner.h"
25 #include <QPointer>
26 #include <QGraphicsView>
27 #include <QGraphicsRectItem>
28 #include <memory>
29 
30 class QMenu;
31 class QgsLayout;
32 class QgsLayoutViewTool;
36 class QgsLayoutRuler;
38 class QgsLayoutViewSnapMarker;
39 class QgsLayoutReportSectionLabel;
40 
49 class GUI_EXPORT QgsLayoutView: public QGraphicsView
50 {
51 
52 #ifdef SIP_RUN
54  if ( qobject_cast<QgsLayoutView *>( sipCpp ) )
55  sipType = sipType_QgsLayoutView;
56  else
57  sipType = NULL;
58  SIP_END
59 #endif
60 
61  Q_OBJECT
62 
63  Q_PROPERTY( QgsLayout *currentLayout READ currentLayout WRITE setCurrentLayout NOTIFY layoutSet )
64  Q_PROPERTY( QgsLayoutViewTool *tool READ tool WRITE setTool NOTIFY toolSet )
65 
66  public:
67 
70  {
73  };
74 
76  enum PasteMode
77  {
81  };
82 
86  QgsLayoutView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
87 
88  ~QgsLayoutView() override;
89 
95  QgsLayout *currentLayout();
96 
102  SIP_SKIP const QgsLayout *currentLayout() const;
103 
109  void setCurrentLayout( QgsLayout *layout SIP_KEEPREFERENCE );
110 
115  QgsLayoutViewTool *tool();
116 
122  void setTool( QgsLayoutViewTool *tool );
123 
131  void unsetTool( QgsLayoutViewTool *tool );
132 
138  void setPreviewModeEnabled( bool enabled );
139 
144  bool previewModeEnabled() const;
145 
152  void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
153 
160  QgsPreviewEffect::PreviewMode previewMode() const;
161 
166  void scaleSafe( double scale );
167 
171  void setZoomLevel( double level );
172 
177  void setHorizontalRuler( QgsLayoutRuler *ruler );
178 
183  void setVerticalRuler( QgsLayoutRuler *ruler );
184 
189  void setMenuProvider( QgsLayoutViewMenuProvider *provider SIP_TRANSFER );
190 
195  QgsLayoutViewMenuProvider *menuProvider() const;
196 
203  int currentPage() const { return mCurrentPage; }
204 
209  QList< QgsLayoutItemPage * > visiblePages() const;
210 
215  QList< int > visiblePageNumbers() const;
216 
222  void alignSelectedItems( QgsLayoutAligner::Alignment alignment );
223 
229  void distributeSelectedItems( QgsLayoutAligner::Distribution distribution );
230 
236  void resizeSelectedItems( QgsLayoutAligner::Resize resize );
237 
243  void copySelectedItems( ClipboardOperation operation );
244 
250  void copyItems( const QList< QgsLayoutItem * > &items, ClipboardOperation operation );
251 
260  QList< QgsLayoutItem * > pasteItems( PasteMode mode );
261 
271  QList< QgsLayoutItem * > pasteItems( QPointF layoutPoint );
272 
277  bool hasItemsInClipboard() const;
278 
283  QPointF deltaForKeyEvent( QKeyEvent *event );
284 
290  void setPaintingEnabled( bool enabled ); SIP_SKIP
291 
296  void setSectionLabel( const QString &label );
297 
298  public slots:
299 
306  void zoomFull();
307 
314  void zoomWidth();
315 
322  void zoomIn();
323 
330  void zoomOut();
331 
338  void zoomActual();
339 
345  // NOTE - I realize these emitXXX methods are gross, but there's no clean
346  // alternative here. We can't override the non-virtual Qt QGraphicsView
347  // methods, and adding our own renamed methods which call the base class
348  // methods also adds noise to the API.
349  void emitZoomLevelChanged();
350 
351  // Why are these select methods in the view and not in the scene (QgsLayout)?
352  // Well, in my opinion selections are purely a GUI concept. Ideally
353  // NONE of the selection handling would be done in core, but we're restrained
354  // by the QGraphicsScene API here.
355 
363  void selectAll();
364 
370  void deselectAll();
371 
378  void invertSelection();
379 
386  void selectNextItemAbove();
387 
394  void selectNextItemBelow();
395 
402  void raiseSelectedItems();
403 
410  void lowerSelectedItems();
411 
418  void moveSelectedItemsToTop();
419 
426  void moveSelectedItemsToBottom();
427 
433  void lockSelectedItems();
434 
439  void unlockAllItems();
440 
445  void deleteSelectedItems();
446 
451  void deleteItems( const QList< QgsLayoutItem * > &items );
452 
457  void groupSelectedItems();
458 
463  void ungroupSelectedItems();
464 
471  void viewChanged();
472 
479  void pushStatusMessage( const QString &message );
480 
481  signals:
482 
488  void layoutSet( QgsLayout *layout );
489 
494  void toolSet( QgsLayoutViewTool *tool );
495 
499  void zoomLevelChanged();
500 
506  void cursorPosChanged( QPointF layoutPoint );
507 
514  void pageChanged( int page );
515 
521  void statusMessage( const QString &message );
522 
527  void itemFocused( QgsLayoutItem *item );
528 
533  void willBeDeleted();
534 
535  protected:
536  void mousePressEvent( QMouseEvent *event ) override;
537  void mouseReleaseEvent( QMouseEvent *event ) override;
538  void mouseMoveEvent( QMouseEvent *event ) override;
539  void mouseDoubleClickEvent( QMouseEvent *event ) override;
540  void wheelEvent( QWheelEvent *event ) override;
541  void keyPressEvent( QKeyEvent *event ) override;
542  void keyReleaseEvent( QKeyEvent *event ) override;
543  void resizeEvent( QResizeEvent *event ) override;
544  void scrollContentsBy( int dx, int dy ) override;
545  void dragEnterEvent( QDragEnterEvent *e ) override;
546  void paintEvent( QPaintEvent *event ) override;
547 
548  private slots:
549 
550  void invalidateCachedRenders();
551 
552  private:
553 
555  void wheelZoom( QWheelEvent *event );
556 
557  QPointer< QgsLayoutViewTool > mTool;
558 
559  QgsLayoutViewToolTemporaryKeyPan *mSpacePanTool = nullptr;
560  QgsLayoutViewToolTemporaryMousePan *mMidMouseButtonPanTool = nullptr;
561  QgsLayoutViewToolTemporaryKeyZoom *mSpaceZoomTool = nullptr;
562 
563  QPoint mMouseCurrentXY;
564 
565  QgsLayoutRuler *mHorizontalRuler = nullptr;
566  QgsLayoutRuler *mVerticalRuler = nullptr;
567  std::unique_ptr< QgsLayoutViewMenuProvider > mMenuProvider;
568 
569  QgsLayoutViewSnapMarker *mSnapMarker = nullptr;
570  QgsLayoutReportSectionLabel *mSectionLabel = nullptr;
571 
572  QGraphicsLineItem *mHorizontalSnapLine = nullptr;
573  QGraphicsLineItem *mVerticalSnapLine = nullptr;
574 
575  int mCurrentPage = 0;
576 
577  QgsPreviewEffect *mPreviewEffect = nullptr;
578 
579  bool mPaintingEnabled = true;
580 
581  friend class TestQgsLayoutView;
582  friend class QgsLayoutMouseHandles;
583 
584  QGraphicsLineItem *createSnapLine() const;
585 };
586 
587 
600 {
601  public:
602  virtual ~QgsLayoutViewMenuProvider() = default;
603 
605  virtual QMenu *createContextMenu( QWidget *parent SIP_TRANSFER, QgsLayout *layout, QPointF layoutPoint ) const = 0 SIP_FACTORY;
606 };
607 
608 
609 #ifndef SIP_RUN
610 
612 
617 class GUI_EXPORT QgsLayoutViewSnapMarker : public QGraphicsRectItem
618 {
619  public:
620 
621  QgsLayoutViewSnapMarker();
622 
623  void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr ) override;
624 
625  private:
626 
627  int mSize = 0;
628 
629 };
630 
632 #endif
633 
634 #endif // QGSLAYOUTVIEW_H
Paste items in place.
Definition: qgslayoutview.h:80
A custom ruler widget for use with QgsLayoutView, displaying the current zoom and position of the vis...
Base class for graphical items within a QgsLayout.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
A graphical widget to display and interact with QgsLayouts.
Definition: qgslayoutview.h:49
Layout view tool for temporarily panning a layout while a mouse button is depressed.
Paste items in center of view.
Definition: qgslayoutview.h:79
PasteMode
Paste modes.
Definition: qgslayoutview.h:76
Paste items at cursor position.
Definition: qgslayoutview.h:78
int currentPage() const
Returns the page visible in the view.
Layout view tool for temporarily zooming a layout while a key is depressed.
ClipboardOperation
Clipboard operations.
Definition: qgslayoutview.h:69
A graphics effect which can be applied to a widget to simulate various printing and color blindness m...
Distribution
Distribution options.
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:189
#define SIP_KEEPREFERENCE
Definition: qgis_sip.h:86
#define SIP_FACTORY
Definition: qgis_sip.h:76
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:172
Alignment
Alignment options.
Interface for a QgsLayoutView context menu.
Abstract base class for all layout view tools.
Resize
Resize options.
Layout view tool for temporarily panning a layout while a key is depressed.