26#include <QDialogButtonBox>
36 mPreviewFormat = std::make_unique< QgsBasicNumericFormat >();
37 mPreviewFormat->setShowThousandsSeparator(
false );
38 mPreviewFormat->setShowPlusSign(
false );
39 mPreviewFormat->setShowTrailingZeros(
false );
40 mPreviewFormat->setNumberDecimalPlaces( 12 );
43 mCategoryCombo->setCurrentIndex( mCategoryCombo->findData( mCurrentFormat->id() ) );
45 connect( mCategoryCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsNumericFormatSelectorWidget::formatTypeChanged );
58 const QString
id = mCurrentFormat->id();
59 const int index = mCategoryCombo->findData(
id );
62 whileBlocking( mCategoryCombo )->setCurrentIndex( mCategoryCombo->findData( QStringLiteral(
"fallback" ) ) );
66 mCategoryCombo->setCurrentIndex( index );
75 return mCurrentFormat->clone();
80 mExpressionContextGenerator = generator;
81 if (
QgsNumericFormatWidget *w = qobject_cast< QgsNumericFormatWidget * >( stackedWidget->currentWidget() ) )
82 w->registerExpressionContextGenerator( mExpressionContextGenerator );
85void QgsNumericFormatSelectorWidget::formatTypeChanged()
87 const QString newId = mCategoryCombo->currentData().toString();
88 if ( mCurrentFormat->id() == newId )
102void QgsNumericFormatSelectorWidget::formatChanged()
104 if (
QgsNumericFormatWidget *w = qobject_cast< QgsNumericFormatWidget * >( stackedWidget->currentWidget() ) )
105 mCurrentFormat.reset( w->format() );
111void QgsNumericFormatSelectorWidget::populateTypes()
115 std::sort( ids.begin(), ids.end(), [ = ](
const QString & a,
const QString & b )->bool
117 if ( QgsApplication::numericFormatRegistry()->sortKey( a ) < QgsApplication::numericFormatRegistry()->sortKey( b ) )
119 else if ( QgsApplication::numericFormatRegistry()->sortKey( a ) > QgsApplication::numericFormatRegistry()->sortKey( b ) )
123 int res = QString::localeAwareCompare( QgsApplication::numericFormatRegistry()->visibleName( a ), QgsApplication::numericFormatRegistry()->visibleName( b ) );
132 for (
const QString &
id : std::as_const( ids ) )
133 mCategoryCombo->addItem(
QgsApplication::numericFormatRegistry()->visibleName( id ), id );
136void QgsNumericFormatSelectorWidget::updateFormatWidget()
138 if ( stackedWidget->currentWidget() != pageDummy )
141 if (
QgsNumericFormatWidget *w = qobject_cast< QgsNumericFormatWidget * >( stackedWidget->currentWidget() ) )
143 stackedWidget->removeWidget( stackedWidget->currentWidget() );
147 w->setFormat( mCurrentFormat->clone() );
148 stackedWidget->addWidget( w );
149 stackedWidget->setCurrentWidget( w );
152 w->registerExpressionContextGenerator( mExpressionContextGenerator );
156 stackedWidget->setCurrentWidget( pageDummy );
162void QgsNumericFormatSelectorWidget::updateSampleText()
164 const double sampleValue = mCurrentFormat->suggestSampleValue();
165 mSampleLabel->setText( QStringLiteral(
"%1 %2 <b>%3</b>" ).arg( mPreviewFormat->formatDouble( sampleValue,
QgsNumericFormatContext() ) )
166 .arg( QChar( 0x2192 ) )
175 : QDialog( parent, fl )
177 setWindowTitle( tr(
"Numeric Format" ) );
180 mFormatWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
182 QVBoxLayout *layout =
new QVBoxLayout(
this );
183 layout->addWidget( mFormatWidget );
185 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, Qt::Horizontal,
this );
186 layout->addWidget( mButtonBox );
191 connect( mButtonBox->button( QDialogButtonBox::Ok ), &QAbstractButton::clicked,
this, &QDialog::accept );
192 connect( mButtonBox->button( QDialogButtonBox::Cancel ), &QAbstractButton::clicked,
this, &QDialog::reject );
202 return mFormatWidget->
format();
Extends QApplication to provide access to QGIS specific resources such as theme paths,...
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
Abstract interface for generating an expression context.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static QgsNumericFormatGuiRegistry * numericFormatGuiRegistry()
Returns the global numeric format gui registry, used for registering the GUI widgets associated with ...
A context for numeric formats.
The class is used as a container of context for various read/write operations on other objects.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.