ctkVTKDataSetArrayComboBoxTest1.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 <QDebug>
  17. #include <QTimer>
  18. // CTK includes
  19. #include "ctkVTKDataSetArrayComboBox.h"
  20. #include "ctkVTKDataSetModel.h"
  21. // VTK includes
  22. #include <vtkCellData.h>
  23. #include <vtkFloatArray.h>
  24. #include <vtkIntArray.h>
  25. #include <vtkNew.h>
  26. #include <vtkPointData.h>
  27. #include <vtkPoints.h>
  28. #include <vtkPolyData.h>
  29. // STD includes
  30. #include <iostream>
  31. //-----------------------------------------------------------------------------
  32. int ctkVTKDataSetArrayComboBoxTest1(int argc, char * argv [] )
  33. {
  34. QApplication app(argc, argv);
  35. vtkNew<vtkPolyData> dataSet;
  36. vtkNew<vtkIntArray> ints;
  37. ints->SetName("Ints");
  38. dataSet->GetPointData()->AddArray(ints.GetPointer());
  39. vtkNew<vtkFloatArray> floats;
  40. floats->SetName("Floats");
  41. dataSet->GetCellData()->AddArray(floats.GetPointer());
  42. ctkVTKDataSetArrayComboBox comboBox;
  43. comboBox.dataSetModel()->setAttributeTypes(ctkVTKDataSetModel::AllAttribute);
  44. comboBox.setDataSet(dataSet.GetPointer());
  45. if (comboBox.count()!=2)
  46. {
  47. std::cerr << "Line " << __LINE__ << " - Expected 2 items in the combobox\n"
  48. "\tCurrent count: " << comboBox.count() << "\n";
  49. return EXIT_FAILURE;
  50. }
  51. comboBox.setNoneEnabled(true);
  52. if (comboBox.count()!=3)
  53. {
  54. std::cerr << "Line " << __LINE__ << " - Expected 3 items in the combobox\n"
  55. "\tCurrent count: " << comboBox.count() << "\n";
  56. return EXIT_FAILURE;
  57. }
  58. if (!comboBox.itemText(0).isEmpty())
  59. {
  60. std::cerr << "Line " << __LINE__ << " - First combo box item text is expected to be empty\n";
  61. return EXIT_FAILURE;
  62. }
  63. comboBox.setNoneEnabled(false);
  64. if (comboBox.count()!=2)
  65. {
  66. std::cerr << "Line " << __LINE__ << " - Expected 2 items in the combobox\n"
  67. "\tCurrent count: " << comboBox.count() << "\n";
  68. return EXIT_FAILURE;
  69. }
  70. comboBox.show();
  71. if (argc < 2 || QString(argv[1]) != "-I")
  72. {
  73. QTimer::singleShot(1000, &app, SLOT(quit()));
  74. }
  75. return app.exec();
  76. }