QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 "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
49class GUI_EXPORT QgsLayoutView : public QGraphicsView
50{
51#ifdef SIP_RUN
53 if ( qobject_cast<QgsLayoutView *>( sipCpp ) )
54 sipType = sipType_QgsLayoutView;
55 else
56 sipType = NULL;
58#endif
59
60 Q_OBJECT
61
62 Q_PROPERTY( QgsLayout *currentLayout READ currentLayout WRITE setCurrentLayout NOTIFY layoutSet )
63 Q_PROPERTY( QgsLayoutViewTool *tool READ tool WRITE setTool NOTIFY toolSet )
64
65 public:
72
80
84 QgsLayoutView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
85
86 ~QgsLayoutView() override;
87
94
100 SIP_SKIP const QgsLayout *currentLayout() const;
101
107 void setCurrentLayout( QgsLayout *layout SIP_KEEPREFERENCE );
108
114
120 void setTool( QgsLayoutViewTool *tool );
121
129 void unsetTool( QgsLayoutViewTool *tool );
130
136 void setPreviewModeEnabled( bool enabled );
137
142 bool previewModeEnabled() const;
143
150 void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
151
158 QgsPreviewEffect::PreviewMode previewMode() const;
159
164 void scaleSafe( double scale );
165
169 void setZoomLevel( double level );
170
175 void setHorizontalRuler( QgsLayoutRuler *ruler );
176
181 void setVerticalRuler( QgsLayoutRuler *ruler );
182
187 void setMenuProvider( QgsLayoutViewMenuProvider *provider SIP_TRANSFER );
188
193 QgsLayoutViewMenuProvider *menuProvider() const;
194
201 int currentPage() const { return mCurrentPage; }
202
207 QList<QgsLayoutItemPage *> visiblePages() const;
208
213 QList<int> visiblePageNumbers() const;
214
220 void alignSelectedItems( QgsLayoutAligner::Alignment alignment );
221
227 void distributeSelectedItems( QgsLayoutAligner::Distribution distribution );
228
234 void resizeSelectedItems( QgsLayoutAligner::Resize resize );
235
241 void copySelectedItems( ClipboardOperation operation );
242
248 void copyItems( const QList<QgsLayoutItem *> &items, ClipboardOperation operation );
249
258 QList<QgsLayoutItem *> pasteItems( PasteMode mode );
259
269 QList<QgsLayoutItem *> pasteItems( QPointF layoutPoint );
270
275 bool hasItemsInClipboard() const;
276
281 QPointF deltaForKeyEvent( QKeyEvent *event );
282
288 void setPaintingEnabled( bool enabled ) SIP_SKIP;
289
294 void setSectionLabel( const QString &label );
295
296 public slots:
297
304 void zoomFull();
305
312 void zoomWidth();
313
320 void zoomIn();
321
328 void zoomOut();
329
336 void zoomActual();
337
343 // NOTE - I realize these emitXXX methods are gross, but there's no clean
344 // alternative here. We can't override the non-virtual Qt QGraphicsView
345 // methods, and adding our own renamed methods which call the base class
346 // methods also adds noise to the API.
347 void emitZoomLevelChanged();
348
349 // Why are these select methods in the view and not in the scene (QgsLayout)?
350 // Well, in my opinion selections are purely a GUI concept. Ideally
351 // NONE of the selection handling would be done in core, but we're restrained
352 // by the QGraphicsScene API here.
353
361 void selectAll();
362
368 void deselectAll();
369
376 void invertSelection();
377
384 void selectNextItemAbove();
385
392 void selectNextItemBelow();
393
400 void raiseSelectedItems();
401
408 void lowerSelectedItems();
409
416 void moveSelectedItemsToTop();
417
424 void moveSelectedItemsToBottom();
425
431 void lockSelectedItems();
432
437 void unlockAllItems();
438
443 void deleteSelectedItems();
444
449 void deleteItems( const QList<QgsLayoutItem *> &items );
450
455 void groupSelectedItems();
456
461 void ungroupSelectedItems();
462
469 void viewChanged();
470
477 void pushStatusMessage( const QString &message );
478
479 signals:
480
486 void layoutSet( QgsLayout *layout );
487
493
498
504 void cursorPosChanged( QPointF layoutPoint );
505
512 void pageChanged( int page );
513
519 void statusMessage( const QString &message );
520
526
532
533 protected:
534 void mousePressEvent( QMouseEvent *event ) override;
535 void mouseReleaseEvent( QMouseEvent *event ) override;
536 void mouseMoveEvent( QMouseEvent *event ) override;
537 void mouseDoubleClickEvent( QMouseEvent *event ) override;
538 void wheelEvent( QWheelEvent *event ) override;
539 void keyPressEvent( QKeyEvent *event ) override;
540 void keyReleaseEvent( QKeyEvent *event ) override;
541 void resizeEvent( QResizeEvent *event ) override;
542 void scrollContentsBy( int dx, int dy ) override;
543 void dragEnterEvent( QDragEnterEvent *e ) override;
544 void paintEvent( QPaintEvent *event ) override;
545
546 private slots:
547
548 void invalidateCachedRenders();
549
550 private:
552 void wheelZoom( QWheelEvent *event );
553
554 QgsScreenHelper *mScreenHelper = nullptr;
555
556 QPointer<QgsLayoutViewTool> mTool;
557
558 QgsLayoutViewToolTemporaryKeyPan *mSpacePanTool = nullptr;
559 QgsLayoutViewToolTemporaryMousePan *mMidMouseButtonPanTool = nullptr;
560 QgsLayoutViewToolTemporaryKeyZoom *mSpaceZoomTool = nullptr;
561
562 QPoint mMouseCurrentXY;
563
564 QgsLayoutRuler *mHorizontalRuler = nullptr;
565 QgsLayoutRuler *mVerticalRuler = nullptr;
566 std::unique_ptr<QgsLayoutViewMenuProvider> mMenuProvider;
567
568 QgsLayoutViewSnapMarker *mSnapMarker = nullptr;
569 QgsLayoutReportSectionLabel *mSectionLabel = nullptr;
570
571 QGraphicsLineItem *mHorizontalSnapLine = nullptr;
572 QGraphicsLineItem *mVerticalSnapLine = nullptr;
573
574 int mCurrentPage = 0;
575
576 QgsPreviewEffect *mPreviewEffect = nullptr;
577
578 bool mPaintingEnabled = true;
579
580 friend class TestQgsLayoutView;
581 friend class QgsLayoutMouseHandles;
582
583 QGraphicsLineItem *createSnapLine() const;
584};
585
586
598{
599 public:
600 virtual ~QgsLayoutViewMenuProvider() = default;
601
603 virtual QMenu *createContextMenu( QWidget *parent SIP_TRANSFER, QgsLayout *layout, QPointF layoutPoint ) const = 0 SIP_FACTORY;
604};
605
606
607#ifndef SIP_RUN
609
610
615class GUI_EXPORT QgsLayoutViewSnapMarker : public QGraphicsRectItem
616{
617 public:
618 QgsLayoutViewSnapMarker();
619
620 void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr ) override;
621
622 private:
623 int mSize = 0;
624};
625
627#endif
628
629#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.
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 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.
@ ClipboardCut
Cut items.
@ ClipboardCopy
Copy items.
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:49
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:191
#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:208