mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Allow reseting ratio manually for linked ratio lock buttons
This commit is contained in:
parent
ea453beb73
commit
aebe5a42e6
@ -67,6 +67,12 @@ class QgsRatioLockButton : QToolButton
|
||||
.. seealso:: setWidthSpinBox()
|
||||
%End
|
||||
|
||||
void resetRatio();
|
||||
%Docstring
|
||||
Resets the current width/height ratio, taking the width and height
|
||||
from the current values of the width and height spin boxes.
|
||||
%End
|
||||
|
||||
signals:
|
||||
|
||||
void lockChanged( const bool locked );
|
||||
|
@ -156,3 +156,9 @@ void QgsRatioLockButton::setHeightSpinBox( QDoubleSpinBox *widget )
|
||||
mPrevHeight = widget->value();
|
||||
connect( mHeightSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsRatioLockButton::heightSpinBoxChanged );
|
||||
}
|
||||
|
||||
void QgsRatioLockButton::resetRatio()
|
||||
{
|
||||
mPrevWidth = mWidthSpinBox ? mWidthSpinBox->value() : 0.0;
|
||||
mPrevHeight = mHeightSpinBox ? mHeightSpinBox->value() : 0.0;
|
||||
}
|
||||
|
@ -82,6 +82,12 @@ class GUI_EXPORT QgsRatioLockButton : public QToolButton
|
||||
*/
|
||||
void setHeightSpinBox( QDoubleSpinBox *widget );
|
||||
|
||||
/**
|
||||
* Resets the current width/height ratio, taking the width and height
|
||||
* from the current values of the width and height spin boxes.
|
||||
*/
|
||||
void resetRatio();
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
|
@ -99,6 +99,37 @@ class TestQgsRatioLockButton(unittest.TestCase):
|
||||
self.assertEqual(spin_width.value(), 200)
|
||||
self.assertEqual(spin_height.value(), 1000)
|
||||
|
||||
def testResetRatio(self):
|
||||
w = qgis.gui.QgsRatioLockButton()
|
||||
|
||||
spin_width = QDoubleSpinBox()
|
||||
spin_width.setMaximum(100000)
|
||||
spin_height = QDoubleSpinBox()
|
||||
spin_height.setMaximum(100000)
|
||||
|
||||
spin_width.setValue(1000)
|
||||
w.setWidthSpinBox(spin_width)
|
||||
spin_height.setValue(500)
|
||||
w.setHeightSpinBox(spin_height)
|
||||
|
||||
w.setLocked(True)
|
||||
spin_width.setValue(2000)
|
||||
self.assertEqual(spin_height.value(), 1000)
|
||||
|
||||
spin_width.blockSignals(True)
|
||||
spin_width.setValue(1000)
|
||||
spin_width.blockSignals(False)
|
||||
|
||||
spin_height.setValue(2000)
|
||||
self.assertEqual(spin_width.value(), 4000) # signals were blocked, so ratio wasn't updated
|
||||
|
||||
spin_width.blockSignals(True)
|
||||
spin_width.setValue(2000)
|
||||
spin_width.blockSignals(False)
|
||||
w.resetRatio() # since signals were blocked, we need to manually reset ratio
|
||||
spin_height.setValue(1000)
|
||||
self.assertEqual(spin_width.value(), 1000)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user