ctkActionsWidgetTest1.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <QAction>
  16. #include <QDebug>
  17. #include <QIcon>
  18. #include <QStandardItem>
  19. #include <QStyle>
  20. // CTK includes
  21. #include "ctkActionsWidget.h"
  22. #include "ctkTestApplication.h"
  23. // STD includes
  24. #include <cstdlib>
  25. #include <iostream>
  26. //-----------------------------------------------------------------------------
  27. QCTK_DECLARE_TEST(ctkActionsWidgetTest1)
  28. {
  29. ctkActionsWidget* actionsWidget = new ctkActionsWidget(0);
  30. actionsWidget->show();
  31. QWidget widget;
  32. QIcon informationIcon = actionsWidget->style()->standardIcon(QStyle::SP_MessageBoxInformation);
  33. actionsWidget->addAction(new QAction(0));
  34. actionsWidget->addAction(new QAction(qApp));
  35. actionsWidget->addAction(new QAction("Action Text", qApp));
  36. actionsWidget->addAction(new QAction(informationIcon, "Action Text", qApp));
  37. actionsWidget->addAction(new QAction(0), "category 1");
  38. actionsWidget->addAction(new QAction(qApp), "category 1");
  39. actionsWidget->addAction(new QAction("Action Text", &widget), "category 1");
  40. actionsWidget->addAction(new QAction(informationIcon, "Action Text", qApp), "category 1");
  41. actionsWidget->addAction(new QAction(0), "category 2");
  42. actionsWidget->addAction(new QAction(qApp), "category 3");
  43. actionsWidget->addAction(new QAction("Action Text", &widget), "category 4");
  44. actionsWidget->addAction(new QAction(informationIcon, "Action Text", qApp), "category 5");
  45. if (actionsWidget->groupItem("category 1") == 0 ||
  46. actionsWidget->groupItem("category 1")->rowCount() != 4)
  47. {
  48. qDebug() << "Invalid Category 1";
  49. QCTK_EXIT_TEST(EXIT_FAILURE);
  50. }
  51. // check shortcut
  52. QAction* action = new QAction("custom action", 0);
  53. action->setShortcut(Qt::Key_F1);
  54. action->setToolTip("custom tooltip");
  55. actionsWidget->addAction(action);
  56. QStandardItem* actionItem = actionsWidget->model()->item(9);
  57. if (!actionItem || actionItem->text() != "custom action")
  58. {
  59. qDebug() << "Invalid custom action" << actionItem->text();
  60. QCTK_EXIT_TEST(EXIT_FAILURE);
  61. }
  62. // check update on change
  63. action->setText("new custom action");
  64. QStandardItem* changedActionItem = actionsWidget->model()->item(9);
  65. if (changedActionItem != actionItem ||
  66. changedActionItem->text() != "new custom action")
  67. {
  68. qDebug() << "Invalid action update" << changedActionItem->text();
  69. QCTK_EXIT_TEST(EXIT_FAILURE);
  70. }
  71. widget.addAction(action);
  72. QCTK_EXIT_TEST(EXIT_SUCCESS);
  73. //QTimer::singleShot(500, QApplication::instance(), SLOT(quit()));
  74. }
  75. QCTK_RUN_TEST(ctkActionsWidgetTest1);