ctkXnatDataModel.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*=============================================================================
  2. Plugin: org.commontk.xnat
  3. Copyright (c) University College London,
  4. Centre for Medical Image Computing
  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 "ctkXnatObjectPrivate.h"
  17. #include "ctkXnatSession.h"
  18. #include "ctkXnatProject.h"
  19. #include "ctkXnatDefaultSchemaTypes.h"
  20. #include <QDebug>
  21. class ctkXnatDataModelPrivate : public ctkXnatObjectPrivate
  22. {
  23. explicit ctkXnatDataModelPrivate(ctkXnatSession* session);
  24. virtual ~ctkXnatDataModelPrivate();
  25. private:
  26. friend class ctkXnatDataModel;
  27. ctkXnatSession* session;
  28. };
  29. ctkXnatDataModelPrivate::ctkXnatDataModelPrivate(ctkXnatSession* connection)
  30. : ctkXnatObjectPrivate()
  31. , session(connection)
  32. {
  33. }
  34. ctkXnatDataModelPrivate::~ctkXnatDataModelPrivate()
  35. {
  36. }
  37. ctkXnatDataModel::ctkXnatDataModel(ctkXnatSession* session)
  38. : ctkXnatObject(*new ctkXnatDataModelPrivate(session))
  39. {
  40. }
  41. QList<ctkXnatProject*> ctkXnatDataModel::projects() const
  42. {
  43. QList<ctkXnatProject*> result;
  44. foreach(ctkXnatObject* obj, this->children())
  45. {
  46. result.push_back(static_cast<ctkXnatProject*>(obj));
  47. }
  48. return result;
  49. }
  50. QString ctkXnatDataModel::resourceUri() const
  51. {
  52. return "";
  53. }
  54. QString ctkXnatDataModel::childDataType() const
  55. {
  56. return "Projects";
  57. }
  58. void ctkXnatDataModel::fetchImpl()
  59. {
  60. Q_D(ctkXnatDataModel);
  61. QString projectsUri("/data/archive/projects");
  62. QUuid queryId = d->session->httpGet(projectsUri);
  63. QList<ctkXnatObject*> projects = d->session->httpResults(queryId,
  64. ctkXnatDefaultSchemaTypes::XSI_PROJECT);
  65. qDebug() << "ctkXnatDataModel::fetchImpl(): project number:" << projects.size();
  66. foreach (ctkXnatObject* project, projects)
  67. {
  68. this->add(project);
  69. }
  70. }
  71. ctkXnatSession* ctkXnatDataModel::session() const
  72. {
  73. Q_D(const ctkXnatDataModel);
  74. return d->session;
  75. }