Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
MantidQt::MantidWidgets::UserFunctionDialog Class Reference

A dialog for construction a user fitting function from existing components. More...

#include <UserFunctionDialog.h>

Inheritance diagram for MantidQt::MantidWidgets::UserFunctionDialog:

Public Member Functions

QStringList categories () const
 
QString getFormula () const
 
 UserFunctionDialog (QWidget *parent=nullptr, const QString &formula="")
 
 ~UserFunctionDialog () override
 Write saved functions in the destructor. More...
 

Private Slots

void addExpression ()
 Add selected expression to the user function. More...
 
void helpClicked ()
 Open the help wiki page in the web browser. More...
 
void removeCurrentFunction ()
 Remove the current function. More...
 
void saveFunction ()
 Save the constructed function for future use. More...
 
void selectCategory (const QString &cat)
 Make a category current. More...
 
void selectFunction (const QString &fun)
 Make a function current. More...
 
void updateCategories ()
 Update the GUI element displaying categories. More...
 
void updateFunction ()
 Updates the parameter list. More...
 

Private Member Functions

QSet< QString > categoryNames () const
 Returns a list of category names. More...
 
void checkParameters (QString &expr)
 Check an expression for name clashes with user function. More...
 
bool eventFilter (QObject *obj, QEvent *ev) override
 
QSet< QString > functionNames (const QString &cat) const
 Returns function names in category cat. More...
 
QString getComment (const QString &cat, const QString &fun) const
 Get the comment for saved function in category cat with name fun. More...
 
QString getCurrentCategory () const
 Get the name of currently selected category. More...
 
QString getFunction (const QString &cat, const QString &fun) const
 Get the expression for saved function in category cat with name fun. More...
 
bool isBuiltin (const QString &cat) const
 Checks if a category is a buil-in one and cannot be changed. More...
 
void loadFunctions ()
 Load saved functions form Mantid(.user).properties file. More...
 
void saveToFile ()
 
void setFunction (const QString &cat, const QString &fun, const QString &expr, const QString &comment="")
 Set an expression to a new function in category cat and with name fun. More...
 

Private Attributes

QMap< QString, QString > m_funs
 Container for prerecorded functions: key = category.name, value = formula Records with key = category.name.comment contain comments to corresponding functions. More...
 
Ui::UserFunctionDialog m_uiForm
 User interface elements. More...
 

Detailed Description

A dialog for construction a user fitting function from existing components.

Definition at line 24 of file UserFunctionDialog.h.

Constructor & Destructor Documentation

◆ UserFunctionDialog()

UserFunctionDialog::UserFunctionDialog ( QWidget *  parent = nullptr,
const QString &  formula = "" 
)

◆ ~UserFunctionDialog()

UserFunctionDialog::~UserFunctionDialog ( )
override

Write saved functions in the destructor.

Definition at line 55 of file UserFunctionDialog.cpp.

References saveToFile().

Member Function Documentation

◆ addExpression

void UserFunctionDialog::addExpression ( )
privateslot

Add selected expression to the user function.

Definition at line 164 of file UserFunctionDialog.cpp.

References checkParameters(), m_uiForm, and Mantid::Geometry::rect.

Referenced by UserFunctionDialog().

◆ categories()

QStringList UserFunctionDialog::categories ( ) const

Definition at line 395 of file UserFunctionDialog.cpp.

References m_uiForm.

◆ categoryNames()

QSet< QString > UserFunctionDialog::categoryNames ( ) const
private

Returns a list of category names.

Definition at line 271 of file UserFunctionDialog.cpp.

References m_funs.

Referenced by updateCategories().

◆ checkParameters()

void UserFunctionDialog::checkParameters ( QString &  expr)
private

Check an expression for name clashes with user function.

Parameters
expr:: An expression prepared to be added to the user function.

Definition at line 190 of file UserFunctionDialog.cpp.

References Mantid::API::Expression::getVariables(), m_uiForm, Mantid::API::Expression::parse(), Mantid::API::Expression::renameAll(), MantidQt::MantidWidgets::RenameParDialog::setOutput(), and Mantid::API::Expression::str().

Referenced by addExpression().

◆ eventFilter()

bool UserFunctionDialog::eventFilter ( QObject *  obj,
QEvent *  ev 
)
overrideprivate

Definition at line 403 of file UserFunctionDialog.cpp.

References obj.

◆ functionNames()

QSet< QString > UserFunctionDialog::functionNames ( const QString &  cat) const
private

Returns function names in category cat.

Parameters
cat:: The category for which functions will be returned.
Returns
A set of funtion names.

Definition at line 286 of file UserFunctionDialog.cpp.

References m_funs.

Referenced by saveFunction(), and selectCategory().

◆ getComment()

QString UserFunctionDialog::getComment ( const QString &  cat,
const QString &  fun 
) const
private

Get the comment for saved function in category cat with name fun.

If any of the arguments are empty string or function does not exist return empty string.

Parameters
cat:: The category
fun:: The name of the function

Definition at line 439 of file UserFunctionDialog.cpp.

References m_funs.

Referenced by selectFunction().

◆ getCurrentCategory()

QString UserFunctionDialog::getCurrentCategory ( ) const
private

Get the name of currently selected category.

If no category is selected returns empty string.

Definition at line 303 of file UserFunctionDialog.cpp.

References m_uiForm.

Referenced by saveFunction(), and updateCategories().

◆ getFormula()

QString MantidQt::MantidWidgets::UserFunctionDialog::getFormula ( ) const
inline

Definition at line 31 of file UserFunctionDialog.h.

◆ getFunction()

QString UserFunctionDialog::getFunction ( const QString &  cat,
const QString &  fun 
) const
private

Get the expression for saved function in category cat with name fun.

If any of the arguments are empty string or function does not exist return empty string.

Parameters
cat:: The category
fun:: The name of the function
Returns
An expression that can be used as mu::Parser formula

Definition at line 423 of file UserFunctionDialog.cpp.

References m_funs.

Referenced by selectCategory(), and selectFunction().

◆ helpClicked

void UserFunctionDialog::helpClicked ( )
privateslot

Open the help wiki page in the web browser.

Definition at line 483 of file UserFunctionDialog.cpp.

References MantidQt::API::MantidDesktopServices::openUrl().

Referenced by UserFunctionDialog().

◆ isBuiltin()

bool UserFunctionDialog::isBuiltin ( const QString &  cat) const
private

Checks if a category is a buil-in one and cannot be changed.

Definition at line 478 of file UserFunctionDialog.cpp.

Referenced by removeCurrentFunction(), and selectCategory().

◆ loadFunctions()

void UserFunctionDialog::loadFunctions ( )
private

Load saved functions form Mantid(.user).properties file.

Property: userfunctions.CategoryName.FunctionName = Expression-in-Mu Parser-format

Definition at line 62 of file UserFunctionDialog.cpp.

References Mantid::Kernel::SingletonHolder< T >::Instance(), m_funs, and setFunction().

Referenced by UserFunctionDialog().

◆ removeCurrentFunction

void UserFunctionDialog::removeCurrentFunction ( )
privateslot

Remove the current function.

Definition at line 372 of file UserFunctionDialog.cpp.

References isBuiltin(), m_funs, m_uiForm, saveToFile(), and selectCategory().

Referenced by UserFunctionDialog().

◆ saveFunction

void UserFunctionDialog::saveFunction ( )
privateslot

Save the constructed function for future use.

Definition at line 315 of file UserFunctionDialog.cpp.

References functionNames(), getCurrentCategory(), m_uiForm, saveToFile(), setFunction(), and updateCategories().

Referenced by UserFunctionDialog().

◆ saveToFile()

void UserFunctionDialog::saveToFile ( )
private

◆ selectCategory

void UserFunctionDialog::selectCategory ( const QString &  cat)
privateslot

Make a category current.

Parameters
cat:: The category to select

Definition at line 123 of file UserFunctionDialog.cpp.

References functionNames(), getFunction(), isBuiltin(), m_uiForm, and value.

Referenced by removeCurrentFunction(), and UserFunctionDialog().

◆ selectFunction

void UserFunctionDialog::selectFunction ( const QString &  fun)
privateslot

Make a function current.

Parameters
fun:: The function to select

Definition at line 145 of file UserFunctionDialog.cpp.

References getComment(), getFunction(), m_uiForm, and value.

Referenced by UserFunctionDialog().

◆ setFunction()

void UserFunctionDialog::setFunction ( const QString &  cat,
const QString &  fun,
const QString &  expr,
const QString &  comment = "" 
)
private

Set an expression to a new function in category cat and with name fun.

If any of the arguments are empty string does nothing.

Parameters
cat:: The category
fun:: The name of the function
expr:: The expression
comment:: The comment

Definition at line 457 of file UserFunctionDialog.cpp.

References m_funs.

Referenced by loadFunctions(), and saveFunction().

◆ updateCategories

void UserFunctionDialog::updateCategories ( )
privateslot

Update the GUI element displaying categories.

Definition at line 106 of file UserFunctionDialog.cpp.

References categoryNames(), getCurrentCategory(), and m_uiForm.

Referenced by saveFunction(), and UserFunctionDialog().

◆ updateFunction

void UserFunctionDialog::updateFunction ( )
privateslot

Updates the parameter list.

Definition at line 247 of file UserFunctionDialog.cpp.

References Mantid::API::Expression::getVariables(), m_uiForm, and Mantid::API::Expression::parse().

Referenced by UserFunctionDialog().

Member Data Documentation

◆ m_funs

QMap<QString, QString> MantidQt::MantidWidgets::UserFunctionDialog::m_funs
private

Container for prerecorded functions: key = category.name, value = formula Records with key = category.name.comment contain comments to corresponding functions.

Definition at line 63 of file UserFunctionDialog.h.

Referenced by categoryNames(), functionNames(), getComment(), getFunction(), loadFunctions(), removeCurrentFunction(), saveToFile(), and setFunction().

◆ m_uiForm

Ui::UserFunctionDialog MantidQt::MantidWidgets::UserFunctionDialog::m_uiForm
private

The documentation for this class was generated from the following files: