Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkXnatCreateObjectDialog.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological rmatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 // XNAT
21 #include <QmitkXnatProjectWidget.h>
22 #include <QmitkXnatSubjectWidget.h>
23 
24 // CTK XNAT Core
25 //#include <ctkXnatProject.h>
26 #include <ctkXnatExperiment.h>
27 #include <ctkXnatSubject.h>
28 
29 // Qt
30 #include <QLineEdit>
31 #include <QMessageBox>
32 #include <QPushButton>
33 
34 // Testing
35 #include <iostream>
36 #include <stdio.h>
37 
39  : QDialog(parent), m_Type(type)
40 {
41  switch (m_Type)
42  {
43  // case PROJECT:
44  // m_Object = new ctkXnatProject();
45  // m_Widget = new QmitkXnatProjectWidget(dynamic_cast<ctkXnatProject*>(m_Object));
46  // break;
47  case SUBJECT:
48  m_Object = new ctkXnatSubject();
49  m_Widget = new QmitkXnatSubjectWidget(QmitkXnatSubjectWidget::Mode::CREATE, parent);
50  dynamic_cast<QmitkXnatSubjectWidget *>(m_Widget)->SetSubject(dynamic_cast<ctkXnatSubject *>(m_Object));
51  break;
52  case EXPERIMENT:
53  m_Object = new ctkXnatExperiment();
54  m_Widget = new QmitkXnatExperimentWidget(QmitkXnatExperimentWidget::Mode::CREATE, parent);
55  dynamic_cast<QmitkXnatExperimentWidget *>(m_Widget)->SetExperiment(dynamic_cast<ctkXnatExperiment *>(m_Object));
56  break;
57  default:
58  break;
59  }
60 
61  QList<QLineEdit *> children = m_Widget->findChildren<QLineEdit *>();
62  foreach (QLineEdit *child, children)
63  {
64  child->setReadOnly(false);
65  }
66 
67  QGridLayout *grid = dynamic_cast<QGridLayout *>(m_Widget->layout());
68 
69  QPushButton *btnOk = new QPushButton("Create");
70  QPushButton *btnCancel = new QPushButton("Cancel");
71 
72  QHBoxLayout *hLayout = new QHBoxLayout();
73  hLayout->addWidget(btnOk);
74  hLayout->addWidget(btnCancel);
75 
76  connect(btnOk, SIGNAL(clicked()), this, SLOT(OnAcceptClicked()));
77  connect(btnCancel, SIGNAL(clicked()), this, SLOT(OnCancelClicked()));
78 
79  grid->addLayout(hLayout, grid->rowCount() + 1, 1);
80 
81  // Fill the dialog
82  setLayout(grid);
83 }
84 
86 {
87  delete m_Widget;
88 }
89 
91 {
92  return m_Object;
93 }
94 
96 {
97  // ctkXnatProject* project;
98  ctkXnatSubject *subject;
99  ctkXnatExperiment *experiment;
100 
101  switch (m_Type)
102  {
103  // case PROJECT:
104  // project = dynamic_cast<QmitkXnatProjectWidget*>(m_Widget)->GetProject();
105 
106  // // Check mandatory field
107  // if (project->property("label").isEmpty())
108  // {
109  // QMessageBox msgBox;
110  // msgBox.setIcon(QMessageBox::Warning);
111  // msgBox.setText("Please fill in an ID to create a new project!");
112  // msgBox.exec();
113  // return;
114  // }
115 
116  // m_Object = project;
117  // break;
118 
119  case SUBJECT:
120  subject = dynamic_cast<QmitkXnatSubjectWidget *>(m_Widget)->GetSubject();
121 
122  // Check mandatory field
123  if (subject->property("label").isEmpty())
124  {
125  QMessageBox msgBox;
126  msgBox.setIcon(QMessageBox::Warning);
127  msgBox.setText("Please fill in an ID to create a new subject!");
128  msgBox.exec();
129  return;
130  }
131 
132  m_Object = subject;
133  break;
134 
135  case EXPERIMENT:
136  experiment = dynamic_cast<QmitkXnatExperimentWidget *>(m_Widget)->GetExperiment();
137 
138  // Check mandatory field
139  if (experiment->property("label").isEmpty())
140  {
141  QMessageBox msgBox;
142  msgBox.setIcon(QMessageBox::Warning);
143  msgBox.setText("Please fill in an ID to create a new experiment!");
144  msgBox.exec();
145  return;
146  }
147  else if (experiment->property("xsiType").isEmpty() || experiment->property("xsiType") == "xnat:experimentData")
148  {
149  QMessageBox msgBox;
150  msgBox.setIcon(QMessageBox::Warning);
151  msgBox.setText("Please fill in an XSI Type to create a new experiment!");
152  msgBox.exec();
153  return;
154  }
155 
156  m_Object = experiment;
157  break;
158 
159  default:
160  break;
161  }
162  accept();
163 }
164 
166 {
167  reject();
168 }
QmitkXnatCreateObjectDialog(SpecificType type, QWidget *parent=0)