musredit 1.0.0
Loading...
Searching...
No Matches
PGetParameterBlockDialog.cpp
Go to the documentation of this file.
1/****************************************************************************
2
3 PGetParameterBlockDialog.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 <QPushButton>
49#include <QEvent>
50#include <QDesktopServices>
51#include <QUrl>
52
54
55//----------------------------------------------------------------------------------------------------
74{
75 setupUi(this);
76
77 setModal(true);
78
79 // setup event filter
80 installEventFilter(this);
81
82 fValue_lineEdit->setValidator( new QDoubleValidator(fValue_lineEdit) );
83 fStep_lineEdit->setValidator( new QDoubleValidator(fStep_lineEdit) );
84
85 fParam_plainTextEdit->setFont(QFont("Courier", 10));
86}
87
88//----------------------------------------------------------------------------------------------------
103bool PGetParameterBlockDialog::eventFilter( QObject *obj, QEvent *ev )
104{
105 if (obj == this) {
106 if (ev->type() == QEvent::KeyPress) {
107 QKeyEvent *k = (QKeyEvent*)ev;
108 if (k->key() == Qt::Key_Return) {
109 paramAdd();
110 return true;
111 } else {
112 return false;
113 }
114 } else {
115 return false;
116 }
117 } else {
118 return false;
119 }
120}
121
122//----------------------------------------------------------------------------------------------------
153{
154 QString param, str, spaces;
155
156 // get No
157 str = fParamNo_spinBox->text();
158 if (str.toInt() < 10)
159 param = " " + str + " ";
160 else
161 param = " " + str + " ";
162
163 // get name
164 str = fName_lineEdit->text();
165 if (str.isEmpty()) {
166 QMessageBox::critical(this, "ERROR",
167 "empty parameter name not allowed!",
168 QMessageBox::Ok, QMessageBox::NoButton);
169 return;
170 } else {
171 param += str;
172 if (str.length() < 13)
173 param += spaces.fill(' ', 13-str.length());
174 else
175 param += " ";
176 }
177
178 // get value
179 str = fValue_lineEdit->text();
180 if (str.isEmpty()) {
181 QMessageBox::critical(this, "ERROR",
182 "empty parameter value not allowed!",
183 QMessageBox::Ok, QMessageBox::NoButton);
184 return;
185 } else {
186 param += str;
187 if (str.length() < 10)
188 param += spaces.fill(' ', 10-str.length());
189 else
190 param += " ";
191 }
192
193 // get step
194 str = fStep_lineEdit->text();
195 if (str.isEmpty()) {
196 QMessageBox::critical(this, "ERROR",
197 "empty parameter step not allowed!",
198 QMessageBox::Ok, QMessageBox::NoButton);
199 return;
200 } else {
201 param += str;
202 if (str.length() < 10)
203 param += spaces.fill(' ', 10-str.length());
204 else
205 param += " ";
206 }
207
208 // add positive error none
209 param += "none ";
210
211 if ((fLower_lineEdit->text() != "none") || (fUpper_lineEdit->text() != "none")) {
212 // get lower boundary
213 str = fLower_lineEdit->text();
214 bool ok;
215 double val = str.toDouble(&ok);
216 if (!ok && (str != "none")) {
217 QMessageBox::critical(this, "ERROR",
218 "invalid lower boundary! Must be a double are the key word 'none'",
219 QMessageBox::Ok, QMessageBox::NoButton);
220 return;
221 } else {
222 param += str;
223 if (str.length() < 10)
224 param += spaces.fill(' ', 10-str.length());
225 else
226 param += " ";
227 }
228
229 // get upper boundary
230 str = fUpper_lineEdit->text();
231 val = str.toDouble(&ok);
232 if (!ok && (str != "none")) {
233 QMessageBox::critical(this, "ERROR",
234 "invalid upper boundary! Must be a double are the key word 'none'",
235 QMessageBox::Ok, QMessageBox::NoButton);
236 return;
237 } else {
238 param += str;
239 if (str.length() < 10)
240 param += spaces.fill(' ', 10-str.length());
241 else
242 param += " ";
243 }
244 }
245
246// param += "\n";
247
248 // write parameter string into fParam_textEdit
249 fParam_plainTextEdit->appendPlainText(param);
250
251 // increment No counter in spinBox
252 fParamNo_spinBox->stepUp();
253
254 // reset name lineEdit
255 fName_lineEdit->setText("");
256
257 // reset value lineEdit
258 fValue_lineEdit->setText("");
259
260 // reset step lineEdit
261 fStep_lineEdit->setText("");
262
263 // reset lower boundary lineEdit
264 fLower_lineEdit->setText("none");
265
266 // reset upper boundary lineEdit
267 fUpper_lineEdit->setText("none");
268
269 fName_lineEdit->setFocus();
270}
271
272//----------------------------------------------------------------------------------------------------
281{
282 if (fHelpUrl.isEmpty()) {
283 QMessageBox::information(this, "INFO", "Will eventually show a help window");
284 } else {
285 bool ok = QDesktopServices::openUrl(QUrl(fHelpUrl, QUrl::TolerantMode));
286 if (!ok) {
287 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);
288 QMessageBox::critical( nullptr, tr("FATAL ERROR"), msg, QMessageBox::Close );
289 }
290 }
291}
292
293//----------------------------------------------------------------------------------------------------
294// END
295//----------------------------------------------------------------------------------------------------
Dialog for creating FITPARAMETER blocks in msr files.
void helpContent()
Opens the online help for FITPARAMETER blocks.
bool eventFilter(QObject *obj, QEvent *ev)
Event filter to handle keyboard shortcuts.
QString fHelpUrl
URL to the online documentation for FITPARAMETER blocks.
PGetParameterBlockDialog(const QString helpUrl)
Constructs the FITPARAMETER block dialog.
void paramAdd()
Validates and adds a parameter to the FITPARAMETER block.