From cf8e8c7655ee1af8556c243d1fedde71f6fc14ec Mon Sep 17 00:00:00 2001 From: Andreas Stallinger Date: Thu, 10 Nov 2016 11:09:24 +0100 Subject: [PATCH] ui: log tab --- bin/app/data/color_schemes/bad_rainbow.xml | 4 +- bin/app/data/color_schemes/bright.xml | 17 +- bin/app/data/color_schemes/dark.xml | 4 +- bin/app/data/gui/error_view/error_view.css | 92 -------- bin/app/data/gui/tabbed_view/tabbed_view.css | 92 ++++++++ cmake/CLANGConfig.cmake | 22 +- cmake/pre_install_linux.cmake | 4 +- setup/Linux/Coati.sh | 6 +- setup/Linux/Coati_trial.sh | 26 --- src/lib/CMakeLists.txt | 1 + src/lib/component/ComponentFactory.cpp | 6 +- src/lib/component/ComponentManager.cpp | 4 +- .../component/controller/LogController.cpp | 31 ++- src/lib/component/controller/LogController.h | 16 +- src/lib/component/view/LogView.h | 4 + src/lib/settings/ColorScheme.cpp | 2 +- .../utility/messaging/type/MessageNewLog.h | 34 +++ src/lib/utility/utility.h | 2 + src/lib_gui/qt/element/QtTable.cpp | 24 ++ src/lib_gui/qt/view/QtErrorView.cpp | 25 +-- src/lib_gui/qt/view/QtLogView.cpp | 207 +++++++++++++++++- src/lib_gui/qt/view/QtLogView.h | 57 +++++ src/lib_gui/qt/window/QtIndexingDialog.cpp | 2 +- 23 files changed, 514 insertions(+), 168 deletions(-) delete mode 100755 setup/Linux/Coati_trial.sh create mode 100644 src/lib/utility/messaging/type/MessageNewLog.h diff --git a/bin/app/data/color_schemes/bad_rainbow.xml b/bin/app/data/color_schemes/bad_rainbow.xml index 800c3911..4fcae1e7 100644 --- a/bin/app/data/color_schemes/bad_rainbow.xml +++ b/bin/app/data/color_schemes/bad_rainbow.xml @@ -394,7 +394,7 @@ - + #494949
#C4C4C4
@@ -409,7 +409,7 @@ #383838 #7B7B7B -
+ #494949 #C4C4C4 diff --git a/bin/app/data/color_schemes/bright.xml b/bin/app/data/color_schemes/bright.xml index cc77ca47..47735a52 100644 --- a/bin/app/data/color_schemes/bright.xml +++ b/bin/app/data/color_schemes/bright.xml @@ -362,6 +362,15 @@ white + + + white + black + #878787 + #878787 + + + white
#aaa
black @@ -375,11 +384,5 @@ #F1F1F1 grey - - - white - black - #878787 - #878787 - + diff --git a/bin/app/data/color_schemes/dark.xml b/bin/app/data/color_schemes/dark.xml index 61aa83cd..4f902c0b 100644 --- a/bin/app/data/color_schemes/dark.xml +++ b/bin/app/data/color_schemes/dark.xml @@ -389,7 +389,7 @@ - + #272728
white
@@ -404,7 +404,7 @@ #343434 #969696 -
+ #272728 white diff --git a/bin/app/data/gui/error_view/error_view.css b/bin/app/data/gui/error_view/error_view.css index 0a47bddb..e69de29b 100644 --- a/bin/app/data/gui/error_view/error_view.css +++ b/bin/app/data/gui/error_view/error_view.css @@ -1,92 +0,0 @@ -QTableView { - color: ; - background-color: ; - alternate-background-color: ; - border-radius: 10px; - border: 1px solid ; - margin: 10px; - padding-right: 10px; - font-size: px; -} - -QFrame { - background-color: ; -} - -QTableView::item { - border-left: 1px solid ; -} - -QTableView::item:selected { - color: ; - background-color: ; - alternate-background-color: ; -} - -QHeaderView { - background-color: transparent; -} - -QHeaderView::section:horizontal { - background-color: transparent; - border: none; - border-bottom: 1px solid ; - border-left: 1px solid ; - color: ; - font-size: px; - font-weight: bold; - padding: 1px 6px; - height: px; -} - -QHeaderView::section:vertical { - background-color: transparent; - border: none; - color: ; - font-size: px; - padding-right: 5px; - padding-left: 5px; -} - - -QCheckBox { - color: ; - border-color: ; - /*background-color: ;*/ -} - - - -QScrollBar:vertical { -} - -QScrollBar::handle:vertical { - min-height: 20px; -} - -QScrollBar::add-line:vertical { - height: 20px; - subcontrol-position: bottom; - subcontrol-origin: margin; -} - -QScrollBar::sub-line:vertical { - height: 20px; - subcontrol-position: top; - subcontrol-origin: margin; -} -QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical { - width: 3px; - height: 3px; - background: white; -} - -QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { - background: none; -} - -QTableView QTableCornerButton::section { - background-color: ; - border-bottom: 1px solid ; - border-top-left-radius: 10px; -} diff --git a/bin/app/data/gui/tabbed_view/tabbed_view.css b/bin/app/data/gui/tabbed_view/tabbed_view.css index 3dcb9b22..72dc7703 100644 --- a/bin/app/data/gui/tabbed_view/tabbed_view.css +++ b/bin/app/data/gui/tabbed_view/tabbed_view.css @@ -29,3 +29,95 @@ QTabWidget::pane { margin: 0px; padding: 0px; } + +QTableView { + color: ; + background-color: ; + alternate-background-color: ; + border-radius: 10px; + border: 1px solid ; + margin: 10px; + padding-right: 10px; + font-size: px; +} + +QFrame { + background-color: ; +} + +QTableView::item { + border-left: 1px solid ; +} + +QTableView::item:selected { + color: ; + background-color: ; + alternate-background-color: ; +} + +QHeaderView { + background-color: transparent; +} + +QHeaderView::section:horizontal { + background-color: transparent; + border: none; + border-bottom: 1px solid ; + border-left: 1px solid ; + color: ; + font-size: px; + font-weight: bold; + padding: 1px 6px; + height: px; +} + +QHeaderView::section:vertical { + background-color: transparent; + border: none; + color: ; + font-size: px; + padding-right: 5px; + padding-left: 5px; +} + + +QCheckBox { + color: ; + border-color: ; + /*background-color: ;*/ +} + +QScrollBar:vertical { +} + +QScrollBar::handle:vertical { + min-height: 20px; +} + +QScrollBar::add-line:vertical { + height: 20px; + subcontrol-position: bottom; + subcontrol-origin: margin; +} + +QScrollBar::sub-line:vertical { + height: 20px; + subcontrol-position: top; + subcontrol-origin: margin; +} +QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical { + width: 3px; + height: 3px; + background: white; +} + +QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { + background: none; +} + +QTableView QTableCornerButton::section { + background-color: ; + border-bottom: 1px solid ; + border-top-left-radius: 10px; +} + diff --git a/cmake/CLANGConfig.cmake b/cmake/CLANGConfig.cmake index a686b547..9f31d4a8 100644 --- a/cmake/CLANGConfig.cmake +++ b/cmake/CLANGConfig.cmake @@ -7,7 +7,7 @@ if (UNIX AND APPLE) set(CLANG_BUILD_PATH "$ENV{CLANG_DIR}/build_debug") endif() elseif(UNIX) - set(CLANG_BUILD_PATH "${EXTERNAL_BUILD}/llvm") + set(CLANG_BUILD_PATH "${EXTERNAL_BUILD}/llvm") else() set(CLANG_BUILD_PATH "$ENV{CLANG_DIR}/build") endif() @@ -21,16 +21,20 @@ execute_process( string(REPLACE "-fno-exceptions" "" CLANG_DEFINITIONS "${CLANG_DEFINITIONS}") string(REPLACE "-fno-rtti" "" CLANG_DEFINITIONS "${CLANG_DEFINITIONS}") +if(CMAKE_COMPILER_IS_GNUCXX) + string(REPLACE "-Wcovered-switch-default" "" CLANG_DEFINITIONS "${CLANG_DEFINITIONS}") +endif() + if(UNIX AND NOT APPLE) - set(CLANG_INCLUDE_DIRS - "${EXTERNAL_SRC}/clang/include" - "${CLANG_BUILD_PATH}/tools/clang/include" - ) + set(CLANG_INCLUDE_DIRS + "${EXTERNAL_SRC}/clang/include" + "${CLANG_BUILD_PATH}/tools/clang/include" + ) else() - set(CLANG_INCLUDE_DIRS - "$ENV{CLANG_DIR}/llvm/tools/clang/include" - "${CLANG_BUILD_PATH}/tools/clang/include" - ) + set(CLANG_INCLUDE_DIRS + "$ENV{CLANG_DIR}/llvm/tools/clang/include" + "${CLANG_BUILD_PATH}/tools/clang/include" + ) endif() set(CLANG_LIBRARY_DIRS "${CLANG_BUILD_PATH}/lib") diff --git a/cmake/pre_install_linux.cmake b/cmake/pre_install_linux.cmake index 94057000..382c9b5b 100644 --- a/cmake/pre_install_linux.cmake +++ b/cmake/pre_install_linux.cmake @@ -15,7 +15,7 @@ endfunction() set(upxPath ${CMAKE_CURRENT_LIST_DIR}/../bin/app/Release) execute_process( - COMMAND ${upxPath}/Coati -z /home/vagrant/dev/license.txt + COMMAND ${upxPath}/Coati -z $ENV{HOME}/dev/license.txt ) execute_process( @@ -29,7 +29,7 @@ endfunction() #execute_process( #COMMAND ${upxPath}/Coati -f -d ${upxPath}/../data/projects/javaparser/javaparser.coatiproject #) -#SET (NO_UPX 1) +SET (NO_UPX 1) if (NO_UPX) execute_process( diff --git a/setup/Linux/Coati.sh b/setup/Linux/Coati.sh index cbb5b57e..a0a7d678 100755 --- a/setup/Linux/Coati.sh +++ b/setup/Linux/Coati.sh @@ -12,13 +12,13 @@ COATI_PATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )" #setup data folder if [ ! -d "${HOME}/.config/coati" ]; then # Control will enter here if $DIRECTORY doesn't exist. - mkdir -p ${HOME}/.config/coati + mkdir -p "${HOME}/.config/coati" echo "First start of Coati from this user, copy default configfiles to ~/.config/coati" fi -cp -rn $COATI_PATH/user/* ${HOME}/.config/coati/ +cp -rn "$COATI_PATH/user/*" "${HOME}/.config/coati/" export LD_LIBRARY_PATH="$COATI_PATH/lib:LD_LIBRARY_PATH" export QT_XKB_CONFIG_ROOT="/usr/share/X11/xkb:$QT_XKB_CONFIG_ROOT" export QT_QPA_FONTDIR="$COATI_PATH/data/fonts:$QT_QPA_FONTDIR" -exec $COATI_PATH/Coati $@ +exec "$COATI_PATH/Coati" $@ diff --git a/setup/Linux/Coati_trial.sh b/setup/Linux/Coati_trial.sh deleted file mode 100755 index 7ee86d4f..00000000 --- a/setup/Linux/Coati_trial.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -# get the current directory -SOURCE="${0}" -while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink - DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" - SOURCE="$(readlink "$SOURCE")" - [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located -done -COATI_PATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )" - -#setup data folder -echo $COATI_PATH -if [ ! -d "${HOME}/.config/coatitrial" ]; then - # Control will enter here if $DIRECTORY doesn't exist. - mkdir -p ${HOME}/.config/coatitrial - echo "First start of Coati from this user, copy default configfiles to ~/.config/coati" -fi - -cp -nr $COATI_PATH/user/* ${HOME}/.config/coatitrial/ - -export LD_LIBRARY_PATH="$COATI_PATH/lib:LD_LIBRARY_PATH" -export QT_XKB_CONFIG_ROOT="/usr/share/X11/xkb:$QT_XKB_CONFIG_ROOT" -export QT_QPA_FONTDIR="$COATI_PATH/data/fonts:$QT_QPA_FONTDIR" -exec $COATI_PATH/Coati_trial - diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 18162064..3ac70abd 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -285,6 +285,7 @@ add_files( utility/messaging/type/MessageLoadProject.h utility/messaging/type/MessageMoveIDECursor.h utility/messaging/type/MessageNewErrors.h + utility/messaging/type/MessageNewLog.h utility/messaging/type/MessagePluginPortChange.h utility/messaging/type/MessageProjectEdit.h utility/messaging/type/MessageProjectNew.h diff --git a/src/lib/component/ComponentFactory.cpp b/src/lib/component/ComponentFactory.cpp index 8e80f2fc..931f8789 100644 --- a/src/lib/component/ComponentFactory.cpp +++ b/src/lib/component/ComponentFactory.cpp @@ -20,6 +20,8 @@ #include "component/view/UndoRedoView.h" #include "component/view/ViewFactory.h" +#include "utility/logging/LogManager.h" + std::shared_ptr ComponentFactory::create(ViewFactory* viewFactory, StorageAccess* storageAccess) { std::shared_ptr ptr(new ComponentFactory()); @@ -63,7 +65,9 @@ std::shared_ptr ComponentFactory::createErrorComponent(ViewLayout* vi std::shared_ptr ComponentFactory::createLogComponent(ViewLayout* viewLayout) { std::shared_ptr view = m_viewFactory->createLogView(viewLayout); - std::shared_ptr controller = std::make_shared(m_storageAccess); + std::shared_ptr controller = std::make_shared(); + + LogManager::getInstance()->addLogger(controller); return std::make_shared(view, controller); } diff --git a/src/lib/component/ComponentManager.cpp b/src/lib/component/ComponentManager.cpp index 3d4fa564..2b8f075f 100644 --- a/src/lib/component/ComponentManager.cpp +++ b/src/lib/component/ComponentManager.cpp @@ -63,8 +63,8 @@ void ComponentManager::setup(ViewLayout* viewLayout) std::shared_ptr errorComponent = m_componentFactory->createErrorComponent(tabbedView.get()); m_components.push_back(errorComponent); - //std::shared_ptr logComponent = m_componentFactory->createLogComponent(tabbedView.get()); - //m_components.push_back(logComponent); + std::shared_ptr logComponent = m_componentFactory->createLogComponent(tabbedView.get()); + m_components.push_back(logComponent); } void ComponentManager::clearComponents() diff --git a/src/lib/component/controller/LogController.cpp b/src/lib/component/controller/LogController.cpp index ba621da4..98b89daa 100644 --- a/src/lib/component/controller/LogController.cpp +++ b/src/lib/component/controller/LogController.cpp @@ -1,9 +1,10 @@ #include "component/controller/LogController.h" #include "data/access/StorageAccess.h" +#include "utility/logging/LogManager.h" -LogController::LogController(StorageAccess* storageAccess) - : m_storageAccess(storageAccess) +LogController::LogController() + : Logger("WindowLogger") { } @@ -20,3 +21,29 @@ void LogController::clear() { getView()->clear(); } + +void LogController::logInfo(const LogMessage& message ) +{ + addLog(LOG_INFOS, message); +} + +void LogController::logError(const LogMessage& message ) +{ + addLog(LOG_ERRORS, message); +} + +void LogController::logWarning(const LogMessage& message ) +{ + addLog(LOG_WARNINGS, message); +} + +void LogController::addLog(Logger::LogLevel type, const LogMessage& message) +{ + MessageNewLog(type,message).dispatch(); +} + +void LogController::handleMessage(MessageNewLog* message) +{ + getView()->addLog(message->type, message->message); +} + diff --git a/src/lib/component/controller/LogController.h b/src/lib/component/controller/LogController.h index 80e479fe..9064221b 100644 --- a/src/lib/component/controller/LogController.h +++ b/src/lib/component/controller/LogController.h @@ -4,21 +4,33 @@ #include "component/controller/Controller.h" #include "component/view/LogView.h" +#include "utility/logging/Logger.h" +#include "utility/logging/LogMessage.h" +#include "utility/messaging/type/MessageNewLog.h" +#include "utility/messaging/MessageListener.h" + class StorageAccess; class LogController : public Controller + , public Logger + , public MessageListener { public: - LogController(StorageAccess* storageAccess); + LogController(); ~LogController(); private: LogView* getView() const; + virtual void handleMessage(MessageNewLog* message); virtual void clear(); - StorageAccess* m_storageAccess; + virtual void logInfo(const LogMessage& message); + virtual void logWarning(const LogMessage& message); + virtual void logError(const LogMessage& message); + + void addLog(Logger::LogLevel type, const LogMessage& message); }; #endif // LOG_CONTROLLER_H diff --git a/src/lib/component/view/LogView.h b/src/lib/component/view/LogView.h index 0c79fd39..41cdcaff 100644 --- a/src/lib/component/view/LogView.h +++ b/src/lib/component/view/LogView.h @@ -3,6 +3,9 @@ #include "component/view/View.h" +#include "utility/logging/LogMessage.h" +#include "utility/logging/Logger.h" + class LogView : public View { @@ -13,6 +16,7 @@ public: virtual std::string getName() const; virtual void clear() = 0; + virtual void addLog(Logger::LogLevel type, const LogMessage& message) = 0; }; #endif // LOG_VIEW_H diff --git a/src/lib/settings/ColorScheme.cpp b/src/lib/settings/ColorScheme.cpp index 42e472d5..2436612e 100644 --- a/src/lib/settings/ColorScheme.cpp +++ b/src/lib/settings/ColorScheme.cpp @@ -18,7 +18,7 @@ ColorScheme::~ColorScheme() std::string ColorScheme::getColor(const std::string& key) const { - return getValue(key, ""); + return getValue(key, "#FF1493"); } std::string ColorScheme::getColor(const std::string& key, const std::string& defaultColor) const diff --git a/src/lib/utility/messaging/type/MessageNewLog.h b/src/lib/utility/messaging/type/MessageNewLog.h new file mode 100644 index 00000000..a6ec888b --- /dev/null +++ b/src/lib/utility/messaging/type/MessageNewLog.h @@ -0,0 +1,34 @@ +#ifndef MESSAGE_NEW_LOG_H +#define MESSAGE_NEW_LOG_H + +#include "utility/messaging/Message.h" + +#include "utility/logging/logging.h" + +class MessageNewLog + : public Message +{ +public: + MessageNewLog(const Logger::LogLevel type, const LogMessage& message) + : type(type) + , message(message) + { + setSendAsTask(false); + setIsLogged(false); + } + + static const std::string getStaticType() + { + return "MessageNewLog"; + } + + virtual void print(std::ostream& os) const + { + os << "Log: " << message.message; + } + + const Logger::LogLevel type; + const LogMessage message; +}; + +#endif // MESSAGE_NEW_LOG_H diff --git a/src/lib/utility/utility.h b/src/lib/utility/utility.h index af4783b3..044a6009 100644 --- a/src/lib/utility/utility.h +++ b/src/lib/utility/utility.h @@ -46,6 +46,8 @@ namespace utility template std::vector toStrings(const std::vector& d); + template<> + std::vector toStrings(const std::vector& d); template bool isPermutation(const std::vector& a, const std::vector& b) diff --git a/src/lib_gui/qt/element/QtTable.cpp b/src/lib_gui/qt/element/QtTable.cpp index 328d2617..85d0f962 100644 --- a/src/lib_gui/qt/element/QtTable.cpp +++ b/src/lib_gui/qt/element/QtTable.cpp @@ -5,9 +5,31 @@ #include #include #include +#include +#include #include "settings/ApplicationSettings.h" +class SelectableCellDelegate : public QStyledItemDelegate +{ + QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; +}; + + +QWidget* SelectableCellDelegate::createEditor( + QWidget* parent, + const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + QWidget* editor = QStyledItemDelegate::createEditor(parent, option, index); + QLineEdit* lineEdit = dynamic_cast(editor); + if (lineEdit != nullptr) + { + lineEdit->setReadOnly(true); + } + return editor; +} + QtTable::QtTable(QWidget* parent) : QTableView(parent) , m_rowsToFill(0) @@ -15,6 +37,8 @@ QtTable::QtTable(QWidget* parent) setAlternatingRowColors(true); setShowGrid(false); + this->setItemDelegate(new SelectableCellDelegate()); + verticalHeader()->sectionResizeMode(QHeaderView::Fixed); verticalHeader()->setDefaultAlignment(Qt::AlignRight); diff --git a/src/lib_gui/qt/view/QtErrorView.cpp b/src/lib_gui/qt/view/QtErrorView.cpp index b9aa2eb7..0dd5961c 100644 --- a/src/lib_gui/qt/view/QtErrorView.cpp +++ b/src/lib_gui/qt/view/QtErrorView.cpp @@ -184,9 +184,8 @@ void QtErrorView::setStyleSheet() const QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this); utility::setWidgetBackgroundColor(widget, ColorScheme::getInstance()->getColor("error/background")); - QPalette palette(m_showErrors->palette()); - palette.setColor(QPalette::WindowText, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str())); + palette.setColor(QPalette::WindowText, QColor(ColorScheme::getInstance()->getColor("table/text/normal").c_str())); //palette.setColor(QPalette::Text, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str())); //palette.setColor(QPalette::ButtonText, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str())); @@ -196,9 +195,9 @@ void QtErrorView::setStyleSheet() const m_showNonIndexedErrors->setPalette(palette); m_showNonIndexedFatals->setPalette(palette); - widget->setStyleSheet( - utility::getStyleSheet(ResourcePaths::getGuiPath() + "error_view/error_view.css").c_str() - ); + //widget->setStyleSheet( + //utility::getStyleSheet(ResourcePaths::getGuiPath() + "error_view/error_view.css").c_str() + //); m_table->updateRows(); } @@ -241,10 +240,10 @@ QCheckBox* QtErrorView::createFilterCheckbox(const QString& name, bool checked, m_table->selectionModel()->clearSelection(); ErrorFilter filter; - filter.error = m_showErrors->checkState() == Qt::Checked; - filter.fatal = m_showFatals->checkState() == Qt::Checked; - filter.unindexedError = m_showNonIndexedErrors->checkState() == Qt::Checked; - filter.unindexedFatal = m_showNonIndexedFatals->checkState() == Qt::Checked; + filter.error = m_showErrors->isChecked(); + filter.fatal = m_showFatals->isChecked(); + filter.unindexedError = m_showNonIndexedErrors->isChecked(); + filter.unindexedFatal = m_showNonIndexedFatals->isChecked(); MessageErrorFilterChanged(filter).dispatch(); } @@ -258,19 +257,19 @@ QCheckBox* QtErrorView::createFilterCheckbox(const QString& name, bool checked, bool QtErrorView::isShownError(const ErrorInfo& error) { - if (!error.fatal && error.indexed && m_showErrors->checkState() == Qt::Checked) + if (!error.fatal && error.indexed && m_showErrors->isChecked()) { return true; } - if (error.fatal && error.indexed && m_showFatals->checkState() == Qt::Checked) + if (error.fatal && error.indexed && m_showFatals->isChecked()) { return true; } - if (!error.fatal && !error.indexed && m_showNonIndexedErrors->checkState() == Qt::Checked) + if (!error.fatal && !error.indexed && m_showNonIndexedErrors->isChecked()) { return true; } - if (error.fatal && !error.indexed && m_showNonIndexedFatals->checkState() == Qt::Checked) + if (error.fatal && !error.indexed && m_showNonIndexedFatals->isChecked()) { return true; } diff --git a/src/lib_gui/qt/view/QtLogView.cpp b/src/lib_gui/qt/view/QtLogView.cpp index b82405ac..bb31e55f 100644 --- a/src/lib_gui/qt/view/QtLogView.cpp +++ b/src/lib_gui/qt/view/QtLogView.cpp @@ -3,11 +3,21 @@ #include #include #include +#include +#include +#include "settings/ApplicationSettings.h" +#include "settings/ColorScheme.h" #include "qt/view/QtViewWidgetWrapper.h" +#include "utility/messaging/type/MessageRefresh.h" +#include "utility/ResourcePaths.h" +#include "qt/utility/utilityQt.h" +#include "qt/element/QtTable.h" + QtLogView::QtLogView(ViewLayout* viewLayout) : LogView(viewLayout) + , m_addLogFunctor(std::bind(&QtLogView::doAddLog, this, std::placeholders::_1, std::placeholders::_2)) , m_clearFunctor(std::bind(&QtLogView::doClear, this)) , m_refreshFunctor(std::bind(&QtLogView::doRefreshView, this)) { @@ -27,17 +37,107 @@ void QtLogView::initView() QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this); QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); - layout->setContentsMargins(0, 0, 0, 0); + layout->setContentsMargins(0, 10, 0, 5); layout->setSpacing(0); widget->setLayout(layout); - QLabel* label = new QLabel("test log view"); + QHBoxLayout* headerLayout = new QHBoxLayout(); + headerLayout->addSpacing(10); - widget->layout()->addWidget(label); + m_viewEnabled = new QCheckBox("Enable"); + m_viewEnabled->setChecked(ApplicationSettings::getInstance()->getLoggingEnabled()); + connect(m_viewEnabled, &QCheckBox::stateChanged, + [=](int){ + setLoggingEnabled(m_viewEnabled->isChecked()); + } + ); + headerLayout->addWidget(m_viewEnabled); + headerLayout->addSpacing(25); + m_showAstLogging = new QCheckBox("Ast"); + m_showAstLogging->setEnabled(m_viewEnabled->isChecked()); + m_showAstLogging->setChecked(ApplicationSettings::getInstance()->getVerboseIndexerLoggingEnabled()); + connect(m_showAstLogging, &QCheckBox::stateChanged, + [=](int){ + setAstLoggingEnabled(m_showAstLogging->isChecked()); + } + ); + headerLayout->addWidget(m_showAstLogging); + headerLayout->addStretch(); + + layout->addLayout(headerLayout); + + m_table = new QtTable(this); + m_model = new QStandardItemModel(this); + m_table->setModel(m_model); + + m_model->setColumnCount(3); + m_table->setColumnWidth(LOGVIEW_COLUMN::TYPE, 100); + m_table->setColumnWidth(LOGVIEW_COLUMN::TIMESTAMP, 150); + m_table->setColumnWidth(LOGVIEW_COLUMN::TYPE, 100); + + QStringList headers; + headers << "Type" << "Timestamp" << "Message"; + m_model->setHorizontalHeaderLabels(headers); + + layout->addWidget(m_table); + + QHBoxLayout* filters = new QHBoxLayout(); + filters->addSpacing(15); + + m_showErrors = createFilterCheckbox("error", filters, true); + m_showWarnings = createFilterCheckbox("warnings", filters, true); + m_showInfo = createFilterCheckbox("info", filters); + + filters->addStretch(); + updateMask(); + + layout->addLayout(filters); doRefreshView(); } +QCheckBox* QtLogView::createFilterCheckbox(const QString& name, QBoxLayout* layout, bool checked) +{ + QCheckBox* checkbox = new QCheckBox(name); + checkbox->setChecked(checked); + + connect(checkbox, &QCheckBox::stateChanged, + [=](int) + { + m_table->selectionModel()->clearSelection(); + updateMask(); + updateTable(); + } + ); + + layout->addWidget(checkbox); + layout->addSpacing(25); + + return checkbox; +} + +void QtLogView::setLoggingEnabled(bool enabled) +{ + m_showAstLogging->setEnabled(enabled); + + ApplicationSettings::getInstance()->setLoggingEnabled(enabled); + ApplicationSettings::getInstance()->save(); + MessageRefresh msg; + msg.reloadSettings = true; + msg.uiOnly = true; + msg.dispatchImmediately(); +} + +void QtLogView::setAstLoggingEnabled(bool enabled) +{ + ApplicationSettings::getInstance()->setVerboseIndexerLoggingEnabled(enabled); + ApplicationSettings::getInstance()->save(); + MessageRefresh msg; + msg.reloadSettings = true; + msg.uiOnly = true; + msg.dispatchImmediately(); +} + void QtLogView::refreshView() { m_refreshFunctor(); @@ -48,10 +148,111 @@ void QtLogView::clear() m_clearFunctor(); } +void QtLogView::addLog(Logger::LogLevel type, const LogMessage& message) +{ + m_addLogFunctor(type, message); +} + void QtLogView::doClear() { } void QtLogView::doRefreshView() { + setStyleSheet(); +} + +void QtLogView::setStyleSheet() const +{ + QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this); + utility::setWidgetBackgroundColor(widget, ColorScheme::getInstance()->getColor("error/background")); + + QPalette palette(m_showErrors->palette()); + palette.setColor(QPalette::WindowText, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str())); + //palette.setColor(QPalette::Text, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str())); + //palette.setColor(QPalette::ButtonText, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str())); + + //m_showErrors->setAutoFillBackground(true); + //m_showErrors->setPalette(palette); + //m_showFatals->setPalette(palette); + //m_showNonIndexedErrors->setPalette(palette); + //m_showNonIndexedFatals->setPalette(palette); + + widget->setStyleSheet( + utility::getStyleSheet(ResourcePaths::getGuiPath() + "error_view/error_view.css").c_str() + ); + + m_table->updateRows(); +} + +const char* QtLogView::getLogType(Logger::LogLevel type) const +{ + switch (type) + { + case Logger::LOG_INFOS: + return "INFO"; + case Logger::LOG_WARNINGS: + return "WARNING"; + case Logger::LOG_ERRORS: + return "ERROR"; + case Logger::LOG_ALL: + return "UNKNOWN"; + } +} + +bool QtLogView::isCheckedType(const Logger::LogLevel type) const +{ + return m_mask & type; +} + +void QtLogView::updateTable() +{ + if (!m_model->index(0, 0).data(Qt::DisplayRole).toString().isEmpty()) + { + m_model->removeRows(0, m_model->rowCount()); + } + + for ( Log log : m_logs ) + { + if (log.type & m_mask) + { + addLogToTable(log); + } + } +} + + +void QtLogView::updateMask() +{ + m_mask = + (m_showInfo->isChecked() ? Logger::LOG_INFOS : 0) + + (m_showWarnings->isChecked() ? Logger::LOG_WARNINGS : 0) + + (m_showErrors->isChecked() ? Logger::LOG_ERRORS : 0); +} + +void QtLogView::addLogToTable(Log log) +{ + const int rowNumber = m_table->getFilledRowCount(); + if (rowNumber < m_model->rowCount()) + { + m_model->insertRow(rowNumber); + } + + m_model->setItem(rowNumber, LOGVIEW_COLUMN::TYPE, new QStandardItem(getLogType(log.type))); + m_model->setItem(rowNumber, LOGVIEW_COLUMN::TIMESTAMP, new QStandardItem(log.timestamp.c_str())); + m_model->setItem(rowNumber, LOGVIEW_COLUMN::MESSAGE, new QStandardItem(log.message.c_str())); + m_table->updateRows(); +} + +void QtLogView::doAddLog(Logger::LogLevel type, const LogMessage& message) +{ + if (m_viewEnabled->isChecked() && isCheckedType(type)) + { + Log log( + type, + (message.getFileName().empty() ? "" : message.getFileName() + ": ") + message.message, + message.getTimeString("%H:%M:%S")); + m_logs.push_back(log); + addLogToTable(log); + } } diff --git a/src/lib_gui/qt/view/QtLogView.h b/src/lib_gui/qt/view/QtLogView.h index 1aeca69b..babc828f 100644 --- a/src/lib_gui/qt/view/QtLogView.h +++ b/src/lib_gui/qt/view/QtLogView.h @@ -1,11 +1,21 @@ #ifndef QT_LOG_VIEW_H #define QT_LOG_VIEW_H +#include + #include "component/view/LogView.h" #include "qt/utility/QtThreadedFunctor.h" +#include "utility/logging/Logger.h" + +class QBoxLayout; +class QCheckBox; +class QPalette; +class QStandardItemModel; +class QtTable; class QtLogView : public LogView + , public QWidget { public: QtLogView(ViewLayout* viewLayout); @@ -16,12 +26,59 @@ public: virtual void initView(); virtual void refreshView(); + // Log View Implementation virtual void clear(); + virtual void addLog(Logger::LogLevel type, const LogMessage& message); private: + enum LOGVIEW_COLUMN + { + TYPE = 0, + TIMESTAMP = 1, + MESSAGE = 2, + }; + + struct Log + { + Log(const Logger::LogLevel type, const std::string message, const std::string timestamp) + : type(type) + , message(message) + , timestamp(timestamp){} + const Logger::LogLevel type; + const std::string message; + const std::string timestamp; + }; void doClear(); void doRefreshView(); + void doAddLog(Logger::LogLevel type, const LogMessage& message); + std::vector m_logs; + const char* getLogType(Logger::LogLevel type) const; + void addLogToTable(Log log); + + bool isCheckedType(const Logger::LogLevel type) const; + QCheckBox* createFilterCheckbox(const QString& name, QBoxLayout* layout, bool checked = false); + + void setStyleSheet() const; + + void setLoggingEnabled(bool enabled); + void setAstLoggingEnabled(bool enabled); + + void updateMask(); + void updateTable(); + + int m_mask; + QtTable* m_table; + QStandardItemModel* m_model; + + QCheckBox* m_viewEnabled; + QCheckBox* m_showAstLogging; + + QCheckBox* m_showErrors; + QCheckBox* m_showWarnings; + QCheckBox* m_showInfo; + + QtThreadedFunctor m_addLogFunctor; QtThreadedFunctor m_clearFunctor; QtThreadedFunctor m_refreshFunctor; }; diff --git a/src/lib_gui/qt/window/QtIndexingDialog.cpp b/src/lib_gui/qt/window/QtIndexingDialog.cpp index 02a9038c..a3e7bafe 100644 --- a/src/lib_gui/qt/window/QtIndexingDialog.cpp +++ b/src/lib_gui/qt/window/QtIndexingDialog.cpp @@ -226,7 +226,7 @@ void QtIndexingDialog::handleClose() if (m_type == DIALOG_INDEXING) { - MessageInterruptTasks().dispatch(); + MessageInterruptTasks().dispatchImmediately(); return; }