ui: logview logic in controller
* logfilter in applicationsettings * logview limit 500 entries
This commit is contained in:
@@ -6,24 +6,23 @@
|
||||
#include "utility/messaging/type/MessageDispatchWhenLicenseValid.h"
|
||||
#include "utility/messaging/type/MessageLoadProject.h"
|
||||
#include "utility/logging/LogManager.h"
|
||||
#include "component/controller/LogController.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
|
||||
QtApplication::QtApplication(int& argc, char** argv)
|
||||
: QApplication(argc, argv)
|
||||
{
|
||||
connect(this, &QCoreApplication::aboutToQuit,
|
||||
[=]()
|
||||
{
|
||||
LogManager::getInstance()->setLoggingEnabled(false);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
int QtApplication::exec()
|
||||
{
|
||||
LogManager::getInstance()->setLoggingEnabled(ApplicationSettings::getInstance()->getLoggingEnabled());
|
||||
LogController* log = dynamic_cast<LogController*>(LogManager::getInstance()->getLoggerByType("WindowLogger"));
|
||||
if (log != nullptr)
|
||||
{
|
||||
log->setEnabled(true);
|
||||
}
|
||||
|
||||
return QCoreApplication::exec();
|
||||
return QApplication::exec();
|
||||
}
|
||||
|
||||
// responds to FileOpenEvent specific for Mac
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "settings/ColorScheme.h"
|
||||
#include "qt/view/QtViewWidgetWrapper.h"
|
||||
#include "utility/messaging/type/MessageRefresh.h"
|
||||
#include "utility/messaging/type/MessageLogFilterChanged.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "utility/logging/LogManager.h"
|
||||
@@ -20,6 +21,7 @@
|
||||
QtLogView::QtLogView(ViewLayout* viewLayout)
|
||||
: LogView(viewLayout)
|
||||
, m_addLogFunctor(std::bind(&QtLogView::doAddLog, this, std::placeholders::_1, std::placeholders::_2))
|
||||
, m_addLogsFunctor(std::bind(&QtLogView::doAddLogs, this, std::placeholders::_1 ))
|
||||
, m_clearFunctor(std::bind(&QtLogView::doClear, this))
|
||||
, m_refreshFunctor(std::bind(&QtLogView::doRefreshView, this))
|
||||
{
|
||||
@@ -46,8 +48,10 @@ void QtLogView::initView()
|
||||
QHBoxLayout* headerLayout = new QHBoxLayout();
|
||||
headerLayout->addSpacing(10);
|
||||
|
||||
ApplicationSettings* settings = ApplicationSettings::getInstance().get();
|
||||
|
||||
m_viewEnabled = new QCheckBox("Logging enabled (file, console logging)");
|
||||
m_viewEnabled->setChecked(ApplicationSettings::getInstance()->getLoggingEnabled());
|
||||
m_viewEnabled->setChecked(settings->getLoggingEnabled());
|
||||
|
||||
connect(m_viewEnabled, &QCheckBox::stateChanged,
|
||||
[=](int){
|
||||
@@ -58,7 +62,7 @@ void QtLogView::initView()
|
||||
headerLayout->addSpacing(25);
|
||||
m_showAstLogging = new QCheckBox("AST Logging");
|
||||
m_showAstLogging->setEnabled(m_viewEnabled->isChecked());
|
||||
m_showAstLogging->setChecked(ApplicationSettings::getInstance()->getVerboseIndexerLoggingEnabled());
|
||||
m_showAstLogging->setChecked(settings->getVerboseIndexerLoggingEnabled());
|
||||
connect(m_showAstLogging, &QCheckBox::stateChanged,
|
||||
[=](int){
|
||||
setAstLoggingEnabled(m_showAstLogging->isChecked());
|
||||
@@ -86,9 +90,11 @@ void QtLogView::initView()
|
||||
QHBoxLayout* filters = new QHBoxLayout();
|
||||
filters->addSpacing(15);
|
||||
|
||||
m_showErrors = createFilterCheckbox("error", filters, true);
|
||||
m_showWarnings = createFilterCheckbox("warnings", filters, true);
|
||||
m_showInfo = createFilterCheckbox("info", filters);
|
||||
m_logLevel = settings->getLogFilter();
|
||||
|
||||
m_showErrors = createFilterCheckbox("error", filters, m_logLevel & Logger::LOG_ERRORS);
|
||||
m_showWarnings = createFilterCheckbox("warnings", filters, m_logLevel & Logger::LOG_WARNINGS);
|
||||
m_showInfo = createFilterCheckbox("info", filters, m_logLevel & Logger::LOG_INFOS);
|
||||
|
||||
filters->addStretch();
|
||||
|
||||
@@ -98,7 +104,7 @@ void QtLogView::initView()
|
||||
{
|
||||
doClear();
|
||||
});
|
||||
filters->addWidget(clearButton);
|
||||
//filters->addWidget(clearButton);
|
||||
filters->addSpacing(30);
|
||||
|
||||
updateMask();
|
||||
@@ -131,7 +137,7 @@ QCheckBox* QtLogView::createFilterCheckbox(const QString& name, QBoxLayout* layo
|
||||
void QtLogView::setLoggingEnabled(bool enabled)
|
||||
{
|
||||
m_showAstLogging->setEnabled(enabled);
|
||||
LogManager::getInstance()->setLoggingEnabled(true);
|
||||
LogManager::getInstance()->setLoggingEnabled(enabled);
|
||||
|
||||
ApplicationSettings::getInstance()->setLoggingEnabled(enabled);
|
||||
ApplicationSettings::getInstance()->save();
|
||||
@@ -166,6 +172,11 @@ void QtLogView::addLog(Logger::LogLevel type, const LogMessage& message)
|
||||
m_addLogFunctor(type, message);
|
||||
}
|
||||
|
||||
void QtLogView::addLogs(const std::vector<Log>& logs)
|
||||
{
|
||||
m_addLogsFunctor(logs);
|
||||
}
|
||||
|
||||
void QtLogView::doClear()
|
||||
{
|
||||
if (!m_model->index(0, 0).data(Qt::DisplayRole).toString().isEmpty())
|
||||
@@ -221,7 +232,7 @@ const char* QtLogView::getLogType(Logger::LogLevel type) const
|
||||
|
||||
bool QtLogView::isCheckedType(const Logger::LogLevel type) const
|
||||
{
|
||||
return m_mask & type;
|
||||
return m_logLevel & type;
|
||||
}
|
||||
|
||||
void QtLogView::updateTable()
|
||||
@@ -233,20 +244,21 @@ void QtLogView::updateTable()
|
||||
|
||||
for ( Log log : m_logs )
|
||||
{
|
||||
if (log.type & m_mask)
|
||||
if (log.type & m_logLevel)
|
||||
{
|
||||
addLogToTable(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QtLogView::updateMask()
|
||||
{
|
||||
m_mask =
|
||||
m_logLevel =
|
||||
(m_showInfo->isChecked() ? Logger::LOG_INFOS : 0) +
|
||||
(m_showWarnings->isChecked() ? Logger::LOG_WARNINGS : 0) +
|
||||
(m_showErrors->isChecked() ? Logger::LOG_ERRORS : 0);
|
||||
|
||||
MessageLogFilterChanged(m_logLevel).dispatch();
|
||||
}
|
||||
|
||||
void QtLogView::addLogToTable(Log log)
|
||||
@@ -265,7 +277,7 @@ void QtLogView::addLogToTable(Log log)
|
||||
|
||||
void QtLogView::doAddLog(Logger::LogLevel type, const LogMessage& message)
|
||||
{
|
||||
if (isCheckedType(type))
|
||||
if (type & m_logLevel)
|
||||
{
|
||||
Log log(
|
||||
type,
|
||||
@@ -275,3 +287,16 @@ void QtLogView::doAddLog(Logger::LogLevel type, const LogMessage& message)
|
||||
addLogToTable(log);
|
||||
}
|
||||
}
|
||||
|
||||
void QtLogView::doAddLogs(const std::vector<Log>& logs)
|
||||
{
|
||||
doClear();
|
||||
for(Log log : logs)
|
||||
{
|
||||
if( log.type & m_logLevel )
|
||||
{
|
||||
addLogToTable(log);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ public:
|
||||
// Log View Implementation
|
||||
virtual void clear();
|
||||
virtual void addLog(Logger::LogLevel type, const LogMessage& message);
|
||||
virtual void addLogs(const std::vector<Log>& logs);
|
||||
|
||||
private:
|
||||
enum LOGVIEW_COLUMN
|
||||
@@ -38,23 +39,15 @@ private:
|
||||
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);
|
||||
void doAddLogs(const std::vector<Log>& logs);
|
||||
|
||||
std::vector<Log> m_logs;
|
||||
const char* getLogType(Logger::LogLevel type) const;
|
||||
void addLogToTable(Log log);
|
||||
void setLogFilter();
|
||||
|
||||
bool isCheckedType(const Logger::LogLevel type) const;
|
||||
QCheckBox* createFilterCheckbox(const QString& name, QBoxLayout* layout, bool checked = false);
|
||||
@@ -67,7 +60,7 @@ private:
|
||||
void updateMask();
|
||||
void updateTable();
|
||||
|
||||
int m_mask;
|
||||
Logger::LogLevelMask m_logLevel;
|
||||
QtTable* m_table;
|
||||
QStandardItemModel* m_model;
|
||||
|
||||
@@ -79,6 +72,7 @@ private:
|
||||
QCheckBox* m_showInfo;
|
||||
|
||||
QtThreadedFunctor<Logger::LogLevel, const LogMessage&> m_addLogFunctor;
|
||||
QtThreadedFunctor<const std::vector<Log>&> m_addLogsFunctor;
|
||||
QtThreadedFunctor<void> m_clearFunctor;
|
||||
QtThreadedFunctor<void> m_refreshFunctor;
|
||||
};
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "component/view/View.h"
|
||||
#include "component/view/CompositeView.h"
|
||||
#include "component/view/TabbedView.h"
|
||||
#include "component/controller/LogController.h"
|
||||
#include "LicenseChecker.h"
|
||||
#include "qt/utility/QtContextMenu.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
@@ -318,6 +319,11 @@ void QtMainWindow::contextMenuEvent(QContextMenuEvent* event)
|
||||
|
||||
void QtMainWindow::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
LogController* log = dynamic_cast<LogController*>(LogManager::getInstance()->getLoggerByType("WindowLogger"));
|
||||
if (log != nullptr)
|
||||
{
|
||||
log->setEnabled(false);
|
||||
}
|
||||
MessageWindowClosed().dispatch();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user