36 mPreviewFormat = qgis::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 : qgis::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 ) )