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 );
127 double newScale =
toDouble( scaleTxt, &ok );
154 void QgsScaleComboBox::fixupScale()
157 double oldScale = mScale;
158 bool ok, userSetScale;
160 userSetScale = txtList.
size() != 2;
166 if ( ok && ( newScale != oldScale ) )
169 if ( userSetScale && newScale >= 1.0 )
171 mScale = 1 / newScale;
194 else if ( scale > 1 )
207 QString scaleTxt( scaleString );
220 if ( 2 == txtList.
size() )
229 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
static double toDouble(QString scaleString, bool *ok=NULL)
Helper function to convert a scale string to double.
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
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)
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.
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)
void addItems(const QStringList &texts)
void updateScales(const QStringList &scales=QStringList())
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