From 54fee067dfb2326fa45b2f86deffc985642e65c9 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Sat, 4 Apr 2020 20:26:29 +0200 Subject: [PATCH] little extension which allows to normalize plots. Only dialogs added so far, no functionality yet. --- src/musredit_qt5/mupp/CMakeLists.txt | 1 + src/musredit_qt5/mupp/PGetNormValDialog.cpp | 75 +++++++++++++++++++++ src/musredit_qt5/mupp/PGetNormValDialog.h | 54 +++++++++++++++ src/musredit_qt5/mupp/PmuppGui.cpp | 47 ++++++++++++- src/musredit_qt5/mupp/PmuppGui.h | 7 +- 5 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 src/musredit_qt5/mupp/PGetNormValDialog.cpp create mode 100644 src/musredit_qt5/mupp/PGetNormValDialog.h diff --git a/src/musredit_qt5/mupp/CMakeLists.txt b/src/musredit_qt5/mupp/CMakeLists.txt index 4630b907..da3fd196 100644 --- a/src/musredit_qt5/mupp/CMakeLists.txt +++ b/src/musredit_qt5/mupp/CMakeLists.txt @@ -48,6 +48,7 @@ set(SOURCE_FILES Pmupp.cpp PmuppScript.cpp PmuppGui.cpp + PGetNormValDialog.cpp ) if (APPLE) diff --git a/src/musredit_qt5/mupp/PGetNormValDialog.cpp b/src/musredit_qt5/mupp/PGetNormValDialog.cpp new file mode 100644 index 00000000..fad3a0d1 --- /dev/null +++ b/src/musredit_qt5/mupp/PGetNormValDialog.cpp @@ -0,0 +1,75 @@ +/*************************************************************************** + + PGetNormValDialog.cpp + + Author: Andreas Suter + e-mail: andreas.suter@psi.ch + +***************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2007-2020 by Andreas Suter * + * andreas.suter@psi.ch * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include "PGetNormValDialog.h" + +//------------------------------------------------------------------------------ +PGetNormValDialog::PGetNormValDialog(double dval, QWidget *parent, Qt::WindowFlags f) : + QDialog(parent, f), fValue(dval) +{ + QVBoxLayout *vbox = new QVBoxLayout; + QHBoxLayout *hbox1 = new QHBoxLayout; + QHBoxLayout *hbox2 = new QHBoxLayout; + + vbox->addLayout(hbox1); + vbox->addLayout(hbox2); + + QLabel *lab = new QLabel("Norm Value: "); + QLineEdit *fEdit = new QLineEdit(); + fEdit->setValidator(new QDoubleValidator()); + fEdit->setText(QString("%1").arg(fValue)); + hbox1->addWidget(lab); + hbox1->addWidget(fEdit); + + QPushButton *ok = new QPushButton("OK"); + QPushButton *cancel = new QPushButton("Cancel"); + hbox2->addWidget(ok); + hbox2->addWidget(cancel); + + setModal(true); + + setLayout(vbox); + + connect( fEdit, SIGNAL(textChanged(const QString&)), this, SLOT(gotValue(const QString&))); + connect( ok, SIGNAL(clicked()), this, SLOT(accept())); + connect( cancel, SIGNAL(clicked()), this, SLOT(reject())); +} + +//------------------------------------------------------------------------------ +void PGetNormValDialog::gotValue(const QString& str) +{ + fValue = str.toDouble(); +} diff --git a/src/musredit_qt5/mupp/PGetNormValDialog.h b/src/musredit_qt5/mupp/PGetNormValDialog.h new file mode 100644 index 00000000..0f8e99c1 --- /dev/null +++ b/src/musredit_qt5/mupp/PGetNormValDialog.h @@ -0,0 +1,54 @@ +/*************************************************************************** + + PGetNormValDialog.h + + Author: Andreas Suter + e-mail: andreas.suter@psi.ch + +***************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2007-2020 by Andreas Suter * + * andreas.suter@psi.ch * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _PGETNORMVALDIALOG_H_ +#define _PGETNORMVALDIALOG_H_ + +#include +#include + +class PGetNormValDialog : public QDialog +{ + Q_OBJECT + + public: + PGetNormValDialog(double dval, QWidget *parent = 0, Qt::WindowFlags f = 0); + virtual ~PGetNormValDialog() {} + + virtual double getValue() { return fValue; } + + private: + double fValue; + QLineEdit *fEdit; + + private slots: + virtual void gotValue(const QString& str); +}; + +#endif // _PGETNORMVALDIALOG_H_ diff --git a/src/musredit_qt5/mupp/PmuppGui.cpp b/src/musredit_qt5/mupp/PmuppGui.cpp index d0cebfff..0ee3c1d4 100644 --- a/src/musredit_qt5/mupp/PmuppGui.cpp +++ b/src/musredit_qt5/mupp/PmuppGui.cpp @@ -60,6 +60,7 @@ using namespace std; #include "mupp_version.h" #include "PmuppGui.h" +#include "PGetNormValDialog.h" //---------------------------------------------------------------------------------------------------- /** @@ -207,7 +208,11 @@ PmuppGui::PmuppGui( QStringList fln, QWidget *parent, Qt::WindowFlags f ) fDatime = dt.toTime_t(); fMuppInstance = -1; - fMuppPlot = 0; + fMuppPlot = nullptr; + fNormalizeAction = nullptr; + + fNormalize = false; + fNormVal = 0.0; fMacroPath = QString("./"); fMacroName = QString(""); @@ -526,6 +531,19 @@ void PmuppGui::setupToolActions() a->setStatusTip( tr("Dump XY parameter list") ); connect( a, SIGNAL( triggered() ), this, SLOT( toolDumpXY() ) ); menu->addAction(a); + + menu->addSeparator(); + + fNormalizeAction = new QAction(tr( "Normalize" ), this); + fNormalizeAction->setStatusTip( tr("Plot Data Normalized (y-axis)") ); + fNormalizeAction->setCheckable(true); + connect( fNormalizeAction, SIGNAL( changed() ), this, SLOT( normalize() ) ); + menu->addAction(fNormalizeAction); + + a = new QAction(tr( "Normalize by Value" ), this); + a->setStatusTip( tr("Normalize by Value") ); + connect( a, SIGNAL( triggered() ), this, SLOT( normVal() ) ); + menu->addAction(a); } //---------------------------------------------------------------------------------------------------- @@ -666,6 +684,33 @@ void PmuppGui::toolDumpXY() } } +//---------------------------------------------------------------------------------------------------- +void PmuppGui::normalize() +{ + fNormalize = fNormalizeAction->isChecked(); +} + +//---------------------------------------------------------------------------------------------------- +void PmuppGui::normVal() +{ + PGetNormValDialog *dlg = new PGetNormValDialog(fNormVal); + if (dlg == nullptr) { + QMessageBox::critical(this, "**ERROR**", "Couldn't invoke dialog, sorry :-(", QMessageBox::Ok, QMessageBox::NoButton); + return; + } + + dlg->exec(); + + if (dlg->result() != QDialog::Accepted) { + delete dlg; + return; + } + + fNormVal = dlg->getValue(); + + delete dlg; +} + //---------------------------------------------------------------------------------------------------- /** * @brief PmuppGui::helpCmds diff --git a/src/musredit_qt5/mupp/PmuppGui.h b/src/musredit_qt5/mupp/PmuppGui.h index 22c2dea1..cad0ce51 100644 --- a/src/musredit_qt5/mupp/PmuppGui.h +++ b/src/musredit_qt5/mupp/PmuppGui.h @@ -8,7 +8,7 @@ ***************************************************************************/ /*************************************************************************** - * Copyright (C) 2007-2017 by Andreas Suter * + * Copyright (C) 2007-2020 by Andreas Suter * * andreas.suter@psi.ch * * * * This program is free software; you can redistribute it and/or modify * @@ -114,6 +114,8 @@ public slots: void toolDumpCollections(); void toolDumpXY(); + void normalize(); + void normVal(); void helpCmds(); void helpAbout(); @@ -128,6 +130,8 @@ private: PmuppAdmin *fAdmin; bool fDarkTheme; bool fDarkToolBarIcon; + bool fNormalize; + double fNormVal; uint fDatime; uint fMuppInstance; @@ -142,6 +146,7 @@ private: QMenu *fRecentFilesMenu; ///< recent file menu QAction *fRecentFilesAction[MAX_RECENT_FILES]; ///< array of the recent file actions + QAction *fNormalizeAction; QBoxLayout *fBoxLayout_Main; // top->bottom (0) QBoxLayout *fBoxLayout_Top; // left->right (1)