Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
orthanc-qt/orthancitem.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
261 lines (215 sloc)
6.91 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "orthancitem.hpp" | |
#include <QJsonArray> | |
#include <QJsonObject> | |
#include <QApplication> | |
bool itemSortLess(const OrthancNode *left, const OrthancNode *right) | |
{ | |
if(left->timeStamp()!=right->timeStamp()) | |
return left->timeStamp() < right->timeStamp(); | |
else{ | |
const QVariant lid=left->dig("ID"),rid=right->dig("ID"); | |
qDebug() << left->url().toString() << "and" << right->url().toString() << "have equal timestamp" << left->timeStamp(); | |
return lid < rid; | |
} | |
} | |
bool itemSortMore(const OrthancNode *left, const OrthancNode *right) | |
{ | |
return itemSortLess(right,left); | |
} | |
QStringList &OrthancDynamicNode::pendingChildren()//@todo if this gets called from the constructor, we are in trouble | |
{ | |
if(!m_pending_children) | |
m_pending_children=new QStringList(listChildIDs()); | |
return *m_pending_children; | |
} | |
OrthancDynamicNode::OrthancDynamicNode(QString url,sorterFunc sorter, QObject *parent): | |
OrthancNode(url,parent),children(sorter),incoming(NULL),m_pending_children(NULL){} | |
QStringList OrthancDynamicNode::listChildIDs()const | |
{ | |
QStringList ret; | |
foreach(QJsonValue val,findChildrenList()) | |
ret.push_back(val.toString()); | |
return ret; | |
} | |
int OrthancDynamicNode::childCount()const | |
{ | |
return children.size(); | |
} | |
OrthancItem *OrthancDynamicNode::child(int row) | |
{ | |
child_iterator at=children.begin(); | |
std::advance(at,row); | |
return *at; | |
} | |
OrthancRoot::OrthancRoot(QString type, QObject *parent):OrthancDynamicNode(type,itemSortMore,parent){} | |
QVariant OrthancRoot::data(int /*column*/) | |
{ | |
Q_ASSERT(false); //this should be root .. hence no own "data" | |
return QVariant(); | |
} | |
QJsonValue OrthancResource::dig(const QString &path)const | |
{ | |
return res.dig(path); | |
} | |
QDateTime OrthancResource::timeStamp() const | |
{ | |
const QString date_str = dig(date_path).toString(),time_str = dig(time_path).toString(); | |
const QDate date=QDate::fromString(date_str,"yyyyMMdd"); | |
const QTime time=QTime::fromString(time_str.left(10),"hhmmss.zzz"); | |
return QDateTime(date,time); | |
} | |
QJsonObject OrthancResource::getMainTags() const{ | |
QJsonValue doc=dig("MainDicomTags"); | |
if(doc.isObject()) | |
return doc.toObject(); | |
return QJsonObject(); | |
} | |
QUrl OrthancResource::url()const | |
{ | |
return res.url(); | |
} | |
OrthancNode::OrthancNode(QString url, QObject *parent): | |
OrthancResource(url,qobject_cast<OrthancDynamicNode*>(parent),SLOT(newChild())),OrthancItem(parent){ | |
setObjectName(res.objectName()); | |
} | |
QJsonObject OrthancResource::getStatistics() const | |
{ | |
orthanc::JsonResource sres(res.objectName()+"/statistics",5000); | |
QJsonDocument doc=sres.get(); | |
if(!doc.isObject()) | |
qCritical() << "Could not receive" << &res; | |
return doc.object(); | |
} | |
QStringList OrthancNode::getInstances(int *ksize)const | |
{ | |
if(ksize) | |
*ksize=0; | |
orthanc::JsonResource res(objectName()+"/instances",100000); | |
QJsonDocument doc=res.get(); | |
QStringList ret; | |
if(!doc.isArray()) | |
qCritical() << "Could not receive the instances from" << this; | |
foreach(QJsonValue val,doc.array()){ | |
const QJsonObject ob=val.toObject(); | |
ret.push_back(ob["ID"].toString()); | |
if(ksize) | |
*ksize+=ob["FileSize"].toInt()/1024; | |
} | |
return ret; | |
} | |
bool OrthancDynamicNode::hasChildren() const{ | |
return !children.empty() || ! const_cast<OrthancDynamicNode*>(this)->pendingChildren().isEmpty() ; | |
} | |
void OrthancItem::updatePreview(QGraphicsView */*preview*/) const | |
{ | |
qWarning("Implement %s",__PRETTY_FUNCTION__); | |
} | |
bool OrthancDynamicNode::populate() | |
{ | |
QStringList &pending=pendingChildren(); | |
if(pending.empty() || incoming){ | |
return false;//we're not already populating or there is nothing | |
} else { | |
qDebug() << "populating" << url().toString() << "with" << pending.size() << "children"; | |
QString new_child = pending.takeFirst(); | |
incoming=makeChild(new_child); //start population chain (new child will call "newChild()" slot when ready | |
return true; | |
} | |
} | |
QUrl OrthancNode::downloadUrl() const | |
{ | |
return res.url().toString()+"/archive"; | |
} | |
void OrthancDynamicNode::newChild() | |
{ | |
//should not be run outside population chain | |
Q_ASSERT(m_pending_children); | |
Q_ASSERT(incoming); | |
OrthancNode *done_child=incoming; | |
done_child->disconnect(); | |
if(!m_pending_children->empty()){ | |
const QString new_child = m_pending_children->takeFirst(); | |
incoming=makeChild(new_child); | |
} else | |
incoming=NULL; | |
std::pair<child_iterator,bool> inserted=children.insert(done_child); | |
if(inserted.second){ | |
emit childReady(my_index,done_child,std::distance(children.begin(),inserted.first)); | |
} else { | |
qCritical() << "Failed to list" << done_child << "with" << done_child->getMainTags(); | |
} | |
} | |
QJsonArray OrthancRoot::findChildrenList() const | |
{ | |
QJsonDocument doc=res.get(); | |
if(!doc.isArray()){ | |
qCritical() << "Result of" << res.url() << "is not an array"; | |
return QJsonArray(); | |
} else | |
return doc.array(); | |
} | |
QJsonArray OrthancDynamicNode::findChildrenList() const | |
{ | |
return children_list_name.isEmpty() ? QJsonArray(): dig(children_list_name).toArray(); | |
} | |
OrthancStudy::OrthancStudy(QString id, OrthancDynamicNode *parent):OrthancDynamicNode("/studies/"+id,itemSortLess,parent){ | |
children_list_name="Series"; | |
date_path="MainDicomTags/StudyDate"; | |
time_path="MainDicomTags/StudyTime"; | |
} | |
QVariant OrthancStudy::data(int /*column*/) | |
{ | |
const QString failtext=QString("no StudyDescription found for %1").arg(objectName()); | |
return | |
dig("MainDicomTags/StudyDescription").toString(failtext); | |
} | |
QVariant OrthancSeries::data(int /*column*/) | |
{ | |
const QString failtext=QString("no SeriesNumber or SeriesDescription found for %1").arg(objectName()); | |
const QJsonValue val1=dig("MainDicomTags/SeriesNumber"); | |
const QJsonValue val2=dig("MainDicomTags/SeriesDescription"); | |
if(val1.isUndefined() || val2.isUndefined()) | |
return failtext; | |
else | |
return QString("S%1_%2").arg(val1.toString(),val2.toString()); | |
} | |
QVariant OrthancFrame::data(int /*column*/) | |
{ | |
return QString("Frame %1").arg(m_framenum); | |
} | |
void OrthancFrame::updatePreview(QGraphicsView *preview) const{ | |
orthanc::ImageResource img_res(objectName()+"/preview"); | |
QPixmap pix=QPixmap::fromImage(img_res.get()); | |
preview->scene()->clear(); | |
preview->scene()->addPixmap(pix); | |
preview->adjustSize(); | |
} | |
OrthancNode *OrthancRoot::makeChild(QString id){return new OrthancStudy(id,this);} | |
OrthancNode *OrthancStudy::makeChild(QString id){return new OrthancSeries(id,this);} | |
QUrl OrthancFrame::downloadUrl()const | |
{ | |
QString url=objectName(); | |
int pos = url.lastIndexOf('/',url.lastIndexOf('/')-url.length()-1); | |
url.truncate(pos); | |
return QUrl(qApp->property("host").toString()+url+"/file"); | |
} | |
QJsonArray OrthancSeries::findChildrenList() const | |
{ | |
qWarning() << "Implement me" << __LINE__; | |
return QJsonArray(); | |
} | |
bool OrthancSeries::populate() | |
{ | |
if(m_slices.empty()){ | |
orthanc::JsonResource res(objectName()+"/ordered-slices",100000); | |
QJsonArray slices=res.dig("Slices").toArray(); | |
qDebug() << "populating" << url().toString() << "with" << slices.size() << "slices"; | |
int num=0; | |
foreach (QJsonValue item_url, slices) { | |
num++; | |
OrthancFrame *item=new OrthancFrame(item_url.toString(),num,this); | |
m_slices.append(item); | |
} | |
} | |
return false; | |
} | |