Browse Source

xnat: adding the missing methods, still missing some implementations

Nicolas Toussaint 12 years ago
parent
commit
17ccfa1235

+ 7 - 1
Libs/XNAT/Core/ctkXnatExperiment.cpp

@@ -84,5 +84,11 @@ void ctkXnatExperiment::fetchImpl()
 
 void ctkXnatExperiment::remove()
 {
-  //connection->remove(this);
+  // ctkXnatObject::remove();
+  // getConnection()->remove(this);
+}
+
+bool ctkXnatExperiment::isFile() const
+{
+  return false;
 }

+ 9 - 2
Libs/XNAT/Core/ctkXnatExperiment.h

@@ -43,8 +43,15 @@ public:
   const QString& uri() const;
   void setUri(const QString& uri);
   
-  virtual void reset();
-  virtual void remove();
+  void reset();
+  void remove();
+  
+  bool isFile() const;
+
+  /* bool receivesFiles() const; */
+  /* bool holdsFiles() const; */
+  /* bool isDeletable() const; */
+  /* bool isModifiable() const; */
   
 private:
   

+ 52 - 33
Libs/XNAT/Core/ctkXnatObject.cpp

@@ -25,6 +25,21 @@
 #include "ctkXnatServer.h"
 #include <QVariant>
 
+#include <QDebug>
+
+
+
+ctkXnatObject::ctkXnatObject(ctkXnatObjectPrivate& d)
+: d_ptr(&d)
+{
+}
+
+
+ctkXnatObject::ctkXnatObject()
+: d_ptr(new ctkXnatObjectPrivate())
+{
+}
+
 ctkXnatObject::~ctkXnatObject()
 {
 }
@@ -34,6 +49,11 @@ QString ctkXnatObject::getId() const
   return getProperty("ID");
 }
 
+void ctkXnatObject::setId(const QString& id)
+{
+  setProperty("ID", id);
+}
+
 QString ctkXnatObject::getName() const
 {
   return getProperty("name");
@@ -80,10 +100,19 @@ void ctkXnatObject::addChild(ctkXnatObject::Pointer& child)
   child->d_func()->parent = d->selfPtr;
 }
 
+void ctkXnatObject::removeChild(ctkXnatObject::Pointer& child)
+{
+  Q_D(ctkXnatObject);
+  if (!d->children.removeOne(child))
+  {
+    qWarning() << "ctkXnatObject::removeChild(): Child does not exist";
+  }
+}
+
 void ctkXnatObject::reset()
 {
   Q_D(ctkXnatObject);
-  //d->properties.clear();
+  // d->properties.clear();
   d->children.clear();
   d->fetched = false;
 }
@@ -104,25 +133,19 @@ void ctkXnatObject::fetch()
   }
 }
 
-void ctkXnatObject::download(const QString& /*zipFilename*/)
-{
-  // do nothing
-}
-
-void ctkXnatObject::upload(const QString& /*zipFilename*/)
+ctkXnatConnection* ctkXnatObject::getConnection() const
 {
-  // do nothing
-}
+  const ctkXnatObject* xnatObject = this;
+  const ctkXnatServer* server;
+  do {
+    xnatObject = xnatObject->getParent().data();
+    server = dynamic_cast<const ctkXnatServer*>(xnatObject);
+  }
+  while (xnatObject && !server);
 
-void ctkXnatObject::add(const QString& /*name*/)
-{
-  // do nothing
+  return server ? xnatObject->getConnection() : 0;
 }
 
-void ctkXnatObject::remove()
-{
-  // do nothing
-}
 
 bool ctkXnatObject::isFile() const
 {
@@ -149,31 +172,27 @@ bool ctkXnatObject::isDeletable() const
   return false;
 }
 
-ctkXnatObject::ctkXnatObject()
-: d_ptr(new ctkXnatObjectPrivate())
+
+void ctkXnatObject::download(const QString& /*zipFilename*/)
 {
+  // do nothing
+  // if (!this->isFile())
+  //   return;  
 }
 
