Skip to content

Commit

Permalink
Update displayed value when value proxy is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
finetjul committed Jul 28, 2013
1 parent 1f1dc9c commit bc38808
Show file tree
Hide file tree
Showing 19 changed files with 886 additions and 806 deletions.
44 changes: 44 additions & 0 deletions Libs/Core/Testing/Cpp/ctkLinearValueProxyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ private Q_SLOTS:

void testSetProxyValueNullCoeff();
void testSetProxyValueNullCoeff_data();

void testProxyModified();
void testProxyModified_data();
};

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -460,6 +463,47 @@ void ctkLinearValueProxyTester::testSetProxyValueNullCoeff_data()
<< std::numeric_limits<double>::quiet_NaN();
}


// ----------------------------------------------------------------------------
void ctkLinearValueProxyTester::testProxyModified()
{
ctkLinearValueProxy proxy;
proxy.setCoefficient(5.0);
proxy.setOffset(5.0);

QSignalSpy proxyAboutToBeModifiedSpy(&proxy, SIGNAL(proxyAboutToBeModified()));
QSignalSpy proxyModifiedSpy(&proxy, SIGNAL(proxyModified()));

QFETCH(bool, changeCoefficient);
QFETCH(double, coefficientOrOffset);
if (changeCoefficient)
{
proxy.setCoefficient(coefficientOrOffset);
}
else
{
proxy.setOffset(coefficientOrOffset);
}
QFETCH(int, expectedSignalCount);
ctkTest::COMPARE(proxyAboutToBeModifiedSpy.count(), expectedSignalCount);
ctkTest::COMPARE(proxyModifiedSpy.count(), expectedSignalCount);
}

// ----------------------------------------------------------------------------
void ctkLinearValueProxyTester::testProxyModified_data()
{
QTest::addColumn<double>("coefficientOrOffset");
QTest::addColumn<bool>("changeCoefficient");
QTest::addColumn<int>("expectedSignalCount");

QTest::newRow("change coefficient") << 10.0 << true << 1;
QTest::newRow("same coefficient") << 5.0 << true << 0;
QTest::newRow("null coefficient") << 0.0 << true << 1;
QTest::newRow("change offset") << 10.0 << false << 1;
QTest::newRow("same offset") << 5.0 << false << 0;
QTest::newRow("null offset") << 0.0 << false << 1;
}

// ----------------------------------------------------------------------------
CTK_TEST_MAIN(ctkLinearValueProxyTest)
#include "moc_ctkLinearValueProxyTest.cpp"
6 changes: 4 additions & 2 deletions Libs/Core/ctkLinearValueProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ void ctkLinearValueProxy::setCoefficient(double newCoeff)
{
return;
}

emit proxyAboutToBeModified();
d->Coefficient = newCoeff;
this->updateProxyValue();
emit proxyModified();
}

// --------------------------------------------------------------------------
Expand All @@ -120,7 +121,8 @@ void ctkLinearValueProxy::setOffset(double newOffset)
{
return;
}

emit proxyAboutToBeModified();
d->Offset = newOffset;
this->updateProxyValue();
emit proxyModified();
}
3 changes: 3 additions & 0 deletions Libs/Core/ctkValueProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public Q_SLOTS:
void valueChanged(double);
void proxyValueChanged(double);

void proxyAboutToBeModified();
void proxyModified();

protected:
QScopedPointer<ctkValueProxyPrivate> d_ptr;

Expand Down
4 changes: 0 additions & 4 deletions Libs/Testing/ctkTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ inline void COMPARE(double v1, double v2)
QVERIFY(v1 == std::numeric_limits<double>::infinity());
}
// QCOMPARE doesn't like to compare zeroes
else if (v2 == 0.0)
{
QCOMPARE(v1 + 1.0, 1.0);
}
else
{
QCOMPARE(v1, v2);
Expand Down
3 changes: 3 additions & 0 deletions Libs/Widgets/Testing/Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(TEST_SOURCES
ctkCoordinatesWidgetValueProxyTest.cpp
ctkCrosshairLabelTest1.cpp
ctkDirectoryButtonTest1.cpp
ctkDoubleRangeSliderTest.cpp
ctkDoubleRangeSliderTest1.cpp
ctkDoubleRangeSliderTest2.cpp
ctkDoubleRangeSliderValueProxyTest.cpp
Expand Down Expand Up @@ -188,6 +189,7 @@ QT4_WRAP_CPP(Tests_MOC_CPP ${Tests_MOC_SRCS})
QT4_GENERATE_MOCS(
ctkCoordinatesWidgetTest.cpp
ctkCoordinatesWidgetValueProxyTest.cpp
ctkDoubleRangeSliderTest.cpp
ctkDoubleRangeSliderValueProxyTest.cpp
ctkDoubleSliderTest.cpp
ctkDoubleSliderValueProxyTest.cpp
Expand Down Expand Up @@ -247,6 +249,7 @@ SIMPLE_TEST( ctkCoordinatesWidgetValueProxyTest )
SIMPLE_TEST( ctkCrosshairLabelTest1 )
SIMPLE_TEST( ctkDateRangeWidgetTest1 )
SIMPLE_TEST( ctkDirectoryButtonTest1 )
SIMPLE_TEST( ctkDoubleRangeSliderTest )
SIMPLE_TEST( ctkDoubleRangeSliderTest1 )
SIMPLE_TEST( ctkDoubleRangeSliderTest2 )
SIMPLE_TEST( ctkDoubleRangeSliderValueProxyTest )
Expand Down
127 changes: 127 additions & 0 deletions Libs/Widgets/Testing/Cpp/ctkDoubleRangeSliderTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*=========================================================================
Library: CTK
Copyright (c) Kitware Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.commontk.org/LICENSE
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

// Qt includes
#include <QApplication>
#include <QTest>

// CTK includes
#include "ctkDoubleRangeSlider.h"
#include "ctkTest.h"

//-----------------------------------------------------------------------------
class ctkDoubleRangeSliderTester: public QObject
{
Q_OBJECT
private slots:
void testUI();

void testRange();
void testRange_data();

void testSingleStep();
void testSingleStep_data();
};

// ----------------------------------------------------------------------------
void ctkDoubleRangeSliderTester::testUI()
{
ctkDoubleRangeSlider slider;
slider.show();
QTest::qWaitForWindowShown(&slider);
// qApp->exec();
}

// ----------------------------------------------------------------------------
void ctkDoubleRangeSliderTester::testRange()
{
ctkDoubleRangeSlider slider;

QFETCH(double, minimum);
QFETCH(double, maximum);
slider.setRange(minimum, maximum);

QFETCH(double, expectedMinimum);
QFETCH(double, expectedMaximum);
QFETCH(double, expectedMinimumValue);
QFETCH(double, expectedMaximumValue);

QCOMPARE(slider.minimum(), expectedMinimum);
QCOMPARE(slider.maximum(), expectedMaximum);
QCOMPARE(slider.minimumValue(), expectedMinimumValue);
QCOMPARE(slider.maximumValue(), expectedMaximumValue);
}

// ----------------------------------------------------------------------------
void ctkDoubleRangeSliderTester::testRange_data()
{
QTest::addColumn<double>("minimum");
QTest::addColumn<double>("maximum");
QTest::addColumn<double>("expectedMinimum");
QTest::addColumn<double>("expectedMaximum");
QTest::addColumn<double>("expectedMinimumValue");
QTest::addColumn<double>("expectedMaximumValue");

QTest::newRow("[20.123,20.1234]") << 20.123 << 20.1234
<< 20.123 << 20.1234 << 20.123 << 20.1234;
}

// ----------------------------------------------------------------------------
void ctkDoubleRangeSliderTester::testSingleStep()
{
ctkDoubleRangeSlider slider;
slider.setValues(25., 75.);

QFETCH(double, minimum);
QFETCH(double, maximum);
slider.setRange(minimum, maximum);

QFETCH(double, singleStep);
slider.setSingleStep(singleStep);

QFETCH(double, expectedMinimumValue);
QFETCH(double, expectedMaximumValue);
QCOMPARE(slider.minimumValue(), expectedMinimumValue);
QCOMPARE(slider.maximumValue(), expectedMaximumValue);
}

// ----------------------------------------------------------------------------
void ctkDoubleRangeSliderTester::testSingleStep_data()
{
QTest::addColumn<double>("minimum");
QTest::addColumn<double>("maximum");
QTest::addColumn<double>("singleStep");
QTest::addColumn<double>("expectedMinimumValue");
QTest::addColumn<double>("expectedMaximumValue");

QTest::newRow("1.") << 0. << 100. << 1. << 25. << 75.;
QTest::newRow("100.") << 0. << 100. << 100. << 25. << 75.;
QTest::newRow("0.1") << 0. << 100. << 0.1 << 25. << 75.;
QTest::newRow("min") << 0. << 100. << std::numeric_limits<double>::min() << 25. << 75.;
QTest::newRow("max") << 0. << 100. << std::numeric_limits<double>::max() << 25. << 75.;
QTest::newRow("-max") << 0. << 100. << -std::numeric_limits<double>::max() << 25. << 75.;
QTest::newRow("-inf") << 0. << 100. << -std::numeric_limits<double>::infinity() << 25. << 75.;
QTest::newRow("inf") << 0. << 100. << std::numeric_limits<double>::infinity() << 25. << 75.;
QTest::newRow("NaN") << 0. << 100. << std::numeric_limits<double>::quiet_NaN() << 25. << 75.;
}

// ----------------------------------------------------------------------------
CTK_TEST_MAIN(ctkDoubleRangeSliderTest)
#include "moc_ctkDoubleRangeSliderTest.cpp"
Loading

0 comments on commit bc38808

Please sign in to comment.