From 5a971a5b21f7c631773b107004e872b5286873bc Mon Sep 17 00:00:00 2001 From: EndrII Date: Tue, 18 Feb 2020 22:28:17 +0300 Subject: [PATCH] added new help functions --- QuasarApp.pro | 2 ++ helpdata.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ helpdata.h | 38 ++++++++++++++++++++++++++++++++++++++ params.cpp | 27 +++++++++++++++++---------- params.h | 15 +++++++++++++-- 5 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 helpdata.cpp create mode 100644 helpdata.h diff --git a/QuasarApp.pro b/QuasarApp.pro index 773d7e1..efd36cf 100644 --- a/QuasarApp.pro +++ b/QuasarApp.pro @@ -33,6 +33,7 @@ CONFIG(release, debug|release): { } SOURCES += \ + helpdata.cpp \ quasarapp.cpp \ params.cpp \ locales.cpp \ @@ -40,6 +41,7 @@ SOURCES += \ global.cpp HEADERS += \ + helpdata.h \ quasarapp.h \ quasarapp_global.h \ params.h \ diff --git a/helpdata.cpp b/helpdata.cpp new file mode 100644 index 0000000..2fd97bd --- /dev/null +++ b/helpdata.cpp @@ -0,0 +1,44 @@ +#include "helpdata.h" +#include + +int MAX_LENGTH = 80; +void QuasarAppUtils::Help::print(const QuasarAppUtils::Help::Options &charter) { + for (auto line = charter.begin(); line != charter.end(); ++line) { + print(line.key(), line.value()); + } +} + +void QuasarAppUtils::Help::print(const QuasarAppUtils::Help::Charters &help) { + for (auto line = help.begin(); line != help.end(); ++line) { + std::string expander('-', MAX_LENGTH); + + std::cout << line.key().toStdString()<< std::endl; + std::cout << expander << std::endl; + print(line.value()); + std::cout << expander << std::endl; + } +} + +void QuasarAppUtils::Help::print(const QString &key, const QString &value) { + + int keyLength = key.size() + 2; + std::cout << key.toStdString() << ": "; + + std::string expander(' ', keyLength); + auto words = value.split(" "); + + int currentLength = keyLength; + for (const auto& word : words) { + if (currentLength < MAX_LENGTH) { + std::cout << word.toStdString(); + currentLength += 2 + word.size(); + } else { + std::cout << std::endl << expander << ": "; + currentLength = keyLength; + } + } +} + +void QuasarAppUtils::Help::setLineLength(int newLength) { + MAX_LENGTH = newLength; +} diff --git a/helpdata.h b/helpdata.h new file mode 100644 index 0000000..6146be7 --- /dev/null +++ b/helpdata.h @@ -0,0 +1,38 @@ +#ifndef HELPDATA_H +#define HELPDATA_H + +#include +namespace QuasarAppUtils{ + +namespace Help { +typedef QHash Options; +typedef QHash Charters; + +/** + * @brief print - line of help + * @param key - option name + * @param value - description of option + */ +void print(const QString& key, const QString& value); + +/** + * @brief print = help Charter + * @param charter - charter of help + */ +void print(const Options& charter); + +/** + * @brief print - all help + * @param help - help for printing + */ +void print(const Charters& help); + +/** + * @brief setLineLength - sets new length of helps line + * @param newLength - new size + */ +void setLineLength(int newLength); +} +} + +#endif // HELPDATA_H diff --git a/params.cpp b/params.cpp index ff69830..25f2945 100644 --- a/params.cpp +++ b/params.cpp @@ -63,16 +63,15 @@ void Params::verboseLog(const QString &log, VerboseLvl vLvl) { } } -QStringList Params::getparamsHelp() { - return - { - {""}, - { " -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' "}, - { " noWriteInFileLog : Disables loging into file"}, - { ""} +Help::Charters Params::getparamsHelp() { + return { + { + "Base Options", { + {"-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'"}, + {"noWriteInFileLog", "Disables loging into file"} + } + } }; } @@ -82,6 +81,14 @@ void Params::showHelp(const QStringList &help) { } } +void Params::showHelp(const Help::Charters &help) { + Help::print(help); +} + +void Params::showHelp() { + Help::print(getparamsHelp()); +} + int Params::size() { return params.size(); } diff --git a/params.h b/params.h index 46543d7..c52e977 100644 --- a/params.h +++ b/params.h @@ -10,7 +10,7 @@ #include #include "quasarapp_global.h" - +#include "helpdata.h" namespace QuasarAppUtils { @@ -96,7 +96,7 @@ public: * @brief getparamsHelp * @return help string of default params */ - static QStringList getparamsHelp(); + static Help::Charters getparamsHelp(); /** * @brief showHelp - show all strings of help @@ -104,6 +104,12 @@ public: */ static void showHelp(const QStringList& help); + /** + * @brief showHelp - show structe of help value + * @param help + */ + static void showHelp(const Help::Charters& help); + /** * @brief size * @return size of all params array @@ -115,6 +121,11 @@ public: * @return size of params entered in conosole */ static int customParamasSize(); + + /** + * @brief showHelp - show base help section of QuasarAppLib + */ + static void showHelp(); }; }