-ctkXnatObject::ctkXnatObject(ctkXnatObjectPrivate& d)
-: d_ptr(&d)
+void ctkXnatObject::upload(const QString& /*zipFilename*/)
 {
+  // do nothing
+  // if (!this->isFile())
+  //   return;  
 }
 
-ctkXnatConnection* ctkXnatObject::getConnection() const
+void ctkXnatObject::add(const QString& /*name*/)
 {
-  const ctkXnatObject* xnatObject = this;
-  const ctkXnatServer* server;
-  do {
-    xnatObject = xnatObject->getParent().data();
-    server = dynamic_cast<const ctkXnatServer*>(xnatObject);
-  }
-  while (xnatObject && !server);
-
-  return server ? xnatObject->getConnection() : 0;
+  // do nothing
 }
 
-void ctkXnatObject::setId(const QString& id)
+void ctkXnatObject::remove()
 {
-  setProperty("ID", id);
+  // do nothing
 }
-

+ 1 - 0
Libs/XNAT/Core/ctkXnatObject.h

@@ -54,6 +54,7 @@ public:
   QList<ctkXnatObject::Pointer> getChildren() const;
 
   void addChild(Pointer& child);
+  void removeChild(Pointer& child);
 
   bool isFetched() const;
 

+ 7 - 1
Libs/XNAT/Core/ctkXnatProject.cpp

@@ -125,5 +125,11 @@ void ctkXnatProject::fetchImpl()
 
 void ctkXnatProject::remove()
 {
-  //connection->remove(this);
+  // ctkXnatObject::remove();
+  // getConnection()->remove(this);
+}
+
+bool ctkXnatProject::isFile() const
+{
+  return false;
 }

+ 9 - 3
Libs/XNAT/Core/ctkXnatProject.h

@@ -53,9 +53,15 @@ public:
   const QString& uri() const;
   void setUri(const QString& uri);
 
-  virtual void reset();
-
-  virtual void remove();
+  void reset();
+  void remove();
+  
+  bool isFile() const;
+
+  /* bool receivesFiles() const; */
+  /* bool holdsFiles() const; */
+  /* bool isDeletable() const; */
+  /* bool isModifiable() const; */
 
 private:
 

+ 6 - 5
Libs/XNAT/Core/ctkXnatScan.cpp

@@ -84,10 +84,11 @@ void ctkXnatScan::fetchImpl()
 
 void ctkXnatScan::remove()
 {
-  //connection->remove(this);
+  // ctkXnatObject::remove();
+  // getConnection()->remove(this);
 }
 
-// void ctkXnatScan::download(ctkXnatConnection* connection, const QString& zipFileName)
-// {
-//   connection->download(this, zipFileName);
-// }
+bool ctkXnatScan::isFile() const
+{
+  return false;
+}

+ 9 - 2
Libs/XNAT/Core/ctkXnatScan.h

@@ -43,8 +43,15 @@ public:
   const QString& uri() const;
   void setUri(const QString& uri);
   
-  virtual void reset();
-  virtual void remove();
+  void reset();
+  void remove();
+  
+  bool isFile() const;
+
+  /* bool receivesFiles() const; */
+  /* bool holdsFiles() const; */
+  /* bool isDeletable() const; */
+  /* bool isModifiable() const; */
   
 private:
   

+ 6 - 5
Libs/XNAT/Core/ctkXnatScanFolder.cpp

@@ -86,10 +86,11 @@ void ctkXnatScanFolder::fetchImpl()
 
 void ctkXnatScanFolder::remove()
 {
-  //connection->remove(this);
+  // ctkXnatObject::remove();
+  // getConnection()->remove(this);
 }
 
-// void ctkXnatScanFolder::download(ctkXnatConnection* connection, const QString& zipFileName)
-// {
-//   connection->downloadScanFiles(dynamic_cast<ctkXnatExperiment*>(getParent()), zipFileName);
-// }
+bool ctkXnatScanFolder::isFile() const
+{
+  return false;
+}

+ 9 - 2
Libs/XNAT/Core/ctkXnatScanFolder.h

@@ -43,8 +43,15 @@ public:
   const QString& uri() const;
   void setUri(const QString& uri);
   
