QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsscalewidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsscalewidget.h
3 --------------------------------------
4 Date : 08.01.2015
5 Copyright : (C) 2014 Denis Rouzaud
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
16#ifndef QGSSCALEWIDGET_H
17#define QGSSCALEWIDGET_H
18
19#include <QWidget>
20#include <QToolButton>
21
22
23#include "qgsscalecombobox.h"
24#include "qgis_gui.h"
25#include "qgis_sip.h"
26
27class QgsMapCanvas;
28
34class GUI_EXPORT QgsScaleWidget : public QWidget
35{
36 Q_OBJECT
37 Q_PROPERTY( bool showCurrentScaleButton READ showCurrentScaleButton WRITE setShowCurrentScaleButton )
38 Q_PROPERTY( bool scale READ scale WRITE setScale NOTIFY scaleChanged )
39 Q_PROPERTY( bool minScale READ minScale WRITE setMinScale )
40
41 public:
46 explicit QgsScaleWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
47
54 void setShowCurrentScaleButton( bool showCurrentScaleButton );
55
60 bool showCurrentScaleButton() { return mShowCurrentScaleButton; }
61
65 void setMapCanvas( QgsMapCanvas *canvas );
66
71 QString scaleString() const { return mScaleComboBox->scaleString(); }
72
77 bool setScaleString( const QString &string ) { return mScaleComboBox->setScaleString( string ); }
78
84 double scale() const { return mScaleComboBox->scale(); }
85
93 bool isNull() const;
94
101 double minScale() const { return mScaleComboBox->minScale(); }
102
110 static QString toString( double scale ) { return QgsScaleComboBox::toString( scale ); }
111
118 static double toDouble( const QString &scaleString, bool *ok = nullptr ) { return QgsScaleComboBox::toDouble( scaleString, ok ); }
119
127 void setAllowNull( bool allowNull );
128
136 bool allowNull() const;
137
146 void setPredefinedScales( const QVector<double> &scales );
147
148 public slots:
149
155 void setScale( double scale );
156
161 void updateScales( const QStringList &scales = QStringList() ) { mScaleComboBox->updateScales( scales ); }
162
167 void setScaleFromCanvas();
168
175 void setMinScale( double scale ) { mScaleComboBox->setMinScale( scale ); }
176
186 void setNull();
187
188 signals:
189
194 void scaleChanged( double scale );
195
196 private slots:
197
198 void menuAboutToShow();
199
200 private:
201 QgsScaleComboBox *mScaleComboBox = nullptr;
202 QToolButton *mCurrentScaleButton = nullptr;
203 QgsMapCanvas *mCanvas = nullptr;
204 QMenu *mMenu = nullptr;
205 bool mShowCurrentScaleButton = false;
206};
207
208#endif // QGSSCALEWIDGET_H
Map canvas is a class for displaying all GIS data types on a canvas.
A combobox which lets the user select map scale from predefined list and highlights nearest to curren...
static QString toString(double scale)
Helper function to convert a scale double to scale string.
static double toDouble(const QString &string, bool *ok=nullptr)
Helper function to convert a scale string to double.
A combobox which lets the user select map scale from predefined list and highlights nearest to curren...
void scaleChanged(double scale)
Emitted when user has finished editing/selecting a new scale.
void updateScales(const QStringList &scales=QStringList())
Sets the list of predefined scales to show in the widget.
double minScale() const
Returns the minimum scale, or 0 if no minimum scale set.
void setMinScale(double scale)
Set the minimum allowed scale.
QString scaleString() const
Returns the selected scale as a string, e.g.
double scale() const
Returns the selected scale as a double.
static QString toString(double scale)
Helper function to convert a scale double to scale string.
static double toDouble(const QString &scaleString, bool *ok=nullptr)
Helper function to convert a scale string to double.
bool setScaleString(const QString &string)
Set the selected scale from a string, e.g.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53