labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

XYDataReductionCurveDock.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  File : XYDataReductionCurveDock.cpp
3  Project : LabPlot
4  --------------------------------------------------------------------
5  Copyright : (C) 2016 Stefan Gerlach (stefan.gerlach@uni.kn)
6  Copyright : (C) 2017 Alexander Semke (alexander.semke@web.de)
7  Description : widget for editing properties of data reduction curves
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21  * GNU General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public License *
24  * along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26  * Boston, MA 02110-1301 USA *
27  * *
28  ***************************************************************************/
29 
32 #include "backend/core/Project.h"
35 
36 #include <QMenu>
37 #include <QWidgetAction>
38 #include <QStandardItemModel>
39 #include <QStatusBar>
40 #include <QProgressBar>
41 
42 /*!
43  \class XYDataReductionCurveDock
44  \brief Provides a widget for editing the properties of the XYDataReductionCurves
45  (2D-curves defined by an data reduction) currently selected in
46  the project explorer.
47 
48  If more then one curves are set, the properties of the first column are shown.
49  The changes of the properties are applied to all curves.
50  The exclusions are the name, the comment and the datasets (columns) of
51  the curves - these properties can only be changed if there is only one single curve.
52 
53  \ingroup kdefrontend
54 */
55 
56 XYDataReductionCurveDock::XYDataReductionCurveDock(QWidget* parent, QStatusBar* sb) : XYCurveDock(parent), statusBar(sb) {
57 }
58 
59 /*!
60  * // Tab "General"
61  */
63  QWidget* generalTab = new QWidget(ui.tabGeneral);
64  uiGeneralTab.setupUi(generalTab);
65  m_leName = uiGeneralTab.leName;
66  m_leComment = uiGeneralTab.leComment;
67 
68  auto* gridLayout = static_cast<QGridLayout*>(generalTab->layout());
69  gridLayout->setContentsMargins(2, 2, 2, 2);
70  gridLayout->setHorizontalSpacing(2);
71  gridLayout->setVerticalSpacing(2);
72 
73  uiGeneralTab.cbDataSourceType->addItem(i18n("Spreadsheet"));
74  uiGeneralTab.cbDataSourceType->addItem(i18n("XY-Curve"));
75 
76  cbDataSourceCurve = new TreeViewComboBox(generalTab);
77  gridLayout->addWidget(cbDataSourceCurve, 5, 2, 1, 3);
78  cbXDataColumn = new TreeViewComboBox(generalTab);
79  gridLayout->addWidget(cbXDataColumn, 6, 2, 1, 3);
80  cbYDataColumn = new TreeViewComboBox(generalTab);
81  gridLayout->addWidget(cbYDataColumn, 7, 2, 1, 3);
82 
83  for (int i = 0; i < NSL_GEOM_LINESIM_TYPE_COUNT; ++i)
84  uiGeneralTab.cbType->addItem(i18n(nsl_geom_linesim_type_name[i]));
85  uiGeneralTab.cbType->setItemData(nsl_geom_linesim_type_visvalingam_whyatt, i18n("This method is much slower than any other"), Qt::ToolTipRole);
86 
87  uiGeneralTab.sbMin->setRange(-std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
88  uiGeneralTab.sbMax->setRange(-std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
89  uiGeneralTab.sbTolerance->setRange(0.0, std::numeric_limits<double>::max());
90  uiGeneralTab.sbTolerance2->setRange(0.0, std::numeric_limits<double>::max());
91 
92  uiGeneralTab.pbRecalculate->setIcon(QIcon::fromTheme("run-build"));
93 
94  auto* layout = new QHBoxLayout(ui.tabGeneral);
95  layout->setMargin(0);
96  layout->addWidget(generalTab);
97 
98  //Slots
99  connect(uiGeneralTab.chkVisible, &QCheckBox::clicked, this, &XYDataReductionCurveDock::visibilityChanged);
100  connect(uiGeneralTab.cbDataSourceType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &XYDataReductionCurveDock::dataSourceTypeChanged);
101  connect(uiGeneralTab.cbAutoRange, &QCheckBox::clicked, this, &XYDataReductionCurveDock::autoRangeChanged);
102  connect(uiGeneralTab.sbMin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &XYDataReductionCurveDock::xRangeMinChanged);
103  connect(uiGeneralTab.sbMax, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &XYDataReductionCurveDock::xRangeMaxChanged);
104  connect(uiGeneralTab.dateTimeEditMin, &QDateTimeEdit::dateTimeChanged, this, &XYDataReductionCurveDock::xRangeMinDateTimeChanged);
105  connect(uiGeneralTab.dateTimeEditMax, &QDateTimeEdit::dateTimeChanged, this, &XYDataReductionCurveDock::xRangeMaxDateTimeChanged);
106  connect(uiGeneralTab.chkAuto, &QCheckBox::clicked, this, &XYDataReductionCurveDock::autoToleranceChanged);
107  connect(uiGeneralTab.sbTolerance, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &XYDataReductionCurveDock::toleranceChanged);
108  connect(uiGeneralTab.chkAuto2, &QCheckBox::clicked, this, &XYDataReductionCurveDock::autoTolerance2Changed);
109  connect(uiGeneralTab.sbTolerance2, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &XYDataReductionCurveDock::tolerance2Changed);
110  connect(uiGeneralTab.pbRecalculate, &QPushButton::clicked, this, &XYDataReductionCurveDock::recalculateClicked);
111 
115 }
116 
118  //if there are more then one curve in the list, disable the tab "general"
119  if (m_curvesList.size() == 1) {
120  uiGeneralTab.lName->setEnabled(true);
121  uiGeneralTab.leName->setEnabled(true);
122  uiGeneralTab.lComment->setEnabled(true);
123  uiGeneralTab.leComment->setEnabled(true);
124 
125  uiGeneralTab.leName->setText(m_curve->name());
126  uiGeneralTab.leComment->setText(m_curve->comment());
127  } else {
128  uiGeneralTab.lName->setEnabled(false);
129  uiGeneralTab.leName->setEnabled(false);
130  uiGeneralTab.lComment->setEnabled(false);
131  uiGeneralTab.leComment->setEnabled(false);
132 
133  uiGeneralTab.leName->setText(QString());
134  uiGeneralTab.leComment->setText(QString());
135  }
136 
137  //show the properties of the first curve
141 
142  //data source
143  uiGeneralTab.cbDataSourceType->setCurrentIndex(static_cast<int>(m_dataReductionCurve->dataSourceType()));
144  this->dataSourceTypeChanged(uiGeneralTab.cbDataSourceType->currentIndex());
148 
149  //range widgets
150  const auto* plot = static_cast<const CartesianPlot*>(m_dataReductionCurve->parentAspect());
151  m_dateTimeRange = (plot->xRangeFormat() != CartesianPlot::RangeFormat::Numeric);
152  if (!m_dateTimeRange) {
153  uiGeneralTab.sbMin->setValue(m_dataReductionData.xRange.first());
154  uiGeneralTab.sbMax->setValue(m_dataReductionData.xRange.last());
155  } else {
156  uiGeneralTab.dateTimeEditMin->setDateTime( QDateTime::fromMSecsSinceEpoch(m_dataReductionData.xRange.first()) );
157  uiGeneralTab.dateTimeEditMax->setDateTime( QDateTime::fromMSecsSinceEpoch(m_dataReductionData.xRange.last()) );
158  }
159 
160  uiGeneralTab.lMin->setVisible(!m_dateTimeRange);
161  uiGeneralTab.sbMin->setVisible(!m_dateTimeRange);
162  uiGeneralTab.lMax->setVisible(!m_dateTimeRange);
163  uiGeneralTab.sbMax->setVisible(!m_dateTimeRange);
164  uiGeneralTab.lMinDateTime->setVisible(m_dateTimeRange);
165  uiGeneralTab.dateTimeEditMin->setVisible(m_dateTimeRange);
166  uiGeneralTab.lMaxDateTime->setVisible(m_dateTimeRange);
167  uiGeneralTab.dateTimeEditMax->setVisible(m_dateTimeRange);
168 
169  //auto range
170  uiGeneralTab.cbAutoRange->setChecked(m_dataReductionData.autoRange);
171  this->autoRangeChanged();
172 
173  // update list of selectable types
175 
176  uiGeneralTab.cbType->setCurrentIndex(m_dataReductionData.type);
178  uiGeneralTab.chkAuto->setChecked(m_dataReductionData.autoTolerance);
179  this->autoToleranceChanged();
180  uiGeneralTab.sbTolerance->setValue(m_dataReductionData.tolerance);
182  uiGeneralTab.chkAuto2->setChecked(m_dataReductionData.autoTolerance2);
183  this->autoTolerance2Changed();
184  uiGeneralTab.sbTolerance2->setValue(m_dataReductionData.tolerance2);
186 
187  this->showDataReductionResult();
188 
189  //enable the "recalculate"-button if the source data was changed since the last dataReduction
191 
192  uiGeneralTab.chkVisible->setChecked( m_curve->isVisible() );
193 
194  //Slots
203 }
204 
209 
210  QList<const AbstractAspect*> hiddenAspects;
211  for (auto* curve : m_curvesList)
212  hiddenAspects << curve;
213  cbDataSourceCurve->setHiddenAspects(hiddenAspects);
214 
219  };
222 
226 
228 }
229 
230 /*!
231  sets the curves. The properties of the curves in the list \c list can be edited in this widget.
232 */
234  m_initializing = true;
235  m_curvesList = list;
236  m_curve = list.first();
237  m_aspect = m_curve;
240  this->setModel();
241  m_dataReductionData = m_dataReductionCurve->dataReductionData();
242 
244  uiGeneralTab.sbMin->setLocale(numberLocale);
245  uiGeneralTab.sbMax->setLocale(numberLocale);
246  uiGeneralTab.sbTolerance->setLocale(numberLocale);
247  uiGeneralTab.sbTolerance2->setLocale(numberLocale);
248 
249  initGeneralTab();
250  initTabs();
251  m_initializing = false;
252 
253  //hide the "skip gaps" option after the curves were set
254  ui.lLineSkipGaps->hide();
255  ui.chkLineSkipGaps->hide();
256 }
257 
258 //*************************************************************
259 //**** SLOTs for changes triggered in XYFitCurveDock *****
260 //*************************************************************
262  const auto type = (XYAnalysisCurve::DataSourceType)index;
264  uiGeneralTab.lDataSourceCurve->hide();
265  cbDataSourceCurve->hide();
266  uiGeneralTab.lXColumn->show();
267  cbXDataColumn->show();
268  uiGeneralTab.lYColumn->show();
269  cbYDataColumn->show();
270  } else {
271  uiGeneralTab.lDataSourceCurve->show();
272  cbDataSourceCurve->show();
273  uiGeneralTab.lXColumn->hide();
274  cbXDataColumn->hide();
275  uiGeneralTab.lYColumn->hide();
276  cbYDataColumn->hide();
277  }
278 
279  if (m_initializing)
280  return;
281 
282  for (auto* curve : m_curvesList)
283  dynamic_cast<XYDataReductionCurve*>(curve)->setDataSourceType(type);
284 }
285 
286 void XYDataReductionCurveDock::dataSourceCurveChanged(const QModelIndex& index) {
287  auto* aspect = static_cast<AbstractAspect*>(index.internalPointer());
288  auto* dataSourceCurve = dynamic_cast<XYCurve*>(aspect);
289 
290 // // disable deriv orders and accuracies that need more data points
291 // this->updateSettings(dataSourceCurve->xColumn());
292 
293  if (m_initializing)
294  return;
295 
296  for (auto* curve : m_curvesList)
297  dynamic_cast<XYDataReductionCurve*>(curve)->setDataSourceCurve(dataSourceCurve);
298 }
299 
300 void XYDataReductionCurveDock::xDataColumnChanged(const QModelIndex& index) {
301  if (m_initializing)
302  return;
303 
304  auto* aspect = static_cast<AbstractAspect*>(index.internalPointer());
305  auto* column = dynamic_cast<AbstractColumn*>(aspect);
306 
307  for (auto* curve : m_curvesList)
308  dynamic_cast<XYDataReductionCurve*>(curve)->setXDataColumn(column);
309 
310  //TODO: this->updateSettings(column); ?
311  if (column != nullptr && uiGeneralTab.cbAutoRange->isChecked()) {
312  uiGeneralTab.sbMin->setValue(column->minimum());
313  uiGeneralTab.sbMax->setValue(column->maximum());
314  }
315 
317  cbXDataColumn->setInvalid(false);
318 
319  updateTolerance();
321 }
322 
323 void XYDataReductionCurveDock::yDataColumnChanged(const QModelIndex& index) {
324  if (m_initializing)
325  return;
326 
327  auto* aspect = static_cast<AbstractAspect*>(index.internalPointer());
328  auto* column = dynamic_cast<AbstractColumn*>(aspect);
329 
330  for (auto* curve : m_curvesList)
331  dynamic_cast<XYDataReductionCurve*>(curve)->setYDataColumn(column);
332 
334  cbYDataColumn->setInvalid(false);
335 
336  updateTolerance();
338 }
339 
341  const AbstractColumn* xDataColumn = nullptr;
342  const AbstractColumn* yDataColumn = nullptr;
344  xDataColumn = m_dataReductionCurve->xDataColumn();
345  yDataColumn = m_dataReductionCurve->yDataColumn();
346  } else {
347  if (m_dataReductionCurve->dataSourceCurve()) {
348  xDataColumn = m_dataReductionCurve->dataSourceCurve()->xColumn();
349  yDataColumn = m_dataReductionCurve->dataSourceCurve()->yColumn();
350  }
351  }
352 
353  if (xDataColumn == nullptr || yDataColumn == nullptr)
354  return;
355 
356  //copy all valid data points for calculating tolerance to temporary vectors
357  QVector<double> xdataVector;
358  QVector<double> ydataVector;
359  const double xmin = m_dataReductionData.xRange.first();
360  const double xmax = m_dataReductionData.xRange.last();
361  XYAnalysisCurve::copyData(xdataVector, ydataVector, xDataColumn, yDataColumn, xmin, xmax);
362 
363  if (xdataVector.size() > 1)
364  uiGeneralTab.cbType->setEnabled(true);
365  else {
366  uiGeneralTab.cbType->setEnabled(false);
367  return;
368  }
369  DEBUG("automatic tolerance:");
370  DEBUG("clip_diag_perpoint =" << nsl_geom_linesim_clip_diag_perpoint(xdataVector.data(), ydataVector.data(), (size_t)xdataVector.size()));
371  DEBUG("clip_area_perpoint =" << nsl_geom_linesim_clip_area_perpoint(xdataVector.data(), ydataVector.data(), (size_t)xdataVector.size()));
372  DEBUG("avg_dist_perpoint =" << nsl_geom_linesim_avg_dist_perpoint(xdataVector.data(), ydataVector.data(), (size_t)xdataVector.size()));
373 
374  const auto type = (nsl_geom_linesim_type)uiGeneralTab.cbType->currentIndex();
376  m_dataReductionData.tolerance = 10. * nsl_geom_linesim_clip_diag_perpoint(xdataVector.data(), ydataVector.data(), (size_t)xdataVector.size());
378  m_dataReductionData.tolerance = 0.1 * nsl_geom_linesim_clip_area_perpoint(xdataVector.data(), ydataVector.data(), (size_t)xdataVector.size());
380  m_dataReductionData.tolerance = xdataVector.size()/10.; // reduction to 10%
381  else
382  m_dataReductionData.tolerance = 2.*nsl_geom_linesim_avg_dist_perpoint(xdataVector.data(), ydataVector.data(), xdataVector.size());
383  //m_dataReductionData.tolerance = nsl_geom_linesim_clip_diag_perpoint(xdataVector.data(), ydataVector.data(), xdataVector.size());
384  uiGeneralTab.sbTolerance->setValue(m_dataReductionData.tolerance);
385 }
386 
388  const auto type = (nsl_geom_linesim_type)uiGeneralTab.cbType->currentIndex();
389 
391  uiGeneralTab.sbTolerance2->setValue(10);
393  uiGeneralTab.sbTolerance2->setValue(5*uiGeneralTab.sbTolerance->value());
394  else if (type == nsl_geom_linesim_type_lang)
395  uiGeneralTab.sbTolerance2->setValue(10);
396 }
397 
399  bool autoRange = uiGeneralTab.cbAutoRange->isChecked();
400  m_dataReductionData.autoRange = autoRange;
401 
402  uiGeneralTab.lMin->setEnabled(!autoRange);
403  uiGeneralTab.sbMin->setEnabled(!autoRange);
404  uiGeneralTab.lMax->setEnabled(!autoRange);
405  uiGeneralTab.sbMax->setEnabled(!autoRange);
406  uiGeneralTab.lMinDateTime->setEnabled(!autoRange);
407  uiGeneralTab.dateTimeEditMin->setEnabled(!autoRange);
408  uiGeneralTab.lMaxDateTime->setEnabled(!autoRange);
409  uiGeneralTab.dateTimeEditMax->setEnabled(!autoRange);
410 
411  if (autoRange) {
412  const AbstractColumn* xDataColumn = nullptr;
414  xDataColumn = m_dataReductionCurve->xDataColumn();
415  else {
416  if (m_dataReductionCurve->dataSourceCurve())
417  xDataColumn = m_dataReductionCurve->dataSourceCurve()->xColumn();
418  }
419 
420  if (xDataColumn) {
421  if (!m_dateTimeRange) {
422  uiGeneralTab.sbMin->setValue(xDataColumn->minimum());
423  uiGeneralTab.sbMax->setValue(xDataColumn->maximum());
424  } else {
425  uiGeneralTab.dateTimeEditMin->setDateTime(QDateTime::fromMSecsSinceEpoch(xDataColumn->minimum()));
426  uiGeneralTab.dateTimeEditMax->setDateTime(QDateTime::fromMSecsSinceEpoch(xDataColumn->maximum()));
427  }
428  }
429  }
430 }
431 
433  m_dataReductionData.xRange.first() = value;
434  uiGeneralTab.pbRecalculate->setEnabled(true);
435 }
436 
438  m_dataReductionData.xRange.last() = value;
439  uiGeneralTab.pbRecalculate->setEnabled(true);
440 }
441 
442 void XYDataReductionCurveDock::xRangeMinDateTimeChanged(const QDateTime& dateTime) {
443  if (m_initializing)
444  return;
445 
446  m_dataReductionData.xRange.first() = dateTime.toMSecsSinceEpoch();
447  uiGeneralTab.pbRecalculate->setEnabled(true);
448 }
449 
450 void XYDataReductionCurveDock::xRangeMaxDateTimeChanged(const QDateTime& dateTime) {
451  if (m_initializing)
452  return;
453 
454  m_dataReductionData.xRange.last() = dateTime.toMSecsSinceEpoch();
455  uiGeneralTab.pbRecalculate->setEnabled(true);
456 }
457 
459  const auto type = (nsl_geom_linesim_type)index;
461 
462  switch (type) {
467  uiGeneralTab.lOption->setText(i18n("Tolerance (distance):"));
468  uiGeneralTab.sbTolerance->setDecimals(6);
469  uiGeneralTab.sbTolerance->setMinimum(0);
470  uiGeneralTab.sbTolerance->setSingleStep(0.01);
471  uiGeneralTab.lOption2->hide();
472  uiGeneralTab.chkAuto2->hide();
473  uiGeneralTab.sbTolerance2->hide();
474  if (uiGeneralTab.chkAuto->isChecked())
475  updateTolerance();
476  break;
478  uiGeneralTab.lOption->setText(i18n("Number of points:"));
479  uiGeneralTab.sbTolerance->setDecimals(0);
480  uiGeneralTab.sbTolerance->setMinimum(2);
481  uiGeneralTab.sbTolerance->setSingleStep(1);
482  uiGeneralTab.lOption2->hide();
483  uiGeneralTab.chkAuto2->hide();
484  uiGeneralTab.sbTolerance2->hide();
485  if (uiGeneralTab.chkAuto->isChecked())
486  updateTolerance();
487  break;
489  uiGeneralTab.lOption->setText(i18n("Step size:"));
490  uiGeneralTab.sbTolerance->setValue(10);
491  uiGeneralTab.sbTolerance->setDecimals(0);
492  uiGeneralTab.sbTolerance->setMinimum(1);
493  uiGeneralTab.sbTolerance->setSingleStep(1);
494  uiGeneralTab.lOption2->hide();
495  uiGeneralTab.chkAuto2->hide();
496  uiGeneralTab.sbTolerance2->hide();
497  break;
498  case nsl_geom_linesim_type_perpdist: // repeat option
499  uiGeneralTab.lOption->setText(i18n("Tolerance (distance):"));
500  uiGeneralTab.sbTolerance->setDecimals(6);
501  uiGeneralTab.sbTolerance->setMinimum(0);
502  uiGeneralTab.sbTolerance->setSingleStep(0.01);
503  uiGeneralTab.sbTolerance2->show();
504  uiGeneralTab.lOption2->show();
505  uiGeneralTab.chkAuto2->show();
506  uiGeneralTab.lOption2->setText(i18n("Repeats:"));
507  uiGeneralTab.sbTolerance2->setDecimals(0);
508  uiGeneralTab.sbTolerance2->setMinimum(1);
509  uiGeneralTab.sbTolerance2->setSingleStep(1);
510  if (uiGeneralTab.chkAuto->isChecked())
511  updateTolerance();
512  if (uiGeneralTab.chkAuto2->isChecked())
514  break;
516  uiGeneralTab.lOption->setText(i18n("Tolerance (area):"));
517  uiGeneralTab.sbTolerance->setDecimals(6);
518  uiGeneralTab.sbTolerance->setMinimum(0);
519  uiGeneralTab.sbTolerance->setSingleStep(0.01);
520  uiGeneralTab.lOption2->hide();
521  uiGeneralTab.chkAuto2->hide();
522  uiGeneralTab.sbTolerance2->hide();
523  if (uiGeneralTab.chkAuto->isChecked())
524  updateTolerance();
525  break;
526  case nsl_geom_linesim_type_opheim: // min/max tol options
527  uiGeneralTab.lOption->setText(i18n("Minimum tolerance:"));
528  uiGeneralTab.sbTolerance->setDecimals(6);
529  uiGeneralTab.sbTolerance->setMinimum(0);
530  uiGeneralTab.sbTolerance->setSingleStep(0.01);
531  uiGeneralTab.lOption2->setText(i18n("Maximum tolerance:"));
532  uiGeneralTab.lOption2->show();
533  uiGeneralTab.chkAuto2->show();
534  uiGeneralTab.sbTolerance2->show();
535  uiGeneralTab.sbTolerance2->setDecimals(6);
536  uiGeneralTab.sbTolerance2->setMinimum(0);
537  uiGeneralTab.sbTolerance2->setSingleStep(0.01);
538  if (uiGeneralTab.chkAuto->isChecked())
539  updateTolerance();
540  if (uiGeneralTab.chkAuto2->isChecked())
542  break;
543  case nsl_geom_linesim_type_lang: // distance/region
544  uiGeneralTab.lOption->setText(i18n("Tolerance (distance):"));
545  uiGeneralTab.sbTolerance->setDecimals(6);
546  uiGeneralTab.sbTolerance->setMinimum(0);
547  uiGeneralTab.sbTolerance->setSingleStep(0.01);
548  uiGeneralTab.lOption2->setText(i18n("Search region:"));
549  uiGeneralTab.lOption2->show();
550  uiGeneralTab.chkAuto2->show();
551  uiGeneralTab.sbTolerance2->show();
552  uiGeneralTab.sbTolerance2->setDecimals(0);
553  uiGeneralTab.sbTolerance2->setMinimum(1);
554  uiGeneralTab.sbTolerance2->setSingleStep(1);
555  if (uiGeneralTab.chkAuto->isChecked())
556  updateTolerance();
557  if (uiGeneralTab.chkAuto2->isChecked())
559  break;
560  }
561 
562  uiGeneralTab.pbRecalculate->setEnabled(true);
563 }
564 
566  const auto autoTolerance = (bool)uiGeneralTab.chkAuto->isChecked();
567  m_dataReductionData.autoTolerance = autoTolerance;
568 
569  if (autoTolerance) {
570  uiGeneralTab.sbTolerance->setEnabled(false);
571  updateTolerance();
572  } else
573  uiGeneralTab.sbTolerance->setEnabled(true);
574 }
575 
578  uiGeneralTab.pbRecalculate->setEnabled(true);
579 }
580 
582  const auto autoTolerance2 = (bool)uiGeneralTab.chkAuto2->isChecked();
583  m_dataReductionData.autoTolerance2 = autoTolerance2;
584 
585  if (autoTolerance2) {
586  uiGeneralTab.sbTolerance2->setEnabled(false);
588  } else
589  uiGeneralTab.sbTolerance2->setEnabled(true);
590 }
591 
594  uiGeneralTab.pbRecalculate->setEnabled(true);
595 }
596 
598  //show a progress bar in the status bar
599  auto* progressBar = new QProgressBar();
600  progressBar->setMinimum(0);
601  progressBar->setMaximum(100);
602  connect(m_curve, SIGNAL(completed(int)), progressBar, SLOT(setValue(int)));
603  statusBar->clearMessage();
604  statusBar->addWidget(progressBar, 1);
605  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
606 
607  for (auto* curve : m_curvesList)
608  dynamic_cast<XYDataReductionCurve*>(curve)->setDataReductionData(m_dataReductionData);
609 
610  QApplication::restoreOverrideCursor();
611  statusBar->removeWidget(progressBar);
612 
613  uiGeneralTab.pbRecalculate->setEnabled(false);
614  emit info(i18n("Data reduction status: %1", m_dataReductionCurve->dataReductionResult().status));
615 }
616 
618  if (m_initializing)
619  return;
620 
621  //no dataReductioning possible without the x- and y-data
622  bool hasSourceData = false;
624  AbstractAspect* aspectX = static_cast<AbstractAspect*>(cbXDataColumn->currentModelIndex().internalPointer());
625  AbstractAspect* aspectY = static_cast<AbstractAspect*>(cbYDataColumn->currentModelIndex().internalPointer());
626  hasSourceData = (aspectX != nullptr && aspectY != nullptr);
627  if (aspectX) {
629  cbXDataColumn->setInvalid(false);
630  }
631  if (aspectY) {
633  cbYDataColumn->setInvalid(false);
634  }
635  } else {
636  hasSourceData = (m_dataReductionCurve->dataSourceCurve() != nullptr);
637  }
638 
639  uiGeneralTab.pbRecalculate->setEnabled(hasSourceData);
640 }
641 
642 /*!
643  * show the result and details of the dataReduction
644  */
647  if (!dataReductionResult.available) {
648  uiGeneralTab.teResult->clear();
649  return;
650  }
651 
652  QString str = i18n("status: %1", dataReductionResult.status) + "<br>";
653 
654  if (!dataReductionResult.valid) {
655  uiGeneralTab.teResult->setText(str);
656  return; //result is not valid, there was an error which is shown in the status-string, nothing to show more.
657  }
658 
660  if (dataReductionResult.elapsedTime > 1000)
661  str += i18n("calculation time: %1 s", numberLocale.toString(dataReductionResult.elapsedTime/1000)) + "<br>";
662  else
663  str += i18n("calculation time: %1 ms", numberLocale.toString(dataReductionResult.elapsedTime)) + "<br>";
664 
665  str += "<br>";
666 
667  str += i18n("number of points: %1", numberLocale.toString(static_cast<qulonglong>(dataReductionResult.npoints))) + "<br>";
668  str += i18n("positional squared error: %1", numberLocale.toString(dataReductionResult.posError)) + "<br>";
669  str += i18n("area error: %1", numberLocale.toString(dataReductionResult.areaError)) + "<br>";
670 
671  uiGeneralTab.teResult->setText(str);
672 }
673 
674 //*************************************************************
675 //*********** SLOTs for changes triggered in XYCurve **********
676 //*************************************************************
677 //General-Tab
679  if (m_curve != aspect)
680  return;
681 
682  m_initializing = true;
683  if (aspect->name() != uiGeneralTab.leName->text())
684  uiGeneralTab.leName->setText(aspect->name());
685  else if (aspect->comment() != uiGeneralTab.leComment->text())
686  uiGeneralTab.leComment->setText(aspect->comment());
687  m_initializing = false;
688 }
689 
691  m_initializing = true;
692  uiGeneralTab.cbDataSourceType->setCurrentIndex(static_cast<int>(type));
693  m_initializing = false;
694 }
695 
697  m_initializing = true;
699  m_initializing = false;
700 }
701 
703  m_initializing = true;
705  m_initializing = false;
706 }
707 
709  m_initializing = true;
711  m_initializing = false;
712 }
713 
715  m_initializing = true;
716  m_dataReductionData = dataReductionData;
717  //uiGeneralTab.cbType->setCurrentIndex(m_dataReductionData.type);
718  //this->typeChanged();
719 
720  this->showDataReductionResult();
721  m_initializing = false;
722 }
723 
725  this->enableRecalculate();
726 }
727 
729  m_initializing = true;
730  uiGeneralTab.chkVisible->setChecked(on);
731  m_initializing = false;
732 }
Base class of all persistent objects in a Project.
void aspectDescriptionChanged(const AbstractAspect *)
Emitted after the name, comment or caption spec have changed.
QString name() const
QString comment() const
AbstractAspect * parentAspect() const
Return my parent Aspect or 0 if I currently don't have one.
virtual Project * project()
Return the Project this Aspect belongs to, or 0 if it is currently not part of one.
Interface definition for data with column logic.
virtual double maximum(int count=0) const
virtual double minimum(int count=0) const
Represents a tree of AbstractAspect objects as a Qt item model.
QLineEdit * m_leName
Definition: BaseDock.h:68
QLineEdit * m_leComment
Definition: BaseDock.h:69
AbstractAspect * m_aspect
Definition: BaseDock.h:70
bool m_initializing
Definition: BaseDock.h:67
A xy-plot.
Definition: CartesianPlot.h:58
Provides a QTreeView in a QComboBox.
void setInvalid(bool invalid, const QString &tooltip=QString())
void setModel(QAbstractItemModel *)
void setHiddenAspects(const QList< const AbstractAspect * > &)
QModelIndex currentModelIndex() const
void useCurrentIndexText(const bool set)
void setTopLevelClasses(const QList< AspectType > &)
void currentModelIndexChanged(const QModelIndex &)
void yDataColumnChanged(const AbstractColumn *)
static void copyData(QVector< double > &xData, QVector< double > &yData, const AbstractColumn *xDataColumn, const AbstractColumn *yDataColumn, double xMin, double xMax)
void dataSourceTypeChanged(XYAnalysisCurve::DataSourceType)
void dataSourceCurveChanged(const XYCurve *)
void xDataColumnChanged(const AbstractColumn *)
void sourceDataChanged()
Provides a widget for editing the properties of the XYCurves (2D-curves) currently selected in the pr...
Definition: XYCurveDock.h:46
void initTabs()
XYCurve * m_curve
Definition: XYCurveDock.h:82
AspectTreeModel * m_aspectTreeModel
Definition: XYCurveDock.h:83
void info(const QString &)
virtual void setModel()
QList< XYCurve * > m_curvesList
Definition: XYCurveDock.h:81
void setModelIndexFromAspect(TreeViewComboBox *, const AbstractAspect *)
Ui::XYCurveDock ui
Definition: XYCurveDock.h:80
void visibilityChanged(bool)
void checkColumnAvailability(TreeViewComboBox *, const AbstractColumn *, const QString &columnPath)
A 2D-curve, provides an interface for editing many properties of the curve.
Definition: XYCurve.h:46
bool isVisible() const override
Return whether the element is (at least) partially visible.
Definition: XYCurve.cpp:216
bool isSourceDataChangedSinceLastRecalc() const
Definition: XYCurve.cpp:329
void visibilityChanged()
Definition: XYCurve.cpp:902
void curveDataSourceCurveChanged(const XYCurve *)
void curveYDataColumnChanged(const AbstractColumn *)
void xDataColumnChanged(const QModelIndex &)
void xRangeMaxDateTimeChanged(const QDateTime &)
void setCurves(QList< XYCurve * >)
XYDataReductionCurve::DataReductionData m_dataReductionData
void yDataColumnChanged(const QModelIndex &)
void curveDataReductionDataChanged(const XYDataReductionCurve::DataReductionData &)
void dataSourceCurveChanged(const QModelIndex &)
TreeViewComboBox * cbDataSourceCurve
XYDataReductionCurve * m_dataReductionCurve
Ui::XYDataReductionCurveDockGeneralTab uiGeneralTab
void curveXDataColumnChanged(const AbstractColumn *)
void xRangeMinDateTimeChanged(const QDateTime &)
void curveDescriptionChanged(const AbstractAspect *)
XYDataReductionCurveDock(QWidget *parent, QStatusBar *sb)
void curveDataSourceTypeChanged(XYAnalysisCurve::DataSourceType)
A xy-curve defined by a data reduction.
const DataReductionResult & dataReductionResult() const
void dataReductionDataChanged(const XYDataReductionCurve::DataReductionData &)
#define DEBUG(x)
Definition: macros.h:50
#define SET_NUMBER_LOCALE
Definition: macros.h:75
#define i18n(m)
Definition: nsl_common.h:38
double nsl_geom_linesim_clip_area_perpoint(const double xdata[], const double ydata[], const size_t n)
double nsl_geom_linesim_avg_dist_perpoint(const double xdata[], const double ydata[], const size_t n)
double nsl_geom_linesim_clip_diag_perpoint(const double xdata[], const double ydata[], const size_t n)
const char * nsl_geom_linesim_type_name[]
#define NSL_GEOM_LINESIM_TYPE_COUNT
nsl_geom_linesim_type
@ nsl_geom_linesim_type_opheim
@ nsl_geom_linesim_type_douglas_peucker_variant
@ nsl_geom_linesim_type_perpdist
@ nsl_geom_linesim_type_lang
@ nsl_geom_linesim_type_interp
@ nsl_geom_linesim_type_visvalingam_whyatt
@ nsl_geom_linesim_type_raddist
@ nsl_geom_linesim_type_nthpoint
@ nsl_geom_linesim_type_douglas_peucker
@ nsl_geom_linesim_type_reumann_witkam