Skip to content

Commit bd3fd74

Browse files
committed
Merge pull request #2863 from pvalsecc/minMaxScale
Add check to make sure minScale<=maxScale.
2 parents a3c76c6 + 4f18701 commit bd3fd74

10 files changed

+107
-63
lines changed

python/gui/qgsscalecombobox.sip

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ class QgsScaleComboBox : QComboBox
1717
//! Function to set the selected scale from text
1818
bool setScaleString( const QString& scaleTxt );
1919
//! Function to read the selected scale as double
20-
double scale();
20+
double scale() const;
2121
//! Function to set the selected scale from double
2222
void setScale( double scale );
23+
//! Function to read the min scale
24+
double minScale() const;
2325

2426
//! Helper function to convert a double to scale string
2527
// Performs rounding, so an exact representation is not to
@@ -30,10 +32,12 @@ class QgsScaleComboBox : QComboBox
3032

3133
signals:
3234
//! Signal is emitted when *user* has finished editing/selecting a new scale.
33-
void scaleChanged();
35+
void scaleChanged( double scale );
3436

3537
public slots:
3638
void updateScales( const QStringList &scales = QStringList() );
39+
//! Function to set the min scale
40+
void setMinScale( double scale );
3741

3842
protected:
3943
void showPopup();

python/gui/qgsscalewidget.sip

+7-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ class QgsScaleWidget : QWidget
2626
//! Function to set the selected scale from text
2727
bool setScaleString( const QString& scaleTxt );
2828
//! Function to read the selected scale as double
29-
double scale();
29+
double scale() const;
3030
//! Function to set the selected scale from double
3131
void setScale( double scale );
32+
//! Function to read the min scale
33+
double minScale() const;
3234

3335
//! Helper function to convert a double to scale string
3436
// Performs rounding, so an exact representation is not to
@@ -43,9 +45,12 @@ class QgsScaleWidget : QWidget
4345
//! assign the current scale from the map canvas
4446
void setScaleFromCanvas();
4547

48+
//! Function to set the min scale
49+
void setMinScale( double scale );
50+
4651
signals:
4752
//! Signal is emitted when *user* has finished editing/selecting a new scale.
48-
void scaleChanged();
53+
void scaleChanged( double scale );
4954

5055

5156
};

src/app/qgisapp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,7 @@ void QgisApp::createStatusBar()
20572057
mScaleEdit->setToolTip( tr( "Current map scale (formatted as x:y)" ) );
20582058

20592059
statusBar()->addPermanentWidget( mScaleEdit, 0 );
2060-
connect( mScaleEdit, SIGNAL( scaleChanged() ), this, SLOT( userScale() ) );
2060+
connect( mScaleEdit, SIGNAL( scaleChanged( double ) ), this, SLOT( userScale() ) );
20612061

