QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 <memory>
21
22#include "qgis_gui.h"
23#include "qgis_sip.h"
24#include "qgslayoutaligner.h"
25#include "qgslayoutitempage.h"
26#include "qgslayoutviewtool.h"
27#include "qgsprevieweffect.h"
28
29#include <QGraphicsRectItem>
30#include <QGraphicsView>
31#include <QPointer>
32
33class QMenu;
34class QgsLayout;
38class QgsLayoutRuler;
40class QgsLayoutViewSnapMarker;
41class QgsLayoutReportSectionLabel;
42class QgsScreenHelper;
43
51class GUI_EXPORT QgsLayoutView : public QGraphicsView
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
65 Q_PROPERTY( QgsLayoutViewTool *tool READ tool WRITE setTool NOTIFY toolSet )
66
67 public:
74
82
86 QgsLayoutView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
87
88 ~QgsLayoutView() override;
89
96
102 SIP_SKIP const QgsLayout *currentLayout() const;
103
110
116
123
132
138 void setPreviewModeEnabled( bool enabled );
139
144 bool previewModeEnabled() const;
145
153
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
190
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
495
500
506 void cursorPosChanged( QPointF layoutPoint );
507
514 void pageChanged( int page );
515
521 void statusMessage( const QString &message );
522
528
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:
554 void wheelZoom( QWheelEvent *event );
555
556 QgsScreenHelper *mScreenHelper = nullptr;
557
558 QPointer<QgsLayoutViewTool> mTool;
559
560 QgsLayoutViewToolTemporaryKeyPan *mSpacePanTool = nullptr;
561 QgsLayoutViewToolTemporaryMousePan *mMidMouseButtonPanTool = nullptr;
562 QgsLayoutViewToolTemporaryKeyZoom *mSpaceZoomTool = nullptr;
563
564 QPoint mMouseCurrentXY;
565
566 QgsLayoutRuler *mHorizontalRuler = nullptr;
567 QgsLayoutRuler *mVerticalRuler = nullptr;
568 std::unique_ptr<QgsLayoutViewMenuProvider> mMenuProvider;
569
570 QgsLayoutViewSnapMarker *mSnapMarker = nullptr;
571 QgsLayoutReportSectionLabel *mSectionLabel = nullptr;
572
573 QGraphicsLineItem *mHorizontalSnapLine = nullptr;
574 QGraphicsLineItem *mVerticalSnapLine = nullptr;
575
576 int mCurrentPage = 0;
577
578 QgsPreviewEffect *mPreviewEffect = nullptr;
579
580 bool mPaintingEnabled = true;
581
582 friend class TestQgsLayoutView;
584
585 QGraphicsLineItem *createSnapLine() const;
586};
587
588
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
611
612
617class GUI_EXPORT QgsLayoutViewSnapMarker : public QGraphicsRectItem
618{
619 public:
620 QgsLayoutViewSnapMarker();
621
622 void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr ) override;
623
624 private:
625 int mSize = 0;
626};
627
629#endif
630
631#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.
QgsLayoutView(QWidget *parent=nullptr)
Constructor for QgsLayoutView.
void cursorPosChanged(QPointF layoutPoint)
Emitted when the mouse cursor coordinates change within the view.
PasteMode
Paste modes.
@ PasteModeCenter
Paste items in center of view.
@ PasteModeInPlace
Paste items in place.
@ PasteModeCursor
Paste items at cursor position.
void mouseMoveEvent(QMouseEvent *event) override
QgsLayout * currentLayout
void setMenuProvider(QgsLayoutViewMenuProvider *provider)
Sets a provider for context menus.
void dragEnterEvent(QDragEnterEvent *e) override
void resizeEvent(QResizeEvent *event) override
void mouseReleaseEvent(QMouseEvent *event) override
friend class QgsLayoutMouseHandles
QgsPreviewEffect::PreviewMode previewMode() const
Returns the preview mode which may be used to modify the view's appearance.
void setTool(QgsLayoutViewTool *tool)
Sets the tool currently being used in the view.
void zoomLevelChanged()
Emitted whenever the zoom level of the view is changed.
friend class TestQgsLayoutView
void willBeDeleted()
Emitted in the destructor when the view is about to be deleted, but is still in a perfectly valid sta...
void setHorizontalRuler(QgsLayoutRuler *ruler)
Sets a horizontal ruler to synchronize with the view state.
void setPreviewMode(QgsPreviewEffect::PreviewMode mode)
Sets the preview mode which should be used to modify the view's appearance.
void keyPressEvent(QKeyEvent *event) override
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 setPreviewModeEnabled(bool enabled)
Sets whether a preview effect should be used to alter the view's appearance.
void layoutSet(QgsLayout *layout)
Emitted when a layout is set for the view.
void setCurrentLayout(QgsLayout *layout)
Sets the current layout to edit in the view.
int currentPage() const
Returns the page visible in the view.
void wheelEvent(QWheelEvent *event) override
ClipboardOperation
Clipboard operations.
@ ClipboardCut
Cut items.
@ ClipboardCopy
Copy items.
bool previewModeEnabled() const
Returns true if a preview effect is being used to alter the view's appearance.
void setVerticalRuler(QgsLayoutRuler *ruler)
Sets a vertical ruler to synchronize with the view state.
QgsLayoutViewTool * tool()
Returns the currently active tool for the view.
void setZoomLevel(double level)
Sets the zoom level for the view, where a zoom level of 1.0 corresponds to 100%.
QgsLayoutViewTool * tool
void unsetTool(QgsLayoutViewTool *tool)
Unsets the current view tool, if it matches the specified tool.
void toolSet(QgsLayoutViewTool *tool)
Emitted when the current tool is changed.
void mouseDoubleClickEvent(QMouseEvent *event) override
void scaleSafe(double scale)
Scales the view in a safe way, by limiting the acceptable range of the scale applied.
void pageChanged(int page)
Emitted when the page visible in the view is changed.
void scrollContentsBy(int dx, int dy) override
void paintEvent(QPaintEvent *event) override
void keyReleaseEvent(QKeyEvent *event) override
QgsLayoutViewMenuProvider * menuProvider() const
Returns the provider for context menus.
void mousePressEvent(QMouseEvent *event) override
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:50
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:199
#define SIP_KEEPREFERENCE
Definition qgis_sip.h:94
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_END
Definition qgis_sip.h:216