ctkCmdLineModuleParameterGroup.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 Brigham and Women's Hospital (BWH) All Rights Reserved.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use d 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
  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. #include "ctkCmdLineModuleParameterGroup.h"
  15. struct ctkCmdLineModuleParameterGroupPrivate
  16. {
  17. ~ctkCmdLineModuleParameterGroupPrivate()
  18. {
  19. qDeleteAll(Parameters);
  20. }
  21. QString Label;
  22. QString Description;
  23. bool Advanced;
  24. QList<ctkCmdLineModuleParameter*> Parameters;
  25. };
  26. //----------------------------------------------------------------------------
  27. ctkCmdLineModuleParameterGroup::ctkCmdLineModuleParameterGroup()
  28. : d_ptr(new ctkCmdLineModuleParameterGroupPrivate())
  29. {
  30. }
  31. //----------------------------------------------------------------------------
  32. ctkCmdLineModuleParameterGroup::~ctkCmdLineModuleParameterGroup()
  33. {
  34. delete d_ptr;
  35. }
  36. //----------------------------------------------------------------------------
  37. void ctkCmdLineModuleParameterGroup::setLabel(const QString& label)
  38. {
  39. Q_D(ctkCmdLineModuleParameterGroup);
  40. d->Label = label;
  41. }
  42. //----------------------------------------------------------------------------
  43. QString ctkCmdLineModuleParameterGroup::label() const
  44. {
  45. Q_D(const ctkCmdLineModuleParameterGroup);
  46. return d->Label;
  47. }
  48. //----------------------------------------------------------------------------
  49. void ctkCmdLineModuleParameterGroup::setDescription(const QString& description)
  50. {
  51. Q_D(ctkCmdLineModuleParameterGroup);
  52. d->Description = description;
  53. }
  54. //----------------------------------------------------------------------------
  55. QString ctkCmdLineModuleParameterGroup::description() const
  56. {
  57. Q_D(const ctkCmdLineModuleParameterGroup);
  58. return d->Description;
  59. }
  60. //----------------------------------------------------------------------------
  61. void ctkCmdLineModuleParameterGroup::setAdvanced(bool advanced)
  62. {
  63. Q_D(ctkCmdLineModuleParameterGroup);
  64. d->Advanced = advanced;
  65. }
  66. //----------------------------------------------------------------------------
  67. bool ctkCmdLineModuleParameterGroup::advanced() const
  68. {
  69. Q_D(const ctkCmdLineModuleParameterGroup);
  70. return d->Advanced;
  71. }
  72. //----------------------------------------------------------------------------
  73. void ctkCmdLineModuleParameterGroup::addParameter(ctkCmdLineModuleParameter* parameter)
  74. {
  75. Q_D(ctkCmdLineModuleParameterGroup);
  76. d->Parameters.push_back(parameter);
  77. }
  78. //----------------------------------------------------------------------------
  79. QList<ctkCmdLineModuleParameter*> ctkCmdLineModuleParameterGroup::parameters() const
  80. {
  81. Q_D(const ctkCmdLineModuleParameterGroup);
  82. return d->Parameters;
  83. }
  84. //----------------------------------------------------------------------------
  85. bool ctkCmdLineModuleParameterGroup::hasParameter(const QString& name) const
  86. {
  87. Q_D(const ctkCmdLineModuleParameterGroup);
  88. foreach(const ctkCmdLineModuleParameter* param, d->Parameters)
  89. {
  90. if (param->name() == name) return true;
  91. }
  92. return false;
  93. }
  94. //----------------------------------------------------------------------------
  95. ctkCmdLineModuleParameter* ctkCmdLineModuleParameterGroup::parameter(const QString& name) const
  96. {
  97. Q_D(const ctkCmdLineModuleParameterGroup);
  98. foreach(ctkCmdLineModuleParameter* param, d->Parameters)
  99. {
  100. if (param->name() == name) return param;
  101. }
  102. return 0;
  103. }
  104. //----------------------------------------------------------------------------
  105. bool ctkCmdLineModuleParameterGroup::hasReturnParameters() const
  106. {
  107. Q_D(const ctkCmdLineModuleParameterGroup);
  108. // iterate over each parameter in d group
  109. foreach(const ctkCmdLineModuleParameter* param, d->Parameters)
  110. {
  111. if (param->isReturnParameter())
  112. {
  113. return true;
  114. }
  115. }
  116. return false;
  117. }
  118. //----------------------------------------------------------------------------
  119. bool ctkCmdLineModuleParameterGroup::writeParameterFile(QTextStream& in, bool withHandlesToBulkParameters) const
  120. {
  121. Q_D(const ctkCmdLineModuleParameterGroup);
  122. // iterate over each parameter in d group
  123. foreach(const ctkCmdLineModuleParameter* param, d->Parameters)
  124. {
  125. // write out all parameters or just the ones that are not bulk parameters
  126. QString tag = param->tag();
  127. if (withHandlesToBulkParameters ||
  128. !(tag == "image" || tag == "geometry" || tag == "transform" ||
  129. tag == "table" || tag == "measurement" ||
  130. tag == "point" || tag == "region")) // point and region are special
  131. {
  132. in << param->name() << " = " << param->defaultValue() << endl;
  133. // multiple="true" may have to be handled differently
  134. }
  135. }
  136. return true;
  137. }
  138. //----------------------------------------------------------------------------
  139. QTextStream & operator<<(QTextStream &os, const ctkCmdLineModuleParameterGroup &group)
  140. {
  141. os << " Advanced: " << (group.advanced() ? "true" : "false") << '\n';
  142. os << " Label: " << group.label() << '\n';
  143. os << " Description: " << group.description() << '\n';
  144. os << " Parameters: " << '\n';
  145. foreach(ctkCmdLineModuleParameter* param, group.parameters())
  146. {
  147. os << *param;
  148. }
  149. return os;
  150. }