QGIS API Documentation 3.29.0-Master (da8bb1db43)
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 "qgslayoutviewtool.h"
26#include <QPointer>
27#include <QGraphicsView>
28#include <QGraphicsRectItem>
29#include <memory>
30
31class QMenu;
32class QgsLayout;
36class QgsLayoutRuler;
38class QgsLayoutViewSnapMarker;
39class QgsLayoutReportSectionLabel;
40class QgsScreenHelper;
41
50class GUI_EXPORT QgsLayoutView: public QGraphicsView
51{
52
53#ifdef SIP_RUN
55 if ( qobject_cast<QgsLayoutView *>( sipCpp ) )
56 sipType = sipType_QgsLayoutView;
57 else
58 sipType = NULL;
60#endif
61
62 Q_OBJECT
63
64 Q_PROPERTY( QgsLayout *currentLayout READ currentLayout WRITE setCurrentLayout NOTIFY layoutSet )
65 Q_PROPERTY( QgsLayoutViewTool *tool READ tool WRITE setTool NOTIFY toolSet )
66
67 public:
68
71 {
74 };
75
78 {
82 };
83
87 QgsLayoutView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
88
89 ~QgsLayoutView() override;
90
97
103 SIP_SKIP const QgsLayout *currentLayout() const;
104
110 void setCurrentLayout( QgsLayout *layout SIP_KEEPREFERENCE );
111
117
123 void setTool( QgsLayoutViewTool *tool );
124
132 void unsetTool( QgsLayoutViewTool *tool );
133
139 void setPreviewModeEnabled( bool enabled );
140
145 bool previewModeEnabled() const;
146
153 void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
154
161 QgsPreviewEffect::PreviewMode previewMode() const;
162
167 void scaleSafe( double scale );
168
172 void setZoomLevel( double level );
173
178 void setHorizontalRuler( QgsLayoutRuler *ruler );
179
184 void setVerticalRuler( QgsLayoutRuler *ruler );
185
190 void setMenuProvider( QgsLayoutViewMenuProvider *provider SIP_TRANSFER );
191
196 QgsLayoutViewMenuProvider *menuProvider() const;
197
204 int currentPage() const { return mCurrentPage; }
205
210 QList< QgsLayoutItemPage * > visiblePages() const;
211
216 QList< int > visiblePageNumbers() const;
217
223 void alignSelectedItems( QgsLayoutAligner::Alignment alignment );
224
230 void distributeSelectedItems( QgsLayoutAligner::Distribution distribution );
231
237 void resizeSelectedItems( QgsLayoutAligner::Resize resize );
238
244 void copySelectedItems( ClipboardOperation operation );
245
251 void copyItems( const QList< QgsLayoutItem * > &items, ClipboardOperation operation );
252
261 QList< QgsLayoutItem * > pasteItems( PasteMode mode );
262
272 QList< QgsLayoutItem * > pasteItems( QPointF layoutPoint );
273
278 bool hasItemsInClipboard() const;
279
284 QPointF deltaForKeyEvent( QKeyEvent *event );
285
291 void setPaintingEnabled( bool enabled ); SIP_SKIP
292
297 void setSectionLabel( const QString &label );
298
299 public slots:
300
307 void zoomFull();
308
315 void zoomWidth();
316
323 void zoomIn();
324
331 void zoomOut();
332
339 void zoomActual();
340
346 // NOTE - I realize these emitXXX methods are gross, but there's no clean
347 // alternative here. We can't override the non-virtual Qt QGraphicsView
348 // methods, and adding our own renamed methods which call the base class
349 // methods also adds noise to the API.
350 void emitZoomLevelChanged();
351
352 // Why are these select methods in the view and not in the scene (QgsLayout)?
353 // Well, in my opinion selections are purely a GUI concept. Ideally
354 // NONE of the selection handling would be done in core, but we're restrained
355 // by the QGraphicsScene API here.
356
364 void selectAll();
365
371 void deselectAll();
372
379 void invertSelection();
380
387 void selectNextItemAbove();
388
395 void selectNextItemBelow();
396
403 void raiseSelectedItems();
404
411 void lowerSelectedItems();
412
419 void moveSelectedItemsToTop();
420
427 void moveSelectedItemsToBottom();
428
434 void lockSelectedItems();
435
440 void unlockAllItems();
441
446 void deleteSelectedItems();
447
452 void deleteItems( const QList< QgsLayoutItem * > &items );
453
458 void groupSelectedItems();
459
464 void ungroupSelectedItems();
465
472 void viewChanged();
473
480 void pushStatusMessage( const QString &message );
481
482 signals:
483
489 void layoutSet( QgsLayout *layout );
490
496
501
507 void cursorPosChanged( QPointF layoutPoint );
508
515 void pageChanged( int page );
516
522 void statusMessage( const QString &message );
523
529
535
536 protected:
537 void mousePressEvent( QMouseEvent *event ) override;
538 void mouseReleaseEvent( QMouseEvent *event ) override;
539 void mouseMoveEvent( QMouseEvent *event ) override;
540 void mouseDoubleClickEvent( QMouseEvent *event ) override;
541 void wheelEvent( QWheelEvent *event ) override;
542 void keyPressEvent( QKeyEvent *event ) override;
543 void keyReleaseEvent( QKeyEvent *event ) override;
544 void resizeEvent( QResizeEvent *event ) override;
545 void scrollContentsBy( int dx, int dy ) override;
546 void dragEnterEvent( QDragEnterEvent *e ) override;
547 void paintEvent( QPaintEvent *event ) override;
548
549 private slots:
550
551 void invalidateCachedRenders();
552
553 private:
554
556 void wheelZoom( QWheelEvent *event );
557
558 QgsScreenHelper *mScreenHelper = nullptr;
559
560 QPointer< QgsLayoutViewTool > mTool;
561
562 QgsLayoutViewToolTemporaryKeyPan *mSpacePanTool = nullptr;
563 QgsLayoutViewToolTemporaryMousePan *mMidMouseButtonPanTool = nullptr;
564 QgsLayoutViewToolTemporaryKeyZoom *mSpaceZoomTool = nullptr;
565
566 QPoint mMouseCurrentXY;
567
568 QgsLayoutRuler *mHorizontalRuler = nullptr;
569 QgsLayoutRuler *mVerticalRuler = nullptr;
570 std::unique_ptr< QgsLayoutViewMenuProvider > mMenuProvider;
571
572 QgsLayoutViewSnapMarker *mSnapMarker = nullptr;
573 QgsLayoutReportSectionLabel *mSectionLabel = nullptr;
574
575 QGraphicsLineItem *mHorizontalSnapLine = nullptr;
576 QGraphicsLineItem *mVerticalSnapLine = nullptr;
577
578 int mCurrentPage = 0;
579
580 QgsPreviewEffect *mPreviewEffect = nullptr;
581
582 bool mPaintingEnabled = true;
583
584 friend class TestQgsLayoutView;
585 friend class QgsLayoutMouseHandles;
586
587 QGraphicsLineItem *createSnapLine() const;
588};
589
590
603{
604 public:
605 virtual ~QgsLayoutViewMenuProvider() = default;
606
608 virtual QMenu *createContextMenu( QWidget *parent SIP_TRANSFER, QgsLayout *layout, QPointF layoutPoint ) const = 0 SIP_FACTORY;
609};
610
611
612#ifndef SIP_RUN
614
615
620class GUI_EXPORT QgsLayoutViewSnapMarker : public QGraphicsRectItem
621{
622 public:
623
624 QgsLayoutViewSnapMarker();
625
626 void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr ) override;
627
628 private:
629
630 int mSize = 0;
631
632};
633
635#endif
636
637#endif // QGSLAYOUTVIEW_H
Alignment
Alignment options.
Resize
Resize options.
Distribution
Distribution options.
Base class for graphical items within a QgsLayout.
A custom ruler widget for use with QgsLayoutView, displaying the current zoom and position of the vis...
Interface for a QgsLayoutView context menu.
virtual QMenu * createContextMenu(QWidget *parent, QgsLayout *layout, QPointF layoutPoint) const =0
Returns a newly created menu instance (or nullptr on error)
virtual ~QgsLayoutViewMenuProvider()=default
Layout view tool for temporarily panning a layout while a key is depressed.
Layout view tool for temporarily zooming a layout while a key is depressed.
Layout view tool for temporarily panning a layout while a mouse button is depressed.
Abstract base class for all layout view tools.
A graphical widget to display and interact with QgsLayouts.
Definition: qgslayoutview.h:51
void cursorPosChanged(QPointF layoutPoint)
Emitted when the mouse cursor coordinates change within the view.
PasteMode
Paste modes.
Definition: qgslayoutview.h:78
@ PasteModeCenter
Paste items in center of view.
Definition: qgslayoutview.h:80
@ PasteModeInPlace
Paste items in place.
Definition: qgslayoutview.h:81
@ PasteModeCursor
Paste items at cursor position.
Definition: qgslayoutview.h:79
void zoomLevelChanged()
Emitted whenever the zoom level of the view is changed.
void willBeDeleted()
Emitted in the destructor when the view is about to be deleted, but is still in a perfectly valid sta...
QgsLayout * currentLayout()
Returns the current layout associated with the view.
void statusMessage(const QString &message)
Emitted when the view has a message for display in a parent window's status bar.
void itemFocused(QgsLayoutItem *item)
Emitted when an item is "focused" in the view, i.e.
void layoutSet(QgsLayout *layout)
Emitted when a layout is set for the view.
int currentPage() const
Returns the page visible in the view.
ClipboardOperation
Clipboard operations.
Definition: qgslayoutview.h:71
@ ClipboardCut
Cut items.
Definition: qgslayoutview.h:72
@ ClipboardCopy
Copy items.
Definition: qgslayoutview.h:73
QgsLayoutViewTool * tool()
Returns the currently active tool for the view.
void toolSet(QgsLayoutViewTool *tool)
Emitted when the current tool is changed.
void pageChanged(int page)
Emitted when the page visible in the view is changed.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:51
A graphics effect which can be applied to a widget to simulate various printing and color blindness m...
A utility class for dynamic handling of changes to screen properties.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
#define SIP_KEEPREFERENCE
Definition: qgis_sip.h:86
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_END
Definition: qgis_sip.h:203