17#include "moc_qgsnumericformatselectorwidget.cpp"
27#include <QDialogButtonBox>
37 mPreviewFormat = std::make_unique< QgsBasicNumericFormat >();
38 mPreviewFormat->setShowThousandsSeparator(
false );
39 mPreviewFormat->setShowPlusSign(
false );
40 mPreviewFormat->setShowTrailingZeros(
false );
41 mPreviewFormat->setNumberDecimalPlaces( 12 );
44 mCategoryCombo->setCurrentIndex( mCategoryCombo->findData( mCurrentFormat->id() ) );
46 connect( mCategoryCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsNumericFormatSelectorWidget::formatTypeChanged );
59 const QString
id = mCurrentFormat->id();
60 const int index = mCategoryCombo->findData(
id );
63 whileBlocking( mCategoryCombo )->setCurrentIndex( mCategoryCombo->findData( QStringLiteral(
"fallback" ) ) );
67 mCategoryCombo->setCurrentIndex( index );
76 return mCurrentFormat->clone();
81 mExpressionContextGenerator = generator;
82 if (
QgsNumericFormatWidget *w = qobject_cast< QgsNumericFormatWidget * >( stackedWidget->currentWidget() ) )
83 w->registerExpressionContextGenerator( mExpressionContextGenerator );
86void QgsNumericFormatSelectorWidget::formatTypeChanged()
88 const QString newId = mCategoryCombo->currentData().toString();
89 if ( mCurrentFormat->id() == newId )
103void QgsNumericFormatSelectorWidget::formatChanged()
105 if (
QgsNumericFormatWidget *w = qobject_cast< QgsNumericFormatWidget * >( stackedWidget->currentWidget() ) )
106 mCurrentFormat.reset( w->format() );
112void QgsNumericFormatSelectorWidget::populateTypes()
116 std::sort( ids.begin(), ids.end(), [ = ](
const QString & a,
const QString & b )->bool
118 if ( QgsApplication::numericFormatRegistry()->sortKey( a ) < QgsApplication::numericFormatRegistry()->sortKey( b ) )
120 else if ( QgsApplication::numericFormatRegistry()->sortKey( a ) > QgsApplication::numericFormatRegistry()->sortKey( b ) )
124 int res = QString::localeAwareCompare( QgsApplication::numericFormatRegistry()->visibleName( a ), QgsApplication::numericFormatRegistry()->visibleName( b ) );
133 for (
const QString &
id : std::as_const( ids ) )
134 mCategoryCombo->addItem(
QgsApplication::numericFormatRegistry()->visibleName( id ), id );
137void QgsNumericFormatSelectorWidget::updateFormatWidget()
139 if ( stackedWidget->currentWidget() != pageDummy )
142 if (
QgsNumericFormatWidget *w = qobject_cast< QgsNumericFormatWidget * >( stackedWidget->currentWidget() ) )
144 stackedWidget->removeWidget( stackedWidget->currentWidget() );
148 w->setFormat( mCurrentFormat->clone() );
149 stackedWidget->addWidget( w );
150 stackedWidget->setCurrentWidget( w );
153 w->registerExpressionContextGenerator( mExpressionContextGenerator );
157 stackedWidget->setCurrentWidget( pageDummy );
163void QgsNumericFormatSelectorWidget::updateSampleText()
165 const double sampleValue = mCurrentFormat->suggestSampleValue();
166 mSampleLabel->setText( QStringLiteral(
"%1 %2 <b>%3</b>" ).arg( mPreviewFormat->formatDouble( sampleValue,
QgsNumericFormatContext() ) )
167 .arg( QChar( 0x2192 ) )
176 : QDialog( parent, fl )
178 setWindowTitle( tr(
"Numeric Format" ) );
181 mFormatWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
183 QVBoxLayout *layout =
new QVBoxLayout(
this );
184 layout->addWidget( mFormatWidget );
186 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, Qt::Horizontal,
this );
187 layout->addWidget( mButtonBox );
192 connect( mButtonBox->button( QDialogButtonBox::Ok ), &QAbstractButton::clicked,
this, &QDialog::accept );
193 connect( mButtonBox->button( QDialogButtonBox::Cancel ), &QAbstractButton::clicked,
this, &QDialog::reject );
203 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.