musredit 1.0.0
Loading...
Searching...
No Matches
PGetFunctionsBlockDialog.cpp
Go to the documentation of this file.
1/****************************************************************************
2
3 PGetFunctionsBlockDialog.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 <QTextEdit>
44#include <QLineEdit>
45#include <QMessageBox>
46#include <QRegularExpression>
47#include <QEvent>
48#include <QDesktopServices>
49#include <QUrl>
50
51#include <QtDebug>
52
54
55//----------------------------------------------------------------------------------------------------
66{
67 setupUi(this);
68
69 setModal(true);
70
71 fFunctionInput_lineEdit->setFocus();
72}
73
74//----------------------------------------------------------------------------------------------------
98{
99 QString str = fFunctionInput_lineEdit->text();
100
101 if (str.isEmpty())
102 return;
103
104 // validation
105
106 // check that the function string starts with 'fun'
107 if (!str.trimmed().startsWith("fun")) {
108 QMessageBox::critical(this, "addFunction",
109 "a function has to start with 'funX' (X a number).\nNeeds to be fixed.",
110 QMessageBox::Ok, QMessageBox::NoButton);
111 return;
112 }
113
114 // check if function string contains 'funX ='
115 if (str.indexOf( QRegularExpression("fun\\d+\\s*=") ) == -1) {
116 QMessageBox::critical(this, "addFunction",
117 "a function has to start with 'funX =' (X a positive number).\nNeeds to be fixed.",
118 QMessageBox::Ok, QMessageBox::NoButton);
119 return;
120 }
121
122 // check if function string contains more than one 'funX'
123 if (str.trimmed().lastIndexOf("fun", -1, Qt::CaseInsensitive) > 0) {
124 QMessageBox::critical(this, "addFunction",
125 "a function cannot contain more than one function,\ni.e. fun2 = fun1 + par1 is not OK.",
126 QMessageBox::Ok, QMessageBox::NoButton);
127 return;
128 }
129
130 // add to Functions block
131 fFunctionBlock_plainTextEdit->appendPlainText(str);
132
133 // clear functions input text
134 fFunctionInput_lineEdit->clear();
135}
136
137//----------------------------------------------------------------------------------------------------
146{
147 if (fHelpUrl.isEmpty()) {
148 QMessageBox::information(this, "INFO", "Will eventually show a help window");
149 } else {
150 bool ok = QDesktopServices::openUrl(QUrl(fHelpUrl, QUrl::TolerantMode));
151 if (!ok) {
152 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);
153 QMessageBox::critical( nullptr, tr("FATAL ERROR"), msg, QMessageBox::Close );
154 }
155 }
156}
157
158//----------------------------------------------------------------------------------------------------
159// END
160//----------------------------------------------------------------------------------------------------
Dialog for creating FUNCTIONS blocks in msr files.
void addFunction()
Validates and adds a function to the FUNCTIONS block.
QString fHelpUrl
URL to the online documentation for FUNCTIONS blocks.
PGetFunctionsBlockDialog(const QString helpUrl="")
Constructs the FUNCTIONS block dialog.
void helpContent()
Opens the online help for FUNCTIONS blocks.