CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxHelperWidgets.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 
13 /*
14  * sscHelperWidgets.cpp
15  *
16  * Created on: May 18, 2010
17  * Author: christiana
18  */
19 #include "cxHelperWidgets.h"
20 
21 #include <iostream>
22 #include "boost/shared_ptr.hpp"
23 #include "cxDoubleWidgets.h"
25 #include "cxCheckBoxWidget.h"
26 #include "cxColorSelectWidget.h"
27 #include "cxTypeConversions.h"
29 #include "cxDoubleSpanSlider.h"
30 #include "cxFilenameWidget.h"
32 #include "cxDataSelectWidget.h"
34 #include "cxFilePathProperty.h"
35 #include "cxFilePreviewProperty.h"
36 #include "cxFilePreviewWidget.h"
37 #include "cxLogger.h"
38 
39 namespace cx
40 {
41 QWidget* createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget* parent, PropertyPtr data, QGridLayout* gridLayout, int row)
42 {
43  QWidget* retval = NULL;
44 
45  //make cx widgets
46  SelectDataStringPropertyBasePtr dsda = boost::dynamic_pointer_cast<SelectDataStringPropertyBase>(data);
47  if (dsda)
48  {
49  retval = new DataSelectWidget(viewService, patientModelService, parent, dsda, gridLayout, row);
50  return retval;
51  }
52  if(retval != NULL)
53  return retval;
54 
55  retval = sscCreateDataWidget(parent, data, gridLayout, row);
56  return retval;
57 }
58 
59 QWidget* sscCreateDataWidget(QWidget* parent, PropertyPtr data, QGridLayout* gridLayout, int row)
60 {
61  FilePathPropertyPtr fp = boost::dynamic_pointer_cast<FilePathProperty>(data);
62  if (fp)
63  {
64  return new FilenameWidget(parent, fp, gridLayout, row);
65  }
66 
67  StringPropertyBasePtr str = boost::dynamic_pointer_cast<StringPropertyBase>(data);
68  if (str)
69  {
70  // if (str->getGuiRepresentation()==StringPropertyBase::grFILENAME)
71  // return new FilenameWidget(parent, str, gridLayout, row);
72  if (str->getAllowOnlyValuesInRange())
73  return new LabeledComboBoxWidget(parent, str, gridLayout, row);
74  else
75  return new LabeledLineEditWidget(parent, str, gridLayout, row);
76  }
77 
78  DoublePropertyBasePtr dbl = boost::dynamic_pointer_cast<DoublePropertyBase>(data);
79  if (dbl)
80  {
82  switch(gui)
83  {
85  return new SpinBoxAndSliderGroupWidget(parent, dbl, gridLayout, row);
86  break;
88  return new SpinBoxGroupWidget(parent, dbl, gridLayout, row);
89  break;
91  return new SpinBoxAndDialGroupWidget(parent, dbl, gridLayout, row);
92  }
93  }
94 
95  BoolPropertyBasePtr bl = boost::dynamic_pointer_cast<BoolPropertyBase>(data);
96  if (bl)
97  {
98  return new CheckBoxWidget(parent, bl, gridLayout, row);
99  }
100 
101  ColorPropertyBasePtr cl = boost::dynamic_pointer_cast<ColorPropertyBase>(data);
102  if (cl)
103  {
104  return new ColorSelectWidget(parent, cl, gridLayout, row);
105  }
106  DoublePairPropertyBasePtr doublepair = boost::dynamic_pointer_cast<DoublePairPropertyBase>(data);
107  if (doublepair)
108  {
109  return new SliderRangeGroupWidget(parent, doublepair, gridLayout, row);
110  }
111 
112  FilePreviewPropertyPtr filePreview = boost::dynamic_pointer_cast<FilePreviewProperty>(data);
113  if (filePreview)
114  {
115  return new FilePreviewWidget(parent, filePreview, gridLayout, row);
116  }
117 
118  std::cout << "Failed to create Data Widget for " << (data ? data->getDisplayName() : "NULL") << std::endl;
119 
120  return NULL;
121 }
122 
123 QWidget* addDummyMargin(QWidget* widget)
124 {
125  QHBoxLayout* topLayout = new QHBoxLayout;
126  topLayout->setContentsMargins(1,0,0,0);
127  widget->setLayout(topLayout);
128  return widget;
129 }
130 
131 QHBoxLayout* mergeWidgetsIntoHBoxLayout(QWidget* first, QWidget* second)
132 {
133  QHBoxLayout* hackLayout = new QHBoxLayout;
134  hackLayout->setMargin(0);
135  hackLayout->setSpacing(0);
136 
137  if (first)
138  hackLayout->addWidget(first);
139  if (second)
140  hackLayout->addWidget(second);
141 
142  return hackLayout;
143 }
144 
145 }
QWidget * addDummyMargin(QWidget *widget)
virtual GuiRepresentation getGuiRepresentation()
Widget for the BoolPropertyBase.
boost::shared_ptr< class FilePreviewProperty > FilePreviewPropertyPtr
Composite widget for filename edit.
boost::shared_ptr< class ViewService > ViewServicePtr
Widget for the ColorPropertyBase.
Composite widget for string selection.
boost::shared_ptr< DoublePairPropertyBase > DoublePairPropertyBasePtr
Composite widget for string edit.
QWidget * createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
QHBoxLayout * mergeWidgetsIntoHBoxLayout(QWidget *first, QWidget *second)
Abstract interface for interaction with internal string-valued data.
Composite widget for scalar data manipulation.
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
boost::shared_ptr< class StringPropertyBase > StringPropertyBasePtr
View a xml document.
boost::shared_ptr< class Property > PropertyPtr
boost::shared_ptr< class BoolPropertyBase > BoolPropertyBasePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
boost::shared_ptr< class DoublePropertyBase > DoublePropertyBasePtr
Property that connects to a file. Allows file preview and edit.
Composite widget for scalar data manipulation.
QWidget * sscCreateDataWidget(QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
boost::shared_ptr< class ColorPropertyBase > ColorPropertyBasePtr
Abstract interface for interaction with internal data structure: A pair of doubles.
boost::shared_ptr< class FilePathProperty > FilePathPropertyPtr
Composite widget for scalar data manipulation.
Namespace for all CustusX production code.