QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgslayoutruler.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutruler.h
3 ----------------
4 Date : July 2017
5 Copyright : (C) 2017 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSLAYOUTRULER_H
16#define QGSLAYOUTRULER_H
17
18#include "qgis_gui.h"
19#include "qgis_sip.h"
20#include <QWidget>
21#include <QPointer>
22#include <QMenu>
23#include <memory>
24
25class QgsLayout;
26class QGraphicsLineItem;
27class QgsLayoutView;
28class QgsLayoutGuide;
29
37class GUI_EXPORT QgsLayoutRuler: public QWidget
38{
39 Q_OBJECT
40
41 public:
42
46 explicit QgsLayoutRuler( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::Orientation orientation = Qt::Horizontal );
47
48 QSize minimumSizeHint() const override;
49
55 void setSceneTransform( const QTransform &transform );
56
61 QgsLayoutView *layoutView() { return mView; }
62
67 void setLayoutView( QgsLayoutView *view );
68
73 int rulerSize() const { return mRulerMinSize; }
74
79 void setContextMenu( QMenu *menu );
80
81 public slots:
82
88 void setCursorPosition( QPointF position );
89
90 signals:
92 void cursorPosChanged( QPointF position );
93
94 protected:
95 void paintEvent( QPaintEvent *event ) override;
96 void mouseMoveEvent( QMouseEvent *event ) override;
97 void mousePressEvent( QMouseEvent *event ) override;
98 void mouseReleaseEvent( QMouseEvent *event ) override;
99
100 private:
101 static const int VALID_SCALE_MULTIPLES[];
102 static const int VALID_SCALE_MAGNITUDES[];
103
104 Qt::Orientation mOrientation = Qt::Horizontal;
105 QgsLayoutView *mView = nullptr;
106
107 QTransform mTransform;
108 QPoint mMarkerPos;
109
110 QFont mRulerFont;
111 std::unique_ptr< QFontMetrics > mRulerFontMetrics;
112
113 double mScaleMinPixelsWidth = 0.0;
114 int mRulerMinSize;
115 int mMinPixelsPerDivision;
116 int mPixelsBetweenLineAndText;
117 int mTextBaseline;
118 int mMinSpacingVerticalLabels;
119
120 int mDragGuideTolerance = 0;
121 QgsLayoutGuide *mDraggingGuide = nullptr;
122 double mDraggingGuideOldPosition = 0.0;
123 QgsLayoutGuide *mHoverGuide = nullptr;
124
125 bool mCreatingGuide = false;
126 QGraphicsLineItem *mGuideItem = nullptr;
127
129 QPolygonF mGuideMarker;
130
131 QPointer< QMenu > mMenu;
132
134 int optimumScale( double minPixelDiff, int &magnitude, int &multiple );
135
140 int optimumNumberDivisions( double rulerScale, int scaleMultiple );
141
143 void drawRotatedText( QPainter *painter, QPointF pos, const QString &text );
144
150 void drawSmallDivisions( QPainter *painter, double startPos, int numDivisions, double rulerScale, double maxPos = 0 );
151
153 void drawMarkerPos( QPainter *painter );
154
155 void drawGuideMarkers( QPainter *painter, QgsLayout *layout );
156
158 void drawGuideAtPos( QPainter *painter, QPoint pos );
159
160 void createTemporaryGuideItem();
161
162 QPointF convertLocalPointToLayout( QPoint localPoint ) const;
163
164 QPoint convertLayoutPointToLocal( QPointF layoutPoint ) const;
165
170 QgsLayoutGuide *guideAtPoint( QPoint localPoint ) const;
171
172};
173
174#endif // QGSLAYOUTRULER_H
Contains the configuration for a single snap guide used by a layout.
A custom ruler widget for use with QgsLayoutView, displaying the current zoom and position of the vis...
void cursorPosChanged(QPointF position)
Emitted when mouse cursor coordinates change.
QgsLayoutView * layoutView()
Returns the current layout view associated with the ruler.
int rulerSize() const
Returns the ruler size (either the height of a horizontal ruler or the width of a vertical rule).
A graphical widget to display and interact with QgsLayouts.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:49
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53