Skip to content
Permalink
Browse files

Merge pull request #2863 from pvalsecc/minMaxScale

Add check to make sure minScale<=maxScale.
  • Loading branch information
m-kuhn committed Mar 20, 2016
2 parents a3c76c6 + 4f18701 commit bd3fd748f1e170c8aeb20fbc4f40966f70d33c5b
@@ -17,9 +17,11 @@ class QgsScaleComboBox : QComboBox
//! Function to set the selected scale from text
bool setScaleString( const QString& scaleTxt );
//! Function to read the selected scale as double
double scale();
double scale() const;
//! Function to set the selected scale from double
void setScale( double scale );
//! Function to read the min scale
double minScale() const;

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

signals:
//! Signal is emitted when *user* has finished editing/selecting a new scale.
void scaleChanged();
void scaleChanged( double scale );

public slots:
void updateScales( const QStringList &scales = QStringList() );
//! Function to set the min scale
void setMinScale( double scale );

protected:
void showPopup();
@@ -26,9 +26,11 @@ class QgsScaleWidget : QWidget
//! Function to set the selected scale from text
bool setScaleString( const QString& scaleTxt );
//! Function to read the selected scale as double
double scale();
double scale() const;
//! Function to set the selected scale from double
void setScale( double scale );
//! Function to read the min scale
double minScale() const;

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

//! Function to set the min scale
void setMinScale( double scale );

signals:
//! Signal is emitted when *user* has finished editing/selecting a new scale.
void scaleChanged();
void scaleChanged( double scale );


};
@@ -2057,7 +2057,7 @@ void QgisApp::createStatusBar()
mScaleEdit->setToolTip( tr( "Current map scale (formatted as x:y)" ) );

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

if ( QgsMapCanvas::rotationEnabled() )
{
@@ -24,7 +24,7 @@
#include <QSettings>
#include <QLineEdit>

QgsScaleComboBox::QgsScaleComboBox( QWidget* parent ) : QComboBox( parent ), mScale( 1.0 )
QgsScaleComboBox::QgsScaleComboBox( QWidget* parent ) : QComboBox( parent ), mScale( 1.0 ), mMinScale( 0.0 )
{
updateScales();

@@ -126,6 +126,11 @@ bool QgsScaleComboBox::setScaleString( const QString& scaleTxt )
{
bool ok;
double newScale = toDouble( scaleTxt, &ok );
double oldScale = mScale;
if ( newScale < mMinScale )
{
newScale = mMinScale;
}
if ( ! ok )
{
return false;
@@ -135,12 +140,16 @@ bool QgsScaleComboBox::setScaleString( const QString& scaleTxt )
mScale = newScale;
setEditText( toString( mScale ) );
clearFocus();
if ( mScale != oldScale )
{
emit scaleChanged( mScale );
}
return true;
}
}

//! Function to read the selected scale as double
double QgsScaleComboBox::scale()
double QgsScaleComboBox::scale() const
{
return mScale;
}
@@ -154,34 +163,24 @@ void QgsScaleComboBox::setScale( double scale )
//! Slot called when QComboBox has changed
void QgsScaleComboBox::fixupScale()
{
double newScale;
double oldScale = mScale;
bool ok, userSetScale;
QStringList txtList = currentText().split( ':' );
userSetScale = txtList.size() != 2;
bool userSetScale = txtList.size() != 2;

// QgsDebugMsg( QString( "entered with oldScale: %1" ).arg( oldScale ) );
newScale = toDouble( currentText(), &ok );
bool ok;
double newScale = toDouble( currentText(), &ok );

// Valid string representation
if ( ok && ( newScale != oldScale ) )
if ( ok )
{
// if a user types scale = 2345, we transform to 1:2345
if ( userSetScale && newScale >= 1.0 )
{
mScale = 1 / newScale;
newScale = 1 / newScale;
}
else
{
mScale = newScale;
}
setScale( mScale );
emit scaleChanged();
setScale( newScale );
}
else
{
// Invalid string representation or same scale
// Reset to the old
setScale( mScale );
}
}
@@ -241,4 +240,11 @@ double QgsScaleComboBox::toDouble( const QString& scaleString, bool * returnOk )
return scale;
}


void QgsScaleComboBox::setMinScale( double scale )
{
mMinScale = scale;
if ( mScale < scale )
{
setScale( scale );
}
}
@@ -36,9 +36,11 @@ class GUI_EXPORT QgsScaleComboBox : public QComboBox
//! Function to set the selected scale from text
bool setScaleString( const QString& scaleTxt );
//! Function to read the selected scale as double
double scale();
double scale() const;
//! Function to set the selected scale from double
void setScale( double scale );
//! Function to read the min scale
double minScale() const { return mMinScale; }

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

signals:
//! Signal is emitted when *user* has finished editing/selecting a new scale.
void scaleChanged();
void scaleChanged( double scale );

public slots:
void updateScales( const QStringList &scales = QStringList() );
//! Function to set the min scale
void setMinScale( double scale );

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

private:
double mScale;
double mMinScale;
};

