35 #include "vibrationanalysissettings.h"
36 #include "vibrationanalysisoutput.h"
43 #include <QMessageBox>
44 #include <QMainWindow>
47 : IOptionsPage(parent)
49 , selectedItem(nullptr)
64 QWidget *optionsPageWidget =
new QWidget;
67 options_page =
new Ui::ScopeGadgetOptionsPage();
68 options_page->setupUi(optionsPageWidget);
76 options_page->cmbXAxisScatterplot2d->addItem(
"Time series",
82 options_page->cmbSpectrogramSource->addItem(
"Custom",
84 options_page->cmbSpectrogramSource->addItem(
"Vibration Analysis",
89 options_page->cmbColorMapSpectrogram->addItem(
"Jet",
ColorMap::JET);
97 QString previous = NULL;
99 foreach (QVector<UAVDataObject *> list, objList) {
105 }
else if (name != previous) {
114 std::sort(toAdd.begin(), toAdd.end());
116 foreach (QString elem, toAdd) {
119 options_page->cmbUAVObjects->addItem(elem);
120 options_page->cmbUAVObjectsSpectrogram->addItem(elem);
123 QStringList mathFunctions;
124 mathFunctions <<
"None"
126 <<
"Standard deviation"
129 options_page->mathFunctionComboBox->addItems(mathFunctions);
130 options_page->cmbMathFunctionSpectrogram->addItems(mathFunctions);
133 if (options_page->cmbUAVObjects->currentIndex() >= 0) {
134 on_cmbUAVObjects_currentIndexChanged(options_page->cmbUAVObjects->currentText());
138 options_page->cmbScale->addItem(
"10^-9", -9);
139 options_page->cmbScale->addItem(
"10^-6", -6);
140 options_page->cmbScale->addItem(
"10^-5", -5);
141 options_page->cmbScale->addItem(
"10^-4", -4);
142 options_page->cmbScale->addItem(
"10^-3", -3);
143 options_page->cmbScale->addItem(
".01", -2);
144 options_page->cmbScale->addItem(
".1", -1);
145 options_page->cmbScale->addItem(
"1", 0);
146 options_page->cmbScale->addItem(
"10", 1);
147 options_page->cmbScale->addItem(
"100", 2);
148 options_page->cmbScale->addItem(
"10^3", 3);
149 options_page->cmbScale->addItem(
"10^4", 4);
150 options_page->cmbScale->addItem(
"10^5", 5);
151 options_page->cmbScale->addItem(
"10^6", 6);
152 options_page->cmbScale->addItem(
"10^9", 9);
153 options_page->cmbScale->addItem(
"10^12", 12);
156 options_page->cmbScale->setCurrentIndex(options_page->cmbScale->findData(0));
159 options_page->btnColor->setAutoFillBackground(
true);
162 dataSourceStyleSheetTemplate =
"QListView::item:selected {border: 2px solid white; background: "
163 "rgba(255,255,255,50); selection-color: rgba(%1,%2,%3,255) }";
166 connect(options_page->cmbXAxisScatterplot2d,
167 QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this,
168 &ScopeGadgetOptionsPage::on_cmbXAxisScatterplot2d_currentIndexChanged);
169 connect(options_page->cmb2dPlotType,
170 QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this,
171 &ScopeGadgetOptionsPage::on_cmb2dPlotType_currentIndexChanged);
172 connect(options_page->cmb3dPlotType,
173 QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this,
174 &ScopeGadgetOptionsPage::on_cmb3dPlotType_currentIndexChanged);
175 connect(options_page->cmbUAVObjects,
176 QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this,
177 &ScopeGadgetOptionsPage::on_cmbUAVObjects_currentIndexChanged);
178 connect(options_page->cmbUAVObjectsSpectrogram,
179 QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this,
180 &ScopeGadgetOptionsPage::on_cmbUAVObjectsSpectrogram_currentIndexChanged);
181 connect(options_page->btnAdd2dCurve, &QAbstractButton::clicked,
this,
182 &ScopeGadgetOptionsPage::on_btnAdd2dCurve_clicked);
183 connect(options_page->btnApply2dCurve, &QAbstractButton::clicked,
this,
184 &ScopeGadgetOptionsPage::on_btnApply2dCurve_clicked);
185 connect(options_page->btnRemove2dCurve, &QAbstractButton::clicked,
this,
186 &ScopeGadgetOptionsPage::on_btnRemove2dCurve_clicked);
187 connect(options_page->lst2dCurves, &QListWidget::currentRowChanged,
this,
188 &ScopeGadgetOptionsPage::on_lst2dCurves_currentRowChanged);
189 connect(options_page->btnColor, &QAbstractButton::clicked,
this,
190 &ScopeGadgetOptionsPage::on_btnColor_clicked);
191 connect(options_page->mathFunctionComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
192 this, &ScopeGadgetOptionsPage::on_mathFunctionComboBox_currentIndexChanged);
193 connect(options_page->cmbSpectrogramSource,
194 QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this,
195 &ScopeGadgetOptionsPage::on_cmbSpectrogramSource_currentIndexChanged);
196 connect(options_page->lst2dCurves, &QListWidget::itemClicked,
this,
197 &ScopeGadgetOptionsPage::on_lst2dItem_clicked);
204 emit on_cmb2dPlotType_currentIndexChanged(options_page->cmb2dPlotType->currentText());
205 emit on_cmb3dPlotType_currentIndexChanged(options_page->cmb3dPlotType->currentText());
206 emit on_cmbUAVObjectsSpectrogram_currentIndexChanged(
207 options_page->cmbUAVObjectsSpectrogram->currentText());
210 foreach (QSpinBox *sp, findChildren<QSpinBox *>()) {
211 sp->installEventFilter(
this);
213 foreach (QDoubleSpinBox *sp, findChildren<QDoubleSpinBox *>()) {
214 sp->installEventFilter(
this);
216 foreach (QSlider *sp, findChildren<QSlider *>()) {
217 sp->installEventFilter(
this);
219 foreach (QComboBox *sp, findChildren<QComboBox *>()) {
220 sp->installEventFilter(
this);
223 return optionsPageWidget;
232 bool ScopeGadgetOptionsPage::eventFilter(QObject *obj, QEvent *evt)
235 if (evt->type() == QEvent::Wheel
236 && (qobject_cast<QAbstractSpinBox *>(obj) || qobject_cast<QComboBox *>(obj)
237 || qobject_cast<QAbstractSlider *>(obj))) {
241 return ScopeGadgetOptionsPage::eventFilter(obj, evt);
244 void ScopeGadgetOptionsPage::on_mathFunctionComboBox_currentIndexChanged(
int currentIndex)
246 if (currentIndex > 0) {
247 options_page->spnMeanSamples->setEnabled(
true);
249 options_page->spnMeanSamples->setEnabled(
false);
258 void ScopeGadgetOptionsPage::on_cmbSpectrogramSource_currentIndexChanged(QString currentText)
261 == options_page->cmbSpectrogramSource->itemText(
262 options_page->cmbSpectrogramSource->findData(
264 int vibrationTestIdx =
265 options_page->cmbUAVObjectsSpectrogram->findText(
"VibrationTestOutput");
266 options_page->cmbUAVObjectsSpectrogram->setCurrentIndex(vibrationTestIdx);
267 options_page->cmbUAVObjectsSpectrogram->setEnabled(
false);
272 VibrationAnalysisOutput *vibrationAnalysisOutput =
273 VibrationAnalysisOutput::GetInstance(objManager);
274 VibrationAnalysisSettings *vibrationAnalysisSettings =
275 VibrationAnalysisSettings::GetInstance(objManager);
276 VibrationAnalysisSettings::DataFields vibrationAnalysisSettingsData =
277 vibrationAnalysisSettings->getData();
280 options_page->cmbUAVObjectsSpectrogram->setCurrentIndex(
281 options_page->cmbUAVObjectsSpectrogram->findText(vibrationAnalysisOutput->getName()));
284 switch (vibrationAnalysisSettingsData.FFTWindowSize) {
286 case VibrationAnalysisSettings::FFTWINDOWSIZE_16:
289 case VibrationAnalysisSettings::FFTWINDOWSIZE_64:
292 case VibrationAnalysisSettings::FFTWINDOWSIZE_256:
295 case VibrationAnalysisSettings::FFTWINDOWSIZE_1024:
296 fftWindowSize = 1024;
301 options_page->sbSpectrogramWidth->setRange(0, fftWindowSize / 2);
304 options_page->sbSpectrogramWidth->setValue(fftWindowSize / 2);
305 options_page->sbSpectrogramFrequency->setValue(
306 1000.0f / vibrationAnalysisSettingsData.SampleRate);
308 options_page->sbSpectrogramFrequency->setEnabled(
false);
309 options_page->sbSpectrogramWidth->setEnabled(
false);
311 options_page->cmbUavoFieldSpectrogram->clear();
323 options_page->cmbUavoFieldSpectrogram->addItem(field->
getName());
328 options_page->cmbUAVObjectsSpectrogram->setEnabled(
true);
336 void ScopeGadgetOptionsPage::on_btnColor_clicked()
338 QColor color = QColorDialog::getColor(QColor(options_page->btnColor->text()));
339 if (color.isValid()) {
340 setButtonColor(color);
348 void ScopeGadgetOptionsPage::set2dYAxisWidgetFromDataSource()
350 bool parseOK =
false;
351 QListWidgetItem *listItem = options_page->lst2dCurves->currentItem();
353 if (listItem ==
nullptr)
357 int currentIndex = options_page->cmbUAVObjects->findText(
358 listItem->data(Qt::UserRole +
UR_UAVOBJECT).toString());
359 options_page->cmbUAVObjects->setCurrentIndex(currentIndex);
362 options_page->cmbUAVField->findText(listItem->data(Qt::UserRole +
UR_UAVFIELD).toString());
363 options_page->cmbUAVField->setCurrentIndex(currentIndex);
365 currentIndex = options_page->cmbScale->findData(listItem->data(Qt::UserRole +
UR_SCALE),
366 Qt::UserRole, Qt::MatchExactly);
367 options_page->cmbScale->setCurrentIndex(currentIndex);
370 QVariant varColor = listItem->data(Qt::UserRole +
UR_COLOR);
371 int rgb = varColor.toInt(&parseOK);
373 rgb = QColor(Qt::red).rgb();
376 setButtonColor(QColor((QRgb)rgb));
379 QString styleSheet = dataSourceStyleSheetTemplate.arg(QColor((QRgb)rgb).red())
380 .arg(QColor((QRgb)rgb).green())
381 .arg(QColor((QRgb)rgb).blue());
382 options_page->lst2dCurves->setStyleSheet(styleSheet);
384 unsigned int mean = listItem->data(Qt::UserRole +
UR_MEAN).toUInt(&parseOK);
387 options_page->spnMeanSamples->setValue(mean);
389 currentIndex = options_page->mathFunctionComboBox->findText(
391 options_page->mathFunctionComboBox->setCurrentIndex(currentIndex);
399 void ScopeGadgetOptionsPage::setButtonColor(
const QColor &color)
403 options_page->btnColor->setText(color.name());
404 options_page->btnColor->setPalette(QPalette(color));
412 void ScopeGadgetOptionsPage::on_cmbUAVObjects_currentIndexChanged(QString val)
414 options_page->cmbUAVField->clear();
430 options_page->cmbUAVField->addItem(field->
getName() +
"-" + elemName);
433 options_page->cmbUAVField->addItem(field->
getName());
443 void ScopeGadgetOptionsPage::on_cmbUAVObjectsSpectrogram_currentIndexChanged(QString val)
445 options_page->cmbUavoFieldSpectrogram->clear();
462 options_page->cmbUavoFieldSpectrogram->addItem(field->
getName() +
"-" + elemName);
465 options_page->cmbUavoFieldSpectrogram->addItem(field->
getName());
469 unsigned int maxWidth = objManager->
getNumInstances(objData->getObjID());
470 options_page->sbSpectrogramWidth->setRange(0, maxWidth);
471 options_page->sbSpectrogramWidth->setValue(maxWidth);
488 void ScopeGadgetOptionsPage::on_btnAdd2dCurve_clicked()
490 bool parseOK =
false;
491 QString uavObject = options_page->cmbUAVObjects->currentText();
492 QString uavField = options_page->cmbUAVField->currentText();
494 options_page->cmbScale->itemData(options_page->cmbScale->currentIndex()).toInt(&parseOK);
499 unsigned int mean = options_page->spnMeanSamples->value();
500 QString mathFunction = options_page->mathFunctionComboBox->currentText();
502 QVariant varColor = (int)QColor(options_page->btnColor->text()).rgb();
505 addPlot2dCurveConfig(uavObject, uavField, scale, mean, mathFunction, varColor);
511 void ScopeGadgetOptionsPage::on_btnApply2dCurve_clicked()
513 bool parseOK =
false;
514 QString uavObjectName = options_page->cmbUAVObjects->currentText();
515 QString uavFieldName = options_page->cmbUAVField->currentText();
517 options_page->cmbScale->itemData(options_page->cmbScale->currentIndex()).toInt(&parseOK);
522 unsigned int mean = options_page->spnMeanSamples->value();
523 QString mathFunction = options_page->mathFunctionComboBox->currentText();
525 QVariant varColor = (int)QColor(options_page->btnColor->text()).rgb();
528 QListWidgetItem *listWidgetItem = options_page->lst2dCurves->currentItem();
529 if (listWidgetItem == NULL) {
531 msgBox.setText(tr(
"No curve selected."));
532 msgBox.setInformativeText(tr(
"Please select a curve or generate one with the "
535 msgBox.setStandardButtons(QMessageBox::Ok);
541 qDebug() << uavObjectName <<
" " << uavFieldName <<
" " << scale <<
" " << mean <<
" "
542 << mathFunction <<
" " << varColor <<
" ";
544 setPlot2dCurveProperties(listWidgetItem, uavObjectName, uavFieldName, scale, mean, mathFunction,
551 void ScopeGadgetOptionsPage::on_btnRemove2dCurve_clicked()
553 options_page->lst2dCurves->takeItem(options_page->lst2dCurves->currentIndex().row());
565 void ScopeGadgetOptionsPage::addPlot2dCurveConfig(QString uavObjectName, QString uavFieldName,
566 int scale,
unsigned int mean,
567 QString mathFunction, QVariant varColor)
569 QString listItemDisplayText = uavObjectName +
"." + uavFieldName;
570 options_page->lst2dCurves->addItem(listItemDisplayText);
571 int itemIdx = options_page->lst2dCurves->count() - 1;
572 QListWidgetItem *listWidgetItem =
573 options_page->lst2dCurves->item(itemIdx);
576 setPlot2dCurveProperties(listWidgetItem, uavObjectName, uavFieldName, scale, mean, mathFunction,
580 options_page->lst2dCurves->setCurrentRow(itemIdx);
595 void ScopeGadgetOptionsPage::setPlot2dCurveProperties(QListWidgetItem *listWidgetItem,
596 QString uavObject, QString uavField,
597 int scale,
unsigned int mean,
598 QString mathFunction, QVariant varColor)
600 bool parseOK =
false;
601 QString listItemDisplayText;
604 if (uavObject !=
"") {
606 listItemDisplayText = uavObject +
"." + uavField;
607 rgbColor = (QRgb)varColor.toInt(&parseOK);
609 rgbColor = qRgb(255, 0, 0);
611 listItemDisplayText =
"New graph";
612 rgbColor = qRgb(255, 0, 0);
616 listWidgetItem->setText(listItemDisplayText);
619 QColor color = QColor(rgbColor);
620 QString styleSheet = dataSourceStyleSheetTemplate.arg(QColor(rgbColor).red())
621 .arg(QColor(rgbColor).green())
622 .arg(QColor(rgbColor).blue());
623 listWidgetItem->setTextColor(color);
624 options_page->lst2dCurves->setStyleSheet(
628 listWidgetItem->setData(Qt::UserRole +
UR_UAVOBJECT, QVariant(uavObject));
629 listWidgetItem->setData(Qt::UserRole +
UR_UAVFIELD, QVariant(uavField));
630 listWidgetItem->setData(Qt::UserRole +
UR_SCALE, QVariant(scale));
631 listWidgetItem->setData(Qt::UserRole +
UR_COLOR, varColor);
632 listWidgetItem->setData(Qt::UserRole +
UR_MEAN, QVariant(mean));
633 listWidgetItem->setData(Qt::UserRole +
UR_MATHFUNCTION, QVariant(mathFunction));
644 void ScopeGadgetOptionsPage::on_lst2dCurves_currentRowChanged(
int currentRow)
646 Q_UNUSED(currentRow);
647 set2dYAxisWidgetFromDataSource();
655 void ScopeGadgetOptionsPage::on_cmbXAxisScatterplot2d_currentIndexChanged(QString currentText)
657 if (currentText ==
"Series") {
658 options_page->spnDataSize->setSuffix(
" samples");
659 }
else if (currentText ==
"Time series") {
660 options_page->spnDataSize->setSuffix(
" seconds");
668 void ScopeGadgetOptionsPage::on_cmb2dPlotType_currentIndexChanged(QString currentText)
670 if (currentText ==
"Scatter plot") {
671 options_page->sw2dXAxis->setCurrentWidget(options_page->sw2dSeriesStack);
672 on_cmbXAxisScatterplot2d_currentIndexChanged(
673 options_page->cmbXAxisScatterplot2d->currentText());
674 }
else if (currentText ==
"Histogram") {
675 options_page->spnMaxNumBins->setSuffix(
" bins");
676 options_page->sw2dXAxis->setCurrentWidget(options_page->sw2dHistogramStack);
685 void ScopeGadgetOptionsPage::on_lst2dItem_clicked(QListWidgetItem *listItem)
687 if (listItem == selectedItem) {
688 listItem->setSelected(
false);
689 options_page->lst2dCurves->setCurrentRow(-1);
690 selectedItem =
nullptr;
692 selectedItem = listItem;
700 void ScopeGadgetOptionsPage::on_cmb3dPlotType_currentIndexChanged(QString currentText)
702 if (currentText ==
"Spectrogram") {
703 options_page->stackedWidget3dPlots->setCurrentWidget(options_page->sw3dSpectrogramStack);
706 options_page->cmbSpectrogramSource->setCurrentIndex(
707 options_page->cmbSpectrogramSource->findData(
709 }
else if (currentText ==
"Time series") {
710 options_page->stackedWidget3dPlots->setCurrentWidget(options_page->sw3dTimeSeriesStack);
virtual void setGuiConfiguration(Ui::ScopeGadgetOptionsPage *)=0
void apply()
ScopeGadgetOptionsPage::apply Called when the user presses OK. Applies the current values to the scop...
Core plugin system that manages the plugins, their life cycle and their registered objects...
static ICore * instance()
QList< UAVObjectField * > getFields()
QStringList getElementNames() const
void applyGuiConfiguration(Ui::ScopeGadgetOptionsPage *options_page)
ScopeGadgetConfiguration::applyGuiConfiguration Uses GUI information to create new scopes...
QWidget * createPage(QWidget *parent)
ScopeGadgetOptionsPage::createPage creates options page widget (uses the UI file) ...
UAVObject * getObject(const QString &name, quint32 instId=0)
QVector< QVector< UAVDataObject * > > getDataObjectsVector()
qint32 getNumInstances(const QString &name)
FieldType getType() const
ScopeGadgetOptionsPage(ScopeGadgetConfiguration *config, QObject *parent=nullptr)