Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxFilterSetupWidget.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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. 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 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxFilterSetupWidget.h"
34 
35 #include <QGroupBox>
36 #include <QCheckBox>
37 #include "cxFilterPresetWidget.h"
39 #include "cxVisServices.h"
40 #include "cxLogger.h"
41 
42 namespace cx
43 {
44 FilterSetupWidget::FilterSetupWidget(VisServicesPtr services, QWidget* parent, XmlOptionFile options, bool addFrame) :
45  BaseWidget(parent, "FilterSetupWidget", "FilterSetup"),
46  mServices(services)
47 {
48  mFrame = NULL;
49 
50  QVBoxLayout* toptopLayout = new QVBoxLayout(this);
51  toptopLayout->setMargin(0);
52 
53  QWidget* topWidget = new QWidget;
54  QVBoxLayout* topLayout = new QVBoxLayout(topWidget);
55  topLayout->setMargin(0);
56 
57  if (addFrame)
58  {
59  mFrame = this->wrapInGroupBox(topWidget, "Algorithm");
60  toptopLayout->addWidget(mFrame);
61  }
62  else
63  {
64  toptopLayout->addWidget(topWidget);
65  }
66 
67  mObscuredListener.reset(new WidgetObscuredListener(this));
68  connect(mObscuredListener.get(), SIGNAL(obscured(bool)), this, SLOT(obscuredSlot(bool)));
69 
70  mOptions = options;
71 
72  mInputsWidget = new OptionsWidget(mServices->view(), mServices->patient(), this);
73  mOutputsWidget = new OptionsWidget(mServices->view(), mServices->patient(), this);
74  mOptionsWidget = new OptionsWidget(mServices->view(), mServices->patient(), this);
75  mPresetWidget = new FilterPresetWidget(this);
76  mAdvancedButton = new QCheckBox("Show advanced options", this);
77  connect(mAdvancedButton, SIGNAL(stateChanged(int)), this, SLOT(showAdvancedOptions(int)));
78 
79  topLayout->addWidget(this->wrapInGroupBox(mInputsWidget, "Input"));
80  topLayout->addWidget(this->wrapInGroupBox(mOutputsWidget, "Output"));
81  topLayout->addWidget(mPresetWidget);
82  mOptionsGroupBox = this->wrapInGroupBox(mOptionsWidget, "Options");
83  topLayout->addWidget(mOptionsGroupBox);
84  topLayout->addWidget(mAdvancedButton);
85 }
86 
87 void FilterSetupWidget::obscuredSlot(bool obscured)
88 {
89  if (mCurrentFilter)
90  mCurrentFilter->setActive(!obscured);
91 }
92 
93 void FilterSetupWidget::showAdvancedOptions(int state)
94 {
95  if(state > 0)
96  {
97  mInputsWidget->showAdvanced(true);
98  mOutputsWidget->showAdvanced(true);
99  mOptionsWidget->showAdvanced(true);
100  }else{
101  mInputsWidget->showAdvanced(false);
102  mOutputsWidget->showAdvanced(false);
103  mOptionsWidget->showAdvanced(false);
104  }
105 }
106 
107 void FilterSetupWidget::rebuildOptions()
108 {
109  if(mOptionsWidget)
110  mOptionsWidget->rebuild();
111 }
112 
114 {
115  QString name("None");
116  QString help("");
117  if (mCurrentFilter)
118  {
119  name = mCurrentFilter->getName();
120  help = mCurrentFilter->getHelp();
121  }
122  return QString("<html>"
123  "<h4>%1</h4>"
124  "<p>%2</p>"
125  "</html>").arg(name).arg(help);
126 }
127 
128 void FilterSetupWidget::setVisibilityOfOptionsAndAdvancedOptions()
129 {
130  mAdvancedButton->setVisible(mOptionsWidget->hasAdvancedOptions());
131  this->showAdvancedOptions(mAdvancedButton->isChecked());
132  mOptionsGroupBox->setVisible(mOptionsWidget->hasOptions());
133 }
134 
136 {
137  if (filter==mCurrentFilter)
138  return;
139 
140  if (mCurrentFilter)
141  mCurrentFilter->setActive(false);
142 
143  mCurrentFilter = filter;
144  connect(mCurrentFilter.get(), &Filter::changed, this, &FilterSetupWidget::rebuildOptions);
145 
146  if (mFrame)
147  mFrame->setTitle(mCurrentFilter->getName());
148 
149  if (mCurrentFilter)
150  {
151  mCurrentFilter->setActive(!mObscuredListener->isObscured());
152 
153  mInputsWidget->setOptions(mCurrentFilter->getUid(), mCurrentFilter->getInputTypes(), false);
154  mOutputsWidget->setOptions(mCurrentFilter->getUid(), mCurrentFilter->getOutputTypes(), false);
155  mOptionsWidget->setOptions(mCurrentFilter->getUid(), mCurrentFilter->getOptions(), false);
156 
157  //presets
158  if(mCurrentFilter->hasPresets())
159  {
160  connect(mPresetWidget, &PresetWidget::presetSelected, mCurrentFilter.get(), &Filter::requestSetPresetSlot);
161  //mPresetWidget->setPresets(mCurrentFilter->getPresets());
162  mPresetWidget->setFilter(mCurrentFilter);
163  mCurrentFilter->requestSetPresetSlot("default");
164  mPresetWidget->show();
165  } else
166  mPresetWidget->hide();
167 
168  this->setObjectName(mCurrentFilter->getType());
169 
170  this->setVisibilityOfOptionsAndAdvancedOptions();
171  }
172  else
173  {
174  mInputsWidget->setOptions("", std::vector<PropertyPtr>(), false);
175  mOutputsWidget->setOptions("", std::vector<PropertyPtr>(), false);
176  mOptionsWidget->setOptions("", std::vector<PropertyPtr>(), false);
177  }
178 
179  this->setToolTip(this->generateHelpText());
180 }
181 
183 {
184  if(mOptionsGroupBox->isHidden())
185  {
186  if(mOptionsWidget->hasOptions())
187  {
188  mOptionsGroupBox->show();
189  if(mOptionsWidget->hasAdvancedOptions())
190  mAdvancedButton->show();
191  }
192  mPresetWidget->showDetailed(true);
193  }
194  else
195  {
196  mOptionsGroupBox->hide();
197  mAdvancedButton->hide();
198  mPresetWidget->showDetailed(false);
199  }
200 }
201 
202 } // namespace cx
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
QGroupBox * wrapInGroupBox(QWidget *base, QString name)
void showDetailed(bool detailed)
sets the presetwidget in detailed mode or not
bool hasAdvancedOptions() const
bool hasOptions() const
boost::shared_ptr< class Filter > FilterPtr
QString generateHelpText() const
void setFilter(FilterPtr filter)
void showAdvanced(bool show)
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
void setFilter(FilterPtr filter)
sets which filter to operate on
virtual void requestSetPresetSlot(QString name)=0
void setOptions(QString uid, std::vector< PropertyPtr > options, bool showAdvanced)
void presetSelected(QString name)
Helper class for xml files used to store ssc/cx data.
FilterSetupWidget(VisServicesPtr services, QWidget *parent, XmlOptionFile options, bool addFrame)
void changed()