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/maindlg.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
101 lines (82 sloc)
2.64 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 "maindlg.hpp" | |
#include <QNetworkRequest> | |
#include <QDebug> | |
#include "orthancaccess.hpp" | |
#include "resource.hpp" | |
#include "resourcebrowserview.hpp" | |
#include "downloaddlg.hpp" | |
#include <QProgressDialog> | |
#include <QSettings> | |
#include <QPushButton> | |
#include <QCloseEvent> | |
MainDlg::MainDlg(QWidget *parent) : QDialog(parent) | |
{ | |
setLayout(new QVBoxLayout(this)); | |
orthanc::access().setPrefix(qApp->property("host").toString()); | |
browser=new ResourceBrowserView(this); | |
connect( | |
browser->selectionModel(), | |
SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), | |
SLOT(browser_item_selected(const QItemSelection&, const QItemSelection&)) | |
); | |
layout()->addWidget(browser); | |
download_btn = new QPushButton("download",this); | |
download_btn->setObjectName(QStringLiteral("download_btn")); | |
download_btn->setEnabled(false); | |
layout()->addWidget(download_btn); | |
QMetaObject::connectSlotsByName(this); | |
QSettings settings; | |
settings.beginGroup("MainWindow"); | |
resize(settings.value("size", QSize(800, 400)).toSize()); | |
move(settings.value("pos", QPoint(200, 200)).toPoint()); | |
settings.endGroup(); | |
} | |
void MainDlg::browser_item_selected(const QItemSelection&, const QItemSelection&) | |
{ | |
downloads.clear(); | |
QModelIndexList selected=browser->selectionModel()->selectedIndexes(); | |
// if(!selected.contains(current)) | |
// selected << current; | |
for(QModelIndex idx:selected){ | |
OrthancNode *obj= dynamic_cast<OrthancNode*>(static_cast<QObject*>(idx.internalPointer())); | |
if(obj) | |
downloads.append(obj); | |
} | |
// if an specific item is selected we do not want to download its whole parent | |
// so remove all parents of also selected items | |
for(QModelIndex idx:selected){ | |
const QModelIndex parent=idx.parent(); | |
if(parent.isValid()) | |
downloads.removeAll(dynamic_cast<OrthancNode*>(static_cast<QObject*>(parent.internalPointer()))); | |
} | |
size_t studies=0,series=0; | |
for(OrthancNode *e:downloads){ | |
if(dynamic_cast<OrthancSeries*>(e)) | |
++series; | |
if(dynamic_cast<OrthancStudy*>(e)) | |
++studies; | |
} | |
QString text("download"); | |
if(studies){ | |
text+=QString(" %1 %2").arg(studies).arg(studies>1?"studies":"study"); | |
if(series)text+=" and"; | |
} | |
if(series) | |
text+=QString(" %1 series").arg(series); | |
download_btn->setEnabled(!downloads.isEmpty()); | |
download_btn->setText(text); | |
} | |
void MainDlg::on_download_btn_clicked() | |
{ | |
Q_ASSERT(!downloads.empty()); | |
DownloadDlg *load=new DownloadDlg(qApp->property("host").toString(),downloads,this); | |
load->show(); | |
} | |
void MainDlg::closeEvent(QCloseEvent *e){ | |
QSettings settings; | |
settings.beginGroup("MainWindow"); | |
settings.setValue("size", size()); | |
settings.setValue("pos", pos()); | |
settings.endGroup(); | |
e->accept(); | |
} |