ctkCmdLineModuleDescription.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 "ctkCmdLineModuleDescription.h"
  15. #include "ctkCmdLineModuleDescription_p.h"
  16. #include "ctkCmdLineModuleParameter.h"
  17. #include "ctkCmdLineModuleParameterGroup.h"
  18. #include "ctkException.h"
  19. #include <QTextStream>
  20. //----------------------------------------------------------------------------
  21. ctkCmdLineModuleDescription::ctkCmdLineModuleDescription()
  22. : d(new ctkCmdLineModuleDescriptionPrivate())
  23. {
  24. }
  25. //----------------------------------------------------------------------------
  26. ctkCmdLineModuleDescription::ctkCmdLineModuleDescription(const ctkCmdLineModuleDescription &description)
  27. : d(description.d)
  28. {
  29. }
  30. //----------------------------------------------------------------------------
  31. ctkCmdLineModuleDescription::~ctkCmdLineModuleDescription()
  32. {
  33. }
  34. //----------------------------------------------------------------------------
  35. ctkCmdLineModuleDescription &ctkCmdLineModuleDescription::operator =(const ctkCmdLineModuleDescription &other)
  36. {
  37. d = other.d;
  38. return *this;
  39. }
  40. //----------------------------------------------------------------------------
  41. QString ctkCmdLineModuleDescription::category() const
  42. {
  43. return d->Category;
  44. }
  45. //----------------------------------------------------------------------------
  46. QString ctkCmdLineModuleDescription::title() const
  47. {
  48. return d->Title;
  49. }
  50. //----------------------------------------------------------------------------
  51. QString ctkCmdLineModuleDescription::categoryDotTitle() const
  52. {
  53. return this->category() + "." + this->title();
  54. }
  55. //----------------------------------------------------------------------------
  56. QString ctkCmdLineModuleDescription::description() const
  57. {
  58. return d->Description;
  59. }
  60. //----------------------------------------------------------------------------
  61. QString ctkCmdLineModuleDescription::version() const
  62. {
  63. return d->Version;
  64. }
  65. //----------------------------------------------------------------------------
  66. QString ctkCmdLineModuleDescription::documentationURL() const
  67. {
  68. return d->DocumentationURL;
  69. }
  70. //----------------------------------------------------------------------------
  71. QString ctkCmdLineModuleDescription::license() const
  72. {
  73. return d->License;
  74. }
  75. //----------------------------------------------------------------------------
  76. QString ctkCmdLineModuleDescription::acknowledgements() const
  77. {
  78. return d->Acknowledgements;
  79. }
  80. //----------------------------------------------------------------------------
  81. QString ctkCmdLineModuleDescription::contributor() const
  82. {
  83. return d->Contributor;
  84. }
  85. //----------------------------------------------------------------------------
  86. QIcon ctkCmdLineModuleDescription::logo() const
  87. {
  88. return d->Logo;
  89. }
  90. //----------------------------------------------------------------------------
  91. QList<ctkCmdLineModuleParameterGroup> ctkCmdLineModuleDescription::parameterGroups() const
  92. {
  93. return d->ParameterGroups;
  94. }
  95. //----------------------------------------------------------------------------
  96. bool ctkCmdLineModuleDescription::hasParameter(const QString& name) const
  97. {
  98. // iterate over each parameter group
  99. foreach(const ctkCmdLineModuleParameterGroup group, d->ParameterGroups)
  100. {
  101. if (group.hasParameter(name)) return true;
  102. }
  103. return false;
  104. }
  105. //----------------------------------------------------------------------------
  106. ctkCmdLineModuleParameter ctkCmdLineModuleDescription::parameter(const QString& name) const
  107. {
  108. foreach(const ctkCmdLineModuleParameterGroup group, d->ParameterGroups)
  109. {
  110. if (group.hasParameter(name))
  111. {
  112. return group.parameter(name);
  113. }
  114. }
  115. throw ctkInvalidArgumentException(QString("No parameter named \"%1\" available.").arg(name));
  116. }
  117. //----------------------------------------------------------------------------
  118. bool ctkCmdLineModuleDescription::hasReturnParameters() const
  119. {
  120. // iterate over each parameter group
  121. foreach(const ctkCmdLineModuleParameterGroup group, d->ParameterGroups)
  122. {
  123. if (group.hasReturnParameters()) return true;
  124. }
  125. return false;
  126. }
  127. //----------------------------------------------------------------------------
  128. QTextStream & operator<<(QTextStream &os, const ctkCmdLineModuleDescription &module)
  129. {
  130. os << "Title: " << module.title() << '\n';
  131. os << "Category: " << module.category() << '\n';
  132. os << "Description: " << module.description() << '\n';
  133. os << "Version: " << module.version() << '\n';
  134. os << "DocumentationURL: " << module.documentationURL() << '\n';
  135. os << "License: " << module.license() << '\n';
  136. os << "Contributor: " << module.contributor() << '\n';
  137. os << "Acknowledgements: " << module.acknowledgements() << '\n';
  138. //os << "Logo: " << module.GetLogo() << '\n';
  139. os << "ParameterGroups: " << '\n';
  140. foreach(const ctkCmdLineModuleParameterGroup group, module.parameterGroups())
  141. {
  142. os << group;
  143. }
  144. return os;
  145. }