20622062
if ( QgsMapCanvas::rotationEnabled() )
20632063
{

src/gui/qgsscalecombobox.cpp

+25-19
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <QSettings>
2525
#include <QLineEdit>
2626

27-
QgsScaleComboBox::QgsScaleComboBox( QWidget* parent ) : QComboBox( parent ), mScale( 1.0 )
27+
QgsScaleComboBox::QgsScaleComboBox( QWidget* parent ) : QComboBox( parent ), mScale( 1.0 ), mMinScale( 0.0 )
2828
{
2929
updateScales();
3030

@@ -126,6 +126,11 @@ bool QgsScaleComboBox::setScaleString( const QString& scaleTxt )
126126
{
127127
bool ok;
128128
double newScale = toDouble( scaleTxt, &ok );
129+
double oldScale = mScale;
130+
if ( newScale < mMinScale )
131+
{
132+
newScale = mMinScale;
133+
}
129134
if ( ! ok )
130135
{
131136
return false;
@@ -135,12 +140,16 @@ bool QgsScaleComboBox::setScaleString( const QString& scaleTxt )
135140
mScale = newScale;
136141
setEditText( toString( mScale ) );
137142
clearFocus();
143+
if ( mScale != oldScale )
144+
{
145+
emit scaleChanged( mScale );
146+
}
138147
return true;
139148
}
140149
}
141150

142151
//! Function to read the selected scale as double
143-
double QgsScaleComboBox::scale()
152+
double QgsScaleComboBox::scale() const
144153
{
145154
return mScale;
146155
}
@@ -154,34 +163,24 @@ void QgsScaleComboBox::setScale( double scale )
154163
//! Slot called when QComboBox has changed
155164
void QgsScaleComboBox::fixupScale()
156165
{
157-
double newScale;
158-
double oldScale = mScale;
159-
bool ok, userSetScale;
160166
QStringList txtList = currentText().split( ':' );
161-
userSetScale = txtList.size() != 2;
167+
bool userSetScale = txtList.size() != 2;
162168

163-
// QgsDebugMsg( QString( "entered with oldScale: %1" ).arg( oldScale ) );
164-
newScale = toDouble( currentText(), &ok );
169+
bool ok;
170+
double newScale = toDouble( currentText(), &ok );
165171

166172
// Valid string representation
167-
if ( ok && ( newScale != oldScale ) )
173+
if ( ok )
168174
{
169175
// if a user types scale = 2345, we transform to 1:2345
170176
if ( userSetScale && newScale >= 1.0 )
171177
{
172-
mScale = 1 / newScale;
178+
newScale = 1 / newScale;
173179
}
174-
else
175-
{
176-
mScale = newScale;
177-
}
178-
setScale( mScale );
179-
emit scaleChanged();
180+
setScale( newScale );
180181
}
181182
else
182183
{
183-
// Invalid string representation or same scale
184-
// Reset to the old
185184
setScale( mScale );
186185
}
187186
}
@@ -241,4 +240,11 @@ double QgsScaleComboBox::toDouble( const QString& scaleString, bool * returnOk )
241240
return scale;
242241
}
243242

244-
243+
void QgsScaleComboBox::setMinScale( double scale )
244+
{
245+
mMinScale = scale;
246+
if ( mScale < scale )
247+
{
248+
setScale( scale );
249+
}
250+
}

src/gui/qgsscalecombobox.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ class GUI_EXPORT QgsScaleComboBox : public QComboBox
3636
//! Function to set the selected scale from text
3737
bool setScaleString( const QString& scaleTxt );
3838
//! Function to read the selected scale as double
39-
double scale();
39+
double scale() const;
4040
//! Function to set the selected scale from double
4141
void setScale( double scale );
42+
//! Function to read the min scale
43+
double minScale() const { return mMinScale; }
4244

4345
//! Helper function to convert a double to scale string
4446
// Performs rounding, so an exact representation is not to
@@ -49,10 +51,12 @@ class GUI_EXPORT QgsScaleComboBox : public QComboBox
4951

5052
signals:
5153
//! Signal is emitted when *user* has finished editing/selecting a new scale.
52-
void scaleChanged();
54+
void scaleChanged( double scale );
5355

5456
public slots:
5557
void updateScales( const QStringList &scales = QStringList() );
58+
//! Function to set the min scale
59+
void setMinScale( double scale );
5660

5761
protected:
5862
void showPopup() override;
@@ -62,6 +66,7 @@ class GUI_EXPORT QgsScaleComboBox : public QComboBox
6266

6367
private:
6468
double mScale;
69+
double mMinScale;
6570
};
6671

6772
#endif // QGSSCALECOMBOBOX_H

src/gui/qgsscalerangewidget.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ QgsScaleRangeWidget::QgsScaleRangeWidget( QWidget *parent )
4343

4444
mMinimumScaleWidget = new QgsScaleWidget( this );
4545
mMaximumScaleWidget = new QgsScaleWidget( this );
46+
connect( mMinimumScaleWidget, SIGNAL( scaleChanged( double ) ), mMaximumScaleWidget, SLOT( setMinScale( double ) ) );
4647
mMinimumScaleWidget->setShowCurrentScaleButton( true );
4748
mMaximumScaleWidget->setShowCurrentScaleButton( true );
4849
reloadProjectScales();

