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" ) ) );
 
   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 {
 
  116    if ( QgsApplication::numericFormatRegistry()->sortKey( a ) < QgsApplication::numericFormatRegistry()->sortKey( b ) )
 
  118    else if ( QgsApplication::numericFormatRegistry()->sortKey( a ) > QgsApplication::numericFormatRegistry()->sortKey( b ) )
 
  122      int res = QString::localeAwareCompare( QgsApplication::numericFormatRegistry()->visibleName( a ), QgsApplication::numericFormatRegistry()->visibleName( b ) );
 
  131  for ( 
const QString &
id : std::as_const( ids ) )
 
  132    mCategoryCombo->addItem( 
QgsApplication::numericFormatRegistry()->visibleName( id ), id );
 
  135void QgsNumericFormatSelectorWidget::updateFormatWidget()
 
  137  if ( stackedWidget->currentWidget() != pageDummy )
 
  140    if ( 
QgsNumericFormatWidget *w = qobject_cast<QgsNumericFormatWidget *>( stackedWidget->currentWidget() ) )
 
  142    stackedWidget->removeWidget( stackedWidget->currentWidget() );
 
  146    w->setFormat( mCurrentFormat->clone() );
 
  147    stackedWidget->addWidget( w );
 
  148    stackedWidget->setCurrentWidget( w );
 
  151    w->registerExpressionContextGenerator( mExpressionContextGenerator );
 
  155    stackedWidget->setCurrentWidget( pageDummy );
 
  161void QgsNumericFormatSelectorWidget::updateSampleText()
 
  163  const double sampleValue = mCurrentFormat->suggestSampleValue();
 
  164  mSampleLabel->setText( QStringLiteral( 
"%1 %2 <b>%3</b>" ).arg( mPreviewFormat->formatDouble( sampleValue, 
QgsNumericFormatContext() ) ).arg( QChar( 0x2192 ) ).arg( mCurrentFormat->formatDouble( sampleValue, 
QgsNumericFormatContext() ) ) );
 
  172  : QDialog( parent, fl )
 
  174  setWindowTitle( tr( 
"Numeric Format" ) );
 
  177  mFormatWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
 
  179  QVBoxLayout *layout = 
new QVBoxLayout( 
this );
 
  180  layout->addWidget( mFormatWidget );
 
  182  mButtonBox = 
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, Qt::Horizontal, 
this );
 
  183  layout->addWidget( mButtonBox );
 
  188  connect( mButtonBox->button( QDialogButtonBox::Ok ), &QAbstractButton::clicked, 
this, &QDialog::accept );
 
  189  connect( mButtonBox->button( QDialogButtonBox::Cancel ), &QAbstractButton::clicked, 
this, &QDialog::reject );
 
 
  199  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.
 
A container for the context for various read/write operations on objects.
 
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.