QGIS API Documentation 3.41.0-Master (cea29feecf2)
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:
45 explicit QgsLayoutRuler( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::Orientation orientation = Qt::Horizontal );
46
47 QSize minimumSizeHint() const override;
48
54 void setSceneTransform( const QTransform &transform );
55
60 QgsLayoutView *layoutView() { return mView; }
61
66 void setLayoutView( QgsLayoutView *view );
67
72 int rulerSize() const { return mRulerMinSize; }
73
78 void setContextMenu( QMenu *menu );
79
80 public slots:
81
87 void setCursorPosition( QPointF position );
88
89 signals:
91 void cursorPosChanged( QPointF position );
92
93 protected:
94 void paintEvent( QPaintEvent *event ) override;
95 void mouseMoveEvent( QMouseEvent *event ) override;
96 void mousePressEvent( QMouseEvent *event ) override;
97 void mouseReleaseEvent( QMouseEvent *event ) override;
98
99 private:
100 static const int VALID_SCALE_MULTIPLES[];
101 static const int VALID_SCALE_MAGNITUDES[];
102
103 Qt::Orientation mOrientation = Qt::Horizontal;
104 QgsLayoutView *mView = nullptr;
105
106 QTransform mTransform;
107 QPoint mMarkerPos;
108
109 QFont mRulerFont;
110 std::unique_ptr<QFontMetrics> mRulerFontMetrics;
111
112 double mScaleMinPixelsWidth = 0.0;
113 int mRulerMinSize;
114 int mMinPixelsPerDivision;
115 int mPixelsBetweenLineAndText;
116 int mTextBaseline;
117 int mMinSpacingVerticalLabels;
118
119 int mDragGuideTolerance = 0;
120 QgsLayoutGuide *mDraggingGuide = nullptr;
121 double mDraggingGuideOldPosition = 0.0;
122 QgsLayoutGuide *mHoverGuide = nullptr;
123
124 bool mCreatingGuide = false;
125 QGraphicsLineItem *mGuideItem = nullptr;
126
128 QPolygonF mGuideMarker;
129
130 QPointer<QMenu> mMenu;
131
133 int optimumScale( double minPixelDiff, int &magnitude, int &multiple );
134
139 int optimumNumberDivisions( double rulerScale, int scaleMultiple );
140
142 void drawRotatedText( QPainter *painter, QPointF pos, const QString &text );
143
149 void drawSmallDivisions( QPainter *painter, double startPos, int numDivisions, double rulerScale, double maxPos = 0 );
150
152 void drawMarkerPos( QPainter *painter );
153
154 void drawGuideMarkers( QPainter *painter, QgsLayout *layout );
155
157 void drawGuideAtPos( QPainter *painter, QPoint pos );
158
159 void createTemporaryGuideItem();
160
161 QPointF convertLocalPointToLayout( QPoint localPoint ) const;
162
163 QPoint convertLayoutPointToLocal( QPointF layoutPoint ) const;
164
169 QgsLayoutGuide *guideAtPoint( QPoint localPoint ) const;
170};
171
172#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