24 #include <ctkXnatDataModel.h>
25 #include <ctkXnatExperiment.h>
26 #include <ctkXnatFile.h>
27 #include <ctkXnatProject.h>
28 #include <ctkXnatResource.h>
29 #include <ctkXnatResourceCatalogXmlParser.h>
30 #include <ctkXnatResourceFolder.h>
31 #include <ctkXnatScan.h>
32 #include <ctkXnatScanFolder.h>
33 #include <ctkXnatSubject.h>
42 const QModelIndex &start,
int role,
const QVariant &value,
int hits, Qt::MatchFlags flags)
const
44 QModelIndexList result;
45 uint matchType = flags & 0x0F;
46 Qt::CaseSensitivity cs = flags & Qt::MatchCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
47 bool recurse = flags & Qt::MatchRecursive;
48 bool wrap = flags & Qt::MatchWrap;
49 bool allHits = (hits == -1);
51 QModelIndex p = parent(start);
52 int from = start.row();
56 for (
int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i)
58 for (
int r = from; (r < to) && (allHits || result.count() < hits); ++r)
60 QModelIndex idx = index(r, start.column(), p);
63 QVariant v =
data(idx, role);
65 if (matchType == Qt::MatchExactly)
73 text = value.toString();
74 QString t = v.toString();
78 if (!QRegExp(text, cs).exactMatch(t))
81 case Qt::MatchWildcard:
82 if (!QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t))
85 case Qt::MatchStartsWith:
86 if (!t.startsWith(text, cs))
89 case Qt::MatchEndsWith:
90 if (!t.endsWith(text, cs))
93 case Qt::MatchFixedString:
94 if (!t.compare(text, cs) == 0)
97 case Qt::MatchContains:
99 if (!t.contains(text, cs))
103 if (recurse && hasChildren(idx))
105 result +=
match(index(0, idx.column(), idx),
107 (text.isEmpty() ? value : text),
108 (allHits ? -1 : hits - result.count()),
123 ctkXnatTreeModel::fetchMore(index);
125 catch (ctkRuntimeException e)
134 if (!index.isValid())
139 if (role == Qt::DecorationRole)
141 ctkXnatObject *xnatObject = this->xnatObject(index);
144 if (dynamic_cast<ctkXnatDataModel *>(xnatObject))
146 path =
":/xnat-module/xnat-server.png";
148 else if (dynamic_cast<ctkXnatProject *>(xnatObject))
150 path =
":/xnat-module/xnat-project.png";
152 else if (dynamic_cast<ctkXnatSubject *>(xnatObject))
154 path =
":/xnat-module/xnat-subject.png";
156 else if (dynamic_cast<ctkXnatExperiment *>(xnatObject))
158 path =
":/xnat-module/xnat-experiment.png";
160 else if (dynamic_cast<ctkXnatResourceFolder *>(xnatObject))
162 path =
":/xnat-module/xnat-folder.png";
164 else if (dynamic_cast<ctkXnatResource *>(xnatObject))
166 path =
":/xnat-module/xnat-resource.png";
168 else if (dynamic_cast<ctkXnatScanFolder *>(xnatObject))
170 path =
":/xnat-module/xnat-folder.png";
172 else if (dynamic_cast<ctkXnatScan *>(xnatObject))
174 path =
":/xnat-module/xnat-scan.png";
176 else if (dynamic_cast<ctkXnatFile *>(xnatObject))
178 path =
":/xnat-module/xnat-file.png";
182 return ctkXnatTreeModel::data(index, role);
186 const QMimeData *data, Qt::DropAction action,
int ,
int ,
const QModelIndex &parent)
188 if (action == Qt::IgnoreAction)
192 bool returnVal(
false);
198 ctkXnatObject *parentXnatObj = this->xnatObject(parent);
206 return Qt::CopyAction;
211 Qt::ItemFlags defaultFlags = ctkXnatTreeModel::flags(index);
215 bool droppingAllowed =
dynamic_cast<ctkXnatSubject *
>(this->xnatObject(index)) !=
nullptr;
216 droppingAllowed |=
dynamic_cast<ctkXnatExperiment *
>(this->xnatObject(index)) !=
nullptr;
217 droppingAllowed |=
dynamic_cast<ctkXnatResource *
>(this->xnatObject(index)) !=
nullptr;
218 droppingAllowed |=
dynamic_cast<ctkXnatResourceFolder *
>(this->xnatObject(index)) !=
nullptr;
223 return Qt::ItemIsDropEnabled | defaultFlags;
234 ctkXnatObject *QmitkXnatTreeModel::InternalGetXnatObjectFromUrl(
const QString &xnatObjectType,
236 ctkXnatObject *parent)
239 int start = url.lastIndexOf(xnatObjectType);
243 start += xnatObjectType.length();
244 int length = url.indexOf(
"/", start);
248 QList<ctkXnatObject *> children = parent->children();
249 foreach (ctkXnatObject *child, children)
251 if (url.indexOf(child->resourceUri()) != -1)
261 QModelIndex index = this->index(0, 0, QModelIndex());
262 ctkXnatObject *currentXnatObject =
nullptr;
263 currentXnatObject = this->xnatObject(index);
264 if (currentXnatObject !=
nullptr)
267 ctkXnatObject *project =
nullptr;
268 project = this->InternalGetXnatObjectFromUrl(
"projects/", url, currentXnatObject);
271 ctkXnatObject *subject =
nullptr;
272 if (project !=
nullptr)
274 currentXnatObject = project;
275 subject = this->InternalGetXnatObjectFromUrl(
"subjects/", url, project);
279 ctkXnatObject *experiment =
nullptr;
280 if (subject !=
nullptr)
282 currentXnatObject = subject;
283 experiment = this->InternalGetXnatObjectFromUrl(
"experiments/", url, subject);
287 ctkXnatObject *scan =
nullptr;
288 if (experiment !=
nullptr)
290 currentXnatObject = experiment;
291 scan = this->InternalGetXnatObjectFromUrl(
"scans/", url, experiment);
297 QList<ctkXnatObject *> scans = scan->children();
298 foreach (ctkXnatObject *child, scans)
300 if (url.indexOf(child->resourceUri()) != -1)
307 currentXnatObject->fetch();
308 QList<ctkXnatObject *> bla = currentXnatObject->children();
309 foreach (ctkXnatObject *child, bla)
311 if (child->name() ==
"Resources")
void Error(const QModelIndex &idx)
ctkXnatObject * GetXnatObjectFromUrl(const QString &)
virtual Qt::DropActions supportedDropActions()
static QList< mitk::DataNode * > ToDataNodePtrList(const QByteArray &ba)
static const QString DataNodePtrs
QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const override
virtual Qt::ItemFlags flags(const QModelIndex &index) const
void fetchMore(const QModelIndex &index) override
static bool HandleErrorMessage(const char *_errorMsg)
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
void ResourceDropped(const QList< mitk::DataNode * > &, ctkXnatObject *, const QModelIndex &)
virtual QVariant data(const QModelIndex &index, int role) const