ctkXnatDataModel.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 <QDebug>
  20. class ctkXnatDataModelPrivate : public ctkXnatObjectPrivate
  21. {
  22. explicit ctkXnatDataModelPrivate(ctkXnatSession* session);
  23. virtual ~ctkXnatDataModelPrivate();
  24. private:
  25. friend class ctkXnatDataModel;
  26. ctkXnatSession* session;
  27. };
  28. ctkXnatDataModelPrivate::ctkXnatDataModelPrivate(ctkXnatSession* connection)
  29. : ctkXnatObjectPrivate()
  30. , session(connection)
  31. {
  32. }
  33. ctkXnatDataModelPrivate::~ctkXnatDataModelPrivate()
  34. {
  35. }
  36. ctkXnatDataModel::ctkXnatDataModel(ctkXnatSession* session)
  37. : ctkXnatObject(*new ctkXnatDataModelPrivate(session))
  38. {
  39. }
  40. QList<ctkXnatProject*> ctkXnatDataModel::projects() const
  41. {
  42. QList<ctkXnatProject*> result;
  43. foreach(ctkXnatObject* obj, this->children())
  44. {
  45. result.push_back(static_cast<ctkXnatProject*>(obj));
  46. }
  47. return result;
  48. }
  49. QString ctkXnatDataModel::resourceUri() const
  50. {
  51. return "";
  52. }
  53. void ctkXnatDataModel::fetchImpl()
  54. {
  55. Q_D(ctkXnatDataModel);
  56. QString projectsUri("/data/archive/projects");
  57. QUuid queryId = d->session->httpGet(projectsUri);
  58. QList<ctkXnatObject*> projects = d->session->httpResults(queryId, ctkXnatProject::staticSchemaType());
  59. qDebug() << "ctkXnatDataModel::fetchImpl(): project number:" << projects.size();
  60. foreach (ctkXnatObject* project, projects)
  61. {
  62. this->add(project);
  63. }
  64. }
  65. ctkXnatSession* ctkXnatDataModel::session() const
  66. {
  67. Q_D(const ctkXnatDataModel);
  68. return d->session;
  69. }