ctkButtonGroupTest1.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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 <QPushButton>
  17. // CTK includes
  18. #include "ctkButtonGroup.h"
  19. #include "ctkCollapsibleButton.h"
  20. // STD includes
  21. #include <cstdlib>
  22. #include <iostream>
  23. //-----------------------------------------------------------------------------
  24. int ctkButtonGroupTest1(int argc, char * argv [] )
  25. {
  26. QApplication app(argc, argv);
  27. QPushButton* button1 = new QPushButton(0);
  28. QPushButton* button2 = new QPushButton(0);
  29. QPushButton* button3 = new QPushButton(0);
  30. ctkCollapsibleButton* button4 = new ctkCollapsibleButton(0);
  31. button1->setCheckable(true);
  32. button2->setCheckable(true);
  33. button3->setCheckable(false);
  34. button4->setCheckable(true);
  35. button2->setChecked(true);
  36. button4->setChecked(true);
  37. ctkButtonGroup buttonGroup(0);
  38. //QButtonGroup buttonGroup(0);
  39. buttonGroup.addButton(button1);
  40. buttonGroup.addButton(button2);
  41. buttonGroup.addButton(button3);
  42. buttonGroup.addButton(button4);
  43. if (!button4->isChecked() || button2->isChecked())
  44. {
  45. std::cerr << "ctkButtonGroup::addButton failed"
  46. << button2->isChecked() << " " << button4->isChecked()
  47. << std::endl;
  48. return EXIT_FAILURE;
  49. }
  50. // Click #1: check button1
  51. button1->click();
  52. if (!button1->isChecked() || button4->isChecked())
  53. {
  54. std::cerr << "ctkButtonGroup::click1 failed"
  55. << button1->isChecked() << " " << button4->isChecked()
  56. << std::endl;
  57. return EXIT_FAILURE;
  58. }
  59. // Click #2: uncheck button1
  60. button1->click();
  61. if (button1->isChecked() || button4->isChecked())
  62. {
  63. std::cerr << "ctkButtonGroup::click2 failed"
  64. << button1->isChecked() << " " << button4->isChecked()
  65. << std::endl;
  66. return EXIT_FAILURE;
  67. }
  68. // Click #3: check button1
  69. button1->click();
  70. if (!button1->isChecked() || button4->isChecked())
  71. {
  72. std::cerr << "ctkButtonGroup::click3 failed"
  73. << button1->isChecked() << " " << button4->isChecked()
  74. << std::endl;
  75. return EXIT_FAILURE;
  76. }
  77. // Click #4: check button2
  78. button2->click();
  79. if (!button2->isChecked() || button1->isChecked())
  80. {
  81. std::cerr << "ctkButtonGroup::click4 failed"
  82. << button2->isChecked() << " " << button1->isChecked()
  83. << std::endl;
  84. return EXIT_FAILURE;
  85. }
  86. // Click #5: click button3 keep check on button2
  87. button3->click();
  88. if (!button2->isChecked() || button3->isChecked())
  89. {
  90. std::cerr << "ctkButtonGroup::click5 failed"
  91. << button2->isChecked() << " " << button3->isChecked()
  92. << std::endl;
  93. return EXIT_FAILURE;
  94. }
  95. // Click #6: uncheck button2
  96. button2->click();
  97. if (button2->isChecked())
  98. {
  99. std::cerr << "ctkButtonGroup::click6 failed"
  100. << button2->isChecked() << std::endl;
  101. return EXIT_FAILURE;
  102. }
  103. return EXIT_SUCCESS;
  104. }