QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
25 class QgsMapCanvas;
26 
31 class GUI_EXPORT QgsScaleWidget : public QWidget
32 {
33  Q_OBJECT
34  Q_PROPERTY( bool showCurrentScaleButton READ showCurrentScaleButton WRITE setShowCurrentScaleButton )
35  Q_PROPERTY( bool scale READ scale WRITE setScale NOTIFY scaleChanged )
36  Q_PROPERTY( bool minScale READ minScale WRITE setMinScale )
37 
38  public:
39  explicit QgsScaleWidget( QWidget *parent = nullptr );
40 
41  virtual ~QgsScaleWidget();
42 
45  void setShowCurrentScaleButton( bool showCurrentScaleButton );
46  bool showCurrentScaleButton() { return mShowCurrentScaleButton;}
47 
49  void setMapCanvas( QgsMapCanvas* canvas );
50 
52  QString scaleString() { return mScaleComboBox->scaleString(); }
54  bool setScaleString( const QString& scaleTxt ) { return mScaleComboBox->setScaleString( scaleTxt ); }
56  double scale() const { return mScaleComboBox->scale();}
58  void setScale( double scale );
60  double minScale() const { return mScaleComboBox->minScale(); }
61 
63  // Performs rounding, so an exact representation is not to
64  // be expected.
65  static QString toString( double scale ) { return QgsScaleComboBox::toString( scale ); }
67  static double toDouble( const QString& scaleString, bool *ok = nullptr ) { return QgsScaleComboBox::toDouble( scaleString, ok ); }
68 
69  public slots:
70  void updateScales( const QStringList &scales = QStringList() ) { return mScaleComboBox->updateScales( scales ); }
71 
73  void setScaleFromCanvas();
74 
76  void setMinScale( double scale ) { mScaleComboBox->setMinScale( scale ); }
77 
78  signals:
80  void scaleChanged( double scale );
81 
82  private:
83  QgsScaleComboBox* mScaleComboBox;
84  QToolButton* mCurrentScaleButton;
85  QgsMapCanvas* mCanvas;
86  bool mShowCurrentScaleButton;
87 };
88 
89 #endif // QGSSCALEWIDGET_H
static QString toString(double scale)
Helper function to convert a double to scale string.
A combobox which lets the user select map scale from predefined list and highlights nearest to curren...
QString scaleString()
Function to read the selected scale as text.
bool setScaleString(const QString &scaleTxt)
Function to set the selected scale from text.
double scale() const
Function to read the selected scale as double.
static double toDouble(const QString &scaleString, bool *ok=nullptr)
Helper function to convert a scale string to double.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
static double toDouble(const QString &scaleString, bool *ok=nullptr)
Helper function to convert a scale string to double.
void updateScales(const QStringList &scales=QStringList())
void setMinScale(double scale)
Function to set the min scale.
static QString toString(double scale)
Helper function to convert a double to scale string.
double minScale() const
Function to read the min scale.
A combobox which lets the user select map scale from predefined list and highlights nearest to curren...