24
24
#include < QSettings>
25
25
#include < QLineEdit>
26
26
27
- QgsScaleComboBox::QgsScaleComboBox ( QWidget* parent ) : QComboBox( parent ), mScale( 1.0 )
27
+ QgsScaleComboBox::QgsScaleComboBox ( QWidget* parent ) : QComboBox( parent ), mScale( 1.0 ), mMinScale( 0.0 )
28
28
{
29
29
updateScales ();
30
30
@@ -126,6 +126,11 @@ bool QgsScaleComboBox::setScaleString( const QString& scaleTxt )
126
126
{
127
127
bool ok;
128
128
double newScale = toDouble ( scaleTxt, &ok );
129
+ double oldScale = mScale ;
130
+ if ( newScale < mMinScale )
131
+ {
132
+ newScale = mMinScale ;
133
+ }
129
134
if ( ! ok )
130
135
{
131
136
return false ;
@@ -135,12 +140,16 @@ bool QgsScaleComboBox::setScaleString( const QString& scaleTxt )
135
140
mScale = newScale;
136
141
setEditText ( toString ( mScale ) );
137
142
clearFocus ();
143
+ if ( mScale != oldScale )
144
+ {
145
+ emit scaleChanged ( mScale );
146
+ }
138
147
return true ;
139
148
}
140
149
}
141
150
142
151
// ! Function to read the selected scale as double
143
- double QgsScaleComboBox::scale ()
152
+ double QgsScaleComboBox::scale () const
144
153
{
145
154
return mScale ;
146
155
}
@@ -154,34 +163,24 @@ void QgsScaleComboBox::setScale( double scale )
154
163
// ! Slot called when QComboBox has changed
155
164
void QgsScaleComboBox::fixupScale ()
156
165
{
157
- double newScale;
158
- double oldScale = mScale ;
159
- bool ok, userSetScale;
160
166
QStringList txtList = currentText ().split ( ' :' );
161
- userSetScale = txtList.size () != 2 ;
167
+ bool userSetScale = txtList.size () != 2 ;
162
168
163
- // QgsDebugMsg( QString( "entered with oldScale: %1" ).arg( oldScale ) ) ;
164
- newScale = toDouble ( currentText (), &ok );
169
+ bool ok ;
170
+ double newScale = toDouble ( currentText (), &ok );
165
171
166
172
// Valid string representation
167
- if ( ok && ( newScale != oldScale ) )
173
+ if ( ok )
168
174
{
169
175
// if a user types scale = 2345, we transform to 1:2345
170
176
if ( userSetScale && newScale >= 1.0 )
171
177
{
172
- mScale = 1 / newScale;
178
+ newScale = 1 / newScale;
173
179
}
174
- else
175
- {
176
- mScale = newScale;
177
- }
178
- setScale ( mScale );
179
- emit scaleChanged ();
180
+ setScale ( newScale );
180
181
}
181
182
else
182
183
{
183
- // Invalid string representation or same scale
184
- // Reset to the old
185
184
setScale ( mScale );
186
185
}
187
186
}
@@ -241,4 +240,11 @@ double QgsScaleComboBox::toDouble( const QString& scaleString, bool * returnOk )
241
240
return scale;
242
241
}
243
242
244
-
243
+ void QgsScaleComboBox::setMinScale ( double scale )
244
+ {
245
+ mMinScale = scale;
246
+ if ( mScale < scale )
247
+ {
248
+ setScale ( scale );
249
+ }
250
+ }
0 commit comments