Skip to content

Commit

Permalink
Documentation: Add documentatioon to config.cpp
Browse files Browse the repository at this point in the history
Adds documentation to config.cpp, for functions that were missing it and
also for newly added createDirectoriesOnPath().
  • Loading branch information
tetektoza committed Oct 20, 2023
1 parent 9aaf5d0 commit 8a3f2f2
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions source/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
static QJsonObject theConfig;
QString Config::jsonFilePath;


/**
* @brief Loads current configuration from the config .json file
*
* This function loads current configuration from the config .json file.
* It inserts specific values mapping them to keys, and creates path for the
* config if user has deleted it, or runs app for the first time.
*
* @return Nothing
*/
void Config::loadConfiguration()
{
// create directories on the path if they do not exist
Expand Down Expand Up @@ -50,6 +60,11 @@ void Config::loadConfiguration()
}
}

/**
* @brief Stores current configuration in the config .json file
*
* @return Nothing
*/
void Config::storeConfiguration()
{
QFile saveJson(jsonFilePath);
Expand All @@ -59,6 +74,17 @@ void Config::storeConfiguration()
saveJson.close();
}

/**
* @brief Creates directories on certain path
*
* This function creates directories on certain path. Path location depends on
* if user is working on Windows or Mac/Linux.
*
* If the user works on Windows, it will save it under AppData/.config/[...].
* On any other OS it will save it under /home/user/.config/diasurgical/[...]
*
* @return Returns true if path has been created or already existed - false otherwise
*/
bool Config::createDirectoriesOnPath()
{
#ifdef Q_OS_WINDOWS
Expand All @@ -70,11 +96,28 @@ bool Config::createDirectoriesOnPath()
return QDir().mkpath(jsonFilePath);
}

/**
* @brief Retrieves value from .json config file
*
* This function retrieves value from .json config file by the value
* specified by name parameter.
*
* @return Returns QJsonValue containing value of the parameter specified
* by "name" key, otherwise if not found - returns QJsonValue::Undefined
*/
QJsonValue Config::value(const QString &name)
{
return theConfig.value(name);
}

/**
* @brief Inserts value in .json config file
*
* This function inserts value into .json config file, mapping it with
* the key specified in parameters.
*
* @return Nothing
*/
void Config::insert(const QString &key, const QJsonValue &value)
{
theConfig.insert(key, value);
Expand Down

0 comments on commit 8a3f2f2

Please sign in to comment.