Medical Imaging Interaction Toolkit  2023.12.00
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
QmitkChartData.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef QmitkChartData_h
14 #define QmitkChartData_h
15 
16 #include <QmitkChartWidget.h>
17 #include <QVariant>
18 #include <QApplication>
19 #include <QClipboard>
20 #include <QUrl>
21 #include <QFileDialog>
22 #include <boost/algorithm/string.hpp>
23 #include <fstream>
24 
29 class QmitkChartData : public QObject
30 {
31  Q_OBJECT
32 
33  Q_PROPERTY(QVariant m_xAxisLabel READ GetXAxisLabel WRITE SetXAxisLabel NOTIFY SignalXAxisLabelChanged);
34  Q_PROPERTY(QVariant m_yAxisLabel READ GetYAxisLabel WRITE SetYAxisLabel NOTIFY SignalYAxisLabelChanged);
35  Q_PROPERTY(QVariant m_chartTitle READ GetTitle WRITE SetTitle NOTIFY SignalTitleChanged);
36  Q_PROPERTY(QVariant m_themeName READ GetThemeName WRITE SetThemeName NOTIFY SignalThemeNameChanged);
38  Q_PROPERTY(QVariant m_ShowLegend READ GetShowLegend WRITE SetShowLegend NOTIFY SignalShowLegendChanged);
40  Q_PROPERTY(QVariant m_YAxisScale READ GetYAxisScale WRITE SetYAxisScale NOTIFY SignalYAxisScaleChanged);
44  Q_PROPERTY(QVariant m_StackedData READ GetStackedData WRITE SetStackedData NOTIFY SignalStackedDataChanged);
48  Q_PROPERTY(QVariant m_MaxValueYView READ GetMaxValueYView WRITE SetMaxValueYView NOTIFY SignalMaxValueYViewChanged);
49 
50 public:
52 
53  void SetAppearance(bool showSubChart = true, bool usePercentageInPieChart = false);
54 
55  Q_INVOKABLE QVariant GetXAxisLabel() const { return m_xAxisLabel; };
56  Q_INVOKABLE void SetXAxisLabel(const QVariant& label) { m_xAxisLabel = label; emit SignalXAxisLabelChanged(label); };
57 
58  Q_INVOKABLE QVariant GetYAxisLabel() const { return m_yAxisLabel; };
59  Q_INVOKABLE void SetYAxisLabel(const QVariant& label) { m_yAxisLabel = label; emit SignalYAxisLabelChanged(label); };
60 
61  Q_INVOKABLE QVariant GetTitle() const { return m_chartTitle; };
62  Q_INVOKABLE void SetTitle(const QVariant& title) { m_chartTitle = title; emit SignalTitleChanged(title); };
63 
64  Q_INVOKABLE QVariant GetThemeName() const { return m_themeName; };
65  Q_INVOKABLE void SetThemeName(const QVariant &themeName)
66  {
67  m_themeName = themeName;
68  emit SignalThemeNameChanged(themeName);
69  };
70 
71  Q_INVOKABLE QVariant GetLegendPosition() const { return m_LegendPosition; };
72  Q_INVOKABLE void SetLegendPosition(const QVariant& legendPosition) { m_LegendPosition = legendPosition; emit SignalLegendPositionChanged(legendPosition); };
73 
74  Q_INVOKABLE QVariant GetShowLegend() const { return m_ShowLegend; };
75  Q_INVOKABLE void SetShowLegend(const QVariant& show) { m_ShowLegend = show; emit SignalShowLegendChanged(show); };
76 
77  Q_INVOKABLE QVariant GetShowErrorBars() const { return m_ShowErrorBars; };
78  Q_INVOKABLE void SetShowErrorBars(const QVariant &show)
79  {
80  m_ShowErrorBars = show;
81  emit SignalShowErrorBarsChanged(show);
82  };
83 
84  Q_INVOKABLE QVariant GetYAxisScale() const { return m_YAxisScale; };
85  Q_INVOKABLE void SetYAxisScale(const QVariant& YAxisScale) { m_YAxisScale = YAxisScale; emit SignalYAxisScaleChanged(YAxisScale); };
86 
87  Q_INVOKABLE QVariant GetShowSubchart() const { return m_ShowSubchart; };
88  Q_INVOKABLE void SetShowSubchart(const QVariant& showSubchart) { m_ShowSubchart = showSubchart; emit SignalShowSubchartChanged(showSubchart); };
89 
90  Q_INVOKABLE QVariant GetUsePercentageInPieChart() const { return m_UsePercentageInPieChart; };
91  Q_INVOKABLE void SetUsePercentageInPieChart(const QVariant& usePercentageInPieChart) { m_UsePercentageInPieChart = usePercentageInPieChart; emit SignalUsePercentageInPieChartChanged(usePercentageInPieChart); };
92 
93  Q_INVOKABLE QVariant GetDataPointSize() const { return m_DataPointSize; };
94  Q_INVOKABLE void SetDataPointSize(const QVariant& showDataPoints) { m_DataPointSize = showDataPoints; emit SignalDataPointSizeChanged(showDataPoints); };
95 
96  Q_INVOKABLE QVariant GetStackedData() const { return m_StackedData; };
97  Q_INVOKABLE void SetStackedData(const QVariant& stackedData) { m_StackedData = stackedData; emit SignalStackedDataChanged(m_StackedData); };
98 
99  Q_INVOKABLE QVariant GetMinValueXView() const { return m_MinValueXView; };
100  Q_INVOKABLE void SetMinValueXView(const QVariant &minValueXView)
101  {
102  m_MinValueXView = minValueXView;
104  };
105 
106  Q_INVOKABLE QVariant GetMaxValueXView() const { return m_MaxValueXView; };
107  Q_INVOKABLE void SetMaxValueXView(const QVariant &maxValueXView)
108  {
109  m_MaxValueXView = maxValueXView;
111  };
112 
113  Q_INVOKABLE QVariant GetMinValueYView() const { return m_MinValueYView; };
114  Q_INVOKABLE void SetMinValueYView(const QVariant &minValueYView)
115  {
116  m_MinValueYView = minValueYView;
118  };
119 
120  Q_INVOKABLE QVariant GetMaxValueYView() const { return m_MaxValueYView; };
121  Q_INVOKABLE void SetMaxValueYView(const QVariant &maxValueYView)
122  {
123  m_MaxValueYView = maxValueYView;
125  };
126 
128  {
129  emit SignalImageUrl();
130  };
131 
132 signals:
133  void SignalYAxisLabelChanged(const QVariant label);
134  void SignalXAxisLabelChanged(const QVariant label);
135  void SignalLegendPositionChanged(const QVariant legendPosition);
136  void SignalShowLegendChanged(const QVariant show);
137  void SignalShowErrorBarsChanged(const QVariant show);
138  void SignalYAxisScaleChanged(const QVariant YAxisScale);
139  void SignalTitleChanged(const QVariant title);
140  void SignalThemeNameChanged(const QVariant themeName);
141  void SignalShowSubchartChanged(const QVariant showSubchart);
142  void SignalUsePercentageInPieChartChanged(const QVariant usePercentageInPieChart);
143  void SignalDataPointSizeChanged(const QVariant showDataPoints);
144  void SignalStackedDataChanged(const QVariant stackedData);
145  void SignalMinValueXViewChanged(const QVariant minValueXView);
146  void SignalMaxValueXViewChanged(const QVariant maxValueXView);
147  void SignalMinValueYViewChanged(const QVariant minValueYView);
148  void SignalMaxValueYViewChanged(const QVariant maxValueYView);
149  void SignalImageUrl();
150 
151 public slots:
152  void slotImageUrl(const QString &datafromjs)
153  {
154  QString ds = QUrl::fromPercentEncoding(datafromjs.toLatin1());
155 
156  QString filename = QFileDialog::getSaveFileName(
157  0,
158  tr("Save Plot"),
159  "my_plot.svg",
160  tr("Scalable Vector Graphics (*.svg)") );
161  if (filename.isEmpty())
162  return;
163 
164  std::string out_image = ds.toStdString();
165  boost::algorithm::replace_first(out_image, "data:image/svg+xml,", "");
166  std::ofstream outfile(filename.toStdString());
167  outfile.write(out_image.c_str(), out_image.size());
168  outfile.close();
169  }
170 
171 private:
172  QVariant m_xAxisLabel;
173  QVariant m_yAxisLabel;
174  QVariant m_chartTitle;
175  QVariant m_themeName = "dark";
176 
177  QVariant m_ShowLegend = true;
178  QVariant m_ShowErrorBars;
179  QVariant m_LegendPosition = "topRight";
180  QVariant m_ShowSubchart;
181  QVariant m_YAxisScale;
182  QVariant m_UsePercentageInPieChart;
183  QVariant m_numberDatasets;
184  QVariant m_DataPointSize = 0;
185  QVariant m_StackedData;
186  QVariant m_MinValueXView;
187  QVariant m_MaxValueXView;
188  QVariant m_MinValueYView;
189  QVariant m_MaxValueYView;
190 };
191 
192 #endif
QmitkChartData::SetYAxisScale
Q_INVOKABLE void SetYAxisScale(const QVariant &YAxisScale)
Definition: QmitkChartData.h:85
QmitkChartData::m_ShowErrorBars
QVariant m_ShowErrorBars
Definition: QmitkChartData.h:38
QmitkChartData::GetThemeName
Q_INVOKABLE QVariant GetThemeName() const
Definition: QmitkChartData.h:64
QmitkChartData::SignalMaxValueYViewChanged
void SignalMaxValueYViewChanged(const QVariant maxValueYView)
QmitkChartData::m_chartTitle
QVariant m_chartTitle
Definition: QmitkChartData.h:34
QmitkChartData::SetTitle
Q_INVOKABLE void SetTitle(const QVariant &title)
Definition: QmitkChartData.h:62
QmitkChartData::GetLegendPosition
Q_INVOKABLE QVariant GetLegendPosition() const
Definition: QmitkChartData.h:71
QmitkChartData::m_StackedData
QVariant m_StackedData
Definition: QmitkChartData.h:43
QmitkChartData::SignalXAxisLabelChanged
void SignalXAxisLabelChanged(const QVariant label)
QmitkChartData::GetYAxisLabel
Q_INVOKABLE QVariant GetYAxisLabel() const
Definition: QmitkChartData.h:58
QmitkChartData::GetShowLegend
Q_INVOKABLE QVariant GetShowLegend() const
Definition: QmitkChartData.h:74
QmitkChartData::SignalMaxValueXViewChanged
void SignalMaxValueXViewChanged(const QVariant maxValueXView)
QmitkChartData::SetMinValueXView
Q_INVOKABLE void SetMinValueXView(const QVariant &minValueXView)
Definition: QmitkChartData.h:100
QmitkChartData::SignalYAxisLabelChanged
void SignalYAxisLabelChanged(const QVariant label)
QmitkChartData::SignalMinValueXViewChanged
void SignalMinValueXViewChanged(const QVariant minValueXView)
QmitkChartData::SetAppearance
void SetAppearance(bool showSubChart=true, bool usePercentageInPieChart=false)
QmitkChartData::SetDataPointSize
Q_INVOKABLE void SetDataPointSize(const QVariant &showDataPoints)
Definition: QmitkChartData.h:94
QmitkChartData::SetXAxisLabel
Q_INVOKABLE void SetXAxisLabel(const QVariant &label)
Definition: QmitkChartData.h:56
QmitkChartData::GetMinValueXView
Q_INVOKABLE QVariant GetMinValueXView() const
Definition: QmitkChartData.h:99
QmitkChartData::m_MinValueYView
QVariant m_MinValueYView
Definition: QmitkChartData.h:46
QmitkChartData::GetYAxisScale
Q_INVOKABLE QVariant GetYAxisScale() const
Definition: QmitkChartData.h:84
QmitkChartData::SignalImageUrl
void SignalImageUrl()
QmitkChartData::SetShowErrorBars
Q_INVOKABLE void SetShowErrorBars(const QVariant &show)
Definition: QmitkChartData.h:78
QmitkChartData::SignalStackedDataChanged
void SignalStackedDataChanged(const QVariant stackedData)
QmitkChartData::SignalUsePercentageInPieChartChanged
void SignalUsePercentageInPieChartChanged(const QVariant usePercentageInPieChart)
QmitkChartData::m_LegendPosition
QVariant m_LegendPosition
Definition: QmitkChartData.h:36
QmitkChartData::m_xAxisLabel
QVariant m_xAxisLabel
Definition: QmitkChartData.h:33
QmitkChartData::m_MinValueXView
QVariant m_MinValueXView
Definition: QmitkChartData.h:44
QmitkChartData::SignalShowSubchartChanged
void SignalShowSubchartChanged(const QVariant showSubchart)
QmitkChartData::GetMinValueYView
Q_INVOKABLE QVariant GetMinValueYView() const
Definition: QmitkChartData.h:113
QmitkChartData::SetMinValueYView
Q_INVOKABLE void SetMinValueYView(const QVariant &minValueYView)
Definition: QmitkChartData.h:114
QmitkChartData::SetMaxValueXView
Q_INVOKABLE void SetMaxValueXView(const QVariant &maxValueXView)
Definition: QmitkChartData.h:107
QmitkChartData::SetLegendPosition
Q_INVOKABLE void SetLegendPosition(const QVariant &legendPosition)
Definition: QmitkChartData.h:72
QmitkChartData::m_YAxisScale
QVariant m_YAxisScale
Definition: QmitkChartData.h:39
QmitkChartData::GetMaxValueYView
Q_INVOKABLE QVariant GetMaxValueYView() const
Definition: QmitkChartData.h:120
QmitkChartData::GetTitle
Q_INVOKABLE QVariant GetTitle() const
Definition: QmitkChartData.h:61
QmitkChartData::QmitkChartData
QmitkChartData()
QmitkChartData
This class holds the relevant properties for the chart generation with C3 such as labels and diagram ...
Definition: QmitkChartData.h:29
QmitkChartData::m_themeName
QVariant m_themeName
Definition: QmitkChartData.h:35
QmitkChartData::SetYAxisLabel
Q_INVOKABLE void SetYAxisLabel(const QVariant &label)
Definition: QmitkChartData.h:59
QmitkChartWidget.h
QmitkChartData::GetShowErrorBars
Q_INVOKABLE QVariant GetShowErrorBars() const
Definition: QmitkChartData.h:77
QmitkChartData::SignalShowLegendChanged
void SignalShowLegendChanged(const QVariant show)
QmitkChartData::SetUsePercentageInPieChart
Q_INVOKABLE void SetUsePercentageInPieChart(const QVariant &usePercentageInPieChart)
Definition: QmitkChartData.h:91
QmitkChartData::SignalLegendPositionChanged
void SignalLegendPositionChanged(const QVariant legendPosition)
QmitkChartData::SignalThemeNameChanged
void SignalThemeNameChanged(const QVariant themeName)
QmitkChartData::SetShowSubchart
Q_INVOKABLE void SetShowSubchart(const QVariant &showSubchart)
Definition: QmitkChartData.h:88
QmitkChartData::GetShowSubchart
Q_INVOKABLE QVariant GetShowSubchart() const
Definition: QmitkChartData.h:87
QmitkChartData::SetThemeName
Q_INVOKABLE void SetThemeName(const QVariant &themeName)
Definition: QmitkChartData.h:65
QmitkChartData::GetXAxisLabel
Q_INVOKABLE QVariant GetXAxisLabel() const
Definition: QmitkChartData.h:55
QmitkChartData::m_MaxValueXView
QVariant m_MaxValueXView
Definition: QmitkChartData.h:45
QmitkChartData::SignalShowErrorBarsChanged
void SignalShowErrorBarsChanged(const QVariant show)
QmitkChartData::SignalTitleChanged
void SignalTitleChanged(const QVariant title)
QmitkChartData::SetShowLegend
Q_INVOKABLE void SetShowLegend(const QVariant &show)
Definition: QmitkChartData.h:75
QmitkChartData::EmitSignalImageUrl
void EmitSignalImageUrl()
Definition: QmitkChartData.h:127
QmitkChartData::GetMaxValueXView
Q_INVOKABLE QVariant GetMaxValueXView() const
Definition: QmitkChartData.h:106
QmitkChartData::SetMaxValueYView
Q_INVOKABLE void SetMaxValueYView(const QVariant &maxValueYView)
Definition: QmitkChartData.h:121
QmitkChartData::m_UsePercentageInPieChart
QVariant m_UsePercentageInPieChart
Definition: QmitkChartData.h:41
QmitkChartData::slotImageUrl
void slotImageUrl(const QString &datafromjs)
Definition: QmitkChartData.h:152
QmitkChartData::GetStackedData
Q_INVOKABLE QVariant GetStackedData() const
Definition: QmitkChartData.h:96
QmitkChartData::SignalYAxisScaleChanged
void SignalYAxisScaleChanged(const QVariant YAxisScale)
QmitkChartData::m_ShowLegend
QVariant m_ShowLegend
Definition: QmitkChartData.h:37
QmitkChartData::SignalMinValueYViewChanged
void SignalMinValueYViewChanged(const QVariant minValueYView)
QmitkChartData::m_DataPointSize
QVariant m_DataPointSize
Definition: QmitkChartData.h:42
QmitkChartData::GetUsePercentageInPieChart
Q_INVOKABLE QVariant GetUsePercentageInPieChart() const
Definition: QmitkChartData.h:90
QmitkChartData::SetStackedData
Q_INVOKABLE void SetStackedData(const QVariant &stackedData)
Definition: QmitkChartData.h:97
QmitkChartData::m_ShowSubchart
QVariant m_ShowSubchart
Definition: QmitkChartData.h:40
QmitkChartData::GetDataPointSize
Q_INVOKABLE QVariant GetDataPointSize() const
Definition: QmitkChartData.h:93
QmitkChartData::m_MaxValueYView
QVariant m_MaxValueYView
Definition: QmitkChartData.h:47
QmitkChartData::SignalDataPointSizeChanged
void SignalDataPointSizeChanged(const QVariant showDataPoints)
QmitkChartData::m_yAxisLabel
QVariant m_yAxisLabel
Definition: QmitkChartData.h:33