ctkXnatProjectListModel.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "ctkXnatProjectListModel.h"
  16. #include "ctkXnatProject.h"
  17. #include <QDebug>
  18. ctkXnatProjectListModel::ctkXnatProjectListModel()
  19. {
  20. }
  21. void ctkXnatProjectListModel::setRootObject(const ctkXnatObject::Pointer& root)
  22. {
  23. rootObject = root;
  24. }
  25. int ctkXnatProjectListModel::rowCount(const QModelIndex& /*parent*/) const
  26. {
  27. if (!rootObject) return 0;
  28. return rootObject->getChildren().size();
  29. }
  30. QVariant ctkXnatProjectListModel::data(const QModelIndex& index, int role) const
  31. {
  32. if (!rootObject) return QVariant();
  33. if (role == Qt::DisplayRole)
  34. {
  35. ctkXnatObject::Pointer child = rootObject->getChildren().at(index.row());
  36. if (child.isNull())
  37. {
  38. qWarning() << "child at index" << index << "is NULL!";
  39. }
  40. else
  41. {
  42. QString displayData = child->getName();
  43. if (displayData.isEmpty())
  44. {
  45. displayData = child->getId();
  46. }
  47. return displayData;
  48. }
  49. }
  50. else if (role == Qt::UserRole)
  51. {
  52. return QVariant::fromValue(rootObject->getChildren().at(index.row()));
  53. }
  54. return QVariant();
  55. }
  56. QVariant ctkXnatProjectListModel::headerData(int /*section*/, Qt::Orientation /*orientation*/, int role) const
  57. {
  58. if (role == Qt::DisplayRole)
  59. {
  60. if (!rootObject) return QString("Unavailable");
  61. return QString("Bla");
  62. }
  63. return QVariant();
  64. }