22 #include <QAbstractItemView>
32 setInsertPolicy( QComboBox::NoInsert );
34 connect(
this, SIGNAL( activated(
const QString & ) ),
this, SLOT(
fixupScale() ) );
35 connect( lineEdit(), SIGNAL( editingFinished() ),
this, SLOT(
fixupScale() ) );
45 QStringList myScalesList;
46 QString oldScale = currentText();
48 if ( scales.isEmpty() )
51 QString myScales = settings.value(
"Map/scales",
PROJECT_SCALES ).toString();
52 if ( !myScales.isEmpty() )
54 myScalesList = myScales.split(
"," );
59 QStringList::const_iterator scaleIt = scales.constBegin();
60 for ( ; scaleIt != scales.constEnd(); ++scaleIt )
62 myScalesList.append( *scaleIt );
69 for (
int i = 0; i < myScalesList.size(); ++i )
71 parts = myScalesList[ i ] .split(
':' );
72 denominator = QLocale::system().toDouble( parts[1], &ok );
75 myScalesList[ i ] =
toString( 1.0 / denominator );
81 addItems( myScalesList );
83 blockSignals(
false );
88 QComboBox::showPopup();
90 if ( !currentText().contains(
':' ) )
94 QStringList parts = currentText().split(
':' );
98 long currScale = parts.at( 1 ).toLong( &ok );
99 long nextScale, delta;
100 for (
int i = 0; i < count(); i++ )
102 parts = itemText( i ).split(
':' );
103 nextScale = parts.at( 1 ).toLong( &ok );
104 delta = qAbs( currScale - nextScale );
112 blockSignals(
true );
113 view()->setCurrentIndex( model()->
index( idx, 0 ) );
114 blockSignals(
false );
129 double newScale =
toDouble( scaleTxt, &ok );
162 bool ok, userSetScale;
163 QStringList txtList = currentText().split(
':' );
164 txtList.size() == 2 ? userSetScale =
false : userSetScale = true ;
167 newScale =
toDouble( currentText(), &ok );
170 if ( ok && ( newScale != oldScale ) )
173 if ( userSetScale && newScale >= 1.0 )
198 else if ( scale > 1 )
200 return QString(
"%1:1" ).arg( QLocale::system().
toString( qRound( scale ) ) );
204 return QString(
"1:%1" ).arg( QLocale::system().
toString( qRound( 1.0 / scale ) ) );
211 QString scaleTxt( scaleString );
213 double scale = QLocale::system().toDouble( scaleTxt, &ok );
222 QStringList txtList = scaleTxt.split(
':' );
223 if ( 2 == txtList.size() )
227 int x = QLocale::system().toInt( txtList[ 0 ], &okX );
228 int y = QLocale::system().toInt( txtList[ 1 ], &okY );
232 scale = ( double )x / (
double )y;
void fixupScale()
Slot called when QComboBox has changed.
virtual ~QgsScaleComboBox()
static double toDouble(QString scaleString, bool *ok=NULL)
Helper function to convert a scale string to double.
void setScale(double scale)
Function to set the selected scale from double.
double scale()
Function to read the selected scale as double.
const CORE_EXPORT QString PROJECT_SCALES
bool setScaleString(QString scaleTxt)
Function to set the selected scale from text.
static QString toString(double scale)
Helper function to convert a double to scale string.
void scaleChanged()
Signal is emitted when user has finished editing/selecting a new scale.
QString scaleString()
Function to read the selected scale as text.
QgsScaleComboBox(QWidget *parent=0)
void updateScales(const QStringList &scales=QStringList())
double ANALYSIS_EXPORT min(double x, double y)
returns the minimum of two doubles or the first argument if both are equal