ctkMenuComboBoxTest2.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <QComboBox>
  17. #include <QCompleter>
  18. #include <QDebug>
  19. #include <QIcon>
  20. #include <QLineEdit>
  21. #include <QListWidget>
  22. #include <QMenu>
  23. #include <QTimer>
  24. #include <QToolBar>
  25. #include <QVBoxLayout>
  26. // CTK includes
  27. #include "ctkMenuComboBox.h"
  28. // STD includes
  29. #include <iostream>
  30. //-----------------------------------------------------------------------------
  31. int ctkMenuComboBoxTest2(int argc, char * argv [] )
  32. {
  33. QApplication app(argc, argv);
  34. ctkMenuComboBox* menu = new ctkMenuComboBox();
  35. /// ------ Test setMenu ------
  36. menu->setMenu(new QMenu(0));
  37. if(!menu->menu()->isEmpty())
  38. {
  39. qDebug() << "Line : " << __LINE__
  40. << "ctkMenuComboBox::setMenu failed";
  41. return EXIT_FAILURE;
  42. }
  43. QMenu* file = new QMenu("File");
  44. file->addAction("first");
  45. menu->setMenu(file);
  46. QList<QCompleter* > completer = menu->findChildren<QCompleter *>();
  47. if(menu->menu()->isEmpty()
  48. && completer[0]->model()->rowCount() != 1)
  49. {
  50. qDebug() << "Line : " << __LINE__
  51. << "ctkMenuComboBox::setMenu failed";
  52. return EXIT_FAILURE;
  53. }
  54. /// ------- Test delete Menu -----
  55. //delete menu->menu();
  56. //file = new QMenu("File");
  57. //menu->show();
  58. //return app.exec();
  59. /// ------- Test addAction -------
  60. menu->setMenu(file);
  61. QMenu* informatics = new QMenu("Informatics");
  62. QAction* titi = informatics->addAction("titi");
  63. file->addMenu(informatics);
  64. if(menu->menu()->isEmpty()
  65. && completer[0]->model()->rowCount() != 2)
  66. {
  67. qDebug() << "Line : " << __LINE__
  68. << "ctkMenuComboBox::addAction failed";
  69. return EXIT_FAILURE;
  70. }
  71. /// ------- Test removeAction -------
  72. informatics->removeAction(titi);
  73. if(completer[0]->model()->rowCount() != 1)
  74. {
  75. qDebug() << "Line : " << __LINE__
  76. << "ctkMenuComboBox::removeAction failed";
  77. return EXIT_FAILURE;
  78. }
  79. /// ------- Test add 2 same actions -> only 1 add on the completer --------
  80. informatics->addAction(titi);
  81. file->addAction(titi);
  82. if (completer[0]->model()->rowCount() != 2)
  83. {
  84. qDebug() << "Line : " << __LINE__
  85. << "ctkMenuComboBox::addAction failed";
  86. return EXIT_FAILURE;
  87. }
  88. /// ------- Test remove one of the two --------
  89. informatics->removeAction(titi);
  90. //file->removeAction(first);
  91. if (completer[0]->model()->rowCount() != 2)
  92. {
  93. qDebug() << "Line : " << __LINE__
  94. << "ctkMenuComboBox::addAction failed"
  95. << completer[0]->model()->rowCount();
  96. return EXIT_FAILURE;
  97. }
  98. /// ------- Test remove the second one -------
  99. file->removeAction(titi);
  100. if (completer[0]->model()->rowCount() != 1)
  101. {
  102. qDebug() << "Line : " << __LINE__
  103. << "ctkMenuComboBox::addAction failed"
  104. << completer[0]->model()->rowCount();
  105. return EXIT_FAILURE;
  106. }
  107. menu->show();
  108. if (argc < 2 || QString(argv[1]) != "-I" )
  109. {
  110. QTimer::singleShot(200, &app, SLOT(quit()));
  111. }
  112. return app.exec();
  113. }