src/gui/qgsscalewidget.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ QgsScaleWidget::QgsScaleWidget( QWidget *parent )
3737
layout->addWidget( mCurrentScaleButton );
3838
mCurrentScaleButton->hide();
3939

40-
connect( mScaleComboBox, SIGNAL( scaleChanged() ), this, SIGNAL( scaleChanged() ) );
40+
connect( mScaleComboBox, SIGNAL( scaleChanged( double ) ), this, SIGNAL( scaleChanged( double ) ) );
4141
connect( mCurrentScaleButton, SIGNAL( clicked() ), this, SLOT( setScaleFromCanvas() ) );
4242
}
4343

src/gui/qgsscalewidget.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class GUI_EXPORT QgsScaleWidget : public QWidget
3232
{
3333
Q_OBJECT
3434
Q_PROPERTY( bool showCurrentScaleButton READ showCurrentScaleButton WRITE setShowCurrentScaleButton )
35+
Q_PROPERTY( bool scale READ scale WRITE setScale NOTIFY scaleChanged )
36+
Q_PROPERTY( bool minScale READ minScale WRITE setMinScale )
3537

3638
public:
3739
explicit QgsScaleWidget( QWidget *parent = nullptr );
@@ -51,9 +53,11 @@ class GUI_EXPORT QgsScaleWidget : public QWidget
5153
//! Function to set the selected scale from text
5254
bool setScaleString( const QString& scaleTxt ) { return mScaleComboBox->setScaleString( scaleTxt ); }
5355
//! Function to read the selected scale as double
54-
double scale() { return mScaleComboBox->scale();}
56+
double scale() const { return mScaleComboBox->scale();}
5557
//! Function to set the selected scale from double
5658
void setScale( double scale ) { return mScaleComboBox->setScale( scale ); }
59+
//! Function to read the min scale
60+
double minScale() const { return mScaleComboBox->minScale(); }
5761

5862
//! Helper function to convert a double to scale string
5963
// Performs rounding, so an exact representation is not to
@@ -68,9 +72,12 @@ class GUI_EXPORT QgsScaleWidget : public QWidget
6872
//! assign the current scale from the map canvas
6973
void setScaleFromCanvas();
7074

75+
//! Function to set the min scale
76+
void setMinScale( double scale ) { mScaleComboBox->setMinScale( scale ); }
77+
7178
signals:
7279
//! Signal is emitted when *user* has finished editing/selecting a new scale.
73-
void scaleChanged();
80+
void scaleChanged( double scale );
7481

7582
private:
7683
QgsScaleComboBox* mScaleComboBox;

src/gui/qgsunitselectionwidget.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ QgsMapUnitScaleDialog::QgsMapUnitScaleDialog( QWidget* parent )
2828
mSpinBoxMaxSize->setShowClearButton( false );
2929
connect( mCheckBoxMinScale, SIGNAL( toggled( bool ) ), this, SLOT( configureMinComboBox() ) );
3030
connect( mCheckBoxMaxScale, SIGNAL( toggled( bool ) ), this, SLOT( configureMaxComboBox() ) );
31-
connect( mComboBoxMinScale, SIGNAL( scaleChanged() ), this, SLOT( configureMaxComboBox() ) );
32-
connect( mComboBoxMaxScale, SIGNAL( scaleChanged() ), this, SLOT( configureMinComboBox() ) );
31+
connect( mComboBoxMinScale, SIGNAL( scaleChanged( double ) ), this, SLOT( configureMaxComboBox() ) );
32+
connect( mComboBoxMinScale, SIGNAL( scaleChanged( double ) ), mComboBoxMaxScale, SLOT( setMinScale( double ) ) );
33+
connect( mComboBoxMaxScale, SIGNAL( scaleChanged( double ) ), this, SLOT( configureMinComboBox() ) );
3334

3435
connect( mCheckBoxMinSize, SIGNAL( toggled( bool ) ), mSpinBoxMinSize, SLOT( setEnabled( bool ) ) );
3536
connect( mCheckBoxMaxSize, SIGNAL( toggled( bool ) ), mSpinBoxMaxSize, SLOT( setEnabled( bool ) ) );

0 commit comments

Comments
 (0)