瀏覽代碼

Deleted the no more necessary ctkXnatProjectsListModel.
Added a virtual method to ctkXnatObject for getting the child type.
Overwrited this method in ctkXnatDataModel and ctkXnatProject.

Daniel Knorr 11 年之前
父節點
當前提交
56fa131ce6

+ 5 - 0
Libs/XNAT/Core/ctkXnatDataModel.cpp

@@ -69,6 +69,11 @@ QString ctkXnatDataModel::resourceUri() const
   return "";
 }
 
+QString ctkXnatDataModel::childDataType() const
+{
+  return "Projects";
+}
+
 void ctkXnatDataModel::fetchImpl()
 {
   Q_D(ctkXnatDataModel);

+ 2 - 0
Libs/XNAT/Core/ctkXnatDataModel.h

@@ -41,6 +41,8 @@ public:
 
   ctkXnatSession* session() const;
 
+  virtual QString childDataType() const;
+
 private:
 
   QString resourceUri() const;

+ 5 - 0
Libs/XNAT/Core/ctkXnatObject.cpp

@@ -86,6 +86,11 @@ void ctkXnatObject::setDescription(const QString& description)
   setProperty("description", description);
 }
 
+QString ctkXnatObject::childDataType() const
+{
+  return "Resources";
+}
+
 QString ctkXnatObject::property(const QString& name) const
 {
   Q_D(const ctkXnatObject);

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

@@ -99,6 +99,9 @@ public:
 
   QString schemaType() const;
 
+  /// Gets a human readable name of the child object type.
+  virtual QString childDataType() const;
+
   /// Resets the object so that its properties and children needs to be fetched
   /// again at the next request.
   virtual void reset();

+ 5 - 0
Libs/XNAT/Core/ctkXnatProject.cpp

@@ -64,6 +64,11 @@ QString ctkXnatProject::resourceUri() const
   return QString("%1/data/archive/projects/%2").arg(parent()->resourceUri(), this->id());
 }
 
