ctkVTKDataSetArrayComboBoxEventTranslatorPlayerTest1.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <QAction>
  16. #include <QApplication>
  17. #include <QDebug>
  18. #include <QSignalSpy>
  19. #include <QStandardItemModel>
  20. #include <QTimer>
  21. #include <QTreeView>
  22. // VTK includes
  23. #include <vtkCellData.h>
  24. #include <vtkFloatArray.h>
  25. #include <vtkIntArray.h>
  26. #include <vtkPointData.h>
  27. #include <vtkPoints.h>
  28. #include <vtkPolyData.h>
  29. #include <vtkSmartPointer.h>
  30. // CTK includes
  31. #include "ctkCallback.h"
  32. #include "ctkConfig.h"
  33. #include "ctkVTKDataSetArrayComboBox.h"
  34. #include "ctkEventTranslatorPlayerWidget.h"
  35. // STD includes
  36. #include <cstdlib>
  37. #include <iostream>
  38. namespace
  39. {
  40. QSignalSpy *Spy1;
  41. //-----------------------------------------------------------------------------
  42. void checkFinalWidgetState(void* data)
  43. {
  44. ctkVTKDataSetArrayComboBox* widget = reinterpret_cast<ctkVTKDataSetArrayComboBox*>(data);
  45. CTKCOMPARE(Spy1->count(), 3);
  46. CTKCOMPARE(widget->currentText(), "Floats");
  47. }
  48. }
  49. //-----------------------------------------------------------------------------
  50. int ctkVTKDataSetArrayComboBoxEventTranslatorPlayerTest1(int argc, char * argv [] )
  51. {
  52. QApplication app(argc, argv);
  53. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Visualization/VTK/Widgets/Testing/Cpp/";
  54. // ------------------------
  55. ctkEventTranslatorPlayerWidget etpWidget;
  56. // Test case 1
  57. vtkSmartPointer<vtkPolyData> dataSet =
  58. vtkSmartPointer<vtkPolyData>::New();
  59. vtkSmartPointer<vtkIntArray> ints = vtkSmartPointer<vtkIntArray>::New();
  60. ints->SetName("Ints");
  61. dataSet->GetPointData()->AddArray(ints);
  62. vtkSmartPointer<vtkFloatArray> floats= vtkSmartPointer<vtkFloatArray>::New();
  63. floats->SetName("Floats");
  64. dataSet->GetCellData()->AddArray(floats);
  65. ctkVTKDataSetArrayComboBox* widget = new ctkVTKDataSetArrayComboBox();
  66. widget->setDataSet(dataSet);
  67. widget->show();
  68. QSignalSpy spy1(widget, SIGNAL(currentArrayChanged(QString)));
  69. Spy1 = &spy1;
  70. etpWidget.addTestCase(widget,
  71. xmlDirectory + "ctkVTKDataSetArrayComboBoxEventTranslatorPlayerTest1.xml",
  72. &checkFinalWidgetState);
  73. // ------------------------
  74. if (!app.arguments().contains("-I"))
  75. {
  76. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  77. }
  78. etpWidget.show();
  79. return app.exec();
  80. }