ctkXnatObject.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 <QList>
  19. #include <QObject>
  20. #include <QString>
  21. #include <QMetaType>
  22. class ctkXnatConnection;
  23. class ctkXnatObjectPrivate;
  24. //----------------------------------------------------------------------------
  25. /// \ingroup XNATCore
  26. /// ctkXnatObject is the base class of the objects that represent the nodes in
  27. /// the XNAT data hierarchy.
  28. class CTK_XNAT_CORE_EXPORT ctkXnatObject
  29. {
  30. public:
  31. /// Destructs the ctkXnatObject.
  32. virtual ~ctkXnatObject();
  33. /// Gets the XML Schema type of the object.
  34. QString schemaType() const;
  35. /// Gets the ID of the object.
  36. QString id() const;
  37. /// Sets the ID of the object.
  38. void setId(const QString& id);
  39. /// Gets the resource URI of the object that can be used to access it through
  40. /// the REST API.
  41. virtual QString resourceUri() const = 0;
  42. /// Gets the name of the object.
  43. QString name() const;
  44. /// Sets the name of the object.
  45. void setName(const QString& name);
  46. /// Gets the description of the object.
  47. QString description() const;
  48. /// Sets the description of the object.
  49. void setDescription(const QString& description);
  50. /// Gets the value of the property with the given name.
  51. QString property(const QString& name) const;
  52. /// Sets the value of the property with the given name.
  53. void setProperty(const QString& name, const QVariant& value);
  54. /// Gets the properties of the object.
  55. const QMap<QString, QString>& properties() const;
  56. /// Gets the parent of the object in the data hierarchy. The returned pointer
  57. /// is 0 for the ctkXnatServer objects and different for any other type of
  58. /// XNAT objects.
  59. ctkXnatObject* parent() const;
  60. /// Sets the parent of the object in the data hierarchy.
  61. void setParent(ctkXnatObject* parent);
  62. /// Gets the children of the object.
  63. QList<ctkXnatObject*> children() const;
  64. /// Adds an object to the children of the current one.
  65. void add(ctkXnatObject* child);
  66. /// Removes the object from the children of the current object and removes it from the XNAT server.
  67. void remove(ctkXnatObject* child);
  68. /// Tells if the children and the properties of the objects have been fetched.
  69. bool isFetched() const;
  70. /// Resets the object so that its properties and children needs to be fetched
  71. /// again at the next request.
  72. virtual void reset();
  73. /// Fetches the children and the properties of the object.
  74. void fetch();
  75. /// Checks if the object exists on the XNAT server.
  76. bool exists() const;
  77. /// Creates the object on the XNAT server and sets the new ID.
  78. void save();
  79. /// Deletes the object on the XNAT server and removes it from its parent.
  80. void erase();
  81. virtual void download(const QString&);
  82. virtual void upload(const QString&);
  83. protected:
  84. /// Constructs the ctkXnatObject.
  85. ctkXnatObject(ctkXnatObject* parent = 0, const QString& schemaType = QString());
  86. /// Constructs the ctkXnatObject with the given private part.
  87. ctkXnatObject(ctkXnatObjectPrivate& dd, ctkXnatObject* parent = 0, const QString& schemaType = QString());
  88. /// Gets the object that represents the connection to the XNAT server
  89. /// that stores the current object.
  90. virtual ctkXnatConnection* connection() const;
  91. /// The private implementation part of the object.
  92. const QScopedPointer<ctkXnatObjectPrivate> d_ptr;
  93. private:
  94. friend class ctkXnatConnection;
  95. /// The implementation of the fetch mechanism, called by the fetch() function.
  96. virtual void fetchImpl() = 0;
  97. Q_DECLARE_PRIVATE(ctkXnatObject)
  98. Q_DISABLE_COPY(ctkXnatObject)
  99. };
  100. Q_DECLARE_METATYPE(ctkXnatObject*)
  101. #endif