ctkObjectClassDefinitionImpl.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. #include "ctkObjectClassDefinitionImpl_p.h"
  16. #include "ctkAttributeDefinitionImpl_p.h"
  17. #include <ctkPlugin.h>
  18. #include <ctkPluginConstants.h>
  19. const int ctkObjectClassDefinitionImpl::PID = 0;
  20. const int ctkObjectClassDefinitionImpl::FPID = 1;
  21. const QChar ctkObjectClassDefinitionImpl::LOCALE_SEP = '_';
  22. ctkObjectClassDefinitionImpl::ctkObjectClassDefinitionImpl(const QString& name, const QString& description,
  23. const QString& id, const QString& localization,
  24. const QString& context, int type)
  25. : _name(name), _id(id), _description(description), _locElem(localization, context), _type(type)
  26. {
  27. }
  28. ctkObjectClassDefinitionImpl::ctkObjectClassDefinitionImpl(const ctkObjectClassDefinitionImpl& other)
  29. : _name(other._name), _id(other._id), _description(other._description),
  30. _locElem(other._locElem), _type(other._type), _icon(other._icon)
  31. {
  32. for (int i = 0; i < _required.size(); i++)
  33. {
  34. ctkAttributeDefinitionImplPtr ad(new ctkAttributeDefinitionImpl(*_required.value(i).data()));
  35. this->addAttributeDefinition(ad, true);
  36. }
  37. for (int i = 0; i < _optional.size(); i++)
  38. {
  39. ctkAttributeDefinitionImplPtr ad(new ctkAttributeDefinitionImpl(*_optional.value(i).data()));
  40. this->addAttributeDefinition(ad, false);
  41. }
  42. }
  43. QString ctkObjectClassDefinitionImpl::getName() const
  44. {
  45. return _locElem.getLocalized(_name);
  46. }
  47. void ctkObjectClassDefinitionImpl::setName(const QString& name)
  48. {
  49. _name = name;
  50. }
  51. QString ctkObjectClassDefinitionImpl::getID() const
  52. {
  53. return _id;
  54. }
  55. QString ctkObjectClassDefinitionImpl::getDescription() const
  56. {
  57. return _locElem.getLocalized(_description);
  58. }
  59. void ctkObjectClassDefinitionImpl::setDescription(const QString& description)
  60. {
  61. _description = description;
  62. }
  63. QList<ctkAttributeDefinitionPtr> ctkObjectClassDefinitionImpl::getAttributeDefinitions(Filter filter)
  64. {
  65. QList<ctkAttributeDefinitionPtr> atts;
  66. switch (filter)
  67. {
  68. case REQUIRED:
  69. {
  70. foreach(ctkAttributeDefinitionImplPtr impl, _required)
  71. {
  72. atts.push_back(impl);
  73. }
  74. return atts;
  75. }
  76. case OPTIONAL:
  77. {
  78. foreach(ctkAttributeDefinitionImplPtr impl, _optional)
  79. {
  80. atts.push_back(impl);
  81. }
  82. return atts;
  83. }
  84. case ALL:
  85. default :
  86. {
  87. foreach(ctkAttributeDefinitionImplPtr impl, _required)
  88. {
  89. atts.push_back(impl);
  90. }
  91. foreach(ctkAttributeDefinitionImplPtr impl, _optional)
  92. {
  93. atts.push_back(impl);
  94. }
  95. return atts;
  96. }
  97. }
  98. }
  99. void ctkObjectClassDefinitionImpl::addAttributeDefinition(const ctkAttributeDefinitionImplPtr& ad, bool isRequired)
  100. {
  101. if (isRequired)
  102. {
  103. _required.push_back(ad);
  104. }
  105. else
  106. {
  107. _optional.push_back(ad);
  108. }
  109. }
  110. QByteArray ctkObjectClassDefinitionImpl::getIcon(int sizeHint) const
  111. {
  112. if (!_icon || _icon.getIconSize() != sizeHint)
  113. {
  114. return QByteArray();
  115. }
  116. QSharedPointer<ctkPlugin> p = _icon.getIconPlugin();
  117. return p->getResource(_locElem.getLocalized(_icon.getIconName()));
  118. }
  119. void ctkObjectClassDefinitionImpl::setIcon(const ctkMTIcon& icon)
  120. {
  121. _icon = icon;
  122. }
  123. int ctkObjectClassDefinitionImpl::getType() const
  124. {
  125. return _type;
  126. }
  127. void ctkObjectClassDefinitionImpl::setType(int type)
  128. {
  129. _type = type;
  130. }
  131. void ctkObjectClassDefinitionImpl::setPluginLocalization(const QLocale& assignedLocale, const QSharedPointer<ctkPlugin>& plugin)
  132. {
  133. ctkPluginLocalization pluginLoc = plugin->getPluginLocalization(assignedLocale, _locElem.getLocalizationBase());
  134. _locElem.setPluginLocalization(pluginLoc);
  135. foreach(ctkAttributeDefinitionImplPtr impl, _required)
  136. {
  137. impl->setPluginLocalization(pluginLoc);
  138. }
  139. foreach(ctkAttributeDefinitionImplPtr impl, _optional)
  140. {
  141. impl->setPluginLocalization(pluginLoc);
  142. }
  143. }
  144. QString ctkObjectClassDefinitionImpl::getLocalization() const
  145. {
  146. return _locElem.getLocalizationBase();
  147. }