mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-22 00:14:55 -05:00
Add api to allow validation of QgsOptionsPageWidget before applying
options dialog changes
This commit is contained in:
parent
18979e579c
commit
f288ab1223
@ -39,7 +39,16 @@ help will be retrieved.
|
|||||||
%End
|
%End
|
||||||
|
|
||||||
|
|
||||||
|
virtual bool isValid();
|
||||||
|
%Docstring
|
||||||
|
Validates the current state of the widget.
|
||||||
|
|
||||||
|
Subclasses should return ``True`` if the widget state is currently valid and acceptable to :py:func:`~QgsOptionsPageWidget.apply`.
|
||||||
|
|
||||||
|
The default implementation returns ``True``.
|
||||||
|
|
||||||
|
.. versionadded:: 3.24
|
||||||
|
%End
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
|||||||
@ -166,6 +166,18 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
|
|||||||
// switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
|
// switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
|
||||||
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
|
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
|
||||||
initOptionsBase( false );
|
initOptionsBase( false );
|
||||||
|
// disconnect default connection setup by initOptionsBase for accepting dialog, and insert logic
|
||||||
|
// to validate widgets before allowing dialog to be closed
|
||||||
|
disconnect( mOptButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
|
||||||
|
connect( mOptButtonBox, &QDialogButtonBox::accepted, this, [ = ]
|
||||||
|
{
|
||||||
|
for ( QgsOptionsPageWidget *widget : std::as_const( mAdditionalOptionWidgets ) )
|
||||||
|
{
|
||||||
|
if ( !widget->isValid() )
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
accept();
|
||||||
|
} );
|
||||||
|
|
||||||
// stylesheet setup
|
// stylesheet setup
|
||||||
mStyleSheetBuilder = QgisApp::instance()->styleSheetBuilder();
|
mStyleSheetBuilder = QgisApp::instance()->styleSheetBuilder();
|
||||||
@ -1531,6 +1543,12 @@ void QgsOptions::selectProjectOnLaunch()
|
|||||||
|
|
||||||
void QgsOptions::saveOptions()
|
void QgsOptions::saveOptions()
|
||||||
{
|
{
|
||||||
|
for ( QgsOptionsPageWidget *widget : std::as_const( mAdditionalOptionWidgets ) )
|
||||||
|
{
|
||||||
|
if ( !widget->isValid() )
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QgsSettings settings;
|
QgsSettings settings;
|
||||||
|
|
||||||
mSettings->setValue( QStringLiteral( "UI/UITheme" ), cmbUITheme->currentText() );
|
mSettings->setValue( QStringLiteral( "UI/UITheme" ), cmbUITheme->currentText() );
|
||||||
@ -1999,8 +2017,7 @@ void QgsOptions::saveOptions()
|
|||||||
|
|
||||||
mLocatorOptionsWidget->commitChanges();
|
mLocatorOptionsWidget->commitChanges();
|
||||||
|
|
||||||
const auto constMAdditionalOptionWidgets = mAdditionalOptionWidgets;
|
for ( QgsOptionsPageWidget *widget : std::as_const( mAdditionalOptionWidgets ) )
|
||||||
for ( QgsOptionsPageWidget *widget : constMAdditionalOptionWidgets )
|
|
||||||
{
|
{
|
||||||
widget->apply();
|
widget->apply();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,13 +52,22 @@ class GUI_EXPORT QgsOptionsPageWidget : public QWidget
|
|||||||
*/
|
*/
|
||||||
virtual QString helpKey() const { return QString(); }
|
virtual QString helpKey() const { return QString(); }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the registered highlight widgets used to search and highlight text in
|
* Returns the registered highlight widgets used to search and highlight text in
|
||||||
* options dialogs.
|
* options dialogs.
|
||||||
*/
|
*/
|
||||||
QHash<QWidget *, QgsOptionsDialogHighlightWidget *> registeredHighlightWidgets() {return mHighlightWidgets;} SIP_SKIP
|
QHash<QWidget *, QgsOptionsDialogHighlightWidget *> registeredHighlightWidgets() {return mHighlightWidgets;} SIP_SKIP
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the current state of the widget.
|
||||||
|
*
|
||||||
|
* Subclasses should return TRUE if the widget state is currently valid and acceptable to apply().
|
||||||
|
*
|
||||||
|
* The default implementation returns TRUE.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.24
|
||||||
|
*/
|
||||||
|
virtual bool isValid() { return true; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user