ctkXnatObject.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*=============================================================================
  2. Library: XNAT/Core
  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. #ifndef ctkXnatObject_h
  16. #define ctkXnatObject_h
  17. #include "ctkXNATCoreExport.h"
  18. #include "ctkException.h"
  19. #include <QList>
  20. #include <QObject>
  21. #include <QString>
  22. #include <QMetaType>
  23. class ctkXnatSession;
  24. class ctkXnatObjectPrivate;
  25. /**
  26. * @ingroup XNAT_Core
  27. *
  28. * ctkXnatObject is the base class of the objects that represent the nodes in
  29. * the XNAT data hierarchy.
  30. */
  31. class CTK_XNAT_CORE_EXPORT ctkXnatObject
  32. {
  33. public:
  34. /// Destructs the ctkXnatObject.
  35. virtual ~ctkXnatObject();
  36. /// Gets the global ID of the object.
  37. QString id() const;
  38. /// Sets the ID of the object.
  39. /// @warning You must not change the ID of an existing object
  40. void setId(const QString& id);
  41. /// Gets the resource URI of the object that can be used to access it through
  42. /// the REST API.
  43. virtual QString resourceUri() const = 0;
  44. /// Gets the name of the object.
  45. virtual QString name() const;
  46. /// Sets the name of the object.
  47. virtual void setName(const QString& name);
  48. /// Gets the description of the object.
  49. QString description() const;
  50. /// Sets the description of the object.
  51. void setDescription(const QString& description);
  52. /// Gets the value of the property with the given name.
  53. QString property(const QString& name) const;
  54. /// Sets the value of the property with the given name.
  55. void setProperty(const QString& name, const QVariant& value);
  56. /// Gets the last modification time from the server
  57. QDateTime lastModifiedTime();
  58. /// Sets the last modfication time on the server
  59. void setLastModifiedTime(const QDateTime& lastModifiedTime);
  60. /// Gets the properties of the object.
  61. const QMap<QString, QString>& properties() const;
  62. /// Gets the parent of the object in the data hierarchy. The returned pointer
  63. /// is 0 for the ctkXnatServer objects and different for any other type of
  64. /// XNAT objects.
  65. ctkXnatObject* parent() const;
  66. /// Sets the parent of the object in the data hierarchy.
  67. void setParent(ctkXnatObject* parent);
  68. /// Gets the children of the object.
  69. QList<ctkXnatObject*> children() const;
  70. /// Adds an object to the children of the current one.
  71. void add(ctkXnatObject* child);
  72. /// Removes the object from the children of the current object and removes it from the XNAT server.
  73. void remove(ctkXnatObject* child);
  74. /// Tells if the children and the properties of the objects have been fetched.
  75. bool isFetched() const;
  76. QString schemaType() const;
  77. /// Gets a human readable name of the child object type.
  78. virtual QString childDataType() const;
  79. /// Resets the object so that its properties and children needs to be fetched
  80. /// again at the next request.
  81. virtual void reset();
  82. /// Fetches the children and the properties of the object.
  83. void fetch();
  84. /// Checks if the object exists on the XNAT server.
  85. bool exists() const;
  86. /// Creates the object on the XNAT server and sets the new ID.
  87. void save();
  88. /// Deletes the object on the XNAT server and removes it from its parent.
  89. void erase();
  90. virtual void download(const QString&);
  91. virtual void upload(const QString&);
  92. //QObject* asyncObject() const;
  93. // *********************
  94. // Add signals for async API
  95. //Q_SIGNAL downloadFinished(const QString&);
  96. // *********************
  97. // SLOTS for async error handling
  98. //Q_SLOT serverError(XnatError errorType, const QString& message);
  99. // *********************
  100. // Add blocking methods
  101. // throws ctkXnatTimeoutException
  102. //bool waitForDownloadFinished(const QString&);
  103. protected:
  104. ctkXnatObject(const ctkXnatObject&);
  105. /// Constructs the ctkXnatObject.
  106. ctkXnatObject(ctkXnatObject* parent = 0, const QString& schemaType = QString::null);
  107. /// Constructs the ctkXnatObject with the given private part.
  108. ctkXnatObject(ctkXnatObjectPrivate& dd, ctkXnatObject* parent = 0, const QString& schemaType = QString::null);
  109. /// Gets the object that represents the connection to the XNAT server
  110. /// that stores the current object.
  111. ctkXnatSession* session() const;
  112. /// Fetches the resources of the object
  113. virtual void fetchResources(const QString &path = "/resources");
  114. /// The private implementation part of the object.
  115. const QScopedPointer<ctkXnatObjectPrivate> d_ptr;
  116. private:
  117. friend class ctkXnatSessionPrivate;
  118. void setSchemaType(const QString& schemaType);
  119. /// The implementation of the fetch mechanism, called by the fetch() function.
  120. virtual void fetchImpl() = 0;
  121. Q_DECLARE_PRIVATE(ctkXnatObject)
  122. };
  123. Q_DECLARE_METATYPE(ctkXnatObject*)
  124. #endif