scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

InterpolationDialog.cpp
Go to the documentation of this file.
1 
11 
29 #include "InterpolationDialog.h"
30 #include "Graph.h"
31 #include "MyParser.h"
32 #include "ColorButton.h"
33 #include "Interpolation.h"
34 
35 #include <QGroupBox>
36 #include <QSpinBox>
37 #include <QMessageBox>
38 #include <QPushButton>
39 #include <QLabel>
40 #include <QLineEdit>
41 #include <QComboBox>
42 #include <QLayout>
43 
44 InterpolationDialog::InterpolationDialog( QWidget* parent, Qt::WindowFlags fl )
45  : QDialog( parent, fl )
46 {
47  setWindowTitle(tr("Interpolation Options"));
48 
49  QGroupBox *gb1 = new QGroupBox();
50  QGridLayout *gl1 = new QGridLayout(gb1);
51  gl1->addWidget(new QLabel(tr("Make curve from")), 0, 0);
52 
53  boxName = new QComboBox();
54  gl1->addWidget(boxName, 0, 1);
55 
56  gl1->addWidget(new QLabel(tr("Spline")), 1, 0);
57  boxMethod = new QComboBox();
58  boxMethod->addItem(tr("Linear"));
59  boxMethod->addItem(tr("Cubic"));
60  boxMethod->addItem(tr("Non-rounded Akima"));
61  gl1->addWidget(boxMethod, 1, 1);
62 
63  gl1->addWidget(new QLabel(tr("Points")), 2, 0);
64  boxPoints = new QSpinBox();
65  boxPoints->setRange(3,100000);
66  boxPoints->setSingleStep(10);
67  boxPoints->setValue(1000);
68  gl1->addWidget(boxPoints, 2, 1);
69 
70  gl1->addWidget(new QLabel(tr("From Xmin")), 3, 0);
71  boxStart = new QLineEdit();
72  boxStart->setText(tr("0"));
73  gl1->addWidget(boxStart, 3, 1);
74 
75  gl1->addWidget(new QLabel(tr("To Xmax")), 4, 0);
76  boxEnd = new QLineEdit();
77  gl1->addWidget(boxEnd, 4, 1);
78 
79  gl1->addWidget(new QLabel(tr("Color")), 5, 0);
80 
81  btnColor = new ColorButton();
82  btnColor->setColor(QColor(Qt::red));
83  gl1->addWidget(btnColor, 5, 1);
84  gl1->setRowStretch(6, 1);
85 
86  buttonFit = new QPushButton(tr( "&Make" ));
87  buttonFit->setDefault( true );
88  buttonCancel = new QPushButton(tr( "&Close" ));
89 
90  QVBoxLayout *vl = new QVBoxLayout();
91  vl->addWidget(buttonFit);
92  vl->addWidget(buttonCancel);
93  vl->addStretch();
94 
95  QHBoxLayout *hb = new QHBoxLayout(this);
96  hb->addWidget(gb1);
97  hb->addLayout(vl);
98 
99  connect( boxName, SIGNAL(activated(const QString&)), this, SLOT( activateCurve(const QString&)));
100  connect( buttonFit, SIGNAL( clicked() ), this, SLOT( interpolate() ) );
101  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
102 }
103 
105 {
106 QString curve = boxName->currentText();
107 QStringList curvesList = graph->analysableCurvesList();
108 if (!curvesList.contains(curve))
109  {
110  QMessageBox::critical(this,tr("Warning"),
111  tr("The curve <b> %1 </b> doesn't exist anymore! Operation aborted!").arg(curve));
112  boxName->clear();
113  boxName->addItems(curvesList);
114  return;
115  }
116 
117 double from, to;
118 try
119  {
120  MyParser parser;
121  parser.SetExpr(boxStart->text().replace(",", "."));
122  from = parser.Eval();
123  }
124 catch(mu::ParserError &e)
125  {
126  QMessageBox::critical(this, tr("Start limit error"), QStringFromString(e.GetMsg()));
127  boxStart->setFocus();
128  return;
129  }
130 
131 try
132  {
133  MyParser parser;
134  parser.SetExpr(boxEnd->text().replace(",", "."));
135  to = parser.Eval();
136  }
137 catch(mu::ParserError &e)
138  {
139  QMessageBox::critical(this, tr("End limit error"), QStringFromString(e.GetMsg()));
140  boxEnd->setFocus();
141  return;
142  }
143 
144 if (from >= to)
145  {
146  QMessageBox::critical(this, tr("Input error"), tr("Please enter x limits that satisfy: from < to!"));
147  boxEnd->setFocus();
148  return;
149  }
150 
151 Interpolation *i = new Interpolation((ApplicationWindow *)this->parent(), graph, curve,
152  from, to, boxMethod->currentIndex());
153 i->setOutputPoints(boxPoints->value());
154 i->setColor(btnColor->color());
155 i->run();
156 delete i;
157 }
158 
160 {
161  graph = g;
162  boxName->addItems(g->analysableCurvesList());
163 
164  QString selectedCurve = g->selectedCurveTitle();
165  if (!selectedCurve.isEmpty())
166  {
167  int index = boxName->findText (selectedCurve);
168  boxName->setCurrentIndex(index);
169  }
170 
171  activateCurve(boxName->currentText());
172 
173  connect (graph, SIGNAL(closedGraph()), this, SLOT(close()));
174  connect (graph, SIGNAL(dataRangeChanged()), this, SLOT(changeDataRange()));
175 };
176 
177 void InterpolationDialog::activateCurve(const QString& curveName)
178 {
179  QwtPlotCurve *c = graph->curve(curveName);
180  if (!c)
181  return;
182 
183  ApplicationWindow *app = (ApplicationWindow *)parent();
184  if(!app)
185  return;
186 
187  double start, end;
188  graph->range(graph->curveIndex(curveName), &start, &end);
189  boxStart->setText(QString::number(qMin(start, end), 'g', app->d_decimal_digits));
190  boxEnd->setText(QString::number(qMax(start, end), 'g', app->d_decimal_digits));
191 };
192 
194 {
195 ApplicationWindow *app = (ApplicationWindow *)parent();
196 if(!app)
197  return;
198 
199 double start = graph->selectedXStartValue();
200 double end = graph->selectedXEndValue();
201 boxStart->setText(QString::number(qMin(start, end), 'g', app->d_decimal_digits));
202 boxEnd->setText(QString::number(qMax(start, end), 'g', app->d_decimal_digits));
203 }
InterpolationDialog.h
InterpolationDialog::boxEnd
QLineEdit * boxEnd
Definition: InterpolationDialog.h:56
InterpolationDialog::graph
Graph * graph
Definition: InterpolationDialog.h:66
MyParser.h
Filter::setColor
void setColor(QColor colorId)
Sets the color of the output fit curve.
Definition: Filter.h:64
InterpolationDialog::interpolate
void interpolate()
Definition: InterpolationDialog.cpp:104
ColorButton
A button used for color selection.
Definition: ColorButton.h:54
Interpolation
Definition: Interpolation.h:36
InterpolationDialog::setGraph
void setGraph(Graph *g)
Definition: InterpolationDialog.cpp:159
InterpolationDialog::boxMethod
QComboBox * boxMethod
Definition: InterpolationDialog.h:53
QStringFromString
QString QStringFromString(const std::string &x)
Definition: QStringStdString.h:15
InterpolationDialog::activateCurve
void activateCurve(const QString &curveName)
Definition: InterpolationDialog.cpp:177
InterpolationDialog::buttonCancel
QPushButton * buttonCancel
Definition: InterpolationDialog.h:51
Filter::setOutputPoints
void setOutputPoints(int points)
Sets the number of points in the output curve.
Definition: Filter.h:70
Graph::analysableCurvesList
QStringList analysableCurvesList()
Returns the names of all the curves suitable for data analysis, as a string list. The list excludes e...
Definition: Graph.cpp:1311
ColorButton.h
MyParser
Mathematical parser class based on muParser.
Definition: MyParser.h:52
MyParser::SetExpr
void SetExpr(const QString &x)
Definition: MyParser.h:56
InterpolationDialog::boxName
QComboBox * boxName
Definition: InterpolationDialog.h:52
Graph::selectedXStartValue
double selectedXStartValue()
Definition: Graph.cpp:2787
ColorButton::color
QColor color() const
Get the color of the display part.
Definition: ColorButton.cpp:140
Graph::selectedXEndValue
double selectedXEndValue()
Definition: Graph.cpp:2795
InterpolationDialog::InterpolationDialog
InterpolationDialog(QWidget *parent=0, Qt::WindowFlags fl=0)
Definition: InterpolationDialog.cpp:44
InterpolationDialog::buttonFit
QPushButton * buttonFit
Definition: InterpolationDialog.h:48
Graph::selectedCurveTitle
QString selectedCurveTitle()
Definition: Graph.cpp:1535
InterpolationDialog::changeDataRange
void changeDataRange()
Definition: InterpolationDialog.cpp:193
Interpolation.h
ApplicationWindow
SciDAVis's main window.
Definition: ApplicationWindow.h:122
Graph.h
InterpolationDialog::btnColor
ColorButton * btnColor
Definition: InterpolationDialog.h:57
InterpolationDialog::boxStart
QLineEdit * boxStart
Definition: InterpolationDialog.h:55
Filter::run
virtual bool run()
Actually does the job. Should be reimplemented in derived classes.
Definition: Filter.cpp:208
Graph
A 2D-plotting widget.
Definition: Graph.h:119
ApplicationWindow::d_decimal_digits
int d_decimal_digits
default precision to be used for all other operations than fitting
Definition: ApplicationWindow.h:956
Graph::curve
QwtPlotCurve * curve(int index) const
get curve by index
Definition: Graph.cpp:2821
Graph::curveIndex
int curveIndex(long key) const
Definition: Graph.h:199
ColorButton::setColor
void setColor(const QColor &c)
Set the color of the display part.
Definition: ColorButton.cpp:132
Graph::range
int range(int index, double *start, double *end)
Definition: Graph.cpp:2834
InterpolationDialog::boxPoints
QSpinBox * boxPoints
Definition: InterpolationDialog.h:54