GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoAlgorithmsManagerWidget.cxx
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 
36 #include <QStackedLayout>
37 #include <QLabel>
38 #include <QGroupBox>
39 #include <QPushButton>
40 #include <QPainter>
41 #include <QCheckBox>
42 
43 
45 QGoAlgorithmsManagerWidget( std::string iModeName,
46  QWidget *iParent,
47  std::vector<QString> iVectChannels,
48  QStringList iListTime,
49  bool iOnlyOneMethod,
50  bool NeedApplyResetButton ) : QWidget(iParent), m_MethodComboBox(NULL),
51  m_ChannelComboBox(NULL), m_TimeComboBox(NULL)
52 {
53  this->m_ModeName = iModeName;
54  this->Initialize(iVectChannels, iListTime, iOnlyOneMethod, NeedApplyResetButton);
55 }
56 //-------------------------------------------------------------------------
57 
58 //-------------------------------------------------------------------------
60 {
61 }
62 //-------------------------------------------------------------------------
63 
64 //-------------------------------------------------------------------------
65 void QGoAlgorithmsManagerWidget::Initialize(std::vector<QString> iVectChannels,
66  QStringList iListTime, bool iOnlyOneMethod, bool NeedApplyResetButton)
67 {
68  this->m_VBoxLayout = new QVBoxLayout;
69  QHBoxLayout* HBox = new QHBoxLayout;
70  QFormLayout* FormLayout = new QFormLayout;
71  if (!iListTime.empty() )
72  {
73  this->m_ListTimePoints = iListTime;
74  this->m_TimeComboBox = new QComboBox(this);
75  this->m_TimeComboBox->addItems(iListTime);
76  QLabel* Label= new QLabel("TSlice",this);
77  HBox->addWidget(Label);
78  HBox->addWidget(this->m_TimeComboBox);
79  }
80 
81  this->m_InvertBox = new QCheckBox("Invert", this);
82  HBox->addWidget(this->m_InvertBox);
83 
84  this->m_VBoxLayout->addLayout(HBox);
85  if (!iVectChannels.empty() )
86  {
87  this->m_ChannelComboBox = new QComboBox(this);
88  std::vector<QString>::iterator iter = iVectChannels.begin();
89  while (iter != iVectChannels.end())
90  {
91  this->m_ChannelComboBox->addItem(*iter);
92  ++iter;
93  }
94 
95  FormLayout->addRow(tr("Channel:"), this->m_ChannelComboBox);
96  }
97 
98  this->m_MethodWidgets = new QStackedWidget(this);
99 
100  if (!iOnlyOneMethod)
101  {
102  this->m_MethodComboBox = new QComboBox(this);
103  FormLayout->addRow(tr("Method:"), this->m_MethodComboBox);
104 
105  QObject::connect(this->m_MethodComboBox, SIGNAL(activated(int)),
106  this->m_MethodWidgets, SLOT(setCurrentIndex(int)));
107  }
108 
109  this->m_VBoxLayout->addLayout(FormLayout);
110  this->m_VBoxLayout->addWidget(this->m_MethodWidgets);
111 
112  if (NeedApplyResetButton)
113  {
114  QHBoxLayout* ButtonLayout = new QHBoxLayout;
115  QPushButton* ApplyButton = new QPushButton(tr("Apply"),this);
116  ApplyButton->setShortcut(tr("A", "Apply Algorithm"));
117  ApplyButton->setShortcut(tr("Ctrl+A", "Apply Algorithm"));
118  ApplyButton->setToolTip("Apply Algorithm");
119  QPushButton* ResetButton = new QPushButton(tr("Delete"), this);
120  ResetButton->setShortcut(tr("D", "Delete the seeds"));
121  ResetButton->setShortcut(tr("Ctrl+D", "Delete the seeds"));
122  ResetButton->setToolTip("Delete the seeds");
123  ButtonLayout->addWidget(ApplyButton);
124  ButtonLayout->addWidget(ResetButton);
125  this->m_VBoxLayout->addLayout(ButtonLayout);
126 
127  QObject::connect(ApplyButton, SIGNAL(clicked()),
128  this, SLOT(EmitApplyAlgo()));
129 
130  QObject::connect(ResetButton, SIGNAL(clicked()), this, SIGNAL(ResetClicked()));
131 
132  }
133 
134  this->setLayout(this->m_VBoxLayout);
135  this->m_VBoxLayout->setSizeConstraint(QLayout::SetFixedSize);
136 }
137 //-------------------------------------------------------------------------
138 
139 //-------------------------------------------------------------------------
141 {
142  this->m_MethodWidgets->addWidget(iAlgoWidget);
143  int Index = this->m_MethodWidgets->indexOf(iAlgoWidget);
144  this->m_MethodComboBox->insertItem(Index, iAlgoWidget->GetMethodName().c_str());
145  iAlgoWidget->show();
146  this->m_MethodComboBox->setCurrentIndex(Index);
147  this->m_MethodWidgets->setCurrentWidget(iAlgoWidget);
148 }
149 //-------------------------------------------------------------------------
150 
151 //-------------------------------------------------------------------------
153 {
154  if (this->m_MethodComboBox != NULL)
155  {
156  this->m_MethodComboBox->setCurrentIndex(iIndex);
157  }
158  this->m_MethodWidgets->setCurrentIndex(iIndex);
159 }
160 //-------------------------------------------------------------------------
161 
162 //-------------------------------------------------------------------------
164 {
165  return this->m_ModeName;
166 }
167 //-------------------------------------------------------------------------
168 
169 //-------------------------------------------------------------------------
171 {
173  this->m_ChannelComboBox->findText(iChannel) );
174 }
175 //-------------------------------------------------------------------------
176 
177 //-------------------------------------------------------------------------
179 {
180  if (this->m_TimeComboBox)
181  {
182  this->m_TimeComboBox->clear();
185  this->m_TimeComboBox->findText(iTimePoint) );
186  this->m_TimeComboBox->setEnabled(false);
187  }
188  if (this->m_ChannelComboBox)
189  {
190  this->m_ChannelComboBox->setEnabled(true);
191  }
192 }
193 //-------------------------------------------------------------------------
194 
195 //-------------------------------------------------------------------------
197  QHash<QString, QColor> iListTimePoints, int iIndexChannel)
198 {
199  if (this->m_TimeComboBox)
200  {
201  this->m_TimeComboBox->clear();
202  if (!iListTimePoints.empty() )
203  {
204  QHash<QString, QColor>::iterator iter = iListTimePoints.begin();
205  while(iter != iListTimePoints.end() )
206  {
207  QPixmap pix(12, 12);
208  QPainter painter(&pix);
209  painter.setPen(Qt::gray);
210  QColor color = iter.value();
211  painter.setBrush( QBrush(color) );
212  painter.drawRect(0, 0, 12, 12);
213  QIcon Icon;
214  Icon.addPixmap(pix);
215 
216  this->m_TimeComboBox->addItem(Icon, iter.key());
217 
218  ++iter;
219  }
220  }
221  if (iListTimePoints.size() > 0)
222  {
224  }
225  this->m_TimeComboBox->setEnabled(true);
226  }
227  if (this->m_ChannelComboBox)
228  {
229  this->m_ChannelComboBox->setCurrentIndex(iIndexChannel);
230  this->m_ChannelComboBox->setEnabled(false);
231  }
232 }
233 //-------------------------------------------------------------------------
234 
235 //-------------------------------------------------------------------------
237 {
238  return this->m_MethodComboBox->count();
239 }
240 //-------------------------------------------------------------------------
241 
242 //-------------------------------------------------------------------------
244 {
245  QGoAlgorithmWidget* iCurrentWidget =
247  iCurrentWidget->EmitApplyAlgo();
248 }
249 //-------------------------------------------------------------------------
250 
251 //-------------------------------------------------------------------------
253 {
254  std::string imageName;
255  if(this->m_ChannelComboBox->isEnabled())
256  {
257  imageName = this->m_ChannelComboBox->currentText().toStdString();
258  }
259  else
260  {
261  imageName = this->m_TimeComboBox->currentText().toStdString();
262  }
263  return imageName;
264 }
265 
266 //-------------------------------------------------------------------------
267 
268 //-------------------------------------------------------------------------
270 {
271  return this->m_TimeComboBox->currentText().toInt();
272 }
273 //-------------------------------------------------------------------------
274 
275 //-------------------------------------------------------------------------
277  QWidget* iWidget)
278 {
279  this->m_MethodWidgets->addWidget(iWidget);
280  //int Index = this->m_MethodWidgets->indexOf(iWidget);
281  this->m_MethodWidgets->setCurrentWidget(iWidget);
282 }
283 //-------------------------------------------------------------------------
284 
285 //-------------------------------------------------------------------------
287 {
288  if (this->m_InvertBox->checkState() == Qt::Checked)
289  {
290  return true;
291  }
292  else
293  {
294  return false;
295  }
296 }
297 /*void QGoAlgorithmsManagerWidget::AddMethod(std::string iNameMethod,
298  QWidget* iParametersWidget, QWidget* iAdvParamWidget)
299 {
300  QWidget* MethodWidget = new QWidget(this);
301 
302  QVBoxLayout* MethodLayout = new QVBoxLayout;
303  MethodLayout->addWidget(iParametersWidget);
304 
305  QGoAdvancedParametersWidget* AdvParamWidget =
306  new QGoAdvancedParametersWidget(this);
307  AdvParamWidget->AddAdvancedParamWidget(iAdvParamWidget);
308 
309 
310  MethodLayout->addWidget(AdvParamWidget);
311 
312  MethodWidget->setLayout(MethodLayout);
313  this->m_MethodWidgets->addWidget(MethodWidget);
314 
315  int Index = this->m_MethodWidgets->indexOf(MethodWidget);
316  this->m_MethodComboBox->insertItem(Index,iNameMethod.c_str());
317 }*/
bool empty() const
std::string GetCurrentImageName()
return the number of the selected channel
void EmitApplyAlgo()
method called by the QGoAlgoManagerWidget when the apply button is clicked, emit the signal applyAlgo...
QWidget * currentWidget() const
void AddWidgetForOnlyOneMethod(QWidget *iWidget)
add the widget in the stacked_widgets and hide the methodcombobox as there will be only one method in...
QGoAlgorithmsManagerWidget(std::string iModeName, QWidget *iParent=0, std::vector< QString > iVectChannels=std::vector< QString >(), QStringList iListTime=QStringList(), bool iOnlyOneMethod=false, bool NeedApplyResetButton=true)
void setSizeConstraint(SizeConstraint)
int size() const
void clear()
QString tr(const char *sourceText, const char *disambiguation, int n)
void insertItem(int index, const QString &text, const QVariant &userData)
void addItem(const QString &text, const QVariant &userData)
void drawRect(const QRectF &rectangle)
int findText(const QString &text, QFlags< Qt::MatchFlag > flags) const
void setEnabled(bool)
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
void setCurrentWidget(QWidget *widget)
void setLayout(QLayout *layout)
bool empty() const
void setPen(const QColor &color)
iterator begin()
void setCurrentIndex(int index)
void setBrush(const QBrush &brush)
void addPixmap(const QPixmap &pixmap, Mode mode, State state)
void show()
add the Advanced parameters box if there are parameters inside and reduce it before showing the widge...
void setShortcut(const QKeySequence &key)
void addRow(QWidget *label, QWidget *field)
void SetCurrentIndex(int iIndex)
set the current index in the combobox to iIndex and get the corresponding widget to display ...
T & value() const
const Key & key() const
void SetTSliceForDopplerView(QHash< QString, QColor > iListTimePoints, int iIndexChannel)
int indexOf(QWidget *widget) const
void Initialize(std::vector< QString > iVectChannels=std::vector< QString >(), QStringList iListTime=QStringList(), bool iOnlyOneMethod=false, bool NeedApplyResetButton=true)
add the different widgets, buttons and fill the comboboxes for channel and timepoint ...
void setCurrentIndex(int index)
std::string GetModeName()
return the name of the mode
std::string GetMethodName()
void addItems(const QStringList &texts)
void setToolTip(const QString &)
bool HasMethod()
return true if it has at least one QGoAlgorithmWidget in the stackedWidgets
iterator end()
int addWidget(QWidget *widget)
void EmitApplyAlgo()
after button clicked signal is emitted, get the current widget of the stackedwidgets and call the met...
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Qt::CheckState checkState() const
void SetTSliceForClassicView(QString iTimePoint)
void AddMethod(QGoAlgorithmWidget *iAlgoWidget)
add a widget in the stacked layout with the name of the method associated in the combobox to display ...
void addLayout(QLayout *layout, int stretch)