ctkModuleParameterGroup.cpp 5.2 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 "ctkModuleParameterGroup.h"
  15. struct ctkModuleParameterGroupPrivate
  16. {
  17. ~ctkModuleParameterGroupPrivate()
  18. {
  19. qDeleteAll(Parameters);
  20. }
  21. QString Label;
  22. QString Description;
  23. bool Advanced;
  24. QList<ctkModuleParameter*> Parameters;
  25. };
  26. //----------------------------------------------------------------------------
  27. ctkModuleParameterGroup::ctkModuleParameterGroup()
  28. : d_ptr(new ctkModuleParameterGroupPrivate())
  29. {
  30. }
  31. //----------------------------------------------------------------------------
  32. ctkModuleParameterGroup::~ctkModuleParameterGroup()
  33. {
  34. delete d_ptr;
  35. }
  36. //----------------------------------------------------------------------------
  37. void ctkModuleParameterGroup::setLabel(const QString& label)
  38. {
  39. Q_D(ctkModuleParameterGroup);
  40. d->Label = label;
  41. }
  42. //----------------------------------------------------------------------------
  43. QString ctkModuleParameterGroup::label() const
  44. {
  45. Q_D(const ctkModuleParameterGroup);
  46. return d->Label;
  47. }
  48. //----------------------------------------------------------------------------
  49. void ctkModuleParameterGroup::setDescription(const QString& description)
  50. {
  51. Q_D(ctkModuleParameterGroup);
  52. d->Description = description;
  53. }
  54. //----------------------------------------------------------------------------
  55. QString ctkModuleParameterGroup::description() const
  56. {
  57. Q_D(const ctkModuleParameterGroup);
  58. return d->Description;
  59. }
  60. //----------------------------------------------------------------------------
  61. void ctkModuleParameterGroup::setAdvanced(bool advanced)
  62. {
  63. Q_D(ctkModuleParameterGroup);
  64. d->Advanced = advanced;
  65. }
  66. //----------------------------------------------------------------------------
  67. bool ctkModuleParameterGroup::advanced() const
  68. {
  69. Q_D(const ctkModuleParameterGroup);
  70. return d->Advanced;
  71. }
  72. //----------------------------------------------------------------------------
  73. void ctkModuleParameterGroup::addParameter(ctkModuleParameter* parameter)
  74. {
  75. Q_D(ctkModuleParameterGroup);
  76. d->Parameters.push_back(parameter);
  77. }
  78. //----------------------------------------------------------------------------
  79. QList<ctkModuleParameter*> ctkModuleParameterGroup::parameters() const
  80. {
  81. Q_D(const ctkModuleParameterGroup);
  82. return d->Parameters;
  83. }
  84. //----------------------------------------------------------------------------
  85. bool ctkModuleParameterGroup::hasParameter(const QString& name) const
  86. {
  87. Q_D(const ctkModuleParameterGroup);
  88. foreach(const ctkModuleParameter* param, d->Parameters)
  89. {
  90. if (param->name() == name) return true;
  91. }
  92. return false;
  93. }
  94. //----------------------------------------------------------------------------
  95. ctkModuleParameter* ctkModuleParameterGroup::parameter(const QString& name) const
  96. {
  97. Q_D(const ctkModuleParameterGroup);
  98. foreach(ctkModuleParameter* param, d->Parameters)
  99. {
  100. if (param->name() == name) return param;
  101. }
  102. return 0;
  103. }
  104. //----------------------------------------------------------------------------
  105. bool ctkModuleParameterGroup::hasReturnParameters() const
  106. {
  107. Q_D(const ctkModuleParameterGroup);
  108. // iterate over each parameter in d group
  109. foreach(const ctkModuleParameter* param, d->Parameters)
  110. {
  111. if (param->isReturnParameter())
  112. {
  113. return true;
  114. }
  115. }
  116. return false;
  117. }
  118. //----------------------------------------------------------------------------
  119. bool ctkModuleParameterGroup::writeParameterFile(QTextStream& in, bool withHandlesToBulkParameters) const
  120. {
  121. Q_D(const ctkModuleParameterGroup);
  122. // iterate over each parameter in d group
  123. foreach(const ctkModuleParameter* 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 ctkModuleParameterGroup &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(ctkModuleParameter* param, group.parameters())
  146. {
  147. os << *param;
  148. }
  149. return os;
  150. }