fw4spl
SeriesEditor.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "uiMedDataQt/widget/SeriesEditor.hpp"
8 
9 #include "uiMedDataQt/constants.hpp"
10 #include "uiMedDataQt/InsertSeries.hpp"
11 
12 #include <fwMedData/Series.hpp>
13 #include <fwMedData/types.hpp>
14 
15 #include <boost/algorithm/string.hpp>
16 
17 #include <QFormLayout>
18 #include <QGroupBox>
19 #include <QHBoxLayout>
20 #include <QLabel>
21 #include <QLineEdit>
22 #include <QPushButton>
23 #include <QVBoxLayout>
24 
25 namespace uiMedDataQt
26 {
27 namespace widget
28 {
29 
30 //-----------------------------------------------------------------------------
31 
32 ListInput::ListInput()
33 {
34  m_physicianInput = new QLineEdit();
35  m_addPhysicianButton = new QPushButton(tr("+"));
36  m_addPhysicianButton->setEnabled(false);
37  m_removePhysicianButton = new QPushButton(tr("-"));
38  m_removePhysicianButton->setEnabled(false);
39  m_performingPhysiciansName = new QListWidget();
40 
41  QHBoxLayout* inputLayout = new QHBoxLayout();
42  inputLayout->addWidget(m_physicianInput);
43  inputLayout->addWidget(m_addPhysicianButton);
44  inputLayout->addWidget(m_removePhysicianButton);
45  QVBoxLayout* vLayout = new QVBoxLayout();
46 
47  vLayout->addLayout(inputLayout);
48  vLayout->addWidget(m_performingPhysiciansName);
49 
50  QObject::connect(m_physicianInput, SIGNAL(textChanged(const QString &)),
51  this, SLOT(onInputChanged(const QString &)));
52  QObject::connect(m_addPhysicianButton, SIGNAL(clicked()),
53  this, SLOT(onAddPhysician()));
54  QObject::connect(m_removePhysicianButton, SIGNAL(clicked()),
55  this, SLOT(onRemovePhysician()));
56  QObject::connect(m_performingPhysiciansName, SIGNAL(itemSelectionChanged()), this, SLOT(onSelectionChanged()));
57  this->setLayout(vLayout);
58 }
59 
60 //-----------------------------------------------------------------------------
61 
62 void ListInput::onInputChanged(const QString& text)
63 {
64  m_addPhysicianButton->setEnabled(m_physicianInput->text().count() > 0);
65 }
66 
67 //-----------------------------------------------------------------------------
68 
70 {
71  m_performingPhysiciansName->addItem(new QListWidgetItem(m_physicianInput->text().trimmed()));
72  m_physicianInput->clear();
73 }
74 
75 //-----------------------------------------------------------------------------
76 
78 {
79  QList< QListWidgetItem* > selectedItems = m_performingPhysiciansName->selectedItems();
80  for(int i = 0; i < selectedItems.count(); ++i)
81  {
82  delete selectedItems.at(i);
83  }
84 }
85 
86 //-----------------------------------------------------------------------------
87 
89 {
90  m_removePhysicianButton->setEnabled(m_performingPhysiciansName->selectedItems().count() > 0);
91 }
92 //-----------------------------------------------------------------------------
93 
94 SeriesEditor::SeriesEditor(QWidget* parent) :
95  QWidget(parent)
96 {
97  m_modality = new QLineEdit();
98  m_date = new QLineEdit();
99  m_time = new QLineEdit();
100  m_description = new QLineEdit();
101  m_physicians = new ListInput();
102 
103  QFormLayout* layout = new QFormLayout();
104 
105  layout->addRow(tr("Modality"), m_modality);
106  layout->addRow(tr("Date"), m_date);
107  layout->addRow(tr("Time"), m_time);
108  layout->addRow(tr("Description"), m_description);
109 
110  layout->addRow(tr("Physicians"), m_physicians);
111 
112  QObject::connect(m_date, SIGNAL(textChanged(const QString &)), this, SLOT(onDateChanged(const QString &)));
113  QObject::connect(m_time, SIGNAL(textChanged(const QString &)), this, SLOT(onTimeChanged(const QString &)));
114  QObject::connect(m_description, SIGNAL(textChanged(const QString &)), this, SLOT(onDescChanged(const QString &)));
115 
116  QGroupBox* group = new QGroupBox(tr("Series"));
117  group->setLayout(layout);
118  QVBoxLayout* topLayout = new QVBoxLayout();
119  topLayout->addWidget(group);
120  this->setLayout(topLayout);
121 }
122 
123 //-----------------------------------------------------------------------------
124 
125 SeriesEditor::~SeriesEditor()
126 {
127  QObject::disconnect(m_date, SIGNAL(textChanged(const QString &)), this, SLOT(onDateChanged(const QString &)));
128  QObject::disconnect(m_time, SIGNAL(textChanged(const QString &)), this, SLOT(onTimeChanged(const QString &)));
129  QObject::disconnect(m_description, SIGNAL(textChanged(const QString &)), this,
130  SLOT(onDescChanged(const QString &)));
131 }
132 
133 //-----------------------------------------------------------------------------
134 
135 void SeriesEditor::onDateChanged(const QString& text)
136 {
137  if(m_date->text().trimmed().isEmpty())
138  {
139  m_palette.setColor(QPalette::Base, QColor(Qt::red));
140  }
141  else
142  {
143  m_palette.setColor(QPalette::Base, QColor(Qt::white));
144  }
145 
146  m_date->setPalette(m_palette);
147 }
148 
149 //-----------------------------------------------------------------------------
150 
151 void SeriesEditor::onTimeChanged(const QString& text)
152 {
153  if(m_time->text().trimmed().isEmpty())
154  {
155  m_palette.setColor(QPalette::Base, QColor(Qt::red));
156  }
157  else
158  {
159  m_palette.setColor(QPalette::Base, QColor(Qt::white));
160  }
161 
162  m_time->setPalette(m_palette);
163 }
164 
165 //-----------------------------------------------------------------------------
166 
167 void SeriesEditor::onDescChanged(const QString& text)
168 {
169  if(m_description->text().trimmed().toStdString() == s_INSERT_NEW_SERIES_TEXT)
170  {
171  m_palette.setColor(QPalette::Base, QColor(Qt::red));
172  }
173  else
174  {
175  m_palette.setColor(QPalette::Base, QColor(Qt::white));
176  }
177 
178  m_description->setPalette(m_palette);
179 }
180 
181 //-----------------------------------------------------------------------------
182 
184 {
185  SLM_ASSERT("Given series is null", series);
186  m_series = series;
187 
188  m_modality->setText(QString::fromStdString(m_series->getModality()).trimmed());
189  m_description->setText(QString::fromStdString(m_series->getDescription()).trimmed());
190  m_date->setText(QString::fromStdString(series->getDate()).trimmed());
191  m_time->setText(QString::fromStdString(series->getTime()).trimmed());
192 
193  // force signal (manage empty text case)
194  this->onTimeChanged(m_time->text());
195  this->onDateChanged(m_date->text());
196 
197  m_physicians->getListWidget()->clear();
198  for(::fwMedData::DicomValueType value : m_series->getPerformingPhysiciansName())
199  {
200  QListWidgetItem* newVal
201  = new QListWidgetItem(QString::fromStdString(value).trimmed(), m_physicians->getListWidget());
202  }
203 }
204 
205 //-----------------------------------------------------------------------------
206 
208 {
209  ::fwMedData::Series::sptr series = ::uiMedDataQt::InsertSeries::New();
210  series->setModality(m_modality->text().trimmed().toStdString());
211  series->setDate(m_date->text().trimmed().toStdString());
212  series->setTime(m_time->text().trimmed().toStdString());
213  series->setDescription(m_description->text().trimmed().toStdString());
214 
215  ::fwMedData::DicomValuesType newPerformingPhysiciansName;
216  for(int i = 0; i < m_physicians->getListWidget()->count(); ++i)
217  {
218  newPerformingPhysiciansName.push_back(m_physicians->getListWidget()->item(i)->text().trimmed().toStdString());
219  }
220 
221  series->setPerformingPhysiciansName(newPerformingPhysiciansName);
222 
223  return series;
224 }
225 
226 //-----------------------------------------------------------------------------
227 
229 {
230  return !m_date->text().trimmed().isEmpty()
231  && !m_time->text().trimmed().isEmpty()
232  && m_description->text().trimmed().toStdString() != s_INSERT_NEW_SERIES_TEXT;
233 }
234 
235 //-----------------------------------------------------------------------------
236 
237 } // namespace widget
238 } // namespace uiMedDataQt
239 
The namespace uiMedDataQt contains editors for medical data.
#define SPTR(_cls_)
void onTimeChanged(const QString &)
Triggered when series time text changes.
UIMEDDATAQT_API void setSeries(std::shared_ptr< ::fwMedData::Series > series)
Set referring series.
void onAddPhysician()
Triggered when the add button is clicked, if the input text is not empty.
Widget to edit fwMedData::Series information.
Simple list widget where items can be added/removed from an input widget with add/remove buttons...
const DicomValueType & getTime() const
Time the Series started (0008,0031)
void onSelectionChanged()
Triggered when the selection in the list changes.
void onInputChanged(const QString &)
Triggered when the input text changes.
UIMEDDATAQT_API bool isValid() const
Check if the equipment information entered in UI is valid.
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
const DicomValueType & getDate() const
Date the Series started (0008,0021)
QPointer< QLineEdit > m_physicianInput
Input widget to edit items.
void onRemovePhysician()
Triggered when the remove button is clicked, if an item is selected in the list.
void onDescChanged(const QString &)
Triggered when series description text changes.
void onDateChanged(const QString &)
Triggered when series date text changes.
QPointer< QListWidget > m_performingPhysiciansName
List widget.