ctkXnatListModel.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*=============================================================================
  2. Library: XNAT/Core
  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 "ctkXnatExperiment.h"
  17. #include "ctkXnatListModel.h"
  18. #include "ctkXnatProject.h"
  19. #include "ctkXnatScan.h"
  20. #include "ctkXnatScanFolder.h"
  21. #include "ctkXnatSubject.h"
  22. #include <iostream>
  23. #include <typeinfo>
  24. #include <QDebug>
  25. //----------------------------------------------------------------------------
  26. ctkXnatListModel::ctkXnatListModel()
  27. : RootObject(0)
  28. {
  29. }
  30. //----------------------------------------------------------------------------
  31. void ctkXnatListModel::setRootObject(ctkXnatObject* root)
  32. {
  33. RootObject = root;
  34. }
  35. //----------------------------------------------------------------------------
  36. ctkXnatObject* ctkXnatListModel::rootObject()
  37. {
  38. return RootObject;
  39. }
  40. //----------------------------------------------------------------------------
  41. int ctkXnatListModel::rowCount(const QModelIndex& /*parent*/) const
  42. {
  43. if (!RootObject) return 0;
  44. return RootObject->children().size();
  45. }
  46. //----------------------------------------------------------------------------
  47. QVariant ctkXnatListModel::data(const QModelIndex& index, int role) const
  48. {
  49. if (!RootObject) return QVariant();
  50. if (role == Qt::DisplayRole)
  51. {
  52. ctkXnatObject* child = RootObject->children().at(index.row());
  53. QString displayData = child->name();
  54. if (displayData.isEmpty())
  55. {
  56. displayData = child->property(ctkXnatObject::LABEL);
  57. }
  58. return displayData;
  59. }
  60. else if (role == Qt::UserRole)
  61. {
  62. return QVariant::fromValue(RootObject->children().at(index.row()));
  63. }
  64. return QVariant();
  65. }
  66. //----------------------------------------------------------------------------
  67. QVariant ctkXnatListModel::headerData(int /*section*/, Qt::Orientation /*orientation*/, int role) const
  68. {
  69. if (role == Qt::DisplayRole)
  70. {
  71. if (!RootObject) return QString("Unavailable");
  72. return RootObject->childDataType();
  73. }
  74. return QVariant();
  75. }