+QString ctkXnatProject::childDataType() const
+{
+  return "Subjects";
+}
+
 const QString& ctkXnatProject::secondaryId() const
 {
   Q_D(const ctkXnatProject);

+ 2 - 0
Libs/XNAT/Core/ctkXnatProject.h

@@ -41,6 +41,8 @@ public:
 
   virtual QString resourceUri() const;
 
+  virtual QString childDataType() const;
+
   const QString& secondaryId() const;
   void setSecondaryId(const QString& secondaryId);
 

+ 0 - 2
Libs/XNAT/Widgets/CMakeLists.txt

@@ -9,7 +9,6 @@ set(KIT_export_directive "CTK_XNAT_WIDGETS_EXPORT")
 set(KIT_SRCS
   ctkXnatLoginDialog.cpp
   ctkXnatTreeItem.cpp
-  ctkXnatProjectListModel.cpp
   ctkXnatTreeModel.cpp
   ctkXnatSettings.cpp
   ctkXnatListModel.cpp
@@ -18,7 +17,6 @@ set(KIT_SRCS
 # Files which should be processed by Qts moc
 set(KIT_MOC_SRCS
   ctkXnatLoginDialog.h
-  ctkXnatProjectListModel.h
   ctkXnatTreeModel.h
   ctkXnatListModel.h
 )

+ 11 - 42
Libs/XNAT/Widgets/ctkXnatListModel.cpp

@@ -34,33 +34,33 @@
 #include <QDebug>
 
 ctkXnatListModel::ctkXnatListModel()
-  : rootObject(0)
+  : RootObject(0)
 {
 }
 
 void ctkXnatListModel::setRootObject(ctkXnatObject* root)
 {
-  rootObject = root;
+  RootObject = root;
 }
 
-ctkXnatObject* ctkXnatListModel::getRootObject()
+ctkXnatObject* ctkXnatListModel::rootObject()
 {
-  return rootObject;
+  return RootObject;
 }
 
 int ctkXnatListModel::rowCount(const QModelIndex& /*parent*/) const
 {
-  if (!rootObject) return 0;
-  return rootObject->children().size();
+  if (!RootObject) return 0;
+  return RootObject->children().size();
 }
 
 QVariant ctkXnatListModel::data(const QModelIndex& index, int role) const
 {
-  if (!rootObject) return QVariant();
+  if (!RootObject) return QVariant();
 
   if (role == Qt::DisplayRole)
   {
-    ctkXnatObject* child = rootObject->children().at(index.row());
+    ctkXnatObject* child = RootObject->children().at(index.row());
     if (!child)
     {
       qWarning() << "child at index" << index << "is NULL!";
@@ -77,7 +77,7 @@ QVariant ctkXnatListModel::data(const QModelIndex& index, int role) const
   }
   else if (role == Qt::UserRole)
   {
-    return QVariant::fromValue(rootObject->children().at(index.row()));
+    return QVariant::fromValue(RootObject->children().at(index.row()));
   }
   return QVariant();
 }
@@ -86,40 +86,9 @@ QVariant ctkXnatListModel::headerData(int /*section*/, Qt::Orientation /*orienta
 {
   if (role == Qt::DisplayRole)
   {
-    if (!rootObject) return QString("Unavailable");
+    if (!RootObject) return QString("Unavailable");
 
-    if( dynamic_cast<ctkXnatDataModel*>(rootObject) != NULL )
-    {
-      return QString("Projects");
-    }
-    else if( dynamic_cast<ctkXnatProject*>(rootObject) != NULL )
-    {
-      return QString("Subjects");
-    }
-    else if( dynamic_cast<ctkXnatSubject*>(rootObject) != NULL )
-    {
-      return QString("Experiments");
-    }
-    else if( dynamic_cast<ctkXnatExperiment*>(rootObject) != NULL )
-    {
-      return QString("Kinds of data");
-    }
-    else if( dynamic_cast<ctkXnatScanFolder*>(rootObject) != NULL )
-    {
-      return QString("Image Sessions");
-    }
-    else if( dynamic_cast<ctkXnatScan*>(rootObject) != NULL )
-    {
-      return QString("Resource Folders");
-    }
-    else if( dynamic_cast<ctkXnatScanResource*>(rootObject) != NULL )
-    {
-      return QString("Files");
-    }
-    else
-    {
-      return QString("ERROR");
-    }
+    return RootObject->childDataType();
   }
   return QVariant();
 }

+ 5 - 5
Libs/XNAT/Widgets/ctkXnatListModel.h

@@ -19,8 +19,8 @@
 
 =============================================================================*/
 
-#ifndef CTKXNATPROJECTLISTMODEL_H
-#define CTKXNATPROJECTLISTMODEL_H
+#ifndef CTKXNATLISTMODEL_H
+#define CTKXNATLISTMODEL_H
 
 #include "QAbstractListModel"
 
@@ -35,14 +35,14 @@ class CTK_XNAT_WIDGETS_EXPORT ctkXnatListModel : public QAbstractListModel
 public:
   ctkXnatListModel();
   void setRootObject(ctkXnatObject* root);
-  ctkXnatObject* getRootObject();
+  ctkXnatObject* rootObject();
 
   int rowCount(const QModelIndex &parent) const;
   QVariant data(const QModelIndex &index, int role) const;
   QVariant headerData(int section, Qt::Orientation orientation, int role) const;
 
 private:
-  ctkXnatObject* rootObject;
+  ctkXnatObject* RootObject;
 };
 
-#endif // CTKXNATPROJECTLISTMODEL_H
+#endif // CTKXNATLISTMODEL_H

+ 0 - 81
Libs/XNAT/Widgets/ctkXnatProjectListModel.cpp

@@ -1,81 +0,0 @@
-/*=============================================================================
-
-  Library: CTK
-
-  Copyright (c) German Cancer Research Center,
-    Division of Medical and Biological Informatics
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-
-=============================================================================*/
-
-#include "ctkXnatProjectListModel.h"
-
-#include "ctkXnatProject.h"
-
-#include <QDebug>
-
-ctkXnatProjectListModel::ctkXnatProjectListModel()
-  : rootObject(0)
-{
-}
-
-void ctkXnatProjectListModel::setRootObject(ctkXnatObject* root)
-{
-  rootObject = root;
-}
-
-int ctkXnatProjectListModel::rowCount(const QModelIndex& /*parent*/) const
-{
-  if (!rootObject) return 0;
-  return rootObject->children().size();
-}
-
-QVariant ctkXnatProjectListModel::data(const QModelIndex& index, int role) const
-{
-  if (!rootObject) return QVariant();
-
-  if (role == Qt::DisplayRole)
-  {
-    ctkXnatObject* child = rootObject->children().at(index.row());
-    if (!child)
-    {
-      qWarning() << "child at index" << index << "is NULL!";
-    }
-    else
-    {
-      QString displayData = child->name();
-      if (displayData.isEmpty())
-      {
-        displayData = child->id();
-      }
-      return displayData;
-    }
-  }
-  else if (role == Qt::UserRole)
-  {
-    return QVariant::fromValue(rootObject->children().at(index.row()));
-  }
-  return QVariant();
-}
-
-QVariant ctkXnatProjectListModel::headerData(int /*section*/, Qt::Orientation /*orientation*/, int role) const
-{
-  if (role == Qt::DisplayRole)
-  {
-    if (!rootObject) return QString("Unavailable");
-    return QString("Bla");
-  }
-  return QVariant();
-}
-

+ 0 - 49
Libs/XNAT/Widgets/ctkXnatProjectListModel.h

@@ -1,49 +0,0 @@
-/*=============================================================================
-
-  Library: CTK
-
-  Copyright (c) German Cancer Research Center,
-    Division of Medical and Biological Informatics
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-
-=============================================================================*/
-
-#ifndef CTKXNATPROJECTLISTMODEL_H
-#define CTKXNATPROJECTLISTMODEL_H
-
-#include "QAbstractListModel"
-
-#include "ctkXNATWidgetsExport.h"
-
-class ctkXnatObject;
-
-class CTK_XNAT_WIDGETS_EXPORT ctkXnatProjectListModel : public QAbstractListModel
-{
-  Q_OBJECT
-
-public:
-  ctkXnatProjectListModel();
-  void setRootObject(ctkXnatObject* root);
-
-  int rowCount(const QModelIndex &parent) const;
-  QVariant data(const QModelIndex &index, int role) const;
-  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
-
-private:
-
-  ctkXnatObject* rootObject;
-
-};
-
-#endif // CTKXNATPROJECTLISTMODEL_H