Skip to content

Commit

Permalink
Fix numeric format configuration in dialog mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 4, 2024
1 parent bfb6e1c commit 519b821
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
QgsNumericFormatSelectorWidget.__group__ = ['numericformats']
except NameError:
pass
try:
QgsNumericFormatSelectorDialog.__group__ = ['numericformats']
except NameError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@




class QgsNumericFormatSelectorWidget : QgsPanelWidget
{
%Docstring(signature="appended")
Expand Down Expand Up @@ -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 *
* *
Expand Down
4 changes: 4 additions & 0 deletions python/gui/auto_additions/qgsnumericformatselectorwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
QgsNumericFormatSelectorWidget.__group__ = ['numericformats']
except NameError:
pass
try:
QgsNumericFormatSelectorDialog.__group__ = ['numericformats']
except NameError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@




class QgsNumericFormatSelectorWidget : QgsPanelWidget
{
%Docstring(signature="appended")
Expand Down Expand Up @@ -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 *
* *
Expand Down
44 changes: 42 additions & 2 deletions src/gui/numericformats/qgsnumericformatselectorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
}
53 changes: 52 additions & 1 deletion src/gui/numericformats/qgsnumericformatselectorwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
9 changes: 8 additions & 1 deletion src/gui/symbology/qgssymbollayerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

0 comments on commit 519b821

Please sign in to comment.