Fix numeric format configuration in dialog mode

This commit is contained in:
Nyall Dawson 2024-09-04 15:19:20 +10:00
parent bfb6e1cc76
commit 519b82183c
7 changed files with 202 additions and 6 deletions

View File

@ -7,3 +7,7 @@ try:
QgsNumericFormatSelectorWidget.__group__ = ['numericformats']
except NameError:
pass
try:
QgsNumericFormatSelectorDialog.__group__ = ['numericformats']
except NameError:
pass

View File

@ -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 *
* *

View File

@ -7,3 +7,7 @@ try:
QgsNumericFormatSelectorWidget.__group__ = ['numericformats']
except NameError:
pass
try:
QgsNumericFormatSelectorDialog.__group__ = ['numericformats']
except NameError:
pass

View File

@ -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 *
* *

View File

@ -23,8 +23,8 @@
#include "qgsnumericformatguiregistry.h"
#include "qgsreadwritecontext.h"
#include "qgsbasicnumericformat.h"
#include <mutex>
#include <QDialogButtonBox>
#include <QPushButton>
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 );
}

View File

@ -18,13 +18,15 @@
#include "qgis_gui.h"
#include "qgis_sip.h"
#include "qgsguiutils.h"
#include "ui_qgsnumericformatselectorbase.h"
#include <memory>
#include <QDialog>
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

View File

@ -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();
}
}
}