#endif // QGSSCALECOMBOBOX_H
@@ -43,6 +43,7 @@ QgsScaleRangeWidget::QgsScaleRangeWidget( QWidget *parent )

mMinimumScaleWidget = new QgsScaleWidget( this );
mMaximumScaleWidget = new QgsScaleWidget( this );
connect( mMinimumScaleWidget, SIGNAL( scaleChanged( double ) ), mMaximumScaleWidget, SLOT( setMinScale( double ) ) );
mMinimumScaleWidget->setShowCurrentScaleButton( true );
mMaximumScaleWidget->setShowCurrentScaleButton( true );
reloadProjectScales();
@@ -37,7 +37,7 @@ QgsScaleWidget::QgsScaleWidget( QWidget *parent )
layout->addWidget( mCurrentScaleButton );
mCurrentScaleButton->hide();

connect( mScaleComboBox, SIGNAL( scaleChanged() ), this, SIGNAL( scaleChanged() ) );
connect( mScaleComboBox, SIGNAL( scaleChanged( double ) ), this, SIGNAL( scaleChanged( double ) ) );
connect( mCurrentScaleButton, SIGNAL( clicked() ), this, SLOT( setScaleFromCanvas() ) );
}

@@ -32,6 +32,8 @@ class GUI_EXPORT QgsScaleWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY( bool showCurrentScaleButton READ showCurrentScaleButton WRITE setShowCurrentScaleButton )
Q_PROPERTY( bool scale READ scale WRITE setScale NOTIFY scaleChanged )
Q_PROPERTY( bool minScale READ minScale WRITE setMinScale )

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

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

//! Function to set the min scale
void setMinScale( double scale ) { mScaleComboBox->setMinScale( scale ); }

signals:
//! Signal is emitted when *user* has finished editing/selecting a new scale.
void scaleChanged();
void scaleChanged( double scale );

private:
QgsScaleComboBox* mScaleComboBox;
@@ -28,8 +28,9 @@ QgsMapUnitScaleDialog::QgsMapUnitScaleDialog( QWidget* parent )
mSpinBoxMaxSize->setShowClearButton( false );
connect( mCheckBoxMinScale, SIGNAL( toggled( bool ) ), this, SLOT( configureMinComboBox() ) );
connect( mCheckBoxMaxScale, SIGNAL( toggled( bool ) ), this, SLOT( configureMaxComboBox() ) );
connect( mComboBoxMinScale, SIGNAL( scaleChanged() ), this, SLOT( configureMaxComboBox() ) );
connect( mComboBoxMaxScale, SIGNAL( scaleChanged() ), this, SLOT( configureMinComboBox() ) );
connect( mComboBoxMinScale, SIGNAL( scaleChanged( double ) ), this, SLOT( configureMaxComboBox() ) );
connect( mComboBoxMinScale, SIGNAL( scaleChanged( double ) ), mComboBoxMaxScale, SLOT( setMinScale( double ) ) );
connect( mComboBoxMaxScale, SIGNAL( scaleChanged( double ) ), this, SLOT( configureMinComboBox() ) );

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

0 comments on commit bd3fd74

Please sign in to comment.
You can’t perform that action at this time.