ctkModuleParameterValue.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 this 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 "ctkModuleParameterValue.h"
  15. #include "QDebug"
  16. //----------------------------------------------------------------------------
  17. ctkModuleParameterValue::ctkModuleParameterValue( const ctkModuleParameter& param)
  18. : Parameter( param )
  19. {
  20. }
  21. //----------------------------------------------------------------------------
  22. void ctkModuleParameterValue::setValue( const QVariant& val)
  23. {
  24. value = val;
  25. }
  26. //----------------------------------------------------------------------------
  27. const QVariant& ctkModuleParameterValue::getValue() const
  28. {
  29. return value;
  30. }
  31. //----------------------------------------------------------------------------
  32. const ctkModuleParameter& ctkModuleParameterValue::parameter() const
  33. {
  34. return Parameter;
  35. }
  36. void ctkModuleParameterValue::setDefaultValue()
  37. {
  38. QVariant::Type type = value.type();
  39. if (type == QVariant::Bool)
  40. {
  41. value = (Parameter["Default"].compare("true", Qt::CaseInsensitive) == 0);
  42. }
  43. else if (type == QVariant::Int)
  44. {
  45. value = Parameter["Default"].toInt();
  46. }
  47. else if (type == QVariant::Double)
  48. {
  49. value = Parameter["Default"].toDouble();
  50. }
  51. else if (type == QVariant::String)
  52. {
  53. value = Parameter["Default"];
  54. }
  55. else
  56. {
  57. qDebug() << "Unknown widget value type:" << type;
  58. }
  59. }