ctkXnatObject.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. #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. #define CTK_XNAT_OBJECT(classType_, baseType_, schemaType_) \
  26. classType_(const classType_& other) : baseType_(other) { throw ctkRuntimeException("Copy constructor not implemented"); } \
  27. static const char* staticSchemaType() { return schemaType_; } \
  28. virtual const char* schemaType() const { return schemaType_; }
  29. //----------------------------------------------------------------------------
  30. /// \ingroup XNATCore
  31. /// ctkXnatObject is the base class of the objects that represent the nodes in
  32. /// the XNAT data hierarchy.
  33. class CTK_XNAT_CORE_EXPORT ctkXnatObject
  34. {
  35. public:
  36. /// No-op. Throws a ctkRuntimeException
  37. ctkXnatObject(const ctkXnatObject& other);
  38. /// Destructs the ctkXnatObject.
  39. virtual ~ctkXnatObject();
  40. /// Get the dynamic schema type of object.
  41. virtual const char* schemaType() const = 0;
  42. /// Gets the ID of the object.
  43. QString id() const;
  44. /// Sets the ID of the object.
  45. void setId(const QString& id);
  46. /// Gets the resource URI of the object that can be used to access it through
  47. /// the REST API.
  48. virtual QString resourceUri() const = 0;
  49. /// Gets the name of the object.
  50. QString name() const;
  51. /// Sets the name of the object.
  52. void setName(const QString& name);
  53. /// Gets the description of the object.
  54. QString description() const;
  55. /// Sets the description of the object.
  56. void setDescription(const QString& description);
  57. /// Gets the value of the property with the given name.
  58. QString property(const QString& name) const;
  59. /// Sets the value of the property with the given name.
  60. void setProperty(const QString& name, const QVariant& value);
  61. /// Gets the properties of the object.
  62. const QMap<QString, QString>& properties() const;
  63. /// Gets the parent of the object in the data hierarchy. The returned pointer
  64. /// is 0 for the ctkXnatServer objects and different for any other type of
  65. /// XNAT objects.
  66. ctkXnatObject* parent() const;
  67. /// Sets the parent of the object in the data hierarchy.
  68. void setParent(ctkXnatObject* parent);
  69. /// Gets the children of the object.
  70. QList<ctkXnatObject*> children() const;
  71. /// Adds an object to the children of the current one.
  72. void add(ctkXnatObject* child);
  73. /// Removes the object from the children of the current object and removes it from the XNAT server.
  74. void remove(ctkXnatObject* child);
  75. /// Tells if the children and the properties of the objects have been fetched.
  76. bool isFetched() const;
  77. /// Resets the object so that its properties and children needs to be fetched
  78. /// again at the next request.
  79. virtual void reset();
  80. /// Fetches the children and the properties of the object.
  81. void fetch();
  82. /// Checks if the object exists on the XNAT server.
  83. bool exists() const;
  84. /// Creates the object on the XNAT server and sets the new ID.
  85. void save();
  86. /// Deletes the object on the XNAT server and removes it from its parent.
  87. void erase();
  88. virtual void download(const QString&);
  89. virtual void upload(const QString&);
  90. //QObject* asyncObject() const;
  91. // *********************
  92. // Add signals for async API
  93. //Q_SIGNAL downloadFinished(const QString&);
  94. // *********************
  95. // SLOTS for async error handling
  96. //Q_SLOT serverError(XnatError errorType, const QString& message);
  97. // *********************
  98. // Add blocking methods
  99. // throws ctkXnatTimeoutException
  100. //bool waitForDownloadFinished(const QString&);
  101. protected:
  102. /// Constructs the ctkXnatObject.
  103. ctkXnatObject(ctkXnatObject* parent = 0);
  104. /// Constructs the ctkXnatObject with the given private part.
  105. ctkXnatObject(ctkXnatObjectPrivate& dd, ctkXnatObject* parent = 0);
  106. /// Gets the object that represents the connection to the XNAT server
  107. /// that stores the current object.
  108. ctkXnatSession* session() const;
  109. /// The private implementation part of the object.
  110. const QScopedPointer<ctkXnatObjectPrivate> d_ptr;
  111. private:
  112. friend class ctkXnatConnection;
  113. /// The implementation of the fetch mechanism, called by the fetch() function.
  114. virtual void fetchImpl() = 0;
  115. Q_DECLARE_PRIVATE(ctkXnatObject)
  116. };
  117. Q_DECLARE_METATYPE(ctkXnatObject*)
  118. #endif