Medical Imaging Interaction Toolkit  2022.04.99-2e1e005b
Medical Imaging Interaction Toolkit
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 QmitkC3Data_h
14 #define QmitkC3Data_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 //QmitkC3Data_h
Q_INVOKABLE QVariant GetTitle() const
QVariant m_chartTitle
void SetAppearance(bool showSubChart=true, bool usePercentageInPieChart=false)
Q_INVOKABLE void SetMinValueXView(const QVariant &minValueXView)
QVariant m_MaxValueXView
void SignalLegendPositionChanged(const QVariant legendPosition)
Q_INVOKABLE QVariant GetYAxisScale() const
Q_INVOKABLE void SetShowSubchart(const QVariant &showSubchart)
QVariant m_YAxisScale
Q_INVOKABLE void SetUsePercentageInPieChart(const QVariant &usePercentageInPieChart)
QVariant m_MinValueXView
This class holds the relevant properties for the chart generation with C3 such as labels and diagram ...
Q_INVOKABLE void SetMaxValueXView(const QVariant &maxValueXView)
QVariant m_LegendPosition
Q_INVOKABLE QVariant GetStackedData() const
QVariant m_DataPointSize
Q_INVOKABLE QVariant GetDataPointSize() const
void SignalXAxisLabelChanged(const QVariant label)
Q_INVOKABLE QVariant GetShowErrorBars() const
QVariant m_MinValueYView
void slotImageUrl(const QString &datafromjs)
Q_INVOKABLE QVariant GetThemeName() const
void SignalShowErrorBarsChanged(const QVariant show)
void SignalTitleChanged(const QVariant title)
Q_INVOKABLE void SetDataPointSize(const QVariant &showDataPoints)
Q_INVOKABLE void SetMaxValueYView(const QVariant &maxValueYView)
Q_INVOKABLE QVariant GetLegendPosition() const
Q_INVOKABLE QVariant GetXAxisLabel() const
Q_INVOKABLE QVariant GetMaxValueYView() const
void SignalDataPointSizeChanged(const QVariant showDataPoints)
void SignalYAxisScaleChanged(const QVariant YAxisScale)
void EmitSignalImageUrl()
QVariant m_yAxisLabel
Q_INVOKABLE QVariant GetMinValueYView() const
void SignalImageUrl()
QVariant m_MaxValueYView
void SignalStackedDataChanged(const QVariant stackedData)
Q_INVOKABLE void SetYAxisScale(const QVariant &YAxisScale)
Q_INVOKABLE void SetXAxisLabel(const QVariant &label)
void SignalThemeNameChanged(const QVariant themeName)
Q_INVOKABLE void SetShowLegend(const QVariant &show)
QVariant m_xAxisLabel
Q_INVOKABLE void SetYAxisLabel(const QVariant &label)
void SignalYAxisLabelChanged(const QVariant label)
QVariant m_ShowErrorBars
Q_INVOKABLE QVariant GetMinValueXView() const
Q_INVOKABLE QVariant GetShowSubchart() const
QVariant m_UsePercentageInPieChart
QVariant m_ShowSubchart
Q_INVOKABLE void SetMinValueYView(const QVariant &minValueYView)
void SignalShowSubchartChanged(const QVariant showSubchart)
QVariant m_themeName
Q_INVOKABLE void SetTitle(const QVariant &title)
QVariant m_StackedData
Q_INVOKABLE QVariant GetShowLegend() const
Q_INVOKABLE void SetShowErrorBars(const QVariant &show)
void SignalUsePercentageInPieChartChanged(const QVariant usePercentageInPieChart)
void SignalMinValueYViewChanged(const QVariant minValueYView)
void SignalMaxValueYViewChanged(const QVariant maxValueYView)
void SignalMinValueXViewChanged(const QVariant minValueXView)
Q_INVOKABLE void SetLegendPosition(const QVariant &legendPosition)
Q_INVOKABLE void SetStackedData(const QVariant &stackedData)
Q_INVOKABLE QVariant GetUsePercentageInPieChart() const
Q_INVOKABLE void SetThemeName(const QVariant &themeName)
void SignalMaxValueXViewChanged(const QVariant maxValueXView)
Q_INVOKABLE QVariant GetYAxisLabel() const
Q_INVOKABLE QVariant GetMaxValueXView() const
void SignalShowLegendChanged(const QVariant show)
QVariant m_ShowLegend