improve the doxygen docu of PmuppAdmin.* (musredit_qt6).
This commit is contained in:
@@ -27,6 +27,30 @@
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file PmuppAdmin.cpp
|
||||
*
|
||||
* @brief Implementation of mupp configuration and administration classes.
|
||||
*
|
||||
* This file implements the configuration management system for mupp, including:
|
||||
* - XML parsing of the mupp_startup.xml configuration file
|
||||
* - Recent file history management
|
||||
* - Plot appearance settings (colors and markers)
|
||||
* - Theme preferences for UI elements
|
||||
* - Automatic creation of default configuration files
|
||||
*
|
||||
* The implementation provides:
|
||||
* - PmuppColor: RGB color storage and manipulation
|
||||
* - PmuppAdminXMLParser: XML configuration file parsing
|
||||
* - PmuppAdmin: Main configuration manager with file search hierarchy
|
||||
*
|
||||
* Configuration file handling:
|
||||
* - Searches multiple standard locations for configuration
|
||||
* - Creates default configuration if none found
|
||||
* - Automatically saves recent file history on exit
|
||||
* - Validates configuration values (marker codes, RGB ranges)
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
@@ -48,7 +72,10 @@
|
||||
// implementation of PmuppColor class
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief PmuppColor::PmuppColor. Ctor
|
||||
* @brief Default constructor for PmuppColor.
|
||||
*
|
||||
* Initializes a color with an "UnDef" name and invalid RGB values (-1).
|
||||
* Invalid values indicate the color has not been properly initialized.
|
||||
*/
|
||||
PmuppColor::PmuppColor()
|
||||
{
|
||||
@@ -60,10 +87,15 @@ PmuppColor::PmuppColor()
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief PmuppColor::setRGB. set RGB value
|
||||
* @param r red (0..255)
|
||||
* @param g green (0..255)
|
||||
* @param b blue (0..255)
|
||||
* @brief Sets the RGB color values with validation.
|
||||
*
|
||||
* Sets the red, green, and blue components of the color. Each component
|
||||
* is validated to be in the range [0, 255]. Values outside this range
|
||||
* are ignored and the corresponding component remains unchanged.
|
||||
*
|
||||
* @param r red component (0-255)
|
||||
* @param g green component (0-255)
|
||||
* @param b blue component (0-255)
|
||||
*/
|
||||
void PmuppColor::setRGB(const int r, const int g, const int b)
|
||||
{
|
||||
@@ -79,9 +111,14 @@ void PmuppColor::setRGB(const int r, const int g, const int b)
|
||||
// implementation of PmuppAdminXMLParser class
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>XML Parser class for the mupp administration file.
|
||||
* @brief Constructor for XML parser.
|
||||
*
|
||||
* \param admin pointer to an admin class instance.
|
||||
* Initializes the XML parser and attempts to open and parse the
|
||||
* specified configuration file. The parsed data is stored in the
|
||||
* provided PmuppAdmin object.
|
||||
*
|
||||
* @param fln path to the mupp_startup.xml configuration file
|
||||
* @param admin pointer to the PmuppAdmin instance to populate with parsed data
|
||||
*/
|
||||
PmuppAdminXMLParser::PmuppAdminXMLParser(const QString& fln, PmuppAdmin *admin) : fAdmin(admin)
|
||||
{
|
||||
@@ -98,11 +135,18 @@ PmuppAdminXMLParser::PmuppAdminXMLParser(const QString& fln, PmuppAdmin *admin)
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>parse the mupp startup xml-file.
|
||||
* @brief Parses the mupp startup XML file.
|
||||
*
|
||||
* \param device QFile object of the mupp startup xml-file
|
||||
* This method uses Qt's QXmlStreamReader to parse the configuration file.
|
||||
* It processes each XML element sequentially, calling appropriate handler
|
||||
* methods (startElement, characters, endElement) based on the element type.
|
||||
*
|
||||
* @return true on success, false otherwise
|
||||
* The parser is event-driven and maintains state through the fKeyWord
|
||||
* enumeration to determine how to process element content.
|
||||
*
|
||||
* @param device QIODevice (typically QFile) containing the XML data
|
||||
*
|
||||
* @return true if parsing succeeds without errors, false otherwise
|
||||
*/
|
||||
bool PmuppAdminXMLParser::parse(QIODevice *device)
|
||||
{
|
||||
@@ -137,7 +181,12 @@ bool PmuppAdminXMLParser::parse(QIODevice *device)
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Routine called at the beginning of the XML parsing process.
|
||||
* @brief Handler called at the start of XML document parsing.
|
||||
*
|
||||
* This is invoked when the XML parser encounters the document start.
|
||||
* Currently performs no actions but provides a hook for future initialization.
|
||||
*
|
||||
* @return always returns true
|
||||
*/
|
||||
bool PmuppAdminXMLParser::startDocument()
|
||||
{
|
||||
@@ -147,8 +196,22 @@ bool PmuppAdminXMLParser::startDocument()
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Routine called when a new XML tag is found. Here it is used
|
||||
* to set a tag for filtering afterwards the content.
|
||||
* @brief Handler called when a new XML element is encountered.
|
||||
*
|
||||
* This method is invoked when the parser encounters an opening XML tag.
|
||||
* It identifies the element type and sets the fKeyWord state accordingly,
|
||||
* which determines how the element's content will be processed in the
|
||||
* characters() method.
|
||||
*
|
||||
* Recognized elements:
|
||||
* - path_file_name: Recent file entry
|
||||
* - ignore_theme_auto_detection: Theme detection override
|
||||
* - dark_theme_icon_menu: Menu icon theme
|
||||
* - dark_theme_icon_toolbar: Toolbar icon theme
|
||||
* - marker: Plot marker definition
|
||||
* - color: RGB color definition
|
||||
*
|
||||
* @return always returns true
|
||||
*/
|
||||
bool PmuppAdminXMLParser::startElement()
|
||||
{
|
||||
@@ -173,9 +236,13 @@ bool PmuppAdminXMLParser::startElement()
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Routine called when the end XML tag is found. It is used to
|
||||
* put the filtering tag to 'empty'. It also resets the fFunc flag in case
|
||||
* the entry was a theory function.
|
||||
* @brief Handler called when an XML closing tag is encountered.
|
||||
*
|
||||
* This method is invoked when the parser encounters a closing XML tag.
|
||||
* It resets the fKeyWord state to eEmpty, ending the current element's
|
||||
* context for content processing.
|
||||
*
|
||||
* @return always returns true
|
||||
*/
|
||||
bool PmuppAdminXMLParser::endElement()
|
||||
{
|
||||
@@ -186,8 +253,21 @@ bool PmuppAdminXMLParser::endElement()
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>This routine delivers the content of an XML tag. It fills the
|
||||
* content into the load data structure.
|
||||
* @brief Handler called to process XML element content.
|
||||
*
|
||||
* This method processes the text content between XML opening and closing
|
||||
* tags. The content interpretation depends on the current fKeyWord state
|
||||
* (set by startElement).
|
||||
*
|
||||
* Content processing by element type:
|
||||
* - eRecentFile: Adds file path to recent files list
|
||||
* - eIgnoreThemeAutoDetection: Sets theme auto-detection flag (yes/no/true/false)
|
||||
* - eDarkThemeIconsMenu: Sets menu icon theme preference
|
||||
* - eDarkThemeIconsToolbar: Sets toolbar icon theme preference
|
||||
* - eMarker: Parses marker definition (code[,size])
|
||||
* - eColor: Parses RGB color definition (r,g,b[,name])
|
||||
*
|
||||
* @return true if content is valid, false on parsing errors
|
||||
*/
|
||||
bool PmuppAdminXMLParser::characters()
|
||||
{
|
||||
@@ -273,8 +353,13 @@ bool PmuppAdminXMLParser::characters()
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Called at the end of the XML parse process. It checks if default paths
|
||||
* contain system variables, and if so expand them for the further use.
|
||||
* @brief Handler called at the end of XML document parsing.
|
||||
*
|
||||
* This is invoked when the parser reaches the end of the XML document.
|
||||
* Currently performs no post-processing but provides a hook for future
|
||||
* finalization tasks such as path expansion or validation.
|
||||
*
|
||||
* @return always returns true
|
||||
*/
|
||||
bool PmuppAdminXMLParser::endDocument()
|
||||
{
|
||||
@@ -285,8 +370,20 @@ bool PmuppAdminXMLParser::endDocument()
|
||||
// implementation of PmuppAdmin class
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Initializes that PmuppAdmin object, and calls the XML parser which feeds
|
||||
* the object variables.
|
||||
* @brief Constructor for PmuppAdmin.
|
||||
*
|
||||
* Initializes the administration object and searches for a configuration
|
||||
* file in multiple standard locations. The search proceeds in order:
|
||||
* 1. Current directory (./mupp_startup.xml)
|
||||
* 2. User home directory ($HOME/.musrfit/mupp/mupp_startup.xml)
|
||||
* 3. MUSRFITPATH directory ($MUSRFITPATH/mupp_startup.xml)
|
||||
* 4. ROOTSYS directory ($ROOTSYS/bin/mupp_startup.xml)
|
||||
*
|
||||
* If no configuration file is found, creates a default one in the user's
|
||||
* home directory using the embedded resource template.
|
||||
*
|
||||
* The constructor loads all configuration settings including recent files,
|
||||
* markers, colors, and theme preferences via the PmuppAdminXMLParser.
|
||||
*/
|
||||
PmuppAdmin::PmuppAdmin() : QObject()
|
||||
{
|
||||
@@ -336,7 +433,11 @@ PmuppAdmin::PmuppAdmin() : QObject()
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Destructor
|
||||
* @brief Destructor for PmuppAdmin.
|
||||
*
|
||||
* Saves the current recent file list to the configuration file before
|
||||
* destruction. This ensures that the file history is preserved across
|
||||
* application sessions.
|
||||
*/
|
||||
PmuppAdmin::~PmuppAdmin()
|
||||
{
|
||||
@@ -345,9 +446,14 @@ PmuppAdmin::~PmuppAdmin()
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Add recent path-file name to the internal ring-buffer.
|
||||
* @brief Adds a file to the recent files list.
|
||||
*
|
||||
* \param str recent path-file name to be added
|
||||
* Adds a file path to the front of the recent files ring buffer. If the
|
||||
* file is already in the list, it is not added again (no duplicates).
|
||||
* The list is limited to MAX_RECENT_FILES entries; older entries are
|
||||
* removed when the limit is exceeded.
|
||||
*
|
||||
* @param str the full path and filename to add to recent files
|
||||
*/
|
||||
void PmuppAdmin::addRecentFile(const QString str)
|
||||
{
|
||||
@@ -364,12 +470,14 @@ void PmuppAdmin::addRecentFile(const QString str)
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief PmuppAdmin::getRecentFile. Get a file from the recent files with
|
||||
* index idx.
|
||||
* @param idx
|
||||
* @brief Retrieves a recent file path by index.
|
||||
*
|
||||
* @return return the recent file with index idx if present, otherwise return
|
||||
* an empty string.
|
||||
* Returns the file path at the specified position in the recent files list.
|
||||
* Index 0 refers to the most recently accessed file.
|
||||
*
|
||||
* @param idx zero-based index into the recent files list (0 is most recent)
|
||||
*
|
||||
* @return the file path if index is valid, or an empty string otherwise
|
||||
*/
|
||||
QString PmuppAdmin::getRecentFile(int idx)
|
||||
{
|
||||
@@ -383,10 +491,14 @@ QString PmuppAdmin::getRecentFile(int idx)
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief PmuppAdmin::getMarker. Get the marker with index idx.
|
||||
* @param idx marker index
|
||||
* @brief Retrieves a marker definition by index.
|
||||
*
|
||||
* @return requested marker
|
||||
* Returns the marker at the specified index in the marker list.
|
||||
* Markers are used to define the visual appearance of data points in plots.
|
||||
*
|
||||
* @param idx zero-based index into the marker list
|
||||
*
|
||||
* @return the marker definition if index is valid, or a default marker otherwise
|
||||
*/
|
||||
PmuppMarker PmuppAdmin::getMarker(int idx) {
|
||||
PmuppMarker marker;
|
||||
@@ -399,11 +511,15 @@ PmuppMarker PmuppAdmin::getMarker(int idx) {
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief PmuppAdmin::getColor. Get rgb color codes of name
|
||||
* @param name of the requeset color.
|
||||
* @param r red value (0..255)
|
||||
* @param g green value (0..255)
|
||||
* @param b blue value (0..255
|
||||
* @brief Retrieves a color by name.
|
||||
*
|
||||
* Searches for a color with the specified name and returns its RGB values.
|
||||
* If the color is not found, all RGB components are set to -1.
|
||||
*
|
||||
* @param name the name of the color to retrieve
|
||||
* @param r output parameter: red component (0-255, or -1 if not found)
|
||||
* @param g output parameter: green component (0-255, or -1 if not found)
|
||||
* @param b output parameter: blue component (0-255, or -1 if not found)
|
||||
*/
|
||||
void PmuppAdmin::getColor(QString name, int &r, int &g, int &b)
|
||||
{
|
||||
@@ -426,11 +542,16 @@ void PmuppAdmin::getColor(QString name, int &r, int &g, int &b)
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief PmuppAdmin::getColor. Get color codes of color at index idx
|
||||
* @param idx requested color index
|
||||
* @param r red value (0..255)
|
||||
* @param g green value (0..255)
|
||||
* @param b blue value (0..255)
|
||||
* @brief Retrieves a color by index.
|
||||
*
|
||||
* Returns the RGB values of the color at the specified index in the
|
||||
* color list. If the index is out of range, all RGB components are
|
||||
* set to -1.
|
||||
*
|
||||
* @param idx zero-based index into the color list
|
||||
* @param r output parameter: red component (0-255, or -1 if invalid index)
|
||||
* @param g output parameter: green component (0-255, or -1 if invalid index)
|
||||
* @param b output parameter: blue component (0-255, or -1 if invalid index)
|
||||
*/
|
||||
void PmuppAdmin::getColor(int idx, int &r, int &g, int &b)
|
||||
{
|
||||
@@ -445,9 +566,14 @@ void PmuppAdmin::getColor(int idx, int &r, int &g, int &b)
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief PmuppAdmin::setMaker. Set a marker
|
||||
* @param marker marker code
|
||||
* @param size marker size
|
||||
* @brief Adds a marker definition to the configuration.
|
||||
*
|
||||
* Creates a new marker with the specified code and size, validates it,
|
||||
* and adds it to the marker list. Marker codes must be in the range 1-49
|
||||
* (following ROOT conventions). Invalid markers are rejected with a warning.
|
||||
*
|
||||
* @param marker the marker code (1-49, ROOT style marker codes)
|
||||
* @param size the marker size multiplier
|
||||
*/
|
||||
void PmuppAdmin::setMarker(const int marker, const double size)
|
||||
{
|
||||
@@ -466,11 +592,16 @@ void PmuppAdmin::setMarker(const int marker, const double size)
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief PmuppAdmin::setColor. Set a color
|
||||
* @param r red value (0..255)
|
||||
* @param g green value (0..255)
|
||||
* @param b blue value (0..255)
|
||||
* @param name color name
|
||||
* @brief Adds a color definition to the configuration.
|
||||
*
|
||||
* Creates a new color with the specified RGB values and optional name,
|
||||
* validates it, and adds it to the color list. RGB values must be in
|
||||
* the range 0-255. Invalid colors are rejected with a warning.
|
||||
*
|
||||
* @param r red component (0-255)
|
||||
* @param g green component (0-255)
|
||||
* @param b blue component (0-255)
|
||||
* @param name optional name for the color (empty by default)
|
||||
*/
|
||||
void PmuppAdmin::setColor(const int r, const int g, const int b, QString name)
|
||||
{
|
||||
@@ -490,9 +621,21 @@ void PmuppAdmin::setColor(const int r, const int g, const int b, QString name)
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Merges the recent file ring buffer into mupp_startup.xml and saves it.
|
||||
* If a local copy is present it will be saved there, otherwise the master file
|
||||
* will be used.
|
||||
* @brief Saves the recent files list to the configuration file.
|
||||
*
|
||||
* Updates the mupp_startup.xml file with the current recent file list.
|
||||
* The method first searches for a local configuration file in the current
|
||||
* directory; if not found, it uses the user's home directory version
|
||||
* ($HOME/.musrfit/mupp/mupp_startup.xml).
|
||||
*
|
||||
* The implementation:
|
||||
* 1. Reads the entire configuration file into memory
|
||||
* 2. Removes all existing \<path_file_name\> entries
|
||||
* 3. Inserts current recent files list
|
||||
* 4. Writes the updated configuration back to disk
|
||||
*
|
||||
* This preserves all other configuration settings while updating only
|
||||
* the recent file history.
|
||||
*/
|
||||
void PmuppAdmin::saveRecentFiles()
|
||||
{
|
||||
@@ -561,8 +704,20 @@ void PmuppAdmin::saveRecentFiles()
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief PmuppAdmin::createMuppStartupFile. Create a default mupp_startup.xml
|
||||
* file if not present.
|
||||
* @brief Creates a default mupp_startup.xml configuration file.
|
||||
*
|
||||
* This method is called when no configuration file is found in any of
|
||||
* the standard locations. It creates a new default configuration file
|
||||
* in the user's home directory ($HOME/.musrfit/mupp/mupp_startup.xml).
|
||||
*
|
||||
* The implementation:
|
||||
* 1. Creates the directory $HOME/.musrfit/mupp if it doesn't exist
|
||||
* 2. Loads the default template from embedded resources (mupp_startup.xml.in)
|
||||
* 3. Writes the template to the user's home directory
|
||||
*
|
||||
* The default configuration includes standard marker styles, color
|
||||
* definitions, and empty recent file list, providing a working baseline
|
||||
* for new users or clean installations.
|
||||
*/
|
||||
void PmuppAdmin::createMuppStartupFile()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user