Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkSelectXnatUploadDestinationDialog.cpp
Go to the documentation of this file.
2 #include "ui_QmitkSelectXnatUploadDestinationDialog.h"
3 
4 #include <ctkXnatObject.h>
5 #include <ctkXnatResource.h>
6 #include <ctkXnatResourceFolder.h>
7 #include <ctkXnatSession.h>
8 
9 #include "QmitkXnatTreeModel.h"
10 
11 #include <QModelIndex>
12 
14  const QStringList &availableResources,
15  QWidget *parent)
16  : QDialog(parent),
18  m_Url(""),
19  m_ResourceName(""),
20  m_CreateNewFolder(false)
21 {
22  ui->setupUi(this);
23 
24  m_TreeModel = new QmitkXnatTreeModel();
25  m_TreeModel->addDataModel(session->dataModel());
26  ui->treeView->setModel(m_TreeModel);
27 
28  connect(ui->cbSelectResources,
29  SIGNAL(currentIndexChanged(const QString &)),
30  this,
31  SLOT(OnResourceSelected(const QString &)));
32  connect(ui->treeView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(OnXnatNodeSelected(const QModelIndex &)));
33  connect(ui->rbSelectResource, SIGNAL(toggled(bool)), this, SLOT(OnSelectResource(bool)));
34  connect(ui->rbSelectFromTreeView, SIGNAL(toggled(bool)), this, SLOT(OnSelectFromTreeView(bool)));
35  connect(ui->leResourceName, SIGNAL(textChanged(const QString &)), this, SLOT(OnResourceEntered(const QString &)));
36  connect(ui->pbCancel, SIGNAL(clicked()), this, SLOT(OnCancel()));
37  connect(ui->pbUpload, SIGNAL(clicked()), this, SLOT(OnUpload()));
38 
39  // Initial Setup
40  ui->pbUpload->setEnabled(false);
41  ui->leResourceName->setVisible(false);
42  ui->treeView->hide();
43 
44  if (availableResources.isEmpty())
45  {
46  ui->rbSelectFromTreeView->setChecked(true);
47  ui->rbSelectResource->setEnabled(false);
48  }
49  else
50  {
51  foreach (QString resourceName, availableResources)
52  {
53  ui->cbSelectResources->addItem(resourceName);
54  }
55  ui->cbSelectResources->addItem("Create new resource folder...");
56  }
57 }
58 
60 {
61  delete ui;
62 }
63 
65 {
66  this->done(QDialog::Rejected);
67 }
68 
70 {
71  this->done(QDialog::Accepted);
72 }
73 
75 {
76  ui->pbUpload->setEnabled(false);
77  ui->cbSelectResources->setVisible(selectResource);
78  ui->leResourceName->setVisible(!selectResource);
79  ui->treeView->setVisible(!selectResource);
80  if (selectResource)
81  ui->cbSelectResources->setCurrentIndex(0);
82 }
83 
85 {
86  ui->pbUpload->setEnabled(false);
87  ui->cbSelectResources->setVisible(!selectFromTreeView);
88  ui->leResourceName->setVisible(!selectFromTreeView);
89  ui->treeView->setVisible(selectFromTreeView);
90 }
91 
93 {
94  m_Url = url;
95 }
96 
98 {
99  if (ui->rbSelectResource->isChecked() && !m_Url.isEmpty() && !m_ResourceName.isEmpty())
100  {
101  ctkXnatObject *selectedXnatObject = m_TreeModel->GetXnatObjectFromUrl(m_Url);
102 
103  ctkXnatResource *resource = new ctkXnatResource();
104  resource->setName(m_ResourceName);
105  resource->setParent(selectedXnatObject);
106  if (!resource->exists())
107  resource->save();
108  return resource;
109  }
110  else
111  {
112  QModelIndex index = ui->treeView->selectionModel()->currentIndex();
113  return m_TreeModel->xnatObject(index);
114  }
115 }
116 
118 {
119  if (resource.isEmpty())
120  ui->pbUpload->setEnabled(false);
121 
122  if (resource != "Create new resource folder...")
123  {
124  ui->pbUpload->setEnabled(true);
125  m_ResourceName = resource;
126  ui->leResourceName->hide();
127  }
128  else if (resource == "Create new resource folder...")
129  {
130  ui->pbUpload->setEnabled(false);
131  ui->leResourceName->show();
132  }
133 }
134 
136 {
137  m_CreateNewFolder = !resourceEntered.isEmpty();
138  ui->pbUpload->setEnabled(m_CreateNewFolder);
139  m_ResourceName = resourceEntered;
140 }
141 
143 {
144  if (!index.isValid())
145  return;
146 
147  ctkXnatObject *selectedObject = m_TreeModel->xnatObject(index);
148  ui->pbUpload->setEnabled(dynamic_cast<ctkXnatResource *>(selectedObject) != nullptr);
149 }
ctkXnatObject * GetXnatObjectFromUrl(const QString &)
QmitkSelectXnatUploadDestinationDialog(ctkXnatSession *session, const QStringList &, QWidget *parent=0)