ctkXnatListModel.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 "ctkXnatDataModel.h"
  16. #include "ctkXnatListModel.h"
  17. #include "ctkXnatProject.h"
  18. #include "ctkXnatSubject.h"
  19. #include "ctkXnatExperiment.h"
  20. #include "ctkXnatScanFolder.h"
  21. #include "ctkXnatScan.h"
  22. #include "ctkXnatScanResource.h"
  23. #include <iostream>
  24. #include <typeinfo>
  25. #include <QDebug>
  26. ctkXnatListModel::ctkXnatListModel()
  27. : rootObject(0)
  28. {
  29. }
  30. void ctkXnatListModel::setRootObject(ctkXnatObject* root)
  31. {
  32. rootObject = root;
  33. }
  34. ctkXnatObject* ctkXnatListModel::getRootObject()
  35. {
  36. return rootObject;
  37. }
  38. int ctkXnatListModel::rowCount(const QModelIndex& /*parent*/) const
  39. {
  40. if (!rootObject) return 0;
  41. return rootObject->children().size();
  42. }
  43. QVariant ctkXnatListModel::data(const QModelIndex& index, int role) const
  44. {
  45. if (!rootObject) return QVariant();
  46. if (role == Qt::DisplayRole)
  47. {
  48. ctkXnatObject* child = rootObject->children().at(index.row());
  49. if (!child)
  50. {
  51. qWarning() << "child at index" << index << "is NULL!";
  52. }
  53. else
  54. {
  55. QString displayData = child->name();
  56. if (displayData.isEmpty())
  57. {
  58. displayData = child->id();
  59. }
  60. return displayData;
  61. }
  62. }
  63. else if (role == Qt::UserRole)
  64. {
  65. return QVariant::fromValue(rootObject->children().at(index.row()));
  66. }
  67. return QVariant();
  68. }
  69. QVariant ctkXnatListModel::headerData(int /*section*/, Qt::Orientation /*orientation*/, int role) const
  70. {
  71. if (role == Qt::DisplayRole)
  72. {
  73. if (!rootObject) return QString("Unavailable");
  74. if( dynamic_cast<ctkXnatDataModel*>(rootObject) != NULL )
  75. {
  76. return QString("Projects");
  77. }
  78. else if( dynamic_cast<ctkXnatProject*>(rootObject) != NULL )
  79. {
  80. return QString("Subjects");
  81. }
  82. else if( dynamic_cast<ctkXnatSubject*>(rootObject) != NULL )
  83. {
  84. return QString("Experiments");
  85. }
  86. else if( dynamic_cast<ctkXnatExperiment*>(rootObject) != NULL )
  87. {
  88. return QString("Kinds of data");
  89. }
  90. else if( dynamic_cast<ctkXnatScanFolder*>(rootObject) != NULL )
  91. {
  92. return QString("Image Sessions");
  93. }
  94. else if( dynamic_cast<ctkXnatScan*>(rootObject) != NULL )
  95. {
  96. return QString("Resource Folders");
  97. }
  98. else if( dynamic_cast<ctkXnatScanResource*>(rootObject) != NULL )
  99. {
  100. return QString("Files");
  101. }
  102. else
  103. {
  104. return QString("ERROR");
  105. }
  106. }
  107. return QVariant();
  108. }