Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qgsprojectelevationsettingswidget: Check elevation range values #59327

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ Defines if the clear value should be the minimum or maximum values of the widget
Returns the value used when :py:func:`~QgsDoubleSpinBox.clear` is called.

.. seealso:: :py:func:`setClearValue`
%End

bool isCleared() const;
%Docstring

:return: ``True`` if the value is equal to the clear value.

.. seealso:: :py:func:`clearValue`

.. versionadded:: 3.42
%End

void setLineEditAlignment( Qt::Alignment alignment );
Expand Down
10 changes: 10 additions & 0 deletions python/gui/auto_generated/editorwidgets/qgsdoublespinbox.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ Defines if the clear value should be the minimum or maximum values of the widget
Returns the value used when :py:func:`~QgsDoubleSpinBox.clear` is called.

.. seealso:: :py:func:`setClearValue`
%End

bool isCleared() const;
%Docstring

:return: ``True`` if the value is equal to the clear value.

.. seealso:: :py:func:`clearValue`

.. versionadded:: 3.42
%End

void setLineEditAlignment( Qt::Alignment alignment );
Expand Down
12 changes: 12 additions & 0 deletions src/app/project/qgsprojectelevationsettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ QgsProjectElevationSettingsWidget::QgsProjectElevationSettingsWidget( QWidget *p
else
whileBlocking( mElevationUpperSpin )->clear();

connect( mElevationLowerSpin, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, &QgsProjectElevationSettingsWidget::validate );
connect( mElevationUpperSpin, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, &QgsProjectElevationSettingsWidget::validate );

updateVerticalCrsOptions();
connect( QgsProject::instance(), &QgsProject::crsChanged, this, &QgsProjectElevationSettingsWidget::updateVerticalCrsOptions );

Expand Down Expand Up @@ -241,6 +244,15 @@ bool QgsProjectElevationSettingsWidget::validate()
mMessageBar->pushMessage( tr( "An elevation layer must be selected for a mesh terrain" ), Qgis::MessageLevel::Critical );
}
}

// Show an error message if the lower value is greater than the upper one
// However, do not show the error message if one of the values is not set
if ( !mElevationLowerSpin->isCleared() && !mElevationUpperSpin->isCleared() && ( mElevationLowerSpin->value() >= mElevationUpperSpin->value() ) )
{
valid = false;
mMessageBar->pushMessage( tr( "Upper elevation range must be greater than the lower one" ), Qgis::MessageLevel::Critical );
}

return valid;
}

Expand Down
5 changes: 5 additions & 0 deletions src/gui/editorwidgets/qgsdoublespinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,8 @@ bool QgsDoubleSpinBox::shouldShowClearForValue( const double value ) const
}
return value != clearValue();
}

bool QgsDoubleSpinBox::isCleared() const
{
return value() == clearValue();
}
8 changes: 8 additions & 0 deletions src/gui/editorwidgets/qgsdoublespinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
*/
double clearValue() const;

/**
* \returns TRUE if the value is equal to the clear value.
* \see clearValue()
*
* \since QGIS 3.42
*/
bool isCleared() const;

/**
* Set alignment in the embedded line edit widget
* \param alignment
Expand Down
6 changes: 6 additions & 0 deletions tests/src/gui/testqgsdoublespinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,21 @@ void TestQgsDoubleSpinBox::clear()
spinBox->setMinimum( 1.0 );
spinBox->setValue( 5.0 );
spinBox->setClearValueMode( QgsDoubleSpinBox::MinimumValue );
QVERIFY( !spinBox->isCleared() );
spinBox->clear();
QVERIFY( spinBox->isCleared() );
QCOMPARE( spinBox->value(), 1.0 );
QCOMPARE( spinBox->clearValue(), 1.0 );
spinBox->setClearValueMode( QgsDoubleSpinBox::MaximumValue );
QVERIFY( !spinBox->isCleared() );
spinBox->clear();
QVERIFY( spinBox->isCleared() );
QCOMPARE( spinBox->value(), 10.0 );
QCOMPARE( spinBox->clearValue(), 10.0 );
spinBox->setClearValue( 7.0 );
QVERIFY( !spinBox->isCleared() );
spinBox->clear();
QVERIFY( spinBox->isCleared() );
QCOMPARE( spinBox->value(), 7.0 );
QCOMPARE( spinBox->clearValue(), 7.0 );
delete spinBox;
Expand Down