musrStep 1.0.0
Loading...
Searching...
No Matches
PMusrStep Class Reference

Main dialog class for the musrStep application. More...

#include <PMusrStep.h>

Inheritance diagram for PMusrStep:

Public Member Functions

 PMusrStep (const char *fln, QWidget *parent=Q_NULLPTR)
 Constructor for PMusrStep dialog.
 
bool isValid ()
 Checks if the dialog was initialized successfully.
 

Private Slots

void handleCellChanged (int row, int column)
 Slot called when a table cell value changes.
 
void checkSpecific ()
 Slot that allows selection of parameters by name template.
 
void checkAll ()
 Slot that selects all non-fixed parameters.
 
void unCheckAll ()
 Slot that deselects all parameters.
 
void modifyAuto ()
 Slot that applies automatic step modification to all non-fixed parameters.
 
void modifyChecked ()
 Slot that opens the PModSelect dialog for checked parameters.
 
void saveAndQuit ()
 Slot that saves the modified msr-file and closes the dialog.
 
void handleModSelect (bool automatic, double factor, bool absVal)
 Slot that handles the selection made in the PModSelect dialog.
 

Private Member Functions

void initParam (PParam &param)
 Initializes a PParam structure with empty strings.
 
double lookupTable (const QString str, bool &absVal)
 Determines the appropriate step size factor based on parameter name.
 
QString adoptStep (const QString str, double factor, bool absVal)
 Calculates the new step value based on the current value and factor.
 
int readMsrFile ()
 Reads and parses the FITPARAMETER block from the msr-file.
 
int writeMsrFile ()
 Writes the modified parameters back to the msr-file.
 
QString getLine (QByteArray &data, int &idx)
 Extracts a single line from a byte array.
 
QString updateParamLine (const QString str)
 Reconstructs a parameter line with updated values.
 

Private Attributes

QString fMsrFileName
 Path to the currently open msr-file.
 
bool fValid
 Flag indicating successful initialization.
 
QVector< PParamfParamVec
 Vector storing all fit parameters.
 
std::unique_ptr< QLabel > fTitleLabel
 Label displaying the file name.
 
std::unique_ptr< QTableWidget > fParamTable
 Table widget for parameter display.
 
std::unique_ptr< QPushButton > fCheckSpecific
 Button to select by template.
 
std::unique_ptr< QPushButton > fCheckAll
 Button to select all parameters.
 
std::unique_ptr< QPushButton > fUnCheckAll
 Button to deselect all parameters.
 
std::unique_ptr< QPushButton > fModifyAuto
 Button for automatic modification.
 
std::unique_ptr< QPushButton > fModifySelected
 Button to modify selected parameters.
 
std::unique_ptr< QPushButton > fSave
 Button to save and quit.
 
std::unique_ptr< QPushButton > fCancel
 Button to cancel without saving.
 
PModSelectfModSelect
 Pointer to the modification options dialog.
 

Detailed Description

Main dialog class for the musrStep application.

This class implements the main user interface for viewing and modifying fit parameter step sizes in muSR msr-files. It provides:

  • A table view displaying all fit parameters with their values and step sizes
  • Selection mechanisms for choosing which parameters to modify
  • Automatic and manual step size adjustment options
  • File I/O for reading and writing msr-files

The automatic step size adjustment uses a lookup table based on common muSR parameter naming conventions to determine appropriate step sizes.

See also
PModSelect for the modification options dialog
PParam for the parameter data structure

Constructor & Destructor Documentation

◆ PMusrStep()

PMusrStep::PMusrStep ( const char * fln,
QWidget * parent = Q_NULLPTR )

Constructor for PMusrStep dialog.

Constructor for the PMusrStep main dialog.

Initializes the dialog, reads the msr-file, and populates the parameter table. Sets up all UI elements and signal/slot connections.

Parameters
flnPath to the msr-file to open
parentPointer to the parent widget (default: Q_NULLPTR)

Initializes the dialog with the following operations:

  1. Sets up the window title and icon based on the current theme
  2. Reads and parses the msr-file to extract fit parameters
  3. Creates the parameter table with columns for name, value, and step
  4. Sets up selection buttons (Check Specific, Check All, Uncheck All)
  5. Sets up modification buttons (Modify Automatic, Modify Selected)
  6. Sets up action buttons (Save&Quit, Cancel)
  7. Creates the PModSelect sub-dialog for detailed modification options

The dialog height is automatically adjusted based on the number of parameters, with a maximum limit based on screen resolution.

Parameters
flnPath to the msr-file to open and edit
parentPointer to the parent widget (default: Q_NULLPTR)

Member Function Documentation

◆ adoptStep()

QString PMusrStep::adoptStep ( const QString str,
double factor,
bool absVal )
private

Calculates the new step value based on the current value and factor.

Calculates the new step value based on current value and factor.

Parameters
strThe current parameter value as a string
factorThe scaling factor to apply
absValIf true, return factor directly; if false, return factor * value
Returns
The new step value as a string

Computes the new step size using either:

  • Absolute mode (absVal=true): Returns the factor directly as the step
  • Multiplicative mode (absVal=false): Returns factor * current_value
Parameters
strThe current parameter value as a string
factorThe scaling factor to apply
absValIf true, return factor directly; if false, multiply by value
Returns
The new step value as a QString

◆ checkAll

void PMusrStep::checkAll ( )
privateslot

Slot that selects all non-fixed parameters.

Selects all non-fixed parameters in the table.

Checks all parameters except those with step == 0.

Iterates through all rows and checks parameters whose step value is not "0" or "0.0" (fixed parameters remain unchecked).

◆ checkSpecific

void PMusrStep::checkSpecific ( )
privateslot

Slot that allows selection of parameters by name template.

Allows selection of parameters matching a template string.

Opens an input dialog for the user to enter a template string. All parameters whose names contain the template are selected.

Opens an input dialog where the user can enter a template string. All parameters whose names contain this template (case-sensitive) are then checked, except for fixed parameters (step == 0 or "0.0").

◆ getLine()

QString PMusrStep::getLine ( QByteArray & data,
int & idx )
private

Extracts a single line from a byte array.

Extracts a single line from a byte array at the given position.

Parameters
dataReference to the byte array containing file data
idxReference to the current position index (updated on return)
Returns
The extracted line as a QString

Searches for the next newline character starting at idx and extracts the text between the current position and the newline. The idx parameter is updated to point to the character after the newline.

Parameters
dataReference to the byte array containing file data
idxReference to the current position index (updated to next line start)
Returns
The extracted line as a QString, or empty string if no newline found

◆ handleCellChanged

void PMusrStep::handleCellChanged ( int row,
int column )
privateslot

Slot called when a table cell value changes.

Handles changes to cells in the parameter table.

Validates changes to step values and prevents selection of fixed parameters (step == 0).

Parameters
rowThe row index of the changed cell
columnThe column index of the changed cell

Performs validation when table cells are modified:

  • Column 0 (name): Prevents selection of fixed parameters (step == 0)
  • Column 2 (step): Validates that entered values are valid numbers

If an invalid step value is entered, the cell is restored to its previous value from fParamVec.

Parameters
rowThe row index of the changed cell
columnThe column index of the changed cell

◆ handleModSelect

void PMusrStep::handleModSelect ( bool automatic,
double factor,
bool absVal )
privateslot

Slot that handles the selection made in the PModSelect dialog.

Processes the scaling selection from the PModSelect dialog.

Applies the specified scaling operation to all checked parameters.

Parameters
automaticIf true, use automatic scaling based on parameter names
factorThe scaling factor to apply
absValIf true, factor is used as absolute value; if false, as multiplier

Applies the specified scaling operation to all checked parameters. If automatic mode is selected, the factor is determined by lookupTable() for each parameter individually.

Parameters
automaticIf true, use automatic scaling based on parameter names
factorThe scaling factor (used when automatic is false)
absValIf true, factor is used as absolute value; if false, as multiplier

◆ initParam()

void PMusrStep::initParam ( PParam & param)
private

Initializes a PParam structure with empty strings.

Parameters
paramReference to the PParam structure to initialize

Sets all fields of the parameter structure to empty QString objects. Used before populating a new parameter from file data.

Parameters
paramReference to the PParam structure to initialize

◆ isValid()

bool PMusrStep::isValid ( )
inline

Checks if the dialog was initialized successfully.

Returns false if the msr-file could not be read or parsed.

Returns
true if the dialog is valid and ready for use, false otherwise

◆ lookupTable()

double PMusrStep::lookupTable ( const QString str,
bool & absVal )
private

Determines the appropriate step size factor based on parameter name.

Uses naming conventions to identify parameter types:

  • freq/frq/field: factor = 1e-3
  • lambda/sigma/rlx/rate: factor = 0.1
  • phase/phs: factor = 5.0 (absolute)
  • N0/Nrm/N_bkg/Bgr: factor = 0.01
  • default: factor = 0.01
    Parameters
    strThe parameter name to look up
    absValOutput flag set to true if factor should be used as absolute value
    Returns
    The scaling factor to apply
    Uses common muSR parameter naming conventions to identify parameter types and return appropriate scaling factors:
  • freq, frq, field: factor = 1e-3 (high precision for frequency/field)
  • lambda, sigma, rlx, rate: factor = 0.1 (relaxation rates)
  • phase, phs: factor = 5.0 (absolute value, for phase parameters)
  • N0, Nrm, N_bkg, Bgr: factor = 0.01 (normalization/background)
  • default: factor = 0.01

The comparison is case-insensitive and matches the start of the parameter name.

Parameters
strThe parameter name to look up
absValOutput flag set to true if factor should be used as absolute value
Returns
The scaling factor to apply

◆ modifyAuto

void PMusrStep::modifyAuto ( )
privateslot

Slot that applies automatic step modification to all non-fixed parameters.

Applies automatic step size modification to all non-fixed parameters.

Uses the lookupTable() function to determine appropriate step sizes based on parameter naming conventions.

Iterates through all parameters and applies automatic scaling using lookupTable() and adoptStep(). Fixed parameters (step == 0) are skipped. Both the table display and the internal fParamVec are updated.

◆ modifyChecked

void PMusrStep::modifyChecked ( )
privateslot

Slot that opens the PModSelect dialog for checked parameters.

Opens the modification dialog for checked parameters.

Shows the PModSelect dialog, which allows the user to choose between automatic scaling and manual factor-based scaling for the currently selected parameters.

◆ readMsrFile()

int PMusrStep::readMsrFile ( )
private

Reads and parses the FITPARAMETER block from the msr-file.

Populates fParamVec with all parameters found between FITPARAMETER and THEORY blocks.

Returns
1 on success, -1 if file cannot be opened, -2 on parse error

Opens the msr-file specified in fMsrFileName and extracts all parameters from the FITPARAMETER block (between FITPARAMETER and THEORY keywords). Each parameter line must have either 5 or 7 space-separated fields:

  • 5 fields: number, name, value, step, posErr
  • 7 fields: above plus boundLow, boundHigh

Comment lines (starting with #) and empty lines are ignored.

Returns
1 on success
-1 if file cannot be opened
-2 if a parameter line has invalid format

◆ saveAndQuit

void PMusrStep::saveAndQuit ( )
privateslot

Slot that saves the modified msr-file and closes the dialog.

Saves the modified msr-file and closes the dialog.

Calls writeMsrFile() to save all modifications, then accepts the dialog to close it with a success status.

◆ unCheckAll

void PMusrStep::unCheckAll ( )
privateslot

Slot that deselects all parameters.

Deselects all parameters in the table.

Iterates through all rows and unchecks every parameter, regardless of whether it is fixed or not.

◆ updateParamLine()

QString PMusrStep::updateParamLine ( const QString str)
private

Reconstructs a parameter line with updated values.

Formats the parameter line with proper field widths for msr-file compatibility.

Parameters
strThe original parameter line
Returns
The updated parameter line, or empty string if not a parameter line

Searches fParamVec for a parameter matching the given line, then formats a new parameter line with proper field widths:

  • Column 1 (10 chars, right-aligned): parameter number
  • Column 2 (12+ chars, left-aligned): parameter name
  • Columns 3-5 (11 chars each): value, step, posErr
  • Columns 6-7 (11 chars each, optional): boundLow, boundHigh

The parameter is identified by finding its name sandwiched between spaces in the input string to avoid partial matches.

Parameters
strThe original parameter line to update
Returns
The reconstructed parameter line, or empty string if no match found

◆ writeMsrFile()

int PMusrStep::writeMsrFile ( )
private

Writes the modified parameters back to the msr-file.

Preserves all non-parameter content and updates only the FITPARAMETER block with new step values.

Returns
1 on success, -1 if input file cannot be opened, -2 if output file cannot be opened

Reads the entire original msr-file, then rewrites it with updated step values in the FITPARAMETER block. All other content is preserved unchanged. A "*** FIT DID NOT CONVERGE ***" marker is appended to indicate the file has been modified.

Returns
1 on success
-1 if input file cannot be opened for reading
-2 if output file cannot be opened for writing

Member Data Documentation

◆ fCancel

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

Button to cancel without saving.

◆ fCheckAll

std::unique_ptr<QPushButton> PMusrStep::fCheckAll
private

Button to select all parameters.

◆ fCheckSpecific

std::unique_ptr<QPushButton> PMusrStep::fCheckSpecific
private

Button to select by template.

◆ fModifyAuto

std::unique_ptr<QPushButton> PMusrStep::fModifyAuto
private

Button for automatic modification.

◆ fModifySelected

std::unique_ptr<QPushButton> PMusrStep::fModifySelected
private

Button to modify selected parameters.

◆ fModSelect

PModSelect* PMusrStep::fModSelect
private

Pointer to the modification options dialog.

◆ fMsrFileName

QString PMusrStep::fMsrFileName
private

Path to the currently open msr-file.

◆ fParamTable

std::unique_ptr<QTableWidget> PMusrStep::fParamTable
private

Table widget for parameter display.

◆ fParamVec

QVector<PParam> PMusrStep::fParamVec
private

Vector storing all fit parameters.

◆ fSave

std::unique_ptr<QPushButton> PMusrStep::fSave
private

Button to save and quit.

◆ fTitleLabel

std::unique_ptr<QLabel> PMusrStep::fTitleLabel
private

Label displaying the file name.

◆ fUnCheckAll

std::unique_ptr<QPushButton> PMusrStep::fUnCheckAll
private

Button to deselect all parameters.

◆ fValid

bool PMusrStep::fValid
private

Flag indicating successful initialization.


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