diff --git a/python/PyQt6/gui/auto_additions/qgsnumericformatselectorwidget.py b/python/PyQt6/gui/auto_additions/qgsnumericformatselectorwidget.py index 91e97506a762..c0df5a700d28 100644 --- a/python/PyQt6/gui/auto_additions/qgsnumericformatselectorwidget.py +++ b/python/PyQt6/gui/auto_additions/qgsnumericformatselectorwidget.py @@ -7,3 +7,7 @@ QgsNumericFormatSelectorWidget.__group__ = ['numericformats'] except NameError: pass +try: + QgsNumericFormatSelectorDialog.__group__ = ['numericformats'] +except NameError: + pass diff --git a/python/PyQt6/gui/auto_generated/numericformats/qgsnumericformatselectorwidget.sip.in b/python/PyQt6/gui/auto_generated/numericformats/qgsnumericformatselectorwidget.sip.in index 98bddbe3cccb..79ad3c01f125 100644 --- a/python/PyQt6/gui/auto_generated/numericformats/qgsnumericformatselectorwidget.sip.in +++ b/python/PyQt6/gui/auto_generated/numericformats/qgsnumericformatselectorwidget.sip.in @@ -9,7 +9,6 @@ - class QgsNumericFormatSelectorWidget : QgsPanelWidget { %Docstring(signature="appended") @@ -61,6 +60,52 @@ Emitted whenever the format configured55 in the widget is changed. }; + +class QgsNumericFormatSelectorDialog : QDialog +{ +%Docstring(signature="appended") +A simple dialog for customizing a numeric format. + +.. seealso:: :py:class:`QgsNumericFormatSelectorWidget` + +.. versionadded:: 3.40 +%End + +%TypeHeaderCode +#include "qgsnumericformatselectorwidget.h" +%End + public: + + QgsNumericFormatSelectorDialog( QWidget *parent /TransferThis/ = 0, Qt::WindowFlags flags = QgsGuiUtils::ModalDialogFlags ); +%Docstring +Constructor for QgsNumericFormatSelectorDialog. + +:param parent: parent widget +:param flags: window flags for dialog +%End + + void setFormat( const QgsNumericFormat *format ); +%Docstring +Sets the format to show in the dialog. +%End + + QgsNumericFormat *format() const /TransferBack/; +%Docstring +Returns a new format object representing the settings currently configured in the dialog. + +The caller takes ownership of the returned object. +%End + + void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator ); +%Docstring +Register an expression context ``generator`` class that will be used to retrieve +an expression context for the dialog when required. + +Ownership is not transferred, and the ``generator`` must exist for the lifetime of this dialog. +%End + +}; + /************************************************************************ * This file has been generated automatically from * * * diff --git a/python/gui/auto_additions/qgsnumericformatselectorwidget.py b/python/gui/auto_additions/qgsnumericformatselectorwidget.py index 91e97506a762..c0df5a700d28 100644 --- a/python/gui/auto_additions/qgsnumericformatselectorwidget.py +++ b/python/gui/auto_additions/qgsnumericformatselectorwidget.py @@ -7,3 +7,7 @@ QgsNumericFormatSelectorWidget.__group__ = ['numericformats'] except NameError: pass +try: + QgsNumericFormatSelectorDialog.__group__ = ['numericformats'] +except NameError: + pass diff --git a/python/gui/auto_generated/numericformats/qgsnumericformatselectorwidget.sip.in b/python/gui/auto_generated/numericformats/qgsnumericformatselectorwidget.sip.in index 98bddbe3cccb..79ad3c01f125 100644 --- a/python/gui/auto_generated/numericformats/qgsnumericformatselectorwidget.sip.in +++ b/python/gui/auto_generated/numericformats/qgsnumericformatselectorwidget.sip.in @@ -9,7 +9,6 @@ - class QgsNumericFormatSelectorWidget : QgsPanelWidget { %Docstring(signature="appended") @@ -61,6 +60,52 @@ Emitted whenever the format configured55 in the widget is changed. }; + +class QgsNumericFormatSelectorDialog : QDialog +{ +%Docstring(signature="appended") +A simple dialog for customizing a numeric format. + +.. seealso:: :py:class:`QgsNumericFormatSelectorWidget` + +.. versionadded:: 3.40 +%End + +%TypeHeaderCode +#include "qgsnumericformatselectorwidget.h" +%End + public: + + QgsNumericFormatSelectorDialog( QWidget *parent /TransferThis/ = 0, Qt::WindowFlags flags = QgsGuiUtils::ModalDialogFlags ); +%Docstring +Constructor for QgsNumericFormatSelectorDialog. + +:param parent: parent widget +:param flags: window flags for dialog +%End + + void setFormat( const QgsNumericFormat *format ); +%Docstring +Sets the format to show in the dialog. +%End + + QgsNumericFormat *format() const /TransferBack/; +%Docstring +Returns a new format object representing the settings currently configured in the dialog. + +The caller takes ownership of the returned object. +%End + + void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator ); +%Docstring +Register an expression context ``generator`` class that will be used to retrieve +an expression context for the dialog when required. + +Ownership is not transferred, and the ``generator`` must exist for the lifetime of this dialog. +%End + +}; + /************************************************************************ * This file has been generated automatically from * * * diff --git a/src/gui/numericformats/qgsnumericformatselectorwidget.cpp b/src/gui/numericformats/qgsnumericformatselectorwidget.cpp index 3331dd243458..1cd20bf5e1e0 100644 --- a/src/gui/numericformats/qgsnumericformatselectorwidget.cpp +++ b/src/gui/numericformats/qgsnumericformatselectorwidget.cpp @@ -23,8 +23,8 @@ #include "qgsnumericformatguiregistry.h" #include "qgsreadwritecontext.h" #include "qgsbasicnumericformat.h" -#include - +#include +#include QgsNumericFormatSelectorWidget::QgsNumericFormatSelectorWidget( QWidget *parent ) : QgsPanelWidget( parent ) @@ -166,3 +166,43 @@ void QgsNumericFormatSelectorWidget::updateSampleText() .arg( QChar( 0x2192 ) ) .arg( mCurrentFormat->formatDouble( sampleValue, QgsNumericFormatContext() ) ) ); } + +// +// QgsNumericFormatSelectorDialog +// + +QgsNumericFormatSelectorDialog::QgsNumericFormatSelectorDialog( QWidget *parent, Qt::WindowFlags fl ) + : QDialog( parent, fl ) +{ + setWindowTitle( tr( "Numeric Format" ) ); + + mFormatWidget = new QgsNumericFormatSelectorWidget( this ); + mFormatWidget->layout()->setContentsMargins( 0, 0, 0, 0 ); + + QVBoxLayout *layout = new QVBoxLayout( this ); + layout->addWidget( mFormatWidget ); + + mButtonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, Qt::Horizontal, this ); + layout->addWidget( mButtonBox ); + + setLayout( layout ); + QgsGui::enableAutoGeometryRestore( this ); + + connect( mButtonBox->button( QDialogButtonBox::Ok ), &QAbstractButton::clicked, this, &QDialog::accept ); + connect( mButtonBox->button( QDialogButtonBox::Cancel ), &QAbstractButton::clicked, this, &QDialog::reject ); +} + +void QgsNumericFormatSelectorDialog::setFormat( const QgsNumericFormat *format ) +{ + mFormatWidget->setFormat( format ); +} + +QgsNumericFormat *QgsNumericFormatSelectorDialog::format() const +{ + return mFormatWidget->format(); +} + +void QgsNumericFormatSelectorDialog::registerExpressionContextGenerator( QgsExpressionContextGenerator *generator ) +{ + mFormatWidget->registerExpressionContextGenerator( generator ); +} diff --git a/src/gui/numericformats/qgsnumericformatselectorwidget.h b/src/gui/numericformats/qgsnumericformatselectorwidget.h index f95ef33e04dc..8ca4ce7d3692 100644 --- a/src/gui/numericformats/qgsnumericformatselectorwidget.h +++ b/src/gui/numericformats/qgsnumericformatselectorwidget.h @@ -18,13 +18,15 @@ #include "qgis_gui.h" #include "qgis_sip.h" +#include "qgsguiutils.h" #include "ui_qgsnumericformatselectorbase.h" #include +#include class QgsNumericFormat; class QgsBasicNumericFormat; class QgsExpressionContextGenerator; - +class QDialogButtonBox; /** * \ingroup gui @@ -90,4 +92,53 @@ class GUI_EXPORT QgsNumericFormatSelectorWidget : public QgsPanelWidget, private QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr; }; + +/** + * \class QgsNumericFormatSelectorDialog + * \ingroup gui + * \brief A simple dialog for customizing a numeric format. + * + * \see QgsNumericFormatSelectorWidget() + * \since QGIS 3.40 + */ +class GUI_EXPORT QgsNumericFormatSelectorDialog : public QDialog +{ + Q_OBJECT + + public: + + /** + * Constructor for QgsNumericFormatSelectorDialog. + * \param parent parent widget + * \param flags window flags for dialog + */ + QgsNumericFormatSelectorDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = QgsGuiUtils::ModalDialogFlags ); + + /** + * Sets the format to show in the dialog. + */ + void setFormat( const QgsNumericFormat *format ); + + /** + * Returns a new format object representing the settings currently configured in the dialog. + * + * The caller takes ownership of the returned object. + */ + QgsNumericFormat *format() const SIP_TRANSFERBACK; + + /** + * Register an expression context \a generator class that will be used to retrieve + * an expression context for the dialog when required. + * + * Ownership is not transferred, and the \a generator must exist for the lifetime of this dialog. + */ + void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator ); + + private: + + QgsNumericFormatSelectorWidget *mFormatWidget = nullptr; + QDialogButtonBox *mButtonBox = nullptr; + +}; + #endif //QGSNUMERICFORMATSELECTORWIDGET_H diff --git a/src/gui/symbology/qgssymbollayerwidget.cpp b/src/gui/symbology/qgssymbollayerwidget.cpp index 652d5f28e09a..42671bb8883a 100644 --- a/src/gui/symbology/qgssymbollayerwidget.cpp +++ b/src/gui/symbology/qgssymbollayerwidget.cpp @@ -5697,6 +5697,13 @@ void QgsLinearReferencingSymbolLayerWidget::changeNumberFormat() } else { - // TODO!! dialog mode + QgsNumericFormatSelectorDialog dialog( this ); + dialog.setFormat( mLayer->numericFormat() ); + dialog.registerExpressionContextGenerator( this ); + if ( dialog.exec() ) + { + mLayer->setNumericFormat( dialog.format() ); + emit changed(); + } } }