diff --git a/logdoctor/CMakeLists.txt b/logdoctor/CMakeLists.txt index d2bea8d0..157c19e7 100644 --- a/logdoctor/CMakeLists.txt +++ b/logdoctor/CMakeLists.txt @@ -75,7 +75,6 @@ set(PROJECT_SOURCES utilities/vectors.h modules/shared.h - modules/shared.cpp modules/exceptions.h modules/exceptions.cpp diff --git a/logdoctor/mainwindow.cpp b/logdoctor/mainwindow.cpp index 284cf2f3..27364422 100644 --- a/logdoctor/mainwindow.cpp +++ b/logdoctor/mainwindow.cpp @@ -46,16 +46,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow{ parent } , ui{ new Ui::MainWindow } + , tb_color_schemes{ ColorSec::getColorSchemes() } + , colors{ ColorSec::getColors() } { ////////////////// //// GRAPHICS //// this->ui->setupUi(this); - // initialize the color-schemes map - this->TB_COLOR_SCHEMES = ColorSec::getColorSchemes(); - // initialize the colors map - this->COLORS = ColorSec::getColors(); - // load the main font this->main_font_family = QFontDatabase::applicationFontFamilies( QFontDatabase::addApplicationFont(":/fonts/Metropolis")).at(0); @@ -66,36 +63,36 @@ MainWindow::MainWindow(QWidget *parent) this->script_font_family = QFontDatabase::applicationFontFamilies( QFontDatabase::addApplicationFont(":/fonts/3270")).at(0); // initialize the fonts map - this->FONTS.emplace( "main", QFont( + this->fonts.emplace( "main", QFont( this->main_font_family, this->font_size ) ); - this->FONTS.emplace( "main_italic", QFont( + this->fonts.emplace( "main_italic", QFont( this->main_font_family, this->font_size, -1, true ) ); - this->FONTS.emplace( "main_bold", QFont( + this->fonts.emplace( "main_bold", QFont( this->main_font_family, this->font_size, 1 ) ); - this->FONTS.emplace( "main_big", QFont( + this->fonts.emplace( "main_big", QFont( this->main_font_family, this->font_size_big ) ); - this->FONTS.emplace( "main_small", QFont( + this->fonts.emplace( "main_small", QFont( this->main_font_family, this->font_size_small ) ); - this->FONTS.emplace( "alternative", QFont( + this->fonts.emplace( "alternative", QFont( this->alternative_font_family, this->font_size ) ); - this->FONTS.emplace( "script", QFont( + this->fonts.emplace( "script", QFont( this->script_font_family, this->font_size ) ); // parent fonts - this->ui->mainwidget->setFont( this->FONTS.at( "main_big" ) ); + this->ui->mainwidget->setFont( this->fonts.at( "main_big" ) ); // TextBrowser for the LogFiles - this->TB.setColorScheme( 1, this->TB_COLOR_SCHEMES.at( 1 ) ); - this->TB.setFont( this->FONTS.at( "main" ) ); + this->TB.setColorScheme( 1, this->tb_color_schemes.at( 1 ) ); + this->TB.setFont( this->fonts.at( "main" ) ); this->ui->textLogFiles->setFont( this->TB.getFont() ); // adjust LogsList headers width @@ -270,7 +267,7 @@ MainWindow::MainWindow(QWidget *parent) }; for ( auto chart : charts ) { ColorSec::applyChartTheme( - this->FONTS, chart ); + this->fonts, chart ); } this->ui->listLogFiles->sortByColumn( 0, Qt::SortOrder::AscendingOrder ); @@ -1313,12 +1310,12 @@ void MainWindow::updateUiIcons() void MainWindow::updateUiFonts() { - const QFont& small_font{ this->FONTS.at( "main_small" ) }; - const QFont& font{ this->FONTS.at( "main" ) }; - const QFont& big_font{ this->FONTS.at( "main_big" ) }; - QFont menu_font{ this->FONTS.at( "main_small" ) }; + const QFont& small_font{ this->fonts.at( "main_small" ) }; + const QFont& font{ this->fonts.at( "main" ) }; + const QFont& big_font{ this->fonts.at( "main_big" ) }; + QFont menu_font{ this->fonts.at( "main_small" ) }; menu_font.setPointSizeF( this->font_size_small+1.5 ); - QFont header_font{ this->FONTS.at( "main_small" ) }; + QFont header_font{ this->fonts.at( "main_small" ) }; header_font.setPointSizeF( this->font_size_small+2 ); // menu this->ui->menuLanguage->setFont( menu_font ); @@ -2108,7 +2105,7 @@ void MainWindow::menu_actionSnake_triggered() } else { this->snake.reset( new SnakeGame( - this->FONTS.at("script") ) ); + this->fonts.at("script") ) ); this->snake->show(); } } @@ -2497,20 +2494,20 @@ void MainWindow::appendToLogsList( const LogFile& log_file ) return; } // display with red foreground - item->setForeground( 0, this->COLORS.at( "red" ) ); + item->setForeground( 0, this->colors.at( "red" ) ); } // preliminary check on file size - item->setForeground( 1, this->COLORS.at( (log_file.size() > this->craplog.getWarningSize()) + item->setForeground( 1, this->colors.at( (log_file.size() > this->craplog.getWarningSize()) ? "orange" : "grey" ) ); // set the name item->setText( 0, log_file.name() ); - item->setFont( 0, this->FONTS.at("main") ); + item->setFont( 0, this->fonts.at("main") ); // set the size item->setText( 1, PrintSec::printableSize( log_file.size() ) ); - item->setFont( 1, this->FONTS.at("main_italic") ); + item->setFont( 1, this->fonts.at("main_italic") ); // append the item (on top, forced) item->setCheckState(0, Qt::CheckState::Unchecked ); this->ui->listLogFiles->addTopLevelItem( item ); @@ -2797,10 +2794,10 @@ void MainWindow::craplogFinished() // draw the chart this->craplog.makeChart( this->CHARTS_THEMES.at( static_cast(GlobalConfigs::charts_theme) ), - this->FONTS, + this->fonts, this->ui->chart_MakeStats_Size ); ColorSec::applyChartTheme( - this->FONTS, + this->fonts, this->ui->chart_MakeStats_Size ); this->db_edited = this->craplog.editedDatabase(); // refresh the logs section @@ -2989,7 +2986,7 @@ void MainWindow::drawStatsWarn() this->ui->box_StatsWarn_Day->currentText(), (this->ui->checkBox_StatsWarn_Hour->isChecked()) ? this->ui->box_StatsWarn_Hour->currentText() : "" ); ColorSec::applyChartTheme( - this->FONTS, + this->fonts, this->ui->chart_StatsWarn ); this->setDbWorkingState( false ); } @@ -3186,7 +3183,7 @@ void MainWindow::drawStatsSpeed() FilterOps::parseTextualFilter( this->ui->inLine_StatsSpeed_Query->text() ).value(), FilterOps::parseNumericFilter( this->ui->inLine_StatsSpeed_Response->text() ).value() ); ColorSec::applyChartTheme( - this->FONTS, + this->fonts, this->ui->chart_StatsSpeed ); this->setDbWorkingState( false ); } @@ -3425,10 +3422,10 @@ void MainWindow::drawStatsCount() this->ui->box_StatsCount_Day->currentText(), this->count_fld ); ColorSec::applyChartTheme( - this->FONTS, + this->fonts, this->ui->chart_StatsCount ); this->ui->chart_StatsCount->chart()->setTitleFont( - this->FONTS.at( "main_big" ) ); + this->fonts.at( "main_big" ) ); this->setDbWorkingState( false ); } @@ -3716,7 +3713,7 @@ void MainWindow::drawStatsDay() this->ui->box_StatsDay_LogsField->currentText(), this->getStatsDayParsedFilter().value() ); ColorSec::applyChartTheme( - this->FONTS, + this->fonts, this->ui->chart_StatsDay ); this->setDbWorkingState( false ); } @@ -4005,7 +4002,7 @@ void MainWindow::drawStatsRelat() this->ui->box_StatsRelat_LogsField_2->currentText(), this->getStatsRelatParsedFilter( 2 ).value() ); ColorSec::applyChartTheme( - this->FONTS, + this->fonts, this->ui->chart_StatsRelat ); this->setDbWorkingState( false ); } @@ -4287,7 +4284,7 @@ void MainWindow::on_box_ConfTextBrowser_Font_currentIndexChanged(int index) default: throw GenericException( "Unexpected Font index: "+std::to_string(index), true ); } - const QFont& font{ this->FONTS.at( f ) }; + const QFont& font{ this->fonts.at( f ) }; this->TB.setFont( font ); this->ui->textBrowser_ConfTextBrowser_Preview->setFont( font ); this->ui->preview_ConfApache_Format_Sample->setFont( font ); @@ -4304,7 +4301,7 @@ void MainWindow::on_checkBox_ConfTextBrowser_WideLines_clicked(bool checked) } void MainWindow::on_box_ConfTextBrowser_ColorScheme_currentIndexChanged(int index) { - this->TB.setColorScheme( index, this->TB_COLOR_SCHEMES.at( index ) ); + this->TB.setColorScheme( index, this->tb_color_schemes.at( index ) ); if ( !this->crapnote.isNull() ) { this->crapnote->setColorScheme( index ); } @@ -4327,22 +4324,22 @@ void MainWindow::on_box_ConfCharts_Theme_currentIndexChanged(int index) this->refreshChartsPreview(); ColorSec::applyChartTheme( - this->FONTS, + this->fonts, this->ui->chart_MakeStats_Size ); ColorSec::applyChartTheme( - this->FONTS, + this->fonts, this->ui->chart_StatsWarn ); ColorSec::applyChartTheme( - this->FONTS, + this->fonts, this->ui->chart_StatsSpeed ); ColorSec::applyChartTheme( - this->FONTS, + this->fonts, this->ui->chart_StatsCount ); ColorSec::applyChartTheme( - this->FONTS, + this->fonts, this->ui->chart_StatsDay ); ColorSec::applyChartTheme( - this->FONTS, + this->fonts, this->ui->chart_StatsRelat ); } void MainWindow::refreshChartsPreview() @@ -4409,7 +4406,7 @@ void MainWindow::refreshChartsPreview() // add the bars t_chart->addSeries( bars ); t_chart->setTitle( "Sample preview" ); - t_chart->setTitleFont( this->FONTS.at("main") ); + t_chart->setTitleFont( this->fonts.at("main") ); t_chart->setAnimationOptions( QChart::SeriesAnimations ); QStringList categories; @@ -4418,16 +4415,16 @@ void MainWindow::refreshChartsPreview() QBarCategoryAxis* axisX{ new QBarCategoryAxis() }; axisX->append( categories ); - axisX->setLabelsFont( this->FONTS.at( "main_small" ) ); + axisX->setLabelsFont( this->fonts.at( "main_small" ) ); axisX->setTitleText( "Infoes" ); - axisX->setTitleFont( this->FONTS.at("main_small") ); + axisX->setTitleFont( this->fonts.at("main_small") ); t_chart->addAxis( axisX, Qt::AlignBottom ); bars->attachAxis( axisX ); QValueAxis* axisY{ new QValueAxis() }; axisY->setLabelFormat( "%d" ); axisY->setRange( 0, max ); - axisY->setLabelsFont( this->FONTS.at( "main_small" ) ); + axisY->setLabelsFont( this->fonts.at( "main_small" ) ); t_chart->addAxis( axisY, Qt::AlignLeft ); bars->attachAxis( axisY) ; @@ -4439,7 +4436,7 @@ void MainWindow::refreshChartsPreview() this->ui->chart_ConfCharts_Preview->setRenderHint( QPainter::Antialiasing ); ColorSec::applyChartTheme( - this->FONTS, + this->fonts, this->ui->chart_ConfCharts_Preview ); } diff --git a/logdoctor/mainwindow.h b/logdoctor/mainwindow.h index 85257fd1..73f020c2 100644 --- a/logdoctor/mainwindow.h +++ b/logdoctor/mainwindow.h @@ -664,13 +664,13 @@ private: }; // color schemes - std::unordered_map> TB_COLOR_SCHEMES; + const std::unordered_map> tb_color_schemes; // colors - std::unordered_map COLORS; + const std::unordered_map colors; // fonts - std::unordered_map FONTS; + std::unordered_map fonts; int font_size { 13 }; int font_size_big { 16 }; diff --git a/logdoctor/modules/shared.cpp b/logdoctor/modules/shared.cpp deleted file mode 100644 index 45adad95..00000000 --- a/logdoctor/modules/shared.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -#include "shared.h" - - -TR::TR(QObject *parent) - : QObject{parent} -{ - -} diff --git a/logdoctor/modules/shared.h b/logdoctor/modules/shared.h index 4aefaf05..37505f30 100644 --- a/logdoctor/modules/shared.h +++ b/logdoctor/modules/shared.h @@ -13,7 +13,7 @@ class TR : public QObject { Q_OBJECT public: - explicit TR( QObject* parent=nullptr ); + explicit TR( QObject* parent=nullptr ):QObject{parent}{} }; diff --git a/logdoctor/utilities/io.cpp b/logdoctor/utilities/io.cpp index 6697d52f..29c1784a 100644 --- a/logdoctor/utilities/io.cpp +++ b/logdoctor/utilities/io.cpp @@ -13,23 +13,6 @@ namespace IOutils { -bool exists( std::string_view path ) -{ - if ( path.empty() ) { - return false; - } - return std::filesystem::exists( path ); -} - - -bool isFile( std::string_view path ) -{ - if ( exists( path ) ) { - return std::filesystem::is_regular_file( path ); - } - return false; -} - bool checkFile( std::string_view path, const bool readable, const bool writable ) { if ( isFile( path ) ) { @@ -51,14 +34,6 @@ bool checkFile( std::string_view path, const bool readable, const bool writable } -bool isDir( std::string_view path ) -{ - if ( exists( path )) { - return std::filesystem::is_directory( path ); - } - return false; -} - bool checkDir( std::string_view path, const bool readable, const bool writable ) { if ( isDir( path ) ) { diff --git a/logdoctor/utilities/io.h b/logdoctor/utilities/io.h index d83aa669..e4c6d92d 100644 --- a/logdoctor/utilities/io.h +++ b/logdoctor/utilities/io.h @@ -19,21 +19,36 @@ namespace IOutils \param path The path of the entry \return The result of the check */ -bool exists( std::string_view path ); +inline bool exists( std::string_view path ) +{ + return path.empty() + ? false + : std::filesystem::exists( path ); +} //! Checks if a path exists and points to a file /*! \param path The path of the entry \return The result of the check */ -bool isFile( std::string_view path ); +inline bool isFile( std::string_view path ) +{ + return exists( path ) + ? std::filesystem::is_regular_file( path ) + : false; +} //! Checks if a path exists and points to a directory /*! \param path The path of the entry \return The result of the checks */ -bool isDir( std::string_view path ); +inline bool isDir( std::string_view path ) +{ + return exists( path ) + ? std::filesystem::is_directory( path ) + : false; +} //! Checks if a path exists, if it points to a file and if the user has read and/or write permissions on it /*! diff --git a/logdoctor/utilities/memory.cpp b/logdoctor/utilities/memory.cpp index f627f0f4..66ef2eab 100644 --- a/logdoctor/utilities/memory.cpp +++ b/logdoctor/utilities/memory.cpp @@ -33,8 +33,8 @@ size_t availableMemory() { if ( host_statistics( mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count ) != KERN_SUCCESS ) { throw GenericException("Failed to get host infos", true); } - natural_t n_pages{ vmstat.free_count }; - long page_size{ sysconf( _SC_PAGE_SIZE ) }; + const natural_t n_pages{ vmstat.free_count }; + const long page_size{ sysconf( _SC_PAGE_SIZE ) }; if ( n_pages < 0u || page_size < 0l ) { return 0ul; } @@ -52,8 +52,8 @@ size_t availableMemory() { } return vmt.t_free * static_cast( page_size ); #elif defined( Q_OS_UNIX ) - long n_pages{ sysconf( _SC_AVPHYS_PAGES ) }; - long page_size{ sysconf( _SC_PAGE_SIZE ) }; + const long n_pages{ sysconf( _SC_AVPHYS_PAGES ) }; + const long page_size{ sysconf( _SC_PAGE_SIZE ) }; if ( n_pages < 0l || page_size < 0l ) { return 0ul; } diff --git a/logdoctor/utilities/strings.h b/logdoctor/utilities/strings.h index b0412b42..964290bb 100644 --- a/logdoctor/utilities/strings.h +++ b/logdoctor/utilities/strings.h @@ -42,8 +42,8 @@ size_t count( std::string_view str, std::string_view flag ); inline bool isNumeric( std::string_view str ) { return str.empty() - ? false - : std::all_of( str.cbegin(), str.cend(), CharOps::isNumeric ); + ? false + : std::all_of( str.cbegin(), str.cend(), CharOps::isNumeric ); } //! Checks whether a string only contains alphabetic characters @@ -54,8 +54,8 @@ inline bool isNumeric( std::string_view str ) inline bool isAlphabetic( std::string_view str ) { return str.empty() - ? false - : std::all_of( str.cbegin(), str.cend(), CharOps::isAlphabetic ); + ? false + : std::all_of( str.cbegin(), str.cend(), CharOps::isAlphabetic ); } //! Checks whether a string only contains alpha-numeric characters @@ -66,8 +66,8 @@ inline bool isAlphabetic( std::string_view str ) inline bool isAlnum( std::string_view str ) { return str.empty() - ? false - : std::all_of( str.cbegin(), str.cend(), CharOps::isAlnum ); + ? false + : std::all_of( str.cbegin(), str.cend(), CharOps::isAlnum ); } //! Checks whether a string contains only IPv4/IPv6 chars @@ -80,8 +80,8 @@ inline bool isAlnum( std::string_view str ) inline bool isIP( std::string_view str ) { return str.empty() - ? false - : std::all_of( str.cbegin(), str.cend(), CharOps::isIP ); + ? false + : std::all_of( str.cbegin(), str.cend(), CharOps::isIP ); } //! Checks if a string starts with the given sequence