-  virtual void reset();
-  virtual void remove();
+  void reset();
+  void remove();
+  
+  bool isFile() const;
+
+  /* bool receivesFiles() const; */
+  /* bool holdsFiles() const; */
+  /* bool isDeletable() const; */
+  /* bool isModifiable() const; */
   
 private:
   

+ 6 - 5
Libs/XNAT/Core/ctkXnatScanResource.cpp

@@ -86,10 +86,11 @@ void ctkXnatScanResource::fetchImpl()
 
 void ctkXnatScanResource::remove()
 {
-  //connection->remove(this);
+  // ctkXnatObject::remove();
+  // getConnection()->remove(this);
 }
 
-// void ctkXnatScanResource::download(ctkXnatConnection* connection, const QString& zipFileName)
-// {
-//   connection->download(this, zipFileName);
-// }
+bool ctkXnatScanResource::isFile() const
+{
+  return false;
+}

+ 9 - 2
Libs/XNAT/Core/ctkXnatScanResource.h

@@ -43,8 +43,15 @@ public:
   const QString& uri() const;
   void setUri(const QString& uri);
   
-  virtual void reset();
-  virtual void remove();
+  void reset();
+  void remove();
+  
+  bool isFile() const;
+
+  /* bool receivesFiles() const; */
+  /* bool holdsFiles() const; */
+  /* bool isDeletable() const; */
+  /* bool isModifiable() const; */
   
 private:
   

+ 6 - 6
Libs/XNAT/Core/ctkXnatScanResourceFile.cpp

@@ -42,7 +42,6 @@ public:
   QString uri;
 };
 
-
 ctkXnatScanResourceFile::ctkXnatScanResourceFile()
 : ctkXnatObject(new ctkXnatScanResourceFilePrivate())
 {
@@ -83,10 +82,11 @@ void ctkXnatScanResourceFile::fetchImpl()
 
 void ctkXnatScanResourceFile::remove()
 {
-  //connection->remove(this);
+  // ctkXnatObject::remove();
+  // getConnection()->remove(this);
 }
 
-// void ctkXnatScanResourceFile::download(ctkXnatConnection* connection, const QString& zipFileName)
-// {
-//   connection->download(this, zipFileName);
-// }
+bool ctkXnatScanResourceFile::isFile() const
+{
+  return true;
+}

+ 9 - 2
Libs/XNAT/Core/ctkXnatScanResourceFile.h

@@ -43,8 +43,15 @@ public:
   const QString& uri() const;
   void setUri(const QString& uri);
   
-  virtual void reset();
-  virtual void remove();
+  void reset();
+  void remove();
+  
+  bool isFile() const;
+
+  /* bool receivesFiles() const; */
+  /* bool holdsFiles() const; */
+  /* bool isDeletable() const; */
+  /* bool isModifiable() const; */
   
 private:
   

+ 12 - 0
Libs/XNAT/Core/ctkXnatSubject.cpp

@@ -114,3 +114,15 @@ ctkXnatSubject::Pointer ctkXnatSubject::Create()
   subject->d_func()->selfPtr = subject;
   return subject;
 }
+
+
+void ctkXnatSubject::remove()
+{
+  // ctkXnatObject::remove();
+  // getConnection()->remove(this);
+}
+
+bool ctkXnatSubject::isFile() const
+{
+  return false;
+}

+ 10 - 2
Libs/XNAT/Core/ctkXnatSubject.h

@@ -53,8 +53,16 @@ public:
   const QString& uri() const;
   void setUri(const QString& uri);
 
-  virtual void reset();
-
+  void reset();
+  void remove();
+  
+  bool isFile() const;
+
+  /* bool receivesFiles() const; */
+  /* bool holdsFiles() const; */
+  /* bool isDeletable() const; */
+  /* bool isModifiable() const; */
+  
 private:
 
   friend class qRestResult;

+ 97 - 1
Libs/XNAT/Widgets/ctkXnatTreeModel.cpp

@@ -25,7 +25,6 @@
 #include "ctkXnatObject.h"
 #include "ctkXnatSubject.h"
 
-#include <QDebug>
 #include <QList>
 
 ctkXnatTreeModel::ctkXnatTreeModel()
