22 #include <QAbstractItemView> 38 connect(
lineEdit(), SIGNAL( editingFinished() ),
this, SLOT( fixupScale() ) );
57 myScalesList = myScales.
split(
',' );
63 for ( ; scaleIt != scales.
constEnd(); ++scaleIt )
65 myScalesList.
append( *scaleIt );
72 for (
int i = 0; i < myScalesList.
size(); ++i )
74 parts = myScalesList[ i ] .
split(
':' );
78 myScalesList[ i ] =
toString( 1.0 / denominator );
101 long currScale = parts.
at( 1 ).toLong( &ok );
102 long nextScale, delta;
103 for (
int i = 0; i <
count(); i++ )
106 nextScale = parts.
at( 1 ).toLong( &ok );
107 delta = qAbs( currScale - nextScale );
131 double newScale =
toDouble( scaleTxt, &ok );
132 double oldScale = mScale;
133 if ( newScale < mMinScale && newScale != 0 )
135 newScale = mMinScale;
146 if ( mScale != oldScale )
167 void QgsScaleComboBox::fixupScale()
170 bool userSetScale = txtList.
size() != 2;
179 if ( userSetScale && newScale >= 1.0 )
181 newScale = 1 / newScale;
197 else if ( scale > 1 )
210 QString scaleTxt( scaleString );
223 if ( 2 == txtList.
size() )
232 scale = ( double )x / (
double )
y;
249 if ( mScale < scale && mScale != 0 )
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 scaleChanged(double scale)
Signal is emitted when user has finished editing/selecting a new scale.
void append(const T &value)
static double toDouble(const QString &scaleString, bool *ok=nullptr)
Helper function to convert a scale string to double.
void activated(int index)
double scale() const
Function to read the selected scale as double.
void setMinScale(double scale)
Set the minimum allowed scale.
bool blockSignals(bool block)
static QString toString(double scale)
Helper function to convert a double to scale string.
QLineEdit * lineEdit() const
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)
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
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
QgsScaleComboBox(QWidget *parent=nullptr)
QAbstractItemView * view() const