QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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
6  Email : [email protected]
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 
27 class QgsMapCanvas;
28 
34 class 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:
42 
47  explicit QgsScaleWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
48 
55  void setShowCurrentScaleButton( bool showCurrentScaleButton );
56 
61  bool showCurrentScaleButton() { return mShowCurrentScaleButton;}
62 
66  void setMapCanvas( QgsMapCanvas *canvas );
67 
72  QString scaleString() const { return mScaleComboBox->scaleString(); }
73 
78  bool setScaleString( const QString &string ) { return mScaleComboBox->setScaleString( string ); }
79 
85  double scale() const { return mScaleComboBox->scale(); }
86 
94  bool isNull() const;
95 
102  double minScale() const { return mScaleComboBox->minScale(); }
103 
111  static QString toString( double scale ) { return QgsScaleComboBox::toString( scale ); }
112 
119  static double toDouble( const QString &scaleString, bool *ok = nullptr ) { return QgsScaleComboBox::toDouble( scaleString, ok ); }
120 
128  void setAllowNull( bool allowNull );
129 
137  bool allowNull() const;
138 
139  public slots:
140 
146  void setScale( double scale );
147 
152  void updateScales( const QStringList &scales = QStringList() ) { mScaleComboBox->updateScales( scales ); }
153 
158  void setScaleFromCanvas();
159 
166  void setMinScale( double scale ) { mScaleComboBox->setMinScale( scale ); }
167 
177  void setNull();
178 
179  signals:
180 
185  void scaleChanged( double scale );
186 
187  private slots:
188 
189  void menuAboutToShow();
190 
191  private:
192  QgsScaleComboBox *mScaleComboBox = nullptr;
193  QToolButton *mCurrentScaleButton = nullptr;
194  QgsMapCanvas *mCanvas = nullptr;
195  QMenu *mMenu = nullptr;
196  bool mShowCurrentScaleButton = false;
197 };
198 
199 #endif // QGSSCALEWIDGET_H
QgsScaleWidget::scale
double scale() const
Returns the selected scale as a double.
Definition: qgsscalewidget.h:85
QgsScaleWidget::toString
static QString toString(double scale)
Helper function to convert a scale double to scale string.
Definition: qgsscalewidget.h:111
QgsScaleComboBox
Definition: qgsscalecombobox.h:30
QgsScaleWidget::scaleString
QString scaleString() const
Returns the selected scale as a string, e.g.
Definition: qgsscalewidget.h:72
QgsMapCanvas
Definition: qgsmapcanvas.h:83
QgsScaleWidget::updateScales
void updateScales(const QStringList &scales=QStringList())
Sets the list of predefined scales to show in the combobox.
Definition: qgsscalewidget.h:152
QgsScaleComboBox::toString
static QString toString(double scale)
Helper function to convert a scale double to scale string.
Definition: qgsscalecombobox.cpp:203
qgis_sip.h
QgsScaleWidget
Definition: qgsscalewidget.h:34
QgsScaleWidget::setMinScale
void setMinScale(double scale)
Set the minimum allowed scale.
Definition: qgsscalewidget.h:166
QgsScaleWidget::minScale
double minScale() const
Returns the minimum scale, or 0 if no minimum scale set.
Definition: qgsscalewidget.h:102
QgsScaleComboBox::toDouble
static double toDouble(const QString &string, bool *ok=nullptr)
Helper function to convert a scale string to double.
Definition: qgsscalecombobox.cpp:223
QgsScaleWidget::setScaleString
bool setScaleString(const QString &string)
Set the selected scale from a string, e.g.
Definition: qgsscalewidget.h:78
qgsscalecombobox.h
QgsScaleWidget::toDouble
static double toDouble(const QString &scaleString, bool *ok=nullptr)
Helper function to convert a scale string to double.
Definition: qgsscalewidget.h:119
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53