ctkCmdLineModuleObjectTreeWalker_p.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKCMDLINEMODULEOBJECTTREEWALKER_H
  16. #define CTKCMDLINEMODULEOBJECTTREEWALKER_H
  17. #include <QStack>
  18. #include <QString>
  19. class QObject;
  20. class QVariant;
  21. /**
  22. * \class ctkCmdLineModuleObjectTreeWalker
  23. * \brief Non-exported helper class to iterate through GUI widgets.
  24. * \ingroup CommandLineModulesFrontendQtGui
  25. */
  26. class ctkCmdLineModuleObjectTreeWalker
  27. {
  28. public:
  29. enum TokenType {
  30. NoToken,
  31. Executable,
  32. ParameterGroup,
  33. ParameterContainer,
  34. Parameter
  35. };
  36. ctkCmdLineModuleObjectTreeWalker(QObject* root = 0);
  37. ~ctkCmdLineModuleObjectTreeWalker();
  38. void setRootObject(QObject* root);
  39. void clear();
  40. bool atEnd() const;
  41. bool isParameterGroup() const;
  42. bool isParameterContainer() const;
  43. bool isParameter() const;
  44. QString name() const;
  45. QString label() const;
  46. QVariant value(const QString& propertyName = QString()) const;
  47. void setValue(const QVariant& value, const QString& propertyName = QString());
  48. QString flag() const;
  49. QString longFlag() const;
  50. int index() const;
  51. bool isMultiple() const;
  52. QVariant property(const QString& propName) const;
  53. TokenType readNext();
  54. bool readNextExecutable();
  55. bool readNextParameterGroup();
  56. bool readNextParameterContainer();
  57. bool readNextParameter();
  58. TokenType tokenType() const;
  59. private:
  60. TokenType token(QObject* obj);
  61. bool setCurrent(QObject* obj);
  62. QVariant prefixedProperty(const QString& propName) const;
  63. QObject* RootObject;
  64. QObject* CurrentObject;
  65. TokenType CurrentToken;
  66. bool AtEnd;
  67. QStack<QObject*> ObjectStack;
  68. };
  69. #endif // CTKCMDLINEMODULEOBJECTTREEWALKER_H