Skip to content

Commit

Permalink
qgsdoublespinbox: Introduce isCleared method
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitjano committed Nov 19, 2024
1 parent a34442d commit 8e065a4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ 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
Returns ``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
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ 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
Returns ``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
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

0 comments on commit 8e065a4

Please sign in to comment.