QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
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
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
18#include "qgsapplication.h"
19#include "qgsguiutils.h"
20#include "qgsproject.h"
22#include "qgsscalewidget.h"
23
24#include <QString>
25
26#include "moc_qgsscalerangewidget.cpp"
27
28using namespace Qt::StringLiterals;
29
31 : QWidget( parent )
32
33{
34 mLayout = new QGridLayout( this );
35 mLayout->setContentsMargins( 0, 0, 0, 0 );
36
37 QLabel *minLbl = new QLabel( tr( "Minimum (exclusive)" ), this );
38 minLbl->setWordWrap( true );
39 minLbl->setAlignment( Qt::AlignTop );
40 minLbl->setToolTip( tr(
41 "Minimum scale, i.e. most \"zoomed out\". "
42 "This limit is exclusive, that means the layer will not be displayed on this scale."
43 ) );
44 QLabel *maxLbl = new QLabel( tr( "Maximum (inclusive)" ), this );
45 maxLbl->setWordWrap( true );
46 maxLbl->setAlignment( Qt::AlignTop );
47 maxLbl->setToolTip( tr(
48 "Maximum scale, i.e. most \"zoomed in\". "
49 "This limit is inclusive, that means the layer will be displayed on this scale."
50 ) );
51
52 const int iconSize = QgsGuiUtils::scaleIconSize( 24 );
53 mMinimumScaleIconLabel = new QLabel( this );
54 mMinimumScaleIconLabel->setPixmap( QgsApplication::getThemeIcon( u"/mActionZoomOut.svg"_s ).pixmap( QSize( iconSize, iconSize ) ) );
55 mMaximumScaleIconLabel = new QLabel( this );
56 mMaximumScaleIconLabel->setPixmap( QgsApplication::getThemeIcon( u"/mActionZoomIn.svg"_s ).pixmap( QSize( iconSize, iconSize ) ) );
57
58 mMinimumScaleWidget = new QgsScaleWidget( this );
59 mMaximumScaleWidget = new QgsScaleWidget( this );
60 connect( mMinimumScaleWidget, &QgsScaleWidget::scaleChanged, mMaximumScaleWidget, &QgsScaleWidget::setMinScale );
61 mMinimumScaleWidget->setShowCurrentScaleButton( true );
62 mMaximumScaleWidget->setShowCurrentScaleButton( true );
64 // add start, add comprehension of scales by settings fake ordered values
65 mMinimumScaleWidget->setScale( 100000 );
66 mMaximumScaleWidget->setScale( 1000 );
67
68 mLayout->addWidget( minLbl, 0, 0, 1, 2 );
69 mLayout->addWidget( mMinimumScaleIconLabel, 1, 0 );
70 mLayout->addWidget( mMinimumScaleWidget, 1, 1 );
71 mLayout->addWidget( maxLbl, 0, 2, 1, 2 );
72 mLayout->addWidget( mMaximumScaleIconLabel, 1, 2 );
73 mLayout->addWidget( mMaximumScaleWidget, 1, 3 );
74
75 mLayout->setColumnStretch( 0, 0 );
76 mLayout->setColumnStretch( 1, 3 );
77 mLayout->setColumnStretch( 2, 0 );
78 mLayout->setColumnStretch( 3, 3 );
79
80 connect( mMinimumScaleWidget, &QgsScaleWidget::scaleChanged, this, &QgsScaleRangeWidget::emitRangeChanged );
81 connect( mMaximumScaleWidget, &QgsScaleWidget::scaleChanged, this, &QgsScaleRangeWidget::emitRangeChanged );
82}
83
85{
86 if ( QgsProject::instance()->viewSettings()->useProjectScales() )
87 {
88 const QVector<double> projectScales = QgsProject::instance()->viewSettings()->mapScales();
89 mMinimumScaleWidget->setPredefinedScales( projectScales );
90 mMaximumScaleWidget->setPredefinedScales( projectScales );
91 }
92}
93
95{
96 mMinimumScaleWidget->setMapCanvas( mapCanvas );
97 mMaximumScaleWidget->setMapCanvas( mapCanvas );
98}
99
101{
102 mMinimumScaleWidget->setScale( scale );
103}
104
106{
107 return mMinimumScaleWidget->scale();
108}
109
111{
112 mMaximumScaleWidget->setScale( scale );
113}
114
116{
117 return mMaximumScaleWidget->scale();
118}
119
120void QgsScaleRangeWidget::setScaleRange( double min, double max )
121{
122 setMinimumScale( min );
123 setMaximumScale( max );
124}
125
126void QgsScaleRangeWidget::emitRangeChanged()
127{
129}
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Map canvas is a class for displaying all GIS data types on a canvas.
QVector< double > mapScales() const
Returns the list of custom project map scales.
static QgsProject * instance()
Returns the QgsProject singleton instance.
const QgsProjectViewSettings * viewSettings() const
Returns the project's view settings, which contains settings and properties relating to how a QgsProj...
QgsScaleRangeWidget(QWidget *parent=nullptr)
Constructor for QgsScaleRangeWidget.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas which will be used for the current scale buttons.
void setScaleRange(double min, double max)
Sets the scale range, from min scale (i.e.
void reloadProjectScales()
Call to reload the preset scales from the current project and apply them to the 2 scales combo boxes.
void setMinimumScale(double scale)
Set the minimum scale (i.e.
void rangeChanged(double min, double max)
Emitted when the scale range set in the widget is changed.
void setMaximumScale(double scale)
Set the maximum scale (i.e.
A combobox which lets the user select map scale from predefined list and highlights nearest to curren...
void scaleChanged(double scale)
Emitted when user has finished editing/selecting a new scale.
void setMinScale(double scale)
Set the minimum allowed scale.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...