ctkExampleUseOfWorkflowWidgetUsingDerivedSteps.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 <QTimer>
  17. // CTK includes
  18. #include "ctkWorkflow.h"
  19. #include "ctkWorkflowTabWidget.h"
  20. #include "ctkExampleDerivedWorkflowWidgetStep.h"
  21. // STD includes
  22. #include <cstdlib>
  23. #include <iostream>
  24. ///
  25. /// Simple example of how to setup a workflow using custom steps that
  26. /// were created by deriving ctkWorkflowWidgetStep.
  27. /// See: ctkExampleDerivedWorkflowWidgetStep for an example of how to
  28. /// setup the custom steps.
  29. //-----------------------------------------------------------------------------
  30. int ctkExampleUseOfWorkflowWidgetUsingDerivedSteps ( int argc, char * argv [] )
  31. {
  32. QApplication app(argc, argv);
  33. // this boolean is used in setHideWidgetsOfNonCurrentSteps() below
  34. // false: when a widget does not belong to the current step, it is
  35. // hidden
  36. // true: when a widget does not belong to the current step, it is
  37. // shown, but disabled
  38. bool hideWidgets = false;
  39. // create the workflow
  40. ctkWorkflow* workflow = new ctkWorkflow;
  41. // create the workflow's UI component
  42. ctkWorkflowTabWidget* workflowWidget = new ctkWorkflowTabWidget;
  43. workflowWidget->setWorkflow(workflow);
  44. workflowWidget->setPreText("I am some pre-text");
  45. workflowWidget->setPostText("I am some post-text");
  46. workflowWidget->setHideWidgetsOfNonCurrentSteps(hideWidgets);
  47. // create and add the first workflow step
  48. ctkExampleDerivedWorkflowWidgetStep* testStep1 = new ctkExampleDerivedWorkflowWidgetStep(workflow, "Step 1");
  49. testStep1->setName("Step 1");
  50. testStep1->setDescription("I am in step 1");
  51. // can specify the name of the tab
  52. workflowWidget->addStepArea(testStep1, "tab 1");
  53. // create and add the second workflow step
  54. ctkExampleDerivedWorkflowWidgetStep* testStep2 = new ctkExampleDerivedWorkflowWidgetStep(workflow, "Step 2");
  55. testStep2->setName("Step 2");
  56. testStep2->setDescription("I am in step 2");
  57. // a new tab is automatically created
  58. workflowWidget->addStepArea(testStep2, "tab 2");
  59. // create and add a third workflow step
  60. ctkExampleDerivedWorkflowWidgetStep* testStep3 = new ctkExampleDerivedWorkflowWidgetStep(workflow, "Step 3");
  61. testStep3->setName("Step 3");
  62. testStep3->setDescription("I am in step 3");
  63. // can place a step on a tab that was previously created by
  64. // specifying its index
  65. workflowWidget->addStepArea(testStep3, 1);
  66. // add the steps to the workflow
  67. workflow->addTransition(testStep1, testStep2);
  68. workflow->addTransition(testStep2, testStep3);
  69. // testStep1 is the initial step
  70. workflow->setInitialStep(testStep1);
  71. // testStep3 will be a finish step, since it is the last step in the workflow
  72. // - will perform the processing associated with entering and
  73. // leaving each step, using the default values supplied
  74. // - if successful: brings you back to the step where you requested
  75. // to go to the finish step, so that you can begin customization
  76. // using user inputs if desired
  77. // - if unsuccessful: leaves you in the step of failure, so that you
  78. // can attempt to recify things from there; prints an error message
  79. // at the bottom of the widget. To see this behavior:
  80. // 1) "Next" to step 2
  81. // 2) change step 2's value to something invalid (ex. 0)
  82. // 3) "Back" to step 1
  83. // 4) "finish" - attempts to go to step 3, but leaves you in step 2
  84. // start the workflow
  85. workflow->start();
  86. workflowWidget->show();
  87. // change this value (500) to increase the time that the widget is
  88. // shown
  89. QTimer::singleShot(500, &app, SLOT(quit()));
  90. app.exec();
  91. // stop the workflow
  92. workflow->stop();
  93. QTimer::singleShot(100, &app, SLOT(quit()));
  94. app.exec();
  95. // handles deletion of the workflowWidget, workflow, steps, states
  96. // and transitions
  97. delete workflowWidget;
  98. return EXIT_SUCCESS;
  99. }