QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
38class GUI_EXPORT QgsLayoutRuler: public QWidget
39{
40 Q_OBJECT
41
42 public:
43
47 explicit QgsLayoutRuler( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::Orientation orientation = Qt::Horizontal );
48
49 QSize minimumSizeHint() const override;
50
56 void setSceneTransform( const QTransform &transform );
57
62 QgsLayoutView *layoutView() { return mView; }
63
68 void setLayoutView( QgsLayoutView *view );
69
74 int rulerSize() const { return mRulerMinSize; }
75
80 void setContextMenu( QMenu *menu );
81
82 public slots:
83
89 void setCursorPosition( QPointF position );
90
91 signals:
93 void cursorPosChanged( QPointF );
94
95 protected:
96 void paintEvent( QPaintEvent *event ) override;
97 void mouseMoveEvent( QMouseEvent *event ) override;
98 void mousePressEvent( QMouseEvent *event ) override;
99 void mouseReleaseEvent( QMouseEvent *event ) override;
100
101 private:
102 static const int VALID_SCALE_MULTIPLES[];
103 static const int VALID_SCALE_MAGNITUDES[];
104
105 Qt::Orientation mOrientation = Qt::Horizontal;
106 QgsLayoutView *mView = nullptr;
107
108 QTransform mTransform;
109 QPoint mMarkerPos;
110
111 QFont mRulerFont;
112 std::unique_ptr< QFontMetrics > mRulerFontMetrics;
113
114 double mScaleMinPixelsWidth = 0.0;
115 int mRulerMinSize;
116 int mMinPixelsPerDivision;
117 int mPixelsBetweenLineAndText;
118 int mTextBaseline;
119 int mMinSpacingVerticalLabels;
120
121 int mDragGuideTolerance = 0;
122 QgsLayoutGuide *mDraggingGuide = nullptr;
123 double mDraggingGuideOldPosition = 0.0;
124 QgsLayoutGuide *mHoverGuide = nullptr;
125
126 bool mCreatingGuide = false;
127 QGraphicsLineItem *mGuideItem = nullptr;
128
130 QPolygonF mGuideMarker;
131
132 QPointer< QMenu > mMenu;
133
135 int optimumScale( double minPixelDiff, int &magnitude, int &multiple );
136
141 int optimumNumberDivisions( double rulerScale, int scaleMultiple );
142
144 void drawRotatedText( QPainter *painter, QPointF pos, const QString &text );
145
151 void drawSmallDivisions( QPainter *painter, double startPos, int numDivisions, double rulerScale, double maxPos = 0 );
152
154 void drawMarkerPos( QPainter *painter );
155
156 void drawGuideMarkers( QPainter *painter, QgsLayout *layout );
157
159 void drawGuideAtPos( QPainter *painter, QPoint pos );
160
161 void createTemporaryGuideItem();
162
163 QPointF convertLocalPointToLayout( QPoint localPoint ) const;
164
165 QPoint convertLayoutPointToLocal( QPointF layoutPoint ) const;
166
171 QgsLayoutGuide *guideAtPoint( QPoint localPoint ) const;
172
173};
174
175#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)
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.
Definition: qgslayoutview.h:51
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:51
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53