ctkDoubleRangeSliderTest2.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QApplication>
  16. #include <QSignalSpy>
  17. #include <QTimer>
  18. // CTK includes
  19. #include "ctkDoubleRangeSlider.h"
  20. // STD includes
  21. #include <cstdlib>
  22. #include <iostream>
  23. //-----------------------------------------------------------------------------
  24. int ctkDoubleRangeSliderTest2(int argc, char * argv [] )
  25. {
  26. QApplication app(argc, argv);
  27. ctkDoubleRangeSlider slider(Qt::Horizontal);
  28. QSignalSpy spyRange(&slider, SIGNAL(rangeChanged(double, double)));
  29. slider.setRange(200., 499.01);
  30. if (spyRange.count() != 1 ||
  31. spyRange.first().at(0).toDouble() != 200. ||
  32. spyRange.first().at(1).toDouble() != 499.01)
  33. {
  34. std::cerr << "ctkDoubleRangeSlider::setRange() failed: "
  35. << spyRange.count() << " min: "
  36. << (spyRange.count() ? spyRange.first().at(0).toDouble() : -1.)
  37. << " max: "
  38. << (spyRange.count() ? spyRange.first().at(1).toDouble() : -1.)
  39. << std::endl;
  40. return EXIT_FAILURE;
  41. }
  42. spyRange.clear();
  43. // set again and rangeChanged shouldn't be called
  44. slider.setRange(200., 499.01);
  45. slider.setMinimum(200.);
  46. slider.setMaximum(499.01);
  47. if (spyRange.count() != 0)
  48. {
  49. std::cerr << "ctkDoubleRangeSlider::setRange() fired useless signal: "
  50. << spyRange.count() << " min: "
  51. << spyRange.first().at(0).toDouble() << " max: "
  52. << spyRange.first().at(1).toDouble() << std::endl;
  53. return EXIT_FAILURE;
  54. }
  55. // while it might not change the underline (int) slider, we still need to fire
  56. // an event
  57. slider.setMaximum(499.00);
  58. if (spyRange.count() != 1 ||
  59. spyRange.first().at(0).toDouble() != 200. ||
  60. spyRange.first().at(1).toDouble() != 499.00)
  61. {
  62. std::cerr << "ctkDoubleRangeSlider::setMaximum() failed: "
  63. << spyRange.count() << " min: "
  64. << (spyRange.count() ? spyRange.first().at(0).toDouble() : -1.)
  65. << " max: "
  66. << (spyRange.count() ? spyRange.first().at(1).toDouble() : -1.)
  67. << std::endl;
  68. return EXIT_FAILURE;
  69. }
  70. slider.show();
  71. if (argc < 2 || QString(argv[1]) != "-I" )
  72. {
  73. QTimer::singleShot(200, &app, SLOT(quit()));
  74. }
  75. return app.exec();
  76. }