3 #include "PlotWindowBestFitDialog.h"
7 #include <qwt_plot_spectrogram.h>
10 #include <QColorDialog>
12 #include <QGridLayout>
15 #include <QPushButton>
19 #include "ScatterPlotData.h"
35 QGridLayout *optionsLayout =
new QGridLayout;
38 QLabel *titleLabel =
new QLabel(
"Curve To Fit: ");
41 optionsLayout->addWidget(titleLabel, row, 0);
47 QLabel *equationTitleLabel =
new QLabel(
"Equation from Curve: ");
49 optionsLayout->addWidget(equationTitleLabel, row, 0);
53 QLabel *correlationTitleLabel =
new QLabel(
"Correlation Coefficient (r): ");
55 optionsLayout->addWidget(correlationTitleLabel, row, 0);
59 QLabel *determinationTitleLabel =
new QLabel(
60 "Coefficient of Determination (r<sup>2</sup>): ");
62 optionsLayout->addWidget(determinationTitleLabel, row, 0);
66 QHBoxLayout *applyButtonsLayout =
new QHBoxLayout;
67 applyButtonsLayout->addStretch();
77 QPushButton *cancel =
new QPushButton(
"&Cancel");
78 cancel->setIcon(QIcon::fromTheme(
"dialog-cancel"));
79 connect(cancel, SIGNAL(clicked()),
81 applyButtonsLayout->addWidget(cancel);
84 optionsHolder->setLayout(optionsLayout);
87 applyButtonsHolder->setLayout(applyButtonsLayout);
89 QVBoxLayout *mainLayout =
new QVBoxLayout;
90 mainLayout->addWidget(optionsHolder);
91 mainLayout->addWidget(applyButtonsHolder);
93 setLayout(mainLayout);
100 PlotWindowBestFitDialog::~PlotWindowBestFitDialog() {
127 int dataSize = selected->dataSize();
130 for (
int i = 0; i < dataSize; i++) {
131 data[i].setX(selected->sample(i).x());
132 data[i].setY(a + b * data[i].x());
135 newCurve->
setData(
new QwtPointSeriesData(data));
139 newSymbol.setStyle(QwtSymbol::NoSymbol);
142 QPen pen(newCurve->pen());
143 pen.setStyle(Qt::SolidLine);
146 newCurve->setTitle(selected->title().text() +
" Best Fit");
174 int dataSize = rawXValues.size();
177 for (
int i = 0; i < dataSize; i++) {
178 data[i].setX(rawXValues[i]);
179 data[i].setY(a + b * data[i].x());
182 newCurve->
setData(
new QwtPointSeriesData(data));
186 newSymbol.setStyle(QwtSymbol::NoSymbol);
189 QPen pen(newCurve->pen());
190 pen.setStyle(Qt::SolidLine);
193 newCurve->setTitle(selected->title().text() +
" Best Fit");
213 foreach (QwtPlotSpectrogram *spectrogram, spectrograms) {
214 if (dynamic_cast<ScatterPlotData *>(spectrogram->data())) {
215 m_curvesCombo->addItem( spectrogram->title().text(), qVariantFromValue(spectrogram) );
222 m_curvesCombo->addItem( curve->title().text(), qVariantFromValue(curve) );
234 bool canDeriveEquation =
false;
240 int dataSize = selected->dataSize();
241 for (
int dataPoint = 0; dataPoint < dataSize; dataPoint++) {
242 double x = selected->sample(dataPoint).x();
243 double y = selected->sample(dataPoint).y();
258 int binValue = scatterData->
binCount(i);
277 canDeriveEquation =
true;
286 IString(correlation * correlation).ToQt());
297 if (!canDeriveEquation) {
320 if (selected != NULL && curves.indexOf(selected) == -1) {
338 QwtPlotSpectrogram *selected = NULL;
342 m_curvesCombo->currentIndex()).value<QwtPlotSpectrogram *>();
347 if (selected != NULL && spectrograms.indexOf(selected) == -1) {