mupp 1.1.0
Loading...
Searching...
No Matches
PVarDialog Class Reference

The PVarDialog class provides a GUI for defining custom variables. More...

#include <PVarDialog.h>

Inheritance diagram for PVarDialog:
Collaboration diagram for PVarDialog:

Signals

void check_request (QString varStr, QVector< int > idx)
 Signal emitted when user requests to check variable definitions.
 
void add_request (QString varStr, QVector< int > idx)
 Signal emitted when user requests to add variable definitions.
 

Public Member Functions

 PVarDialog (QVector< PCollInfo > collection_list, bool darkTheme, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
 Constructor for PVarDialog.
 

Private Slots

void check ()
 Slot to validate variable definitions and emit check_request signal.
 
void add ()
 Slot to validate and add variable definitions, emitting add_request signal.
 
void help ()
 Slot to display help information about variable syntax.
 
void showVarNames ()
 Slot to show a dialog displaying variable names from the selected collection.
 

Private Member Functions

bool basic_check ()
 Performs basic validation checks on variable definitions.
 
bool var_consistency_check ()
 Validates that all identifiers exist in selected collections.
 
QStringList collectVarNames (QStringList &list, bool &ok)
 Collects all variable names from a tokenized string list.
 
bool hasErrorDef (QStringList &varNames, QString &name)
 Checks that each variable has a corresponding error definition.
 

Private Attributes

std::unique_ptr< QPlainTextEdit > fVarEdit
 text editor for variable definitions
 
std::unique_ptr< QListWidget > fCollectionView
 list widget displaying available collections
 
std::unique_ptr< QPushButton > fCancel
 cancel button to reject the dialog
 
std::unique_ptr< QPushButton > fAdd
 add button to add variables to mupp GUI
 
std::unique_ptr< QPushButton > fCheck
 check button to validate variable definitions
 
std::unique_ptr< QPushButton > fHelp
 help button to display syntax information
 
std::unique_ptr< QPushButton > fShowVarName
 button to show variable names from selected collection
 
QVector< PCollInfofCollList
 vector holding all collection information
 

Detailed Description

The PVarDialog class provides a GUI for defining custom variables.

This dialog allows users to define custom variables based on existing variables from selected collections. Variables are defined using expressions that can reference collection variables as identifiers (prefixed with '$'). The dialog validates that both a variable and its corresponding error variable (suffixed with 'Err') are defined, and checks that all identifiers exist in the selected collections.

Example variable definition:

var sigSC = pow(abs(pow($sigma,2.0)-pow(0.11,2.0)),0.5)
var sigSCErr = <error_expression>

Definition at line 92 of file PVarDialog.h.

Constructor & Destructor Documentation

◆ PVarDialog()

PVarDialog::PVarDialog ( QVector< PCollInfo > collection_list,
bool darkTheme,
QWidget * parent = nullptr,
Qt::WindowFlags f = Qt::WindowFlags() )

Constructor for PVarDialog.

Parameters
collection_listvector of PCollInfo structures containing all available collections
darkThemeflag indicating whether to use dark theme icons (true) or plain icons (false)
parentoptional parent widget pointer
foptional window flags for the dialog

Creates a variable definition dialog with a text editor for variable expressions and a collection list view. The dialog allows users to define custom variables using expressions that reference collection variables as identifiers (prefixed with '$'). Multiple collections can be selected, and the dialog validates that all identifiers exist in the selected collections.

The dialog includes buttons for:

  • Check: validates variable definitions
  • Add: adds variables to the mupp GUI
  • Help: displays syntax information
  • ShowVarName: displays variable names from selected collection
  • Cancel: closes the dialog
Parameters
collection_listvector of all available collections with their variable names
darkThemeif true, uses dark theme icons; if false, uses plain icons
parentoptional parent widget pointer
foptional window flags for the dialog

Definition at line 113 of file PVarDialog.cpp.

Member Function Documentation

◆ add

void PVarDialog::add ( )
privateslot

Slot to validate and add variable definitions, emitting add_request signal.

Validates and adds variable definitions to the mupp GUI.

Checks that input is present and at least one collection is selected. Performs basic checks and consistency validation. If all checks pass, emits the add_request signal with the variable string and selected collection indices.

Definition at line 220 of file PVarDialog.cpp.

◆ add_request

void PVarDialog::add_request ( QString varStr,
QVector< int > idx )
signal

Signal emitted when user requests to add variable definitions.

Parameters
varStrthe complete variable definition string from the text editor
idxvector of indices indicating which collections are selected

◆ basic_check()

bool PVarDialog::basic_check ( )
private

Performs basic validation checks on variable definitions.

Returns
true if basic checks pass, false otherwise

Validates the following:

  • Input is not empty
  • At least one collection is selected
  • At least one 'var' definition is present
  • Each 'var' keyword is followed by a variable name
  • For each variable, a corresponding error variable (with 'Err' suffix) exists
Returns
true if all basic checks pass, false otherwise (with error message displayed)

Definition at line 331 of file PVarDialog.cpp.

◆ check

void PVarDialog::check ( )
privateslot

Slot to validate variable definitions and emit check_request signal.

Validates variable definitions and emits check_request signal.

Performs basic checks (syntax, presence of 'var' keyword, error variable definitions) and consistency checks (identifiers exist in collections). If validation succeeds, emits the check_request signal with the variable string and selected collection indices.

Definition at line 194 of file PVarDialog.cpp.

◆ check_request

void PVarDialog::check_request ( QString varStr,
QVector< int > idx )
signal

Signal emitted when user requests to check variable definitions.

Parameters
varStrthe complete variable definition string from the text editor
idxvector of indices indicating which collections are selected

◆ collectVarNames()

QStringList PVarDialog::collectVarNames ( QStringList & list,
bool & ok )
private

Collects all variable names from a tokenized string list.

Parameters
listreference to a tokenized string list containing variable definitions
okreference to a boolean flag indicating success or failure
Returns
QStringList containing all collected variable names

Scans the input list for 'var' keywords and extracts the following token as the variable name. Sets the ok flag to false if a 'var' keyword is found at the end of the list without a following variable name.

Parameters
listreference to a tokenized string list containing variable definitions
okreference to boolean flag; set to true if all 'var' keywords have associated names, false otherwise
Returns
QStringList containing all collected variable names

Definition at line 498 of file PVarDialog.cpp.

◆ hasErrorDef()

bool PVarDialog::hasErrorDef ( QStringList & varNames,
QString & name )
private

Checks that each variable has a corresponding error definition.

For every variable name that doesn't end with 'Err', checks that a corresponding variable with 'Err' suffix exists.

Parameters
varNamesreference to a list of variable names to check
namereference to QString that will hold the name of the first variable without an error definition
Returns
true if all variables have error definitions, false otherwise

For every variable name in the list that doesn't contain 'Err', checks that a corresponding variable with an 'Err' suffix exists in the list. If any variable lacks its error counterpart, the variable name is stored in the name parameter.

Parameters
varNamesreference to a list of variable names to validate
namereference to QString that will hold the name of the first variable without an error definition
Returns
true if all non-error variables have corresponding error definitions, false otherwise

Definition at line 530 of file PVarDialog.cpp.

◆ help

void PVarDialog::help ( )
privateslot

Slot to display help information about variable syntax.

Displays help information about variable definition syntax.

Shows a message box explaining the syntax for defining variables:

  • Basic syntax: var <var_name> = <expr>
  • Identifiers are prefixed with '$' (e.g., $sigma)
  • Expressions can use standard mathematical functions
  • Example: var sigSC = pow(abs(pow($sigma,2.0)-pow(0.11,2.0)),0.5)

Definition at line 257 of file PVarDialog.cpp.

◆ showVarNames

void PVarDialog::showVarNames ( )
privateslot

Slot to show a dialog displaying variable names from the selected collection.

Displays variable names from the selected collection.

Shows a PShowVarNameDialog containing all variable names from the currently selected collection. Only one collection can be displayed at a time. Displays error messages if no collection is selected, multiple collections are selected, or if an invalid collection index is encountered.

Definition at line 294 of file PVarDialog.cpp.

◆ var_consistency_check()

bool PVarDialog::var_consistency_check ( )
private

Validates that all identifiers exist in selected collections.

Checks that every identifier (prefixed with '$') used in the variable definitions exists either as a variable being defined or as a variable in one of the selected collections.

Returns
true if all identifiers are valid, false otherwise

Collects all identifiers (prefixed with '$') and variable names from the variable definition string. For each identifier, checks that it either:

  1. Is a variable being defined in the current definition string, or
  2. Exists as a variable in one of the selected collections

Handles both regular identifiers and error identifiers (ending with 'Err'). Displays error message if any identifier is not found in selected collections.

Returns
true if all identifiers are valid, false otherwise (with error message displayed)

Definition at line 397 of file PVarDialog.cpp.

Member Data Documentation

◆ fAdd

std::unique_ptr<QPushButton> PVarDialog::fAdd
private

add button to add variables to mupp GUI

Definition at line 112 of file PVarDialog.h.

◆ fCancel

std::unique_ptr<QPushButton> PVarDialog::fCancel
private

cancel button to reject the dialog

Definition at line 111 of file PVarDialog.h.

◆ fCheck

std::unique_ptr<QPushButton> PVarDialog::fCheck
private

check button to validate variable definitions

Definition at line 113 of file PVarDialog.h.

◆ fCollectionView

std::unique_ptr<QListWidget> PVarDialog::fCollectionView
private

list widget displaying available collections

Definition at line 110 of file PVarDialog.h.

◆ fCollList

QVector<PCollInfo> PVarDialog::fCollList
private

vector holding all collection information

Definition at line 117 of file PVarDialog.h.

◆ fHelp

std::unique_ptr<QPushButton> PVarDialog::fHelp
private

help button to display syntax information

Definition at line 114 of file PVarDialog.h.

◆ fShowVarName

std::unique_ptr<QPushButton> PVarDialog::fShowVarName
private

button to show variable names from selected collection

Definition at line 115 of file PVarDialog.h.

◆ fVarEdit

std::unique_ptr<QPlainTextEdit> PVarDialog::fVarEdit
private

text editor for variable definitions

Definition at line 109 of file PVarDialog.h.


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