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();
78 void QgsNumericFormatSelectorWidget::formatTypeChanged()
80 const QString newId = mCategoryCombo->currentData().toString();
81 if ( mCurrentFormat->id() == newId )
95 void QgsNumericFormatSelectorWidget::formatChanged()
97 if (
QgsNumericFormatWidget *w = qobject_cast< QgsNumericFormatWidget * >( stackedWidget->currentWidget() ) )
98 mCurrentFormat.reset( w->format() );
104 void QgsNumericFormatSelectorWidget::populateTypes()
108 std::sort( ids.begin(), ids.end(), [ = ](
const QString & a,
const QString & b )->bool
110 if ( QgsApplication::numericFormatRegistry()->sortKey( a ) < QgsApplication::numericFormatRegistry()->sortKey( b ) )
112 else if ( QgsApplication::numericFormatRegistry()->sortKey( a ) > QgsApplication::numericFormatRegistry()->sortKey( b ) )
116 int res = QString::localeAwareCompare( QgsApplication::numericFormatRegistry()->visibleName( a ), QgsApplication::numericFormatRegistry()->visibleName( b ) );
125 for (
const QString &
id : std::as_const( ids ) )
129 void QgsNumericFormatSelectorWidget::updateFormatWidget()
131 if ( stackedWidget->currentWidget() != pageDummy )
134 if (
QgsNumericFormatWidget *w = qobject_cast< QgsNumericFormatWidget * >( stackedWidget->currentWidget() ) )
136 stackedWidget->removeWidget( stackedWidget->currentWidget() );
140 w->setFormat( mCurrentFormat->clone() );
141 stackedWidget->addWidget( w );
142 stackedWidget->setCurrentWidget( w );
148 stackedWidget->setCurrentWidget( pageDummy );
154 void QgsNumericFormatSelectorWidget::updateSampleText()
156 const double sampleValue = mCurrentFormat->suggestSampleValue();
157 mSampleLabel->setText( QStringLiteral(
"%1 %2 <b>%3</b>" ).arg( mPreviewFormat->formatDouble( sampleValue,
QgsNumericFormatContext() ) )
158 .arg( QChar( 0x2192 ) )
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
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.