added PGetFunctionsBlockDialog
This commit is contained in:
parent
d4d47c3990
commit
f0f865b476
104
src/musrgui/PGetFunctionsBlockDialog.cpp
Normal file
104
src/musrgui/PGetFunctionsBlockDialog.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
/****************************************************************************
|
||||
|
||||
PGetFunctionsBlockDialog.cpp
|
||||
|
||||
Author: Andreas Suter
|
||||
e-mail: andreas.suter@psi.ch
|
||||
|
||||
$Id$
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2009 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 <qtextedit.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qregexp.h>
|
||||
|
||||
#include "PGetFunctionsBlockDialog.h"
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*/
|
||||
PGetFunctionsBlockDialog::PGetFunctionsBlockDialog(const QString help, QWidget *parent, const char *name,
|
||||
bool modal, WFlags f) :
|
||||
PGetFunctionsBlockDialogBase(parent, name, modal, f),
|
||||
fHelp(help)
|
||||
{
|
||||
fFunctionInput_lineEdit->setFocus();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*/
|
||||
void PGetFunctionsBlockDialog::addFunction()
|
||||
{
|
||||
QString str = fFunctionInput_lineEdit->text();
|
||||
|
||||
// validation
|
||||
|
||||
// check that the function string starts with 'fun'
|
||||
if (!str.stripWhiteSpace().startsWith("fun")) {
|
||||
QMessageBox::critical(this, "addFunction",
|
||||
"a function has to start with 'funX' (X a number).\nNeeds to be fixed.",
|
||||
QMessageBox::Ok, QMessageBox::NoButton);
|
||||
return;
|
||||
}
|
||||
|
||||
// check if function string contains 'funX ='
|
||||
if (str.find( QRegExp("fun\\d+\\s*=") ) == -1) {
|
||||
QMessageBox::critical(this, "addFunction",
|
||||
"a function has to start with 'funX =' (X a positive number).\nNeeds to be fixed.",
|
||||
QMessageBox::Ok, QMessageBox::NoButton);
|
||||
return;
|
||||
}
|
||||
|
||||
// check if function string contains more than one 'funX'
|
||||
if (str.stripWhiteSpace().findRev("fun", -1, false) > 0) {
|
||||
QMessageBox::critical(this, "addFunction",
|
||||
"a function cannot contain more than one function,\ni.e. fun2 = fun1 + par1 is not OK.",
|
||||
QMessageBox::Ok, QMessageBox::NoButton);
|
||||
return;
|
||||
}
|
||||
|
||||
// add to Functions block
|
||||
fFunctionBlock_textEdit->append(str);
|
||||
|
||||
// clear functions input text
|
||||
fFunctionInput_lineEdit->clear();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*/
|
||||
void PGetFunctionsBlockDialog::helpContents()
|
||||
{
|
||||
QMessageBox::information(this, "helpContents",
|
||||
fHelp, QMessageBox::Ok);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// END
|
||||
//----------------------------------------------------------------------------------------------------
|
53
src/musrgui/PGetFunctionsBlockDialog.h
Normal file
53
src/musrgui/PGetFunctionsBlockDialog.h
Normal file
@ -0,0 +1,53 @@
|
||||
/****************************************************************************
|
||||
|
||||
PGetFunctionsBlockDialog.h
|
||||
|
||||
Author: Andreas Suter
|
||||
e-mail: andreas.suter@psi.ch
|
||||
|
||||
$Id$
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2009 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 _PGETFUNCTIONSBLOCKDIALOG_H_
|
||||
#define _PGETFUNCTIONSBLOCKDIALOG_H_
|
||||
|
||||
#include "forms/PGetFunctionsBlockDialogBase.h"
|
||||
|
||||
class PGetFunctionsBlockDialog : public PGetFunctionsBlockDialogBase
|
||||
{
|
||||
public:
|
||||
PGetFunctionsBlockDialog(const QString help = "", QWidget * parent = 0, const char * name = 0,
|
||||
bool modal = FALSE, WFlags f = 0);
|
||||
|
||||
QString getFunctionsBlock() { return fFunctionBlock_textEdit->text(); }
|
||||
|
||||
private slots:
|
||||
void addFunction();
|
||||
void helpContents();
|
||||
|
||||
private:
|
||||
QString fHelp;
|
||||
};
|
||||
|
||||
#endif // _PGETFUNCTIONSBLOCKDIALOG_H_
|
@ -39,6 +39,7 @@
|
||||
#include "PSubTextEdit.h"
|
||||
#include "forms/PGetTitleDialog.h"
|
||||
#include "PGetParameterDialog.h"
|
||||
#include "PGetFunctionsBlockDialog.h"
|
||||
#include "PGetAsymmetryRunBlockDialog.h"
|
||||
#include "PGetSingleHistoRunBlockDialog.h"
|
||||
#include "PGetNonMusrRunBlockDialog.h"
|
||||
@ -156,6 +157,11 @@ void PSubTextEdit::insertTheoryBlock()
|
||||
*/
|
||||
void PSubTextEdit::insertFunctionBlock()
|
||||
{
|
||||
PGetFunctionsBlockDialog *dlg = new PGetFunctionsBlockDialog(fHelp);
|
||||
if (dlg->exec() == QDialog::Accepted) {
|
||||
insert(dlg->getFunctionsBlock());
|
||||
insert("\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
@ -534,8 +534,8 @@ void PTextEdit::fileClose()
|
||||
if (fTabWidget->label(idx).find("*")>0) {
|
||||
int result = QMessageBox::warning(this, "**WARNING**",
|
||||
"Do you really want to close this file.\nChanges will be lost",
|
||||
QMessageBox::Yes, QMessageBox::Cancel);
|
||||
if (result == QMessageBox::Cancel)
|
||||
"Exit", "Cancel");
|
||||
if (result == 1) // Cancel
|
||||
return;
|
||||
}
|
||||
|
||||
@ -555,8 +555,8 @@ void PTextEdit::fileExit()
|
||||
if (fTabWidget->label(i).find("*") > 0) {
|
||||
int result = QMessageBox::warning(this, "**WARNING**",
|
||||
"Do you really want to exit from the applcation.\nChanges will be lost",
|
||||
QMessageBox::Yes, QMessageBox::Cancel);
|
||||
if (result == QMessageBox::Cancel)
|
||||
"Exit", "Cancel");
|
||||
if (result == 1) // Cancel
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
286
src/musrgui/forms/PGetFunctionsBlockDialogBase.ui
Normal file
286
src/musrgui/forms/PGetFunctionsBlockDialogBase.ui
Normal file
@ -0,0 +1,286 @@
|
||||
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
|
||||
<class>PGetFunctionsBlockDialogBase</class>
|
||||
<widget class="QDialog">
|
||||
<property name="name">
|
||||
<cstring>PGetFunctionsBlockDialogBase</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>649</width>
|
||||
<height>630</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="caption">
|
||||
<string>Get Functions</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<pixmap>image0</pixmap>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QTextEdit">
|
||||
<property name="name">
|
||||
<cstring>fHelp_textEdit</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>621</width>
|
||||
<height>230</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Supported basic arithmetics: <tt>+, -, *, /, ()</tt><br>
|
||||
Supported built-in functions: <tt>cos(), sin(), tan(), acos(), asin(), atan(), cosh(), sinh(), tanh(), acosh(), asinh(), atanh(), exp(), log(), ln()</tt><br>
|
||||
Supported pre-defined constants: <br><tt>
|
||||
gamma_mu = 0.0135538817 (MHz/G)<br>
|
||||
pi = 3.1415926535897932846</tt><br>
|
||||
Parameters and Maps are reached via parX, mapY, where X, Y are numbers, e.g. par1, map13<br>
|
||||
Examples:<br>
|
||||
<tt>fun1 = gamma_mu * par3</tt> valid<br>
|
||||
<tt>fun2 = par2/map4 * sin(par3*par5)</tt> valid<br>
|
||||
<tt>fun3 = fun1 + par5</tt> invalid, since functions can not be used with the functions definition</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<enum>WidgetWidth</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLayoutWidget">
|
||||
<property name="name">
|
||||
<cstring>Layout1</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>16</x>
|
||||
<y>580</y>
|
||||
<width>610</width>
|
||||
<height>33</height>
|
||||
</rect>
|
||||
</property>
|
||||
<hbox>
|
||||
<property name="name">
|
||||
<cstring>unnamed</cstring>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>buttonHelp</cstring>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Help</string>
|
||||
</property>
|
||||
<property name="accel">
|
||||
<string>F1</string>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<spacer>
|
||||
<property name="name">
|
||||
<cstring>Horizontal Spacing2</cstring>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>buttonOk</cstring>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&OK</string>
|
||||
</property>
|
||||
<property name="accel">
|
||||
<string></string>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="default">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>buttonCancel</cstring>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Cancel</string>
|
||||
</property>
|
||||
<property name="accel">
|
||||
<string></string>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</hbox>
|
||||
</widget>
|
||||
<widget class="QTextEdit">
|
||||
<property name="name">
|
||||
<cstring>fFunctionBlock_textEdit</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>366</y>
|
||||
<width>621</width>
|
||||
<height>200</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>###############################################################
|
||||
FUNCTIONS
|
||||
</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<enum>WidgetWidth</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QGroupBox">
|
||||
<property name="name">
|
||||
<cstring>fFunctionInput_groupBox</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>250</y>
|
||||
<width>621</width>
|
||||
<height>100</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Input</string>
|
||||
</property>
|
||||
<widget class="QLabel">
|
||||
<property name="name">
|
||||
<cstring>fFunctionInput_textLabel</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>30</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Function:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>fAdd_pushButton</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>490</x>
|
||||
<y>60</y>
|
||||
<width>113</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit">
|
||||
<property name="name">
|
||||
<cstring>fFunctionInput_lineEdit</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<y>30</y>
|
||||
<width>513</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<images>
|
||||
<image name="image0">
|
||||
<data format="PNG" length="270">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b000000d549444154388db594510e84200c44a78653d1f34faf853fd66d2a2aa8fb1222697068cb80d0884cadda7c6e46392c1860c9010da2bd8d4629f1670140a3200869d536ad8a2d63cfc805bc7c338ac766b33eb4c279dadb5be1b72c5ab5c5d2f3028fcda6bff042f40dd2f3f119355477c7708fdd15a3eef8ecf0f2868f847bb733332c1c9d43a344f15e9bca51e25a3cde52493736d3e2d85cb27ff36861d0081ad18b15607b783a785cabb67d4da7bf5e890070f34eb5c245cee2c4cfebc533ca593e211ee2652bdef0bfd7ed4bb1e8f5a947688615932a98c849f587290000000049454e44ae426082</data>
|
||||
</image>
|
||||
</images>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonOk</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>PGetFunctionsBlockDialogBase</receiver>
|
||||
<slot>accept()</slot>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonCancel</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>PGetFunctionsBlockDialogBase</receiver>
|
||||
<slot>reject()</slot>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonHelp</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>PGetFunctionsBlockDialogBase</receiver>
|
||||
<slot>helpContents()</slot>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>fAdd_pushButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>PGetFunctionsBlockDialogBase</receiver>
|
||||
<slot>addFunction()</slot>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>fFunctionInput_lineEdit</sender>
|
||||
<signal>returnPressed()</signal>
|
||||
<receiver>PGetFunctionsBlockDialogBase</receiver>
|
||||
<slot>addFunction()</slot>
|
||||
</connection>
|
||||
</connections>
|
||||
<tabstops>
|
||||
<tabstop>fFunctionInput_lineEdit</tabstop>
|
||||
<tabstop>fAdd_pushButton</tabstop>
|
||||
<tabstop>buttonOk</tabstop>
|
||||
<tabstop>buttonCancel</tabstop>
|
||||
<tabstop>buttonHelp</tabstop>
|
||||
<tabstop>fFunctionBlock_textEdit</tabstop>
|
||||
<tabstop>fHelp_textEdit</tabstop>
|
||||
</tabstops>
|
||||
<slots>
|
||||
<slot access="private">helpContents()</slot>
|
||||
<slot access="private">addFunction()</slot>
|
||||
</slots>
|
||||
<layoutdefaults spacing="6" margin="11"/>
|
||||
</UI>
|
@ -20,6 +20,7 @@ HEADERS = PTextEdit.h \
|
||||
PPrefsDialog.h \
|
||||
PGetDefaultDialog.h \
|
||||
PGetParameterDialog.h \
|
||||
PGetFunctionsBlockDialog.h \
|
||||
PGetAsymmetryRunBlockDialog.h \
|
||||
PGetSingleHistoRunBlockDialog.h \
|
||||
PGetNonMusrRunBlockDialog.h \
|
||||
@ -34,6 +35,7 @@ SOURCES = PTextEdit.cpp \
|
||||
PPrefsDialog.cpp \
|
||||
PGetDefaultDialog.cpp \
|
||||
PGetParameterDialog.cpp \
|
||||
PGetFunctionsBlockDialog.cpp \
|
||||
PGetAsymmetryRunBlockDialog.cpp \
|
||||
PGetSingleHistoRunBlockDialog.cpp \
|
||||
PGetNonMusrRunBlockDialog.cpp \
|
||||
@ -47,6 +49,7 @@ FORMS = forms/PGetDefaultDialogBase.ui \
|
||||
forms/PPrefsDialogBase.ui \
|
||||
forms/PGetTitleDialog.ui \
|
||||
forms/PGetParameterDialogBase.ui \
|
||||
forms/PGetFunctionsBlockDialogBase.ui \
|
||||
forms/PGetAsymmetryRunBlockDialogBase.ui \
|
||||
forms/PGetSingleHistoRunBlockDialogBase.ui \
|
||||
forms/PGetNonMusrRunBlockDialogBase.ui \
|
||||
|
Loading…
x
Reference in New Issue
Block a user