@@ -204,3 +203,100 @@ ctkXnatTreeItem* ctkXnatTreeModel::itemAt(const QModelIndex& index) const
 {
   return static_cast<ctkXnatTreeItem*>(index.internalPointer());
 }
+
+
+bool ctkXnatTreeModel::removeAllRows(const QModelIndex& parent)
+{
+  // do nothing for the root
+  if ( !parent.isValid() )
+  {
+    return false;
+  }
+
+  ctkXnatTreeItem* item = this->itemAt(parent);
+  ctkXnatObject::Pointer xnatObject = item->xnatObject();
+
+  // nt: not sure why the parent.row() is used here instead of the first item in list
+  // that is xnatObject->getChildren()[0];
+  ctkXnatObject::Pointer child = xnatObject->getChildren()[parent.row()];
+
+  if ( child == NULL )
+  {
+    return false;
+  }
+
+  int numberofchildren = child->getChildren().size();
+  if (numberofchildren > 0)
+  {
+    beginRemoveRows(parent, 0, numberofchildren - 1);
+    // xnatObject->removeChild(parent.row());
+    // nt: not sure if this is the right implementation here, should iterate ?
+    xnatObject->removeChild(child);
+    endRemoveRows();
+  }
+  else
+  {
+    // xnatObject->removeChild(parent.row());
+    // nt: not sure if this is the right implementation here, should iterate ?
+    xnatObject->removeChild(child);
+  }
+  return true;
+}
+
+void ctkXnatTreeModel::downloadFile(const QModelIndex& index, const QString& zipFilename)
+{
+  if ( !index.isValid() )
+  {
+    return;
+  }
+
+  ctkXnatTreeItem* item = this->itemAt(index);
+  ctkXnatObject::Pointer xnatObject = item->xnatObject();
+  ctkXnatObject::Pointer child = xnatObject->getChildren()[index.row()];
+  
+  child->download (zipFilename);
+
+  return;
+}
+
+void ctkXnatTreeModel::uploadFile(const QModelIndex& index, const QString& zipFilename)
+{
+  if ( !index.isValid() )
+  {
+    return;
+  }
+
+  ctkXnatTreeItem* item = this->itemAt(index);
+  ctkXnatObject::Pointer xnatObject = item->xnatObject();
+  ctkXnatObject::Pointer child = xnatObject->getChildren()[index.row()];
+  
+  child->upload(zipFilename);
+}
+
+void ctkXnatTreeModel::addEntry(const QModelIndex& index, const QString& name)
+{
+  if ( !index.isValid() )
+  {
+    return;
+  }
+
+  ctkXnatTreeItem* item = this->itemAt(index);
+  ctkXnatObject::Pointer xnatObject = item->xnatObject();
+  ctkXnatObject::Pointer child = xnatObject->getChildren()[index.row()];
+
+  child->add(name);
+}
+
+void ctkXnatTreeModel::removeEntry(const QModelIndex& index)
+{
+  if ( !index.isValid() )
+  {
+    return;
+  }
+
+  ctkXnatTreeItem* item = this->itemAt(index);
+  ctkXnatObject::Pointer xnatObject = item->xnatObject();
+  ctkXnatObject::Pointer child = xnatObject->getChildren()[index.row()];
+
+  child->remove();
+}

+ 9 - 1
Libs/XNAT/Widgets/ctkXnatTreeModel.h

@@ -46,9 +46,17 @@ public:
   virtual bool hasChildren(const QModelIndex& parent) const;
   virtual bool canFetchMore(const QModelIndex& parent) const;
   virtual void fetchMore(const QModelIndex& parent);
-
+  
   void addServer(ctkXnatServer::Pointer server);
 
+  void addEntry (const QModelIndex& index, const QString& name);
+  void removeEntry (const QModelIndex& index);
+
+  bool removeAllRows (const QModelIndex& parent);
+
+  void uploadFile (const QModelIndex& index, const QString& zipFilename);
+  void downloadFile (const QModelIndex& index, const QString& zipFilename);
+  
 private:
 
   ctkXnatTreeItem* itemAt(const QModelIndex& index) const;