CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxFilterWidget.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 "cxFilterWidget.h"
34 
35 #include <QGroupBox>
36 #include <QCheckBox>
37 #include "cxFilterPresetWidget.h"
39 #include "cxVisServices.h"
40 
41 namespace cx
42 {
43 FilterSetupWidget::FilterSetupWidget(VisServicesPtr services, QWidget* parent, XmlOptionFile options, bool addFrame) :
44  BaseWidget(parent, "FilterSetupWidget", "FilterSetup"),
45  mServices(services)
46 {
47  mFrame = NULL;
48 
49  QVBoxLayout* toptopLayout = new QVBoxLayout(this);
50  toptopLayout->setMargin(0);
51 
52  QWidget* topWidget = new QWidget;
53  QVBoxLayout* topLayout = new QVBoxLayout(topWidget);
54  topLayout->setMargin(0);
55 
56  if (addFrame)
57  {
58  mFrame = this->wrapInGroupBox(topWidget, "Algorithm");
59  toptopLayout->addWidget(mFrame);
60  }
61  else
62  {
63  toptopLayout->addWidget(topWidget);
64  }
65 
66  mObscuredListener.reset(new WidgetObscuredListener(this));
67  connect(mObscuredListener.get(), SIGNAL(obscured(bool)), this, SLOT(obscuredSlot(bool)));
68 
69  mOptions = options;
70 
71  mInputsWidget = new OptionsWidget(mServices->visualizationService, mServices->getPatientService(), this);
72  mOutputsWidget = new OptionsWidget(mServices->visualizationService, mServices->getPatientService(), this);
73  mOptionsWidget = new OptionsWidget(mServices->visualizationService, mServices->getPatientService(), this);
74  mPresetWidget = new FilterPresetWidget(this);
75  mAdvancedButton = new QCheckBox("Show &advanced options", this);
76  connect(mAdvancedButton, SIGNAL(stateChanged(int)), this, SLOT(showAdvancedOptions(int)));
77 
78  topLayout->addWidget(this->wrapInGroupBox(mInputsWidget, "Input"));
79  topLayout->addWidget(this->wrapInGroupBox(mOutputsWidget, "Output"));
80  topLayout->addWidget(mPresetWidget);
81  mOptionsGroupBox = this->wrapInGroupBox(mOptionsWidget, "Options");
82  topLayout->addWidget(mOptionsGroupBox);
83  topLayout->addWidget(mAdvancedButton);
84 }
85 
86 void FilterSetupWidget::obscuredSlot(bool obscured)
87 {
88  if (mCurrentFilter)
89  mCurrentFilter->setActive(!obscured);
90 }
91 
92 void FilterSetupWidget::showAdvancedOptions(int state)
93 {
94  if(state > 0)
95  {
96  mInputsWidget->showAdvanced(true);
97  mOutputsWidget->showAdvanced(true);
98  mOptionsWidget->showAdvanced(true);
99  }else{
100  mInputsWidget->showAdvanced(false);
101  mOutputsWidget->showAdvanced(false);
102  mOptionsWidget->showAdvanced(false);
103  }
104 }
105 
106 void FilterSetupWidget::rebuildOptions()
107 {
108  if(mOptionsWidget)
109  mOptionsWidget->rebuild();
110 }
111 
113 {
114  QString name("None");
115  QString help("");
116  if (mCurrentFilter)
117  {
118  name = mCurrentFilter->getName();
119  help = mCurrentFilter->getHelp();
120  }
121  return QString("<html>"
122  "<h4>%1</h4>"
123  "<p>%2</p>"
124  "</html>").arg(name).arg(help);
125 }
126 
128 {
129  if (filter==mCurrentFilter)
130  return;
131 
132  if (mCurrentFilter)
133  mCurrentFilter->setActive(false);
134 
135  mCurrentFilter = filter;
136  connect(mCurrentFilter.get(), SIGNAL(changed()), this, SLOT(rebuildOptions()));
137 
138  if (mFrame)
139  mFrame->setTitle(mCurrentFilter->getName());
140 
141  if (mCurrentFilter)
142  {
143  mCurrentFilter->setActive(!mObscuredListener->isObscured());
144 
145  std::vector<SelectDataStringPropertyBasePtr> inputTypes = mCurrentFilter->getInputTypes();
146  std::vector<SelectDataStringPropertyBasePtr> outputTypes = mCurrentFilter->getOutputTypes();
147  std::vector<PropertyPtr> options = mCurrentFilter->getOptions();
148 
149  mInputsWidget->setOptions(mCurrentFilter->getUid(), mCurrentFilter->getInputTypes(), false);
150  mOutputsWidget->setOptions(mCurrentFilter->getUid(), mCurrentFilter->getOutputTypes(), false);
151  mOptionsWidget->setOptions(mCurrentFilter->getUid(), options, false);
152 
153  //presets
154  if(mCurrentFilter->hasPresets())
155  {
156  connect(mPresetWidget, SIGNAL(presetSelected(QString)), mCurrentFilter.get(), SLOT(requestSetPresetSlot(QString)));
157  //mPresetWidget->setPresets(mCurrentFilter->getPresets());
158  mPresetWidget->setFilter(mCurrentFilter);
159  mCurrentFilter->requestSetPresetSlot("default");
160  mPresetWidget->show();
161  } else
162  mPresetWidget->hide();
163  }
164  else
165  {
166  mInputsWidget->setOptions("", std::vector<PropertyPtr>(), false);
167  mOutputsWidget->setOptions("", std::vector<PropertyPtr>(), false);
168  mOptionsWidget->setOptions("", std::vector<PropertyPtr>(), false);
169  }
170 }
171 
173 {
174  if(mOptionsGroupBox->isHidden())
175  {
176  mOptionsGroupBox->show();
177  mAdvancedButton->show();
178  mPresetWidget->showDetailed(true);
179  }
180  else
181  {
182  mOptionsGroupBox->hide();
183  mAdvancedButton->hide();
184  mPresetWidget->showDetailed(false);
185  }
186 }
187 
188 } // namespace cx
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:61
QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
QGroupBox * wrapInGroupBox(QWidget *base, QString name)
void showDetailed(bool detailed)
sets the presetwidget in detailed mode or not
boost::shared_ptr< class Filter > FilterPtr
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
void setOptions(QString uid, std::vector< PropertyPtr > options, bool showAdvanced)
Helper class for xml files used to store ssc/cx data.
FilterSetupWidget(VisServicesPtr services, QWidget *parent, XmlOptionFile options, bool addFrame)