22 #include <QAbstractItemView>
35 connect(
lineEdit(), SIGNAL( editingFinished() ),
this, SLOT( fixupScale() ) );
54 myScalesList = myScales.
split(
"," );
60 for ( ; scaleIt != scales.
constEnd(); ++scaleIt )
62 myScalesList.
append( *scaleIt );
69 for (
int i = 0; i < myScalesList.
size(); ++i )
71 parts = myScalesList[ i ] .
split(
':' );
75 myScalesList[ i ] =
toString( 1.0 / denominator );
98 long currScale = parts.
at( 1 ).toLong( &ok );
99 long nextScale, delta;
100 for (
int i = 0; i <
count(); i++ )
103 nextScale = parts.
at( 1 ).toLong( &ok );
104 delta = qAbs( currScale - nextScale );
128 double newScale =
toDouble( scaleTxt, &ok );
155 void QgsScaleComboBox::fixupScale()
158 double oldScale = mScale;
159 bool ok, userSetScale;
161 userSetScale = txtList.
size() != 2;
167 if ( ok && ( newScale != oldScale ) )
170 if ( userSetScale && newScale >= 1.0 )
172 mScale = 1 / newScale;
195 else if ( scale > 1 )
208 QString scaleTxt( scaleString );
221 if ( 2 == txtList.
size() )
230 scale = ( double )x / (
double )
y;
static int permissiveToInt(QString string, bool &ok)
Converts a string to an integer in a permissive way, eg allowing for incorrect numbers of digits betw...
QAbstractItemModel * model() const
virtual ~QgsScaleComboBox()
void setCurrentIndex(const QModelIndex &index)
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
static double permissiveToDouble(QString string, bool &ok)
Converts a string to a double in a permissive way, eg allowing for incorrect numbers of digits betwee...
const T & at(int i) const
void setEditText(const QString &text)
QString itemText(int index) const
void setScale(double scale)
Function to set the selected scale from double.
void setEditable(bool editable)
double toDouble(const QString &s, bool *ok) const
bool setScaleString(const QString &scaleTxt)
Function to set the selected scale from text.
void showPopup() override
void append(const T &value)
void activated(int index)
double scale()
Function to read the selected scale as double.
bool blockSignals(bool block)
static QString toString(double scale)
Helper function to convert a double to scale string.
QLineEdit * lineEdit() const
void scaleChanged()
Signal is emitted when user has finished editing/selecting a new scale.
QVariant value(const QString &key, const QVariant &defaultValue) const
const QString PROJECT_SCALES
QString scaleString()
Function to read the selected scale as text.
void setInsertPolicy(InsertPolicy policy)
void setCompleter(QCompleter *completer)
QgsScaleComboBox(QWidget *parent=0)
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
static double toDouble(const QString &scaleString, bool *ok=NULL)
Helper function to convert a scale string to double.
void addItems(const QStringList &texts)
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.
const_iterator constEnd() const
const_iterator constBegin() const
QString currentText() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QAbstractItemView * view() const