ctkVTKPropertyWidgetTest.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.apache.org/licenses/LICENSE-2.0.txt
  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 <QString>
  17. #include <QStyle>
  18. #include <QStyleOptionSlider>
  19. #include <QTimer>
  20. // CTK includes
  21. #include "ctkVTKPropertyWidget.h"
  22. #include "ctkTest.h"
  23. // VTK includes
  24. #include <vtkProperty.h>
  25. // ----------------------------------------------------------------------------
  26. class ctkVTKPropertyWidgetTester: public QObject
  27. {
  28. Q_OBJECT
  29. private slots:
  30. void testGUIEvents();
  31. void testVTKProperty();
  32. void testProperties();
  33. };
  34. // ----------------------------------------------------------------------------
  35. void ctkVTKPropertyWidgetTester::testGUIEvents()
  36. {
  37. ctkVTKPropertyWidget propertyWidget(0);
  38. propertyWidget.show();
  39. qApp->processEvents();
  40. propertyWidget.resize(100, 100);
  41. qApp->processEvents();
  42. propertyWidget.resize(1, 100);
  43. qApp->processEvents();
  44. propertyWidget.resize(100, 1);
  45. qApp->processEvents();
  46. propertyWidget.hide();
  47. qApp->processEvents();
  48. propertyWidget.show();
  49. }
  50. // ----------------------------------------------------------------------------
  51. void ctkVTKPropertyWidgetTester::testVTKProperty()
  52. {
  53. ctkVTKPropertyWidget propertyWidget(0);
  54. vtkProperty* property = propertyWidget.property();
  55. // ctkVTKPropertyWidget -> vtkProperty
  56. double newOpacity(0.9);
  57. propertyWidget.setOpacity(newOpacity);
  58. QCOMPARE(property->GetOpacity(), newOpacity);
  59. // ctkVTKPropertyWidget <- vtkProperty
  60. newOpacity = 0.8;
  61. property->SetOpacity(newOpacity);
  62. QCOMPARE(propertyWidget.opacity(), newOpacity);
  63. // new vtkProperty
  64. property = vtkProperty::New();
  65. newOpacity = 0.7;
  66. property->SetOpacity(newOpacity);
  67. propertyWidget.setProperty(property);
  68. QCOMPARE(propertyWidget.opacity(), newOpacity);
  69. // ctkVTKPropertyWidget -> vtkProperty
  70. newOpacity = 0.6;
  71. propertyWidget.setOpacity(newOpacity);
  72. QCOMPARE(property->GetOpacity(), newOpacity);
  73. // ctkVTKPropertyWidget <- vtkProperty
  74. newOpacity = 0.5;
  75. property->SetOpacity(newOpacity);
  76. QCOMPARE(propertyWidget.opacity(), newOpacity);
  77. property->Delete();
  78. }
  79. // ----------------------------------------------------------------------------
  80. void ctkVTKPropertyWidgetTester::testProperties()
  81. {
  82. ctkVTKPropertyWidget propertyWidget(0);
  83. propertyWidget.setRepresentation(0);
  84. QCOMPARE(propertyWidget.representation(), 0);
  85. propertyWidget.setPointSize(3.5);
  86. QCOMPARE(propertyWidget.pointSize(), 3.5);
  87. propertyWidget.setLineWidth(10.11);
  88. QCOMPARE(propertyWidget.lineWidth(), 10.11);
  89. propertyWidget.setFrontfaceCulling(true);
  90. QCOMPARE(propertyWidget.frontfaceCulling(), true);
  91. propertyWidget.setBackfaceCulling(true);
  92. QCOMPARE(propertyWidget.backfaceCulling(), true);
  93. propertyWidget.setColor(Qt::red);
  94. QCOMPARE(propertyWidget.color(), QColor(Qt::red));
  95. propertyWidget.setOpacity(0.1);
  96. QCOMPARE(propertyWidget.opacity(), 0.1);
  97. propertyWidget.setEdgeVisibility(true);
  98. QCOMPARE(propertyWidget.edgeVisibility(), true);
  99. propertyWidget.setEdgeColor(Qt::blue);
  100. QCOMPARE(propertyWidget.edgeColor(), QColor(Qt::blue));
  101. propertyWidget.setLighting(false);
  102. QCOMPARE(propertyWidget.lighting(), false);
  103. propertyWidget.setInterpolation(0);
  104. QCOMPARE(propertyWidget.interpolation(), 0);
  105. propertyWidget.setShading(false);
  106. QCOMPARE(propertyWidget.shading(), false);
  107. }
  108. // ----------------------------------------------------------------------------
  109. CTK_TEST_MAIN(ctkVTKPropertyWidgetTest)
  110. #include "moc_ctkVTKPropertyWidgetTest.cpp"