mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Added setting of scale programatially
This commit is contained in:
parent
dbbb3c35be
commit
01c4ac7d54
@ -106,6 +106,26 @@ QString QgsScaleComboBox::scaleString()
|
|||||||
{
|
{
|
||||||
return toString( mScale );
|
return toString( mScale );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Function to set the selected scale from text
|
||||||
|
// @note added in 2.0
|
||||||
|
bool QgsScaleComboBox::setScaleString( QString scaleTxt )
|
||||||
|
{
|
||||||
|
bool ok;
|
||||||
|
double newScale = toDouble( scaleTxt, &ok );
|
||||||
|
if ( ! ok )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mScale = newScale;
|
||||||
|
setEditText( toString( mScale ) );
|
||||||
|
clearFocus();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//! Function to read the selected scale as double
|
//! Function to read the selected scale as double
|
||||||
// @note added in 2.0
|
// @note added in 2.0
|
||||||
double QgsScaleComboBox::scale()
|
double QgsScaleComboBox::scale()
|
||||||
@ -113,6 +133,13 @@ double QgsScaleComboBox::scale()
|
|||||||
return mScale;
|
return mScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Function to set the selected scale from double
|
||||||
|
// @note added in 2.0
|
||||||
|
void QgsScaleComboBox::setScale( double scale )
|
||||||
|
{
|
||||||
|
setScaleString( toString( scale ) );
|
||||||
|
}
|
||||||
|
|
||||||
//! Slot called when QComboBox has changed
|
//! Slot called when QComboBox has changed
|
||||||
void QgsScaleComboBox::fixupScale()
|
void QgsScaleComboBox::fixupScale()
|
||||||
{
|
{
|
||||||
@ -128,7 +155,7 @@ void QgsScaleComboBox::fixupScale()
|
|||||||
}
|
}
|
||||||
// We set to the new string representation
|
// We set to the new string representation
|
||||||
// or reset to the old
|
// or reset to the old
|
||||||
setEditText( toString( mScale ) );
|
setScale( mScale );
|
||||||
|
|
||||||
if ( oldScale != mScale )
|
if ( oldScale != mScale )
|
||||||
{
|
{
|
||||||
|
@ -33,9 +33,16 @@ class GUI_EXPORT QgsScaleComboBox : public QComboBox
|
|||||||
//! Function to read the selected scale as text
|
//! Function to read the selected scale as text
|
||||||
// @note added in 2.0
|
// @note added in 2.0
|
||||||
QString scaleString();
|
QString scaleString();
|
||||||
|
//! Function to set the selected scale from text
|
||||||
|
// @note added in 2.0
|
||||||
|
bool setScaleString( QString scaleTxt );
|
||||||
//! Function to read the selected scale as double
|
//! Function to read the selected scale as double
|
||||||
// @note added in 2.0
|
// @note added in 2.0
|
||||||
double scale();
|
double scale();
|
||||||
|
//! Function to set the selected scale from double
|
||||||
|
// @note added in 2.0
|
||||||
|
void setScale( double scale );
|
||||||
|
|
||||||
//! Helper function to convert a double to scale string
|
//! Helper function to convert a double to scale string
|
||||||
// Performs rounding, so an exact representation is not to
|
// Performs rounding, so an exact representation is not to
|
||||||
// be expected.
|
// be expected.
|
||||||
@ -45,9 +52,9 @@ class GUI_EXPORT QgsScaleComboBox : public QComboBox
|
|||||||
// @note added in 2.0
|
// @note added in 2.0
|
||||||
static double toDouble( QString scaleString, bool *ok = NULL );
|
static double toDouble( QString scaleString, bool *ok = NULL );
|
||||||
|
|
||||||
//! Signals is emited when user has finished editing/selecting a new scale.
|
|
||||||
// @note added in 2.0
|
|
||||||
signals:
|
signals:
|
||||||
|
//! Signal is emitted when *user* has finished editing/selecting a new scale.
|
||||||
|
// @note added in 2.0
|
||||||
void scaleChanged();
|
void scaleChanged();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -94,6 +94,21 @@ void TestQgsScaleComboBox::basic()
|
|||||||
QCOMPARE( s->scaleString(), QString( "1:4" ) );
|
QCOMPARE( s->scaleString(), QString( "1:4" ) );
|
||||||
QCOMPARE( s->scale(), ( double ) 0.25 );
|
QCOMPARE( s->scale(), ( double ) 0.25 );
|
||||||
|
|
||||||
|
// Test setting programatically
|
||||||
|
s->setScale(( double ) 0.19 );
|
||||||
|
QCOMPARE( s->scaleString(), QString( "1:5" ) );
|
||||||
|
QCOMPARE( s->scale(), ( double ) 0.2 );
|
||||||
|
|
||||||
|
// Test setting programatically
|
||||||
|
s->setScaleString( QString( "1:240" ) );
|
||||||
|
QCOMPARE( s->scaleString(), QString( "1:240" ) );
|
||||||
|
QCOMPARE( s->scale(), ( double ) 1.0 / ( double ) 240.0 );
|
||||||
|
|
||||||
|
// Test setting programatically illegal string
|
||||||
|
s->setScaleString( QString( "1:2.4" ) );
|
||||||
|
QCOMPARE( s->scaleString(), QString( "1:240" ) );
|
||||||
|
QCOMPARE( s->scale(), ( double ) 1.0 / ( double ) 240.0 );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void TestQgsScaleComboBox::slot_test()
|
void TestQgsScaleComboBox::slot_test()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user