ctkComboBoxTest1.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <QTimer>
  17. // CTK includes
  18. #include "ctkComboBox.h"
  19. // STD includes
  20. #include <cstdlib>
  21. #include <iostream>
  22. //-----------------------------------------------------------------------------
  23. int ctkComboBoxTest1(int argc, char * argv [] )
  24. {
  25. QApplication app(argc, argv);
  26. ctkComboBox comboBox(0);
  27. if (!comboBox.defaultText().isEmpty())
  28. {
  29. std::cerr << "non empty default defaultText" << std::endl;
  30. return EXIT_FAILURE;
  31. }
  32. comboBox.setDefaultText("Select...");
  33. if (comboBox.defaultText() != "Select...")
  34. {
  35. std::cerr << "ctkComboBox::setDefaultText() failed"
  36. << comboBox.defaultText().toStdString() << std::endl;
  37. return EXIT_FAILURE;
  38. }
  39. if (comboBox.currentText() == "Select...")
  40. {
  41. std::cerr << "ctkComboBox::setDefaultText() failed" << std::endl;
  42. return EXIT_FAILURE;
  43. }
  44. QIcon icon = comboBox.style()->standardIcon(QStyle::SP_MessageBoxQuestion);
  45. comboBox.setDefaultIcon(icon);
  46. if (comboBox.defaultIcon().pixmap(20).toImage() !=
  47. icon.pixmap(20).toImage())
  48. {
  49. std::cerr << "ctkComboBox::setDefaultIcon() failed" << std::endl;
  50. return EXIT_FAILURE;
  51. }
  52. if (comboBox.isDefaultForced())
  53. {
  54. std::cerr << "default of ctkComboBox::isDefaultForced() failed" << std::endl;
  55. return EXIT_FAILURE;
  56. }
  57. comboBox.forceDefault(true);
  58. if (!comboBox.isDefaultForced())
  59. {
  60. std::cerr << "ctkComboBox::setDefaultForced() failed" << std::endl;
  61. return EXIT_FAILURE;
  62. }
  63. if (comboBox.elideMode() != Qt::ElideNone)
  64. {
  65. std::cerr << "Wrong default elide mode" << std::endl;
  66. return EXIT_FAILURE;
  67. }
  68. comboBox.setElideMode(Qt::ElideRight);
  69. if (comboBox.elideMode() != Qt::ElideRight)
  70. {
  71. std::cerr << "ctkComboBox::setElideMode() failed" << std::endl;
  72. return EXIT_FAILURE;
  73. }
  74. comboBox.addItem("Item Item Item Item Item Item Item Item 1");
  75. comboBox.addItem("Item Item Item Item Item Item Item Item 2");
  76. comboBox.addItem("Item Item Item Item Item Item Item Item 3");
  77. // adding items shouldn't change anything to the combobox current text
  78. if (comboBox.currentIndex() != 0 ||
  79. comboBox.currentText() != "Item Item Item Item Item Item Item Item 1")
  80. {
  81. std::cerr << "ctkComboBox::addItem failed:"
  82. << comboBox.currentIndex() << " "
  83. << comboBox.currentText().toStdString() << std::endl;
  84. return EXIT_FAILURE;
  85. }
  86. comboBox.show();
  87. if (argc < 2 || QString(argv[1]) != "-I" )
  88. {
  89. QTimer::singleShot(200, &app, SLOT(quit()));
  90. }
  91. return app.exec();
  92. }