ctkXnatObject.h 4.1 KB

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