NorMIT-nav  22.09
An IGT application
cxPipelineWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxPipelineWidget.h"
13 #include "cxHelperWidgets.h"
14 
16 #include <QtWidgets>
17 #include "cxLogger.h"
18 #include "cxTypeConversions.h"
19 #include "cxDataSelectWidget.h"
20 #include "cxSettings.h"
21 
22 namespace cx
23 {
24 
25 PipelineWidgetFilterLine::PipelineWidgetFilterLine(QWidget* parent, FilterPtr filter, QButtonGroup* buttonGroup) :
26  BaseWidget(parent, "PipelineWidgetFilterLine", "PipelineWidgetFilterLine"),
27  mFilter(filter)
28 {
29  QHBoxLayout* layout = new QHBoxLayout(this);
30  connect(this, SIGNAL(requestRunFilter()), this, SLOT(requestRunFilterSlot()));
31 
32  mRadioButton = new QRadioButton(this);
33  buttonGroup->addButton(mRadioButton);
34  connect(mRadioButton, SIGNAL(toggled(bool)), this, SLOT(radioButtonSelectedSlot(bool)));
35  layout->addWidget(mRadioButton);
36  layout->setMargin(0);
37  layout->setSpacing(2);
38 
39  mAlgoNameLabel = new QLabel(QString("<b>%1</b>").arg(mFilter->getName()), this);
40  mAlgoNameLabel->setToolTip(mFilter->getHelp());
41  layout->addWidget(mAlgoNameLabel);
42 
45  layout->addWidget(mTimedAlgorithmProgressBar, 1);
46 
47  mAction = this->createAction(this,
48  QIcon(":/icons/open_icon_library/arrow-right-3.png"),
49  "Run Filter", "",
50  SIGNAL(requestRunFilter()),
51  NULL);
52  mAction->setData(mFilter->getUid());
53 
54  CXSmallToolButton* button = new CXSmallToolButton();
55  button->setObjectName("RunFilterButton");
56  button->setDefaultAction(mAction);
57  layout->addWidget(button);
58 
59 }
60 
61 void PipelineWidgetFilterLine::requestRunFilterSlot()
62 {
63  mRadioButton->setChecked(true);
64 }
65 
66 void PipelineWidgetFilterLine::radioButtonSelectedSlot(bool on)
67 {
68  if (!on)
69  return;
70 
71  emit filterSelected(mFilter->getUid());
72 }
73 
75 {
76  QWidget::mousePressEvent(event);
77 
78  mRadioButton->setChecked(true);
79 }
80 
84 
85 PipelineWidget::PipelineWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget* parent, PipelinePtr pipeline) :
86  BaseWidget(parent, "PipelineWidget", "Pipeline"),
87  mPipeline(pipeline)
88 {
89  this->setToolTip("Run a series of filters");
90  FilterGroupPtr filters = mPipeline->getFilters();
91  std::vector<SelectDataStringPropertyBasePtr> nodes = mPipeline->getNodes();
92  if (filters->size()+1 != nodes.size())
93  reportError("Filter/Node mismatch");
94 
95  QVBoxLayout* topLayout = new QVBoxLayout(this);
96  mButtonGroup = new QButtonGroup(this);
97 
98  struct Inner
99  {
100  static QHBoxLayout* addHMargin(QWidget* base)
101  {
102  QHBoxLayout* layout = new QHBoxLayout;
103  layout->addWidget(base);
104  layout->setContentsMargins(4,0,4,0);
105  return layout;
106  }
107  };
108 
109  for (unsigned i=0; i<filters->size(); ++i)
110  {
111  topLayout->addLayout(Inner::addHMargin(new DataSelectWidget(viewService, patientModelService, this, nodes[i])));
112 
113  PipelineWidgetFilterLine* algoLine = new PipelineWidgetFilterLine(this, filters->get(i), mButtonGroup);
114  connect(algoLine, SIGNAL(requestRunFilter()), this, SLOT(runFilterSlot()));
115  connect(algoLine, SIGNAL(filterSelected(QString)), this, SLOT(filterSelectedSlot(QString)));
116  algoLine->mTimedAlgorithmProgressBar->attach(mPipeline->getTimedAlgorithm(filters->get(i)->getUid()));
117 
118  mAlgoLines.push_back(algoLine);
119  QFrame* frame = this->wrapInFrame(algoLine);
120  frame->layout()->setContentsMargins(4,4,4,4); // nice on linux
121  frame->setObjectName("FilterBackground");
122  topLayout->addWidget(frame);
123  }
124  topLayout->addLayout(Inner::addHMargin(new DataSelectWidget(viewService, patientModelService, this, nodes.back())));
125 
126  topLayout->addSpacing(12);
127 
128  mSetupWidget = new CompactFilterSetupWidget(viewService, patientModelService, this, filters->getOptions(), true);
129  topLayout->addWidget(mSetupWidget);
130 
131  topLayout->addStretch();
132 
133  this->filterSelectedSlot(filters->get(0)->getUid());
134 }
135 
136 
137 void PipelineWidget::filterSelectedSlot(QString uid)
138 {
139  FilterPtr filter = mPipeline->getFilters()->get(uid);
140  mSetupWidget->setFilter(filter);
141 
142  for (unsigned i=0; i<mAlgoLines.size(); ++i)
143  if (mAlgoLines[i]->mFilter->getUid()==uid)
144  mAlgoLines[i]->mRadioButton->setChecked(true);
145 }
146 
147 void PipelineWidget::runFilterSlot()
148 {
149  PipelineWidgetFilterLine* line = dynamic_cast<PipelineWidgetFilterLine*>(sender());
150 
151  if (!line)
152  return;
153 
154  mPipeline->execute(line->mFilter->getUid());
155 }
156 
157 
158 } // namespace cx
cx::PipelineWidgetFilterLine::mAlgoNameLabel
QLabel * mAlgoNameLabel
Definition: cxPipelineWidget.h:36
cx::TimedAlgorithmProgressBar::setShowTextLabel
void setShowTextLabel(bool on)
Definition: cxTimedAlgorithmProgressBar.cpp:97
cxPipelineWidget.h
cxLogger.h
cx::TimedAlgorithmProgressBar
Show progress for a TimedBaseAlgorithm.
Definition: cxTimedAlgorithmProgressBar.h:51
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::BaseWidget
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
CXSmallToolButton
Definition: cxBaseWidget.h:66
cx::PipelineWidgetFilterLine::mAction
QAction * mAction
Definition: cxPipelineWidget.h:37
cx::BaseWidget::createAction
QAction * createAction(QObject *parent, QIcon iconName, QString text, QString tip, T slot, QLayout *layout=NULL, QToolButton *button=new QToolButton())
Definition: cxBaseWidget.h:129
cxHelperWidgets.h
cx::PipelineWidgetFilterLine::filterSelected
void filterSelected(QString uid)
cx::PipelineWidgetFilterLine::mTimedAlgorithmProgressBar
TimedAlgorithmProgressBar * mTimedAlgorithmProgressBar
Definition: cxPipelineWidget.h:38
cx::CompactFilterSetupWidget
Helper widget for displaying the input/output/options part of a Filter. Intended to be included in ot...
Definition: cxCompactFilterSetupWidget.h:35
cx::PipelineWidgetFilterLine::PipelineWidgetFilterLine
PipelineWidgetFilterLine(QWidget *parent, FilterPtr filter, QButtonGroup *buttonGroup)
Definition: cxPipelineWidget.cpp:25
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cx::TimedAlgorithmProgressBar::attach
void attach(TimedAlgorithmPtr algorithm)
Definition: cxTimedAlgorithmProgressBar.cpp:56
cx::ViewServicePtr
boost::shared_ptr< class ViewService > ViewServicePtr
Definition: cxLogicManager.h:28
cxTypeConversions.h
cx::PipelinePtr
boost::shared_ptr< Pipeline > PipelinePtr
Definition: cxPipeline.h:146
cxTimedAlgorithmProgressBar.h
cx::FilterPtr
boost::shared_ptr< class Filter > FilterPtr
Definition: cxForwardDeclarations.h:153
cxSettings.h
cx::PipelineWidgetFilterLine::requestRunFilter
void requestRunFilter()
cx::FilterGroupPtr
boost::shared_ptr< FilterGroup > FilterGroupPtr
Definition: cxFilterGroup.h:65
cx::PipelineWidgetFilterLine
Definition: cxPipelineWidget.h:29
cxDataSelectWidget.h
cx::BaseWidget::wrapInFrame
CXFrame * wrapInFrame(QWidget *base)
Definition: cxBaseWidget.cpp:73
cx::PipelineWidgetFilterLine::mousePressEvent
virtual void mousePressEvent(QMouseEvent *event)
Definition: cxPipelineWidget.cpp:74
cx::PipelineWidgetFilterLine::mRadioButton
QRadioButton * mRadioButton
Definition: cxPipelineWidget.h:35
cx::CompactFilterSetupWidget::setFilter
void setFilter(FilterPtr filter)
Definition: cxCompactFilterSetupWidget.cpp:66
cx::DataSelectWidget
Definition: cxDataSelectWidget.h:38
cx::PipelineWidget::PipelineWidget
PipelineWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PipelinePtr pipeline)
Definition: cxPipelineWidget.cpp:85
cx::reportError
void reportError(QString msg)
Definition: cxLogger.cpp:71
cx::PipelineWidgetFilterLine::mFilter
FilterPtr mFilter
Definition: cxPipelineWidget.h:39