QGIS API Documentation  2.8.2-Wien
 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 : 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 #include "qgsscalerangewidget.h"
17 #include "qgsapplication.h"
18 #include "qgsproject.h"
19 
20 
22  : QWidget( parent )
23  , mCanvas( 0 )
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  mMinimumScaleWidget->setShowCurrentScaleButton( true );
47  mMaximumScaleWidget->setShowCurrentScaleButton( true );
49  // add start, add comprehension of scales by settings fake ordered values
50  mMinimumScaleWidget->setScale( 1.0 / 100000 );
51  mMaximumScaleWidget->setScale( 1.0 / 1000 );
52 
53  mLayout->addWidget( minLbl, 0, 0, 2, 1 );
54  mLayout->addWidget( mMinimumScaleIconLabel, 0, 1 );
55  mLayout->addWidget( mMinimumScaleWidget, 0, 2 );
56  mLayout->addWidget( maxLbl, 0, 3, 2, 1 );
57  mLayout->addWidget( mMaximumScaleIconLabel, 0, 4 );
58  mLayout->addWidget( mMaximumScaleWidget, 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  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 
110 {
111  return qRound( 1.0 / maximumScale() );
112 }
113 
115 {
116  return qRound( 1.0 / minimumScale() );
117 }
118 
120 {
121  setMaximumScale( max );
122  setMinimumScale( min );
123 }
124