QGIS API Documentation  2.4.0-Chugiak
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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( 0 )
24  , mMaximumScaleSetCurrentPushButton( 0 )
25  , mMinimumScaleSetCurrentPushButton( 0 )
26 {
27  mLayout = new QGridLayout( this );
28  mLayout->setContentsMargins( 0, 0, 0, 0 );
29 
30  QLabel* minLbl = new QLabel( tr( "Minimum\n(exclusive)" ), this );
31  minLbl->setWordWrap( true );
32  minLbl->setAlignment( Qt::AlignTop );
33  minLbl->setToolTip( tr( "Minimum scale, i.e. maximum scale denominator. "
34  "This limit is exclusive, that means the layer will not be displayed on this scale." ) );
35  QLabel* maxLbl = new QLabel( tr( "Maximum\n(inclusive)" ), this );
36  maxLbl->setWordWrap( true );
37  maxLbl->setAlignment( Qt::AlignTop );
38  maxLbl->setToolTip( tr( "Maximum scale, i.e. minimum scale denominator. "
39  "This limit is inclusive, that means the layer will be displayed on this scale." ) );
40 
41  mMinimumScaleIconLabel = new QLabel( this );
42  mMinimumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomOut.svg" ) );
43  mMaximumScaleIconLabel = new QLabel( this );
44  mMaximumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomIn.svg" ) );
45 
49  // add start, add comprehension of scales by settings fake ordered values
50  mMinimumScaleComboBox->setCurrentIndex( 2 );
51  mMaximumScaleComboBox->setCurrentIndex( mMinimumScaleComboBox->currentIndex() + 2 );
52 
53  mLayout->addWidget( minLbl, 0, 0, 2, 1 );
54  mLayout->addWidget( mMinimumScaleIconLabel, 0, 1 );
55  mLayout->addWidget( mMinimumScaleComboBox, 0, 2 );
56  mLayout->addWidget( maxLbl, 0, 3, 2, 1 );
57  mLayout->addWidget( mMaximumScaleIconLabel, 0, 4 );
58  mLayout->addWidget( mMaximumScaleComboBox, 0, 5 );
59 
60  mLayout->setColumnStretch( 0, 0 );
61  mLayout->setColumnStretch( 1, 0 );
62  mLayout->setColumnStretch( 2, 3 );
63  mLayout->setColumnStretch( 3, 0 );
64  mLayout->setColumnStretch( 4, 0 );
65  mLayout->setColumnStretch( 5, 3 );
66 }
67 
69 {
70 }
71 
73 {
74  bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
75  if ( projectScales )
76  {
77  QStringList scalesList = QgsProject::instance()->readListEntry( "Scales", "/ScalesList" );
78  mMinimumScaleComboBox->updateScales( scalesList );
79  mMaximumScaleComboBox->updateScales( scalesList );
80  }
81 }
82 
84 {
86  {
89  }
91  {
94  }
95 
96  if ( !mapCanvas )
97  return;
98 
99  mCanvas = mapCanvas;
100 
101  mMinimumScaleSetCurrentPushButton = new QPushButton( tr( "current" ), this );
102  connect( mMinimumScaleSetCurrentPushButton, SIGNAL( clicked() ), this, SLOT( setMinScaleFromCanvas() ) );
103  mMaximumScaleSetCurrentPushButton = new QPushButton( tr( "current" ), this );
104  connect( mMaximumScaleSetCurrentPushButton, SIGNAL( clicked() ), this, SLOT( setMaxScaleFromCanvas() ) );
105 
106  mLayout->addWidget( mMinimumScaleSetCurrentPushButton, 1, 2 );
107  mLayout->addWidget( mMaximumScaleSetCurrentPushButton, 1, 5 );
108 }
109 
111 {
113 }
114 
116 {
117  return mMinimumScaleComboBox->scale();
118 }
119 
121 {
123 }
124 
126 {
127  return mMaximumScaleComboBox->scale();
128 }
129 
131 {
132  return qRound( 1.0 / maximumScale() );
133 }
134 
136 {
137  return qRound( 1.0 / minimumScale() );
138 }
139 
141 {
142  setMaximumScale( max );
143  setMinimumScale( min );
144 }
145 
147 {
149 }
150 
152 {
154 }
155 
156 
double minimumScale()
return the minimum scale
double scale() const
Return the calculated scale of the map.
void setMaximumScale(double scale)
QgsScaleComboBox * mMaximumScaleComboBox
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
void setScale(double scale)
Function to set the selected scale from double.
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=0) const
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:104
double ANALYSIS_EXPORT max(double x, double y)
returns the maximum of two doubles or the first argument if both are equal
QStringList readListEntry(const QString &scope, const QString &key, QStringList def=QStringList(), bool *ok=0) const
key value accessors
QgsMapCanvas * mCanvas
pointer to the map canvas used for current buttons.
void reloadProjectScales()
call to reload the project scales and apply them to the 2 scales combo boxes
double maximumScaleDenom()
return the maximum scale denominator ( = 1 / minimum scale )
double scale()
Function to read the selected scale as double.
double maximumScale()
return the maximum scale
QPushButton * mMinimumScaleSetCurrentPushButton
void setMinimumScale(double scale)
void setScaleRange(double min, double max)
QgsScaleRangeWidget(QWidget *parent=0)
QPushButton * mMaximumScaleSetCurrentPushButton
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:362
void updateScales(const QStringList &scales=QStringList())
double ANALYSIS_EXPORT min(double x, double y)
returns the minimum of two doubles or the first argument if both are equal
void setMapCanvas(QgsMapCanvas *mapCanvas)
set the map canvas which will be used for the current scale buttons
QgsScaleComboBox * mMinimumScaleComboBox
#define tr(sourceText)
A combobox which lets the user select map scale from predefined list and highlights nearest to curren...