24#include "moc_qgslocaleawarenumericlineeditdelegate.cpp"
28QgsLocaleAwareNumericLineEditDelegate::QgsLocaleAwareNumericLineEditDelegate(
Qgis::DataType dataType, QWidget *parent )
29 : QStyledItemDelegate( parent )
30 , mDataType( dataType )
33QWidget *QgsLocaleAwareNumericLineEditDelegate::createEditor( QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const
37 auto editor =
new QLineEdit { parent };
42void QgsLocaleAwareNumericLineEditDelegate::setEditorData( QWidget *editor,
const QModelIndex &index )
const
44 QLineEdit *lineEdit { qobject_cast<QLineEdit *>( editor ) };
47 const QVariant value = index.data();
48 lineEdit->setText( displayText( value, QLocale() ) );
52 QStyledItemDelegate::setEditorData( editor, index );
56void QgsLocaleAwareNumericLineEditDelegate::setModelData( QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index )
const
58 QLineEdit *lineEdit { qobject_cast<QLineEdit *>( editor ) };
61 QStyledItemDelegate::setModelData( editor, model, index );
64 model->setData( index, value );
67QString QgsLocaleAwareNumericLineEditDelegate::displayText(
const QVariant &value,
const QLocale & )
const
72void QgsLocaleAwareNumericLineEditDelegate::setDataType(
const Qgis::DataType &dataType )
DataType
Raster data types.
A custom validator which allows entry of doubles in a locale-tolerant way.
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
int significantDigits(const Qgis::DataType rasterDataType)
Returns the maximum number of significant digits a for the given rasterDataType.
QString displayValueWithMaximumDecimals(const Qgis::DataType dataType, const double value, bool displayTrailingZeroes)
Returns a localized string representation of the value with the appropriate number of decimals suppor...