mirror of
https://github.com/QuasarApp/QuasarAppLib.git
synced 2025-05-02 04:29:41 +00:00
Merge pull request #31 from QuasarApp/task_28
Add detailed documentation for all methods and classes.
This commit is contained in:
commit
c478359c60
@ -43,7 +43,7 @@ add_library(${PROJECT_NAME} ${SOURCE_CPP})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
setVersion(1 4 6)
|
||||
setVersion(1 5 0)
|
||||
|
||||
initAll()
|
||||
addDoc(${PROJECT_NAME}Docs ${CMAKE_CURRENT_SOURCE_DIR}/doxygen.conf)
|
||||
|
38
global.h
38
global.h
@ -96,37 +96,75 @@ constexpr inline T operator ^ (T lhs, T rhs)
|
||||
//};
|
||||
|
||||
template<class T>
|
||||
/**
|
||||
* @brief static_type_hash_32 This function return hash code of the class T.
|
||||
* For get more information see the std [documentation](https://en.cppreference.com/w/cpp/types/type_info/hash_code).
|
||||
* @note This method will create a T object on stack, so if you have a alredy created object use the static_type_hash_32(const T&) function.
|
||||
* @return uint32_t hash code of the class T
|
||||
*/
|
||||
uint32_t static_type_hash_32() noexcept {
|
||||
return typeid (T).hash_code();
|
||||
};
|
||||
|
||||
template<class T>
|
||||
/**
|
||||
* @brief static_type_hash_16 This function return hash code of the class T.
|
||||
* For get more information see the std [documentation](https://en.cppreference.com/w/cpp/types/type_info/hash_code).
|
||||
* @note This method will create a T object on stack, so if you have a alredy created object use the static_type_hash_16(const T&) function.
|
||||
* @return uint16_t hash code of the class T
|
||||
*/
|
||||
uint16_t static_type_hash_16() noexcept {
|
||||
return typeid (T).hash_code() % 0xFFFF;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
/**
|
||||
* @brief static_type_hash_8 This function return hash code of the class T.
|
||||
* For get more information see the std [documentation](https://en.cppreference.com/w/cpp/types/type_info/hash_code).
|
||||
* @note This method will create a T object on stack, so if you have a alredy created object use the static_type_hash_8(const T&) function.
|
||||
* @return uint8_t hash code of the class T
|
||||
*/
|
||||
uint8_t static_type_hash_8() noexcept {
|
||||
return typeid (T).hash_code() % 0xFF;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
/**
|
||||
* @brief static_type_hash_32 This function return hash code of a T type using @a object.
|
||||
* @param object This is object of the T type using for generate hash.
|
||||
* @return uint32_t hash code of the class T
|
||||
*/
|
||||
uint32_t static_type_hash_32(T& object) noexcept {
|
||||
return typeid (object).hash_code();
|
||||
};
|
||||
|
||||
template<class T>
|
||||
/**
|
||||
* @brief static_type_hash_16 This function return hash code of a T type using @a object.
|
||||
* @param object This is object of the T type using for generate hash.
|
||||
* @return uint16_t hash code of the class T
|
||||
*/
|
||||
uint16_t static_type_hash_16(T& object) noexcept {
|
||||
return typeid (object).hash_code() % 0xFFFF;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
/**
|
||||
* @brief static_type_hash_8 This function return hash code of a T type using @a object.
|
||||
* @param object This is object of the T type using for generate hash.
|
||||
* @return uint8_t hash code of the class T
|
||||
*/
|
||||
uint8_t static_type_hash_8(T& object) noexcept {
|
||||
return typeid (object).hash_code() % 0xFF;
|
||||
};
|
||||
|
||||
/// @brief H_8 This is short wraper of the static_type_hash_8 fucntion.
|
||||
#define H_8 static_type_hash_8
|
||||
|
||||
/// @brief H_16 This is short wraper of the static_type_hash_16 fucntion.
|
||||
#define H_16 static_type_hash_16
|
||||
|
||||
/// @brief H_32 This is short wraper of the static_type_hash_32 fucntion.
|
||||
#define H_32 static_type_hash_32
|
||||
|
||||
|
||||
|
68
helpdata.cpp
68
helpdata.cpp
@ -16,7 +16,8 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace QuasarAppUtils {
|
||||
namespace Help {
|
||||
|
||||
static int MAX_LENGTH = -1;
|
||||
static int SectionMargin = 3;
|
||||
@ -26,31 +27,15 @@ static int SectionMargin = 3;
|
||||
#define SECTION_MARGIN SPACES(SectionMargin)
|
||||
#define WIDTH ((MAX_LENGTH > 10)? MAX_LENGTH: width())
|
||||
|
||||
void QuasarAppUtils::Help::print(const QuasarAppUtils::Help::Options &charter) {
|
||||
int maxLength = 0;
|
||||
for (auto line = charter.begin(); line != charter.end(); ++line) {
|
||||
if (line.key().size() > maxLength)
|
||||
maxLength = line.key().size();
|
||||
}
|
||||
|
||||
for (auto line = charter.begin(); line != charter.end(); ++line) {
|
||||
print(line.key(), line.value(), maxLength + SectionMargin);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void QuasarAppUtils::Help::print(const QuasarAppUtils::Help::Charters &help) {
|
||||
for (auto line = help.begin(); line != help.end(); ++line) {
|
||||
QString expander(WIDTH, '-');
|
||||
|
||||
std::cout << line.key().toStdString() << std::endl;
|
||||
std::cout << expander.toStdString() << std::endl;
|
||||
print(line.value());
|
||||
std::cout << std::endl << expander.toStdString() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void QuasarAppUtils::Help::print(const QString &key, const QString &value, int keyLength) {
|
||||
/*
|
||||
* @brief print This method prints the one line of the help.
|
||||
* @param key This is Option name.
|
||||
* @param value This is Description of option.
|
||||
* @param keyLength This is length of the current line.
|
||||
* This is private method of the QuasarAppLibrary.
|
||||
*/
|
||||
void print(const QString& key, const QString& value, int keyLength) {
|
||||
|
||||
auto diffExpander = QString(keyLength - key.size(), ' ');
|
||||
std::cout << SECTION_MARGIN << key.toStdString() << diffExpander.toStdString() << ":";
|
||||
@ -74,11 +59,35 @@ void QuasarAppUtils::Help::print(const QString &key, const QString &value, int k
|
||||
}
|
||||
}
|
||||
|
||||
void QuasarAppUtils::Help::setLineLength(int newLength) {
|
||||
void print(const QuasarAppUtils::Help::Options &oprionsList) {
|
||||
int maxLength = 0;
|
||||
for (auto line = oprionsList.begin(); line != oprionsList.end(); ++line) {
|
||||
if (line.key().size() > maxLength)
|
||||
maxLength = line.key().size();
|
||||
}
|
||||
|
||||
for (auto line = oprionsList.begin(); line != oprionsList.end(); ++line) {
|
||||
print(line.key(), line.value(), maxLength + SectionMargin);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void print(const Section &help) {
|
||||
for (auto line = help.begin(); line != help.end(); ++line) {
|
||||
QString expander(WIDTH, '-');
|
||||
|
||||
std::cout << line.key().toStdString() << std::endl;
|
||||
std::cout << expander.toStdString() << std::endl;
|
||||
print(line.value());
|
||||
std::cout << std::endl << expander.toStdString() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void setLineLength(int newLength) {
|
||||
MAX_LENGTH = newLength;
|
||||
}
|
||||
|
||||
int QuasarAppUtils::Help::width() {
|
||||
int width() {
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
@ -91,3 +100,8 @@ int QuasarAppUtils::Help::width() {
|
||||
return w.ws_col;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
60
helpdata.h
60
helpdata.h
@ -13,41 +13,65 @@
|
||||
|
||||
namespace QuasarAppUtils{
|
||||
|
||||
/**
|
||||
* @brief Help namespace contains functions for printing help in to console. All Print fucntions automaticly calc width of the console and aligns the text to fit the window.
|
||||
*/
|
||||
namespace Help {
|
||||
/**
|
||||
* @brief Options this is list of key - descriptions pairs of help.
|
||||
* @brief Options this is list of **key-descriptions** pairs of help.
|
||||
* The **key** is name of the available argument and **description** is description of the available argument.
|
||||
*
|
||||
* **Example**:
|
||||
*
|
||||
* @code{cpp}
|
||||
* Options myOptionsList = {{"argument1", "This is test argumetn1 of my application."},
|
||||
* {"argument1", "This is test argumetn1 of my application."}};
|
||||
*
|
||||
* @endcode
|
||||
*/
|
||||
typedef QMultiMap<QString, QString> Options;
|
||||
|
||||
/**
|
||||
* @brief Charters ths is list of charters.
|
||||
* @brief Section This is list of the help Sections. The one section it is Title of the section and Help::Options list.
|
||||
*
|
||||
* **Example:**
|
||||
* @code{cpp}
|
||||
* Options myOptionsList = {{"argument1", "This is test argumetn1 of my application."},
|
||||
* {"argument1", "This is test argumetn1 of my application."}};
|
||||
* Section mySections = {{"This Is main section of the help", myOptionsList}};
|
||||
* QuasarAppUtils::Help::print(mySections);
|
||||
* @endcode
|
||||
*/
|
||||
typedef QMultiMap<QString, Options> Charters;
|
||||
typedef QMultiMap<QString, Options> Section;
|
||||
|
||||
/**
|
||||
* @brief Charters is wraper of the Section type.
|
||||
* @warning This type is depricated. Use the Help:Section type.
|
||||
*/
|
||||
typedef Section Charters;
|
||||
|
||||
/**
|
||||
* @brief width This method return current width of the cosole window.
|
||||
* @return width in pxels of the cosole window.
|
||||
*/
|
||||
int width();
|
||||
|
||||
/**
|
||||
* @brief print Line of help.
|
||||
* @param key Option name.
|
||||
* @param value Description of option.
|
||||
* @brief print This method print a one options list.
|
||||
* @param oprionsList This is options list.
|
||||
*/
|
||||
void QUASARAPPSHARED_EXPORT print(const QString& key, const QString& value, int keyLength);
|
||||
void QUASARAPPSHARED_EXPORT print(const Options& oprionsList);
|
||||
|
||||
/**
|
||||
* @brief print Help Charter.
|
||||
* @param charter Charter of help.
|
||||
* @brief print This method print all sections of the help.
|
||||
* @note This is main method for printing helps.
|
||||
* @param help This is sections list.
|
||||
*/
|
||||
void QUASARAPPSHARED_EXPORT print(const Options& charter);
|
||||
void QUASARAPPSHARED_EXPORT print(const Section& help);
|
||||
|
||||
/**
|
||||
* @brief print All help.
|
||||
* @param help Help for printing.
|
||||
*/
|
||||
void QUASARAPPSHARED_EXPORT print(const Charters& help);
|
||||
|
||||
/**
|
||||
* @brief setLineLength sets new length of helps line.
|
||||
* @param newLength New size.
|
||||
* @brief setLineLength sets new length of the help line (width of the console window). If you set this into -1 then the window width will be selected automatically.
|
||||
* @param newLength This is a new size of the console window.
|
||||
*/
|
||||
void QUASARAPPSHARED_EXPORT setLineLength(int newLength);
|
||||
}
|
||||
|
14
locales.h
14
locales.h
@ -22,9 +22,15 @@ namespace QuasarAppUtils {
|
||||
|
||||
/**
|
||||
* @brief The Locales class for parese local files
|
||||
* Example :
|
||||
* **Example :**
|
||||
* @code{cpp}
|
||||
* QuasarAppUtils::Locales::init()
|
||||
* QuasarAppUtils::Locales::init();
|
||||
* @endcode
|
||||
*
|
||||
* @note If you want to add you own location of the qm files then add this into seccond arguments of the Locales::init method.
|
||||
*
|
||||
* @code{cpp}
|
||||
* QuasarAppUtils::Locales::init(QLocale::system(), "myPath");
|
||||
* @endcode
|
||||
*/
|
||||
class QUASARAPPSHARED_EXPORT Locales : public QObject
|
||||
@ -48,8 +54,8 @@ public:
|
||||
static bool init(const QLocale &locale = QLocale::system(),
|
||||
const QSet<QString> & location = {});
|
||||
/**
|
||||
* @brief instance
|
||||
* @return return static object
|
||||
* @brief instance This method return pointer to the Locales service.
|
||||
* @return return pointer to the Locales static object
|
||||
*/
|
||||
static Locales *instance();
|
||||
|
||||
|
56
params.cpp
56
params.cpp
@ -20,13 +20,10 @@
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#define APP_PATH "appPath"
|
||||
#define APP_NAME "appName"
|
||||
|
||||
using namespace QuasarAppUtils;
|
||||
|
||||
static QMap<QString, QString> params = QMap<QString, QString>();
|
||||
static int _argc = 0;
|
||||
QMap<QString, QString> Params::params = QMap<QString, QString>();
|
||||
QString Params::appPath = "";
|
||||
QString Params::appName = "";
|
||||
|
||||
|
||||
bool Params::isEndable(const QString& key) {
|
||||
@ -58,7 +55,7 @@ void Params::log(const QString &log, VerboseLvl vLvl) {
|
||||
}
|
||||
}
|
||||
|
||||
Help::Charters Params::getparamsHelp() {
|
||||
Help::Charters Params::getParamsHelp() {
|
||||
return {
|
||||
{
|
||||
"Base Options", {
|
||||
@ -69,16 +66,6 @@ Help::Charters Params::getparamsHelp() {
|
||||
};
|
||||
}
|
||||
|
||||
void Params::showHelp(const QStringList &help) {
|
||||
for (const QString& line : help) {
|
||||
std::cout << line.toStdString() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Params::showHelp(const Help::Charters &help) {
|
||||
Help::print(help);
|
||||
}
|
||||
|
||||
VerboseLvl Params::getVerboseLvl() {
|
||||
return static_cast<VerboseLvl>(getArg("verbose", DEFAULT_VERBOSE_LVL).toInt());
|
||||
}
|
||||
@ -96,41 +83,31 @@ bool Params::isDebugBuild() {
|
||||
}
|
||||
|
||||
void Params::showHelp() {
|
||||
Help::print(getparamsHelp());
|
||||
Help::print(getParamsHelp());
|
||||
}
|
||||
|
||||
QMap<QString, QString> Params::getUserParamsMap() {
|
||||
auto result = params;
|
||||
result.remove(APP_PATH);
|
||||
result.remove(APP_NAME);
|
||||
|
||||
return result;
|
||||
const QMap<QString, QString>& Params::getUserParamsMap() {
|
||||
return params;
|
||||
}
|
||||
|
||||
void Params::clearParsedData() {
|
||||
params.clear();
|
||||
_argc = 0;
|
||||
appPath = "";
|
||||
appName = "";
|
||||
}
|
||||
|
||||
QString Params::getCurrentExecutable() {
|
||||
return getCurrentExecutableDir() + "/" + getArg(APP_NAME);
|
||||
return getCurrentExecutableDir() + "/" + appName;
|
||||
}
|
||||
|
||||
QString Params::getCurrentExecutableDir() {
|
||||
return getArg(APP_PATH);
|
||||
return appPath;
|
||||
}
|
||||
|
||||
int Params::size() {
|
||||
return params.size();
|
||||
}
|
||||
|
||||
int Params::customParamasSize() {
|
||||
if (_argc)
|
||||
return _argc - 1;
|
||||
|
||||
return size() - 2;
|
||||
}
|
||||
|
||||
QString Params::timeString() {
|
||||
return QDateTime::currentDateTime().toString();
|
||||
}
|
||||
@ -195,7 +172,6 @@ bool Params::parseParams(const int argc, const char *argv[]) {
|
||||
params.push_back(argv[i]);
|
||||
}
|
||||
|
||||
_argc = argc;
|
||||
return parseParams(params);
|
||||
}
|
||||
|
||||
@ -211,8 +187,8 @@ bool Params::parseParams(const QStringList ¶msArray) {
|
||||
memset(buffer, 0, sizeof buffer);
|
||||
|
||||
GetModuleFileNameA(nullptr, buffer, MAX_PATH);
|
||||
params [APP_PATH] = QFileInfo(buffer).absolutePath();
|
||||
params [APP_NAME] = QFileInfo(buffer).fileName();
|
||||
appPath = QFileInfo(buffer).absolutePath();
|
||||
appName = QFileInfo(buffer).fileName();
|
||||
|
||||
#else
|
||||
char path[2048];
|
||||
@ -223,12 +199,12 @@ bool Params::parseParams(const QStringList ¶msArray) {
|
||||
QuasarAppUtils::Error);
|
||||
return false;
|
||||
}
|
||||
params [APP_PATH] = QFileInfo(path).absolutePath();
|
||||
params [APP_NAME] = QFileInfo(path).fileName();
|
||||
appPath = QFileInfo(path).absolutePath();
|
||||
appName = QFileInfo(path).fileName();
|
||||
|
||||
#endif
|
||||
|
||||
if (!getArg(APP_PATH).size()) {
|
||||
if (!appPath.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
272
params.h
272
params.h
@ -8,6 +8,7 @@
|
||||
#ifndef PARAMS_H
|
||||
#define PARAMS_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QVariant>
|
||||
#include "quasarapp_global.h"
|
||||
#include "helpdata.h"
|
||||
@ -15,13 +16,16 @@
|
||||
namespace QuasarAppUtils {
|
||||
|
||||
/**
|
||||
* @brief The Params class for parese app params.
|
||||
* @brief The VerboseLvl enum uses for sets log level.
|
||||
*/
|
||||
|
||||
enum VerboseLvl {
|
||||
/// General information. This logs will marked as a **Info** and printing always.
|
||||
Info = 0x0,
|
||||
/// Error message. This logs will marked as a **Error** and printing if the verbose lvl >= 1
|
||||
Error = 0x1,
|
||||
/// Warning message. This logs will marked as a **Warning** and printing if the verbose lvl >= 2
|
||||
Warning = 0x2,
|
||||
/// Debug message. This logs will marked as a **Debug** and printing if the verbose lvl >= 3
|
||||
Debug = 0x3,
|
||||
|
||||
};
|
||||
@ -33,8 +37,141 @@ enum VerboseLvl {
|
||||
#define DEFAULT_VERBOSE_LVL "3"
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief The Params class Contains fonctions for working with input arguments and logs.
|
||||
* This Class support next comandline arguments.
|
||||
* * **-verbose** (level 1 - 3) Shows debug log
|
||||
* * **-fileLog** (path to file) Sets path of log file. Default it is path to executable file with suffix '.log'
|
||||
*/
|
||||
class QUASARAPPSHARED_EXPORT Params
|
||||
{
|
||||
public:
|
||||
Params() = delete;
|
||||
|
||||
/**
|
||||
* @brief parseParams Parse input data of started application.
|
||||
* @param argc Count of arguments.
|
||||
* @param argv Array of arguments.
|
||||
* @return true if all arguments read successful else false.
|
||||
*/
|
||||
static bool parseParams(const int argc, const char *argv[]);
|
||||
|
||||
/**
|
||||
* @brief parseParams Parse input data of started application.
|
||||
* @param argc Count of arguments.
|
||||
* @param argv Array of arguments.
|
||||
* @return true if all arguments read successful else false.
|
||||
*/
|
||||
static bool parseParams(int argc, char *argv[]);
|
||||
|
||||
/**
|
||||
* @brief parseParams Parse input data of started application.
|
||||
* @param paramsArray Arguments.
|
||||
* @return true if all arguments read successful else false.
|
||||
*/
|
||||
static bool parseParams(const QStringList& paramsArray);
|
||||
|
||||
/**
|
||||
* @brief getArg return string value of a @a key if key is exits else return a @a def value.
|
||||
* If a @a def value not defined retunr empty string.
|
||||
* @param key This is key of a console argument.
|
||||
* @param def This is Default value. If key not exits This function will return a default value.
|
||||
* @return a string value of argument.
|
||||
*/
|
||||
static QString getArg(const QString& key, const QString &def = {});
|
||||
|
||||
/**
|
||||
* @brief setArg sets a new value of a @a key.
|
||||
* @param key This is a name of sets option.
|
||||
* @param val This is a new value of the @a key.
|
||||
*/
|
||||
static void setArg(const QString& key, const QString& val);
|
||||
|
||||
/**
|
||||
* @brief setArg This method sets boolean value of key.
|
||||
* @param key This is name of the console option.
|
||||
* @param enable New value of key.
|
||||
* @note For check is enable @a key argument use the Params::isEndable method.
|
||||
*/
|
||||
static void setEnable(const QString& key, bool enable);
|
||||
|
||||
/**
|
||||
* @brief isEndable This method check if enable a @a key argument.
|
||||
* @param key This is name of the validate arguments
|
||||
* @return true if argument enabled.
|
||||
*/
|
||||
static bool isEndable(const QString& key);
|
||||
|
||||
/**
|
||||
* @brief log This method print @a log text on console.
|
||||
* @param log This is printed text message.
|
||||
* @param vLvl This is verbose level of message, for get more information see the QuasarAppUtils::VerboseLvl enum.
|
||||
* @note All messages will be printed according to the current verbose setting.
|
||||
* @note The verbose level sets by verbose option on console.
|
||||
*/
|
||||
static void log(const QString& log, VerboseLvl vLvl = VerboseLvl::Debug);
|
||||
|
||||
/**
|
||||
* @brief getParamsHelp This method return help object of the params class.
|
||||
* @note All Options from the Params class can be used on any application that incuded this library. So if you printing your own help do not forget print this help.
|
||||
* @return help object of default params.
|
||||
*/
|
||||
static Help::Section getParamsHelp();
|
||||
|
||||
/**
|
||||
* @brief getVerboseLvl This method return the verbose log level.
|
||||
* @return verbose log lvl.
|
||||
*/
|
||||
static VerboseLvl getVerboseLvl();
|
||||
|
||||
/**
|
||||
* @brief isDebug This method return true if the application verbose level >= VerboseLvl::Debug.
|
||||
* @return true if a verbose level >= VerboseLvl::Debug
|
||||
*/
|
||||
static bool isDebug();
|
||||
|
||||
/**
|
||||
* @brief isDebugBuild This method return true if the library buildet in debug mode.
|
||||
* @return true if this library buildet in debug mode.
|
||||
*/
|
||||
static bool isDebugBuild();
|
||||
|
||||
|
||||
/**
|
||||
* @brief size This method return count of the all input arguments.
|
||||
* @return size of all params array.
|
||||
*/
|
||||
static int size();
|
||||
|
||||
/**
|
||||
* @brief showHelp This method shows help of the Params class of the QuasarAppLib.
|
||||
*/
|
||||
static void showHelp();
|
||||
|
||||
/**
|
||||
* @brief getUserParamsMap This method return const reference to the parsed arguments map.
|
||||
* @return A map object with parsed arguments.
|
||||
*/
|
||||
static const QMap<QString, QString> &getUserParamsMap();
|
||||
|
||||
/**
|
||||
* @brief clearParsedData This method clear all parsed data.
|
||||
*/
|
||||
static void clearParsedData();
|
||||
|
||||
/**
|
||||
* @brief getCurrentExecutable This method return path to the current executable.
|
||||
* @return path to current executable.
|
||||
*/
|
||||
static QString getCurrentExecutable();
|
||||
|
||||
/**
|
||||
* @brief getCurrentExecutableDir This method return a path to a folder with the current executable.
|
||||
* @return path of the folder with current executable.
|
||||
*/
|
||||
static QString getCurrentExecutableDir();
|
||||
|
||||
private:
|
||||
static QString timeString();
|
||||
static std::string lvlToString(VerboseLvl vLvl);
|
||||
@ -47,135 +184,10 @@ private:
|
||||
*/
|
||||
static void printWorkingOptions();
|
||||
|
||||
public:
|
||||
Params() = delete;
|
||||
|
||||
/**
|
||||
* @brief parseParams Parse input data of started application.
|
||||
* @param argc Count of arguments.
|
||||
* @param argv Array of arguments.
|
||||
* @return true if all arguments read else false.
|
||||
*/
|
||||
static bool parseParams(const int argc, const char *argv[]);
|
||||
static bool parseParams(int argc, char *argv[]);
|
||||
|
||||
/**
|
||||
* @brief parseParams Parse input data of started application.
|
||||
* @param paramsArray Arguments.
|
||||
* @return true if all arguments read else false.
|
||||
*/
|
||||
static bool parseParams(const QStringList& paramsArray);
|
||||
|
||||
/**
|
||||
* @brief getArg Get string value of key.
|
||||
* @param key This is key of the parameter.
|
||||
* @param def Default value.
|
||||
* @return string value of argument.
|
||||
*/
|
||||
static QString getArg(const QString& key, const QString &def = {});
|
||||
|
||||
/**
|
||||
* @brief setArg Sets value of key.
|
||||
* @param key This is new value of the @a key.
|
||||
*/
|
||||
static void setArg(const QString& key, const QString& val);
|
||||
|
||||
/**
|
||||
* @brief setArg Sets boolean value of key.
|
||||
* @param key
|
||||
* @param enable New value of key.
|
||||
*/
|
||||
static void setEnable(const QString& key, bool enable);
|
||||
|
||||
/**
|
||||
* @brief isEndable Check if enable argument of key.
|
||||
* @param key
|
||||
* @return true if argument enabled.
|
||||
*/
|
||||
static bool isEndable(const QString& key);
|
||||
|
||||
/**
|
||||
* @brief log Print text on console if the flag "vergose" is enabled.
|
||||
* @param log Printed textP.
|
||||
*/
|
||||
static void log(const QString& log, VerboseLvl vLvl = VerboseLvl::Debug);
|
||||
|
||||
/**
|
||||
* @brief getparamsHelp
|
||||
* @return help string of default params.
|
||||
*/
|
||||
static Help::Charters getparamsHelp();
|
||||
|
||||
/**
|
||||
* @brief showHelp Show all strings of help.
|
||||
* @param help
|
||||
*/
|
||||
static void showHelp(const QStringList& help);
|
||||
|
||||
/**
|
||||
* @brief showHelp Show structe of help value.
|
||||
* @param help
|
||||
*/
|
||||
static void showHelp(const Help::Charters& help);
|
||||
|
||||
/**
|
||||
* @brief getVerboseLvl This method return the verbose log level.
|
||||
* @return verbose lvl
|
||||
*/
|
||||
static VerboseLvl getVerboseLvl();
|
||||
|
||||
/**
|
||||
* @brief isDebug
|
||||
* @return true if verbose lvl >= 3
|
||||
*/
|
||||
static bool isDebug();
|
||||
|
||||
/**
|
||||
* @brief isDebugBuild This method return true if the library buildet in debug mode.
|
||||
* @return true if this library buildet in debug mode.
|
||||
*/
|
||||
static bool isDebugBuild();
|
||||
|
||||
|
||||
/**
|
||||
* @brief size This method return size of all params array.
|
||||
* @return size Of all params array.
|
||||
*/
|
||||
static int size();
|
||||
|
||||
/**
|
||||
* @brief customParamasSize This method return a size of params entered in conosole.
|
||||
* @return size of params entered in conosole.
|
||||
*/
|
||||
static int customParamasSize();
|
||||
|
||||
/**
|
||||
* @brief showHelp - show base help section of QuasarAppLib.
|
||||
*/
|
||||
static void showHelp();
|
||||
|
||||
/**
|
||||
* @brief getUserParamsMap.
|
||||
* @return QVariantMap With user params.
|
||||
*/
|
||||
static QMap<QString, QString> getUserParamsMap();
|
||||
|
||||
/**
|
||||
* @brief clearParsedData - This method clear allparsed data.
|
||||
*/
|
||||
static void clearParsedData();
|
||||
|
||||
/**
|
||||
* @brief getCurrentExecutable
|
||||
* @return path to current executable.
|
||||
*/
|
||||
static QString getCurrentExecutable();
|
||||
|
||||
/**
|
||||
* @brief getCurrentExecutableDir This method return a path to a folder with the current executable.
|
||||
* @return path of executable.
|
||||
*/
|
||||
static QString getCurrentExecutableDir();
|
||||
static QMap<QString, QString> params;
|
||||
static QString appPath;
|
||||
static QString appName;
|
||||
|
||||
};
|
||||
}
|
||||
|
12
settings.cpp
12
settings.cpp
@ -26,13 +26,11 @@ Settings::Settings(SettingsSaveMode mode) {
|
||||
_mode = mode;
|
||||
}
|
||||
|
||||
SettingsSaveMode Settings::getMode() const
|
||||
{
|
||||
SettingsSaveMode Settings::getMode() const {
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void Settings::setMode(const SettingsSaveMode &mode)
|
||||
{
|
||||
void Settings::setMode(const SettingsSaveMode &mode) {
|
||||
_mode = mode;
|
||||
}
|
||||
|
||||
@ -41,11 +39,7 @@ Settings *Settings::initSettings(SettingsSaveMode mode) {
|
||||
return res;
|
||||
}
|
||||
|
||||
Settings *Settings::get() {
|
||||
return initSettings();
|
||||
}
|
||||
|
||||
const Settings *Settings::getConst() {
|
||||
Settings *Settings::instance() {
|
||||
return initSettings();
|
||||
}
|
||||
|
||||
|
141
settings.h
141
settings.h
@ -18,87 +18,100 @@ namespace QuasarAppUtils {
|
||||
|
||||
/**
|
||||
* @brief The SettingsSaveMode enum
|
||||
* Auto - value save on hard disk when calling method "value"
|
||||
* manual - save all data on hard disk when calling method Settings::sync
|
||||
*/
|
||||
enum class SettingsSaveMode: quint64 {
|
||||
/// a settings will be saved on hard disk when called the Settings::setValue method.
|
||||
Auto,
|
||||
/// a settings will be saved on hard disk when called the Settings::Sync method.
|
||||
Manual
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The Settings class - singleton for QSettings
|
||||
* @brief The Settings class This is wraper of the QSettings object.
|
||||
* @note This is singleton object.
|
||||
*/
|
||||
class QUASARAPPSHARED_EXPORT Settings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief instance This method return instance of the settings object
|
||||
* @return pointer to a settings object;
|
||||
*/
|
||||
static Settings* instance();
|
||||
|
||||
/**
|
||||
* @brief getValue This method return the value of the settings.
|
||||
* @param key This is name of the required settings value.
|
||||
* @param def This is default value if a value is not finded.
|
||||
* @return value of a @a key
|
||||
*/
|
||||
Q_INVOKABLE QVariant getValue(const QString &key, const QVariant& def);
|
||||
|
||||
/**
|
||||
* @brief getStrValue some as getValue but convert result object to QString type.
|
||||
* @param key This is name of the required settings value.
|
||||
* @param def This is default value if a value is not finded.
|
||||
* @return value of a @a key
|
||||
*/
|
||||
Q_INVOKABLE QString getStrValue(const QString &key, const QString& def);
|
||||
|
||||
/**
|
||||
* @brief sync This method save all setings data on a hard disk;
|
||||
*/
|
||||
void sync();
|
||||
|
||||
/**
|
||||
* @brief getMode This method return the current mode of the settings.
|
||||
* @return the current mode of the settings.
|
||||
*/
|
||||
SettingsSaveMode getMode() const;
|
||||
|
||||
/**
|
||||
* @brief setMode This method sets a new value of the settings mode.
|
||||
* @param mode This is a new value of the settings mode.
|
||||
*/
|
||||
void setMode(const SettingsSaveMode &mode);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief setValue This slot sets new value for a @a key setting
|
||||
* @param key This is name of the changed setting.
|
||||
* @param value This is a new value of the setting
|
||||
*/
|
||||
void setValue(const QString key, const QVariant& value);
|
||||
|
||||
/**
|
||||
* @brief setStrValue This is some as setValue but working with the QString type.
|
||||
* @param key This is name of the changed setting.
|
||||
* @param value This is a new value of the setting
|
||||
*/
|
||||
void setStrValue(const QString& key, const QString& value);
|
||||
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief valueChanged This signal when value of the @a key settings changed
|
||||
* @param key This is name of change setting.
|
||||
* @param value This is a new value of @a key.
|
||||
*/
|
||||
void valueChanged(QString key, QVariant value);
|
||||
|
||||
/**
|
||||
* @brief valueStrChanged some as valueChanged(QString key, QVariant value) but value has ben converted to the QString type.
|
||||
* @param key This is name of change setting.
|
||||
* @param value This is a new value of @a key.
|
||||
*/
|
||||
void valueStrChanged(QString key, QString value);
|
||||
|
||||
private:
|
||||
explicit Settings(SettingsSaveMode mode = SettingsSaveMode::Auto);
|
||||
QSettings *_settings = nullptr;
|
||||
SettingsSaveMode _mode = SettingsSaveMode::Auto;
|
||||
|
||||
static Settings* initSettings(SettingsSaveMode mode = SettingsSaveMode::Auto);
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief get
|
||||
* @return object of all settings app;
|
||||
*/
|
||||
static Settings* get();
|
||||
|
||||
/**
|
||||
* @brief get
|
||||
* @return const object of all settings app;
|
||||
*/
|
||||
static const Settings* getConst();
|
||||
|
||||
/**
|
||||
* @brief getValue
|
||||
* @param key - key of value
|
||||
* @param def - default value if is value not finded
|
||||
* @return value of key
|
||||
*/
|
||||
Q_INVOKABLE QVariant getValue(const QString &key, const QVariant& def);
|
||||
|
||||
/**
|
||||
* @brief getStrValue some as getValue but work with QString
|
||||
*/
|
||||
Q_INVOKABLE QString getStrValue(const QString &key, const QString& def);
|
||||
|
||||
/**
|
||||
* @brief sync - save all data on hard disk;
|
||||
*/
|
||||
void sync();
|
||||
|
||||
/**
|
||||
* @brief getMode
|
||||
* @return
|
||||
*/
|
||||
SettingsSaveMode getMode() const;
|
||||
|
||||
/**
|
||||
* @brief setMode
|
||||
* @param mode
|
||||
*/
|
||||
void setMode(const SettingsSaveMode &mode);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief setValue - set new value of key
|
||||
* @param key - key pf settings
|
||||
* @param value - new value
|
||||
*/
|
||||
void setValue(const QString key, const QVariant& value);
|
||||
|
||||
/**
|
||||
* @brief setStrValue - some as setValue< but use QString
|
||||
*/
|
||||
void setStrValue(const QString& key, const QString& value);
|
||||
|
||||
|
||||
signals:
|
||||
void valueChanged(QString key, QVariant value);
|
||||
void valueStrChanged(QString key, QString value);
|
||||
|
||||
};
|
||||
} ;
|
||||
|
Loading…
x
Reference in New Issue
Block a user