|
| 1 | +/*************************************************************************** |
| 2 | + qgsscalewidget.h |
| 3 | + -------------------------------------- |
| 4 | + Date : 08.01.2015 |
| 5 | + Copyright : (C) 2014 Denis Rouzaud |
| 6 | + Email : denis.rouzaud@gmail.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 | + |
| 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 | + |
| 27 | +/** \ingroup gui |
| 28 | + * A combobox which lets the user select map scale from predefined list |
| 29 | + * and highlights nearest to current scale value |
| 30 | + **/ |
| 31 | +class GUI_EXPORT QgsScaleWidget : public QWidget |
| 32 | +{ |
| 33 | + Q_OBJECT |
| 34 | + Q_PROPERTY( bool showCurrentScaleButton READ showCurrentScaleButton WRITE setShowCurrentScaleButton ) |
| 35 | + |
| 36 | + public: |
| 37 | + explicit QgsScaleWidget(QWidget *parent = 0); |
| 38 | + |
| 39 | + virtual ~QgsScaleWidget(); |
| 40 | + |
| 41 | + //! shows a button to set the scale to the current scale of the map canvas next to the combobox |
| 42 | + //! @note the map canvas must be defined to show the button |
| 43 | + void setShowCurrentScaleButton( bool showCurrentScaleButton ); |
| 44 | + bool showCurrentScaleButton(){ return mShowCurrentScaleButton;} |
| 45 | + |
| 46 | + //! set the map canvas associated to the current button |
| 47 | + void setMapCanvas( QgsMapCanvas* canvas ); |
| 48 | + |
| 49 | + //! Function to read the selected scale as text |
| 50 | + QString scaleString(){return mScaleComboBox->scaleString();} |
| 51 | + //! Function to set the selected scale from text |
| 52 | + bool setScaleString( QString scaleTxt ){return mScaleComboBox->setScaleString(scaleTxt);} |
| 53 | + //! Function to read the selected scale as double |
| 54 | + double scale(){return mScaleComboBox->scale();} |
| 55 | + //! Function to set the selected scale from double |
| 56 | + void setScale( double scale ){return mScaleComboBox->setScale(scale);} |
| 57 | + |
| 58 | + //! Helper function to convert a double to scale string |
| 59 | + // Performs rounding, so an exact representation is not to |
| 60 | + // be expected. |
| 61 | + static QString toString( double scale ){return QgsScaleComboBox::toString(scale);} |
| 62 | + //! Helper function to convert a scale string to double |
| 63 | + static double toDouble( QString scaleString, bool *ok = NULL ){return QgsScaleComboBox::toDouble(scaleString, ok);} |
| 64 | + |
| 65 | + public slots: |
| 66 | + void updateScales( const QStringList &scales = QStringList() ){return mScaleComboBox->updateScales(scales);} |
| 67 | + |
| 68 | + //! assign the current scale from the map canvas |
| 69 | + void setScaleFromCanvas(); |
| 70 | + |
| 71 | + signals: |
| 72 | + //! Signal is emitted when *user* has finished editing/selecting a new scale. |
| 73 | + void scaleChanged(); |
| 74 | + |
| 75 | + private: |
| 76 | + QgsScaleComboBox* mScaleComboBox; |
| 77 | + QToolButton* mCurrentScaleButton; |
| 78 | + QgsMapCanvas* mCanvas; |
| 79 | + bool mShowCurrentScaleButton; |
| 80 | +}; |
| 81 | + |
| 82 | +#endif // QGSSCALEWIDGET_H |
0 commit comments