musredit 1.0.0
Loading...
Searching...
No Matches
PGetPlotBlockDialog.cpp
Go to the documentation of this file.
1/****************************************************************************
2
3 PGetPlotBlockDialog.cpp
4
5 Author: Andreas Suter
6 e-mail: andreas.suter@psi.ch
7
8*****************************************************************************/
9
10/***************************************************************************
11 * Copyright (C) 2009-2026 by Andreas Suter *
12 * andreas.suter@psi.ch *
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program; if not, write to the *
26 * Free Software Foundation, Inc., *
27 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
28 ***************************************************************************/
29
42
43#include <QLineEdit>
44#include <QValidator>
45#include <QMessageBox>
46#include <QSpinBox>
47#include <QTextEdit>
48#include <QComboBox>
49#include <QDesktopServices>
50#include <QUrl>
51
52#include "PGetPlotBlockDialog.h"
53
54//----------------------------------------------------------------------------------------------------
72PGetPlotBlockDialog::PGetPlotBlockDialog(const QString helpUrl) : fHelpUrl(helpUrl)
73{
74 setupUi(this);
75
76 setModal(true);
77
78 // setup event filter
79 installEventFilter(this);
80
81 fXRangeLow_lineEdit->setValidator( new QDoubleValidator(fXRangeLow_lineEdit) );
82 fXRangeUp_lineEdit->setValidator( new QDoubleValidator(fXRangeUp_lineEdit) );
83 fYRangeLow_lineEdit->setValidator( new QDoubleValidator(fYRangeLow_lineEdit) );
84 fYRangeUp_lineEdit->setValidator( new QDoubleValidator(fYRangeUp_lineEdit) );
85
86 fPlot_plainTextEdit->setFont(QFont("Courier", 10));
87}
88
89//----------------------------------------------------------------------------------------------------
119{
120 QString param = "";
121 QString str = "";
122 QString spaces;
123
124 // add begining of plot block if fPlot_plainTextEdit is still empty
125 if (fPlot_plainTextEdit->toPlainText().isEmpty()) {
126 param = "###############################################################\n";
127 }
128
129 // write type
130 param += "PLOT ";
131 if (fType_comboBox->currentText() == "Single Histo") {
132 param += "0 (single histo plot)\n";
133 } else if (fType_comboBox->currentText() == "Asymmetry") {
134 param += "2 (asymmetry plot)\n";
135 } else if (fType_comboBox->currentText() == "MuMinus") {
136 param += "4 (mu minus plot)\n";
137 } else if (fType_comboBox->currentText() == "NonMusr") {
138 param += "8 (non muSR plot)\n";
139 }
140
141 // write runs
142 param += "runs " + fRunList_lineEdit->text() + "\n";
143
144 // write range
145 param += "range ";
146 // lower x-/time range
147 str = fXRangeLow_lineEdit->text();
148 if (str.isEmpty()) {
149 QMessageBox::critical(this, "ERROR",
150 "empty lower time-/x-range name not allowed!",
151 QMessageBox::Ok, QMessageBox::NoButton);
152 return;
153 }
154 param += str;
155 if (str.length() < 8)
156 param += spaces.fill(' ', 8 - str.length());
157 else
158 param += " ";
159
160 // upper x-/time range
161 str = fXRangeUp_lineEdit->text();
162 if (str.isEmpty()) {
163 QMessageBox::critical(this, "ERROR",
164 "empty upper time-/x-range name not allowed!",
165 QMessageBox::Ok, QMessageBox::NoButton);
166 return;
167 }
168 param += str;
169 if (str.length() < 8)
170 param += spaces.fill(' ', 8 - str.length());
171 else
172 param += " ";
173
174 // check y-range: either none given or both
175 if ((fYRangeLow_lineEdit->text().isEmpty() && !fYRangeUp_lineEdit->text().isEmpty()) ||
176 (!fYRangeLow_lineEdit->text().isEmpty() && fYRangeUp_lineEdit->text().isEmpty())) {
177 QMessageBox::critical(this, "ERROR",
178 "Only fully empty y-range, or give lower AND upper y-range is acceptable!\n Will ignore the y-range",
179 QMessageBox::Ok, QMessageBox::NoButton);
180 } else if (!fYRangeLow_lineEdit->text().isEmpty() && !fYRangeUp_lineEdit->text().isEmpty()) {
181 str = fYRangeLow_lineEdit->text();
182 param += str;
183 if (str.length() < 8)
184 param += spaces.fill(' ', 8 - str.length());
185 else
186 param += " ";
187 param += fYRangeUp_lineEdit->text() + "\n";
188 } else {
189 param += "\n";
190 }
191 param += "\n";
192
193 fPlot_plainTextEdit->appendPlainText(param);
194
195 // clean input
196 fRunList_lineEdit->clear();
197 fXRangeLow_lineEdit->clear();
198 fXRangeUp_lineEdit->clear();
199 fYRangeLow_lineEdit->clear();
200 fYRangeUp_lineEdit->clear();
201 fRunList_lineEdit->setFocus();
202}
203
204//----------------------------------------------------------------------------------------------------
213{
214 if (fHelpUrl.isEmpty()) {
215 QMessageBox::information(this, "INFO", "Will eventually show a help window");
216 } else {
217 bool ok = QDesktopServices::openUrl(QUrl(fHelpUrl, QUrl::TolerantMode));
218 if (!ok) {
219 QString msg = QString("<p>Sorry: Couldn't open default web-browser for the help.<br>Please try: <a href=\"%1\">musrfit docu</a> in your web-browser.").arg(fHelpUrl);
220 QMessageBox::critical( nullptr, tr("FATAL ERROR"), msg, QMessageBox::Close );
221 }
222 }
223}
224
225//----------------------------------------------------------------------------------------------------
240bool PGetPlotBlockDialog::eventFilter( QObject *obj, QEvent *ev )
241{
242 if (obj == this) {
243 if (ev->type() == QEvent::KeyPress) {
244 QKeyEvent *k = (QKeyEvent*)ev;
245 if (k->key() == Qt::Key_Return) {
246 addPlot();
247 return true;
248 } else {
249 return false;
250 }
251 } else {
252 return false;
253 }
254 } else {
255 return false;
256 }
257}
258
259//----------------------------------------------------------------------------------------------------
260// END
261//----------------------------------------------------------------------------------------------------
Dialog for creating PLOT blocks in msr files.
PGetPlotBlockDialog(const QString helpUrl)
Constructs the PLOT block dialog.
void addPlot()
Validates and adds a plot specification to the PLOT block.
bool eventFilter(QObject *obj, QEvent *ev)
Event filter to handle keyboard shortcuts.
QString fHelpUrl
URL to the online documentation for PLOT blocks.
void helpContent()
Opens the online help for PLOT blocks.