QGIS API Documentation
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 
20 
22  : QWidget( parent )
23  , mCanvas( nullptr )
24 {
25  mLayout = new QGridLayout( this );
26  mLayout->setContentsMargins( 0, 0, 0, 0 );
27 
28  QLabel* minLbl = new QLabel( tr( "Minimum\n(exclusive)" ), this );
29  minLbl->setWordWrap( true );
30  minLbl->setAlignment( Qt::AlignTop );
31  minLbl->setToolTip( tr( "Minimum scale, i.e. maximum scale denominator. "
32  "This limit is exclusive, that means the layer will not be displayed on this scale." ) );
33  QLabel* maxLbl = new QLabel( tr( "Maximum\n(inclusive)" ), this );
34  maxLbl->setWordWrap( true );
35  maxLbl->setAlignment( Qt::AlignTop );
36  maxLbl->setToolTip( tr( "Maximum scale, i.e. minimum scale denominator. "
37  "This limit is inclusive, that means the layer will be displayed on this scale." ) );
38 
39  mMinimumScaleIconLabel = new QLabel( this );
40  mMinimumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomOut.svg" ) );
41  mMaximumScaleIconLabel = new QLabel( this );
42  mMaximumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomIn.svg" ) );
43 
44  mMinimumScaleWidget = new QgsScaleWidget( this );
45  mMaximumScaleWidget = new QgsScaleWidget( this );
46  connect( mMinimumScaleWidget, SIGNAL( scaleChanged( double ) ), mMaximumScaleWidget, SLOT( setMinScale( double ) ) );
47  mMinimumScaleWidget->setShowCurrentScaleButton( true );
48  mMaximumScaleWidget->setShowCurrentScaleButton( true );
50  // add start, add comprehension of scales by settings fake ordered values
51  mMinimumScaleWidget->setScale( 1.0 / 100000 );
52  mMaximumScaleWidget->setScale( 1.0 / 1000 );
53 
54  mLayout->addWidget( minLbl, 0, 0, 2, 1 );
55  mLayout->addWidget( mMinimumScaleIconLabel, 0, 1 );
56  mLayout->addWidget( mMinimumScaleWidget, 0, 2 );
57  mLayout->addWidget( maxLbl, 0, 3, 2, 1 );
58  mLayout->addWidget( mMaximumScaleIconLabel, 0, 4 );
59  mLayout->addWidget( mMaximumScaleWidget, 0, 5 );
60 
61  mLayout->setColumnStretch( 0, 0 );
62  mLayout->setColumnStretch( 1, 0 );
63  mLayout->setColumnStretch( 2, 3 );
64  mLayout->setColumnStretch( 3, 0 );
65  mLayout->setColumnStretch( 4, 0 );
66  mLayout->setColumnStretch( 5, 3 );
67 }
68 
70 {
71 }
72 
74 {
75  bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
76  if ( projectScales )
77  {
78  QStringList scalesList = QgsProject::instance()->readListEntry( "Scales", "/ScalesList" );
79  mMinimumScaleWidget->updateScales( scalesList );
80  mMaximumScaleWidget->updateScales( scalesList );
81  }
82 }
83 
85 {
86  mMinimumScaleWidget->setMapCanvas( mapCanvas );
87  mMaximumScaleWidget->setMapCanvas( mapCanvas );
88 }
89 
91 {
92  mMinimumScaleWidget->setScale( scale );
93 }
94 
96 {
97  return mMinimumScaleWidget->scale();
98 }
99 
101 {
102  mMaximumScaleWidget->setScale( scale );
103 }
104 
106 {
107  return mMaximumScaleWidget->scale();
108 }
109 
111 {
112  return qRound( 1.0 / maximumScale() );
113 }
114 
116 {
117  return qRound( 1.0 / minimumScale() );
118 }
119 
121 {
122  setMaximumScale( max );
123  setMinimumScale( min );
124 }
125 
double minimumScale()
return the minimum scale
void setContentsMargins(int left, int top, int right, int bottom)
QgsScaleRangeWidget(QWidget *parent=nullptr)
void addWidget(QWidget *widget, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
A combobox which lets the user select map scale from predefined list and highlights nearest to curren...
void setMaximumScale(double scale)
void setPixmap(const QPixmap &)
void setAlignment(QFlags< Qt::AlignmentFlag >)
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
void setScale(double scale)
Function to set the selected scale from double.
QString tr(const char *sourceText, const char *disambiguation, int n)
double minimumScaleDenom()
return the minimum scale denominator ( = 1 / maximum scale )
static QPixmap getThemePixmap(const QString &theName)
Helper to get a theme icon as a pixmap.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:105
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
void reloadProjectScales()
call to reload the project scales and apply them to the 2 scales combo boxes
void setShowCurrentScaleButton(bool showCurrentScaleButton)
shows a button to set the scale to the current scale of the map canvas next to the combobox ...
double maximumScaleDenom()
return the maximum scale denominator ( = 1 / minimum scale )
void updateScales(const QStringList &scales=QStringList())
double maximumScale()
return the maximum scale
void setMinimumScale(double scale)
void setScaleRange(double min, double max)
void setColumnStretch(int column, int stretch)
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:388
void setMapCanvas(QgsMapCanvas *canvas)
set the map canvas associated to the current button
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const
void setToolTip(const QString &)
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setMapCanvas(QgsMapCanvas *mapCanvas)
set the map canvas which will be used for the current scale buttons
void setWordWrap(bool on)