QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgsscalerangewidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsscalerangewidget.cpp
3  --------------------------------------
4  Date : 25.04.2014
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 #include "qgsscalerangewidget.h"
17 #include "qgsapplication.h"
18 #include "qgsproject.h"
19 #include "qgsscalewidget.h"
20 #include "qgsguiutils.h"
21 
23  : QWidget( parent )
24 
25 {
26  mLayout = new QGridLayout( this );
27  mLayout->setContentsMargins( 0, 0, 0, 0 );
28 
29  QLabel *minLbl = new QLabel( tr( "Minimum (exclusive)" ), this );
30  minLbl->setWordWrap( true );
31  minLbl->setAlignment( Qt::AlignTop );
32  minLbl->setToolTip( tr( "Minimum scale, i.e. most \"zoomed out\". "
33  "This limit is exclusive, that means the layer will not be displayed on this scale." ) );
34  QLabel *maxLbl = new QLabel( tr( "Maximum (inclusive)" ), this );
35  maxLbl->setWordWrap( true );
36  maxLbl->setAlignment( Qt::AlignTop );
37  maxLbl->setToolTip( tr( "Maximum scale, i.e. most \"zoomed in\". "
38  "This limit is inclusive, that means the layer will be displayed on this scale." ) );
39 
40  const int iconSize = QgsGuiUtils::scaleIconSize( 24 );
41  mMinimumScaleIconLabel = new QLabel( this );
42  mMinimumScaleIconLabel->setPixmap( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomOut.svg" ) ).pixmap( QSize( iconSize, iconSize ) ) );
43  mMaximumScaleIconLabel = new QLabel( this );
44  mMaximumScaleIconLabel->setPixmap( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomIn.svg" ) ).pixmap( QSize( iconSize, iconSize ) ) );
45 
46  mMinimumScaleWidget = new QgsScaleWidget( this );
47  mMaximumScaleWidget = new QgsScaleWidget( this );
48  connect( mMinimumScaleWidget, &QgsScaleWidget::scaleChanged, mMaximumScaleWidget, &QgsScaleWidget::setMinScale );
49  mMinimumScaleWidget->setShowCurrentScaleButton( true );
50  mMaximumScaleWidget->setShowCurrentScaleButton( true );
52  // add start, add comprehension of scales by settings fake ordered values
53  mMinimumScaleWidget->setScale( 100000 );
54  mMaximumScaleWidget->setScale( 1000 );
55 
56  mLayout->addWidget( minLbl, 0, 0, 1, 2 );
57  mLayout->addWidget( mMinimumScaleIconLabel, 1, 0 );
58  mLayout->addWidget( mMinimumScaleWidget, 1, 1 );
59  mLayout->addWidget( maxLbl, 0, 2, 1, 2 );
60  mLayout->addWidget( mMaximumScaleIconLabel, 1, 2 );
61  mLayout->addWidget( mMaximumScaleWidget, 1, 3 );
62 
63  mLayout->setColumnStretch( 0, 0 );
64  mLayout->setColumnStretch( 1, 3 );
65  mLayout->setColumnStretch( 2, 0 );
66  mLayout->setColumnStretch( 3, 3 );
67 
68  connect( mMinimumScaleWidget, &QgsScaleWidget::scaleChanged, this, &QgsScaleRangeWidget::emitRangeChanged );
69  connect( mMaximumScaleWidget, &QgsScaleWidget::scaleChanged, this, &QgsScaleRangeWidget::emitRangeChanged );
70 }
71 
73 {
74  bool projectScales = QgsProject::instance()->readBoolEntry( QStringLiteral( "Scales" ), QStringLiteral( "/useProjectScales" ) );
75  if ( projectScales )
76  {
77  QStringList scalesList = QgsProject::instance()->readListEntry( QStringLiteral( "Scales" ), QStringLiteral( "/ScalesList" ) );
78  mMinimumScaleWidget->updateScales( scalesList );
79  mMaximumScaleWidget->updateScales( scalesList );
80  }
81 }
82 
84 {
85  mMinimumScaleWidget->setMapCanvas( mapCanvas );
86  mMaximumScaleWidget->setMapCanvas( mapCanvas );
87 }
88 
90 {
91  mMinimumScaleWidget->setScale( scale );
92 }
93 
95 {
96  return mMinimumScaleWidget->scale();
97 }
98 
100 {
101  mMaximumScaleWidget->setScale( scale );
102 }
103 
105 {
106  return mMaximumScaleWidget->scale();
107 }
108 
109 void QgsScaleRangeWidget::setScaleRange( double min, double max )
110 {
111  setMinimumScale( min );
112  setMaximumScale( max );
113 }
114 
115 void QgsScaleRangeWidget::emitRangeChanged()
116 {
118 }
119 
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const
QgsScaleRangeWidget(QWidget *parent=nullptr)
Constructor for QgsScaleRangeWidget.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly...
A combobox which lets the user select map scale from predefined list and highlights nearest to curren...
void setMaximumScale(double scale)
Set the maximum scale (i.e.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void setScale(double scale)
Set the selected scale from a double.
void scaleChanged(double scale)
Emitted when user has finished editing/selecting a new scale.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:73
void reloadProjectScales()
Call to reload the preset scales from the current project and apply them to the 2 scales combo boxes...
void setShowCurrentScaleButton(bool showCurrentScaleButton)
Sets whether to show a button to set the scale to the current scale of the map canvas next to the com...
void updateScales(const QStringList &scales=QStringList())
Sets the list of predefined scales to show in the combobox.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
void setMinScale(double scale)
Set the minimum allowed scale.
void setMinimumScale(double scale)
Set the minimum scale (i.e.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
void setScaleRange(double min, double max)
Sets the scale range, from min scale (i.e.
double maximumScale() const
Returns the selected maximum scale (i.e.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas which will be used for the current scale buttons.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:438
void setMapCanvas(QgsMapCanvas *canvas)
Set the map canvas associated to the current button.
void rangeChanged(double min, double max)
Emitted when the scale range set in the widget is changed.
double minimumScale() const
Returns the selected minimum scale (i.e.