diff --git a/gui/gui.pro b/gui/gui.pro index f15d36c..f899b59 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -17,6 +17,7 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp \ + view/AdvancedFilterDialog.cpp \ view/DialogStartCaptur.cpp \ view/MainWindow.cpp \ viewmodel/displayString/FilePathDisplay.cpp \ @@ -40,6 +41,7 @@ SOURCES += \ viewmodel/tree/util/Log2TreeItemConverter.cpp HEADERS += \ + view/AdvancedFilterDialog.h \ view/DialogStartCaptur.h \ view/MainWindow.h \ viewmodel/displayString/DisplayProviderCreator.h \ @@ -67,6 +69,7 @@ HEADERS += \ viewmodel/tree/util/Log2TreeItemConverter.h FORMS += \ + view/AdvancedFilterDialog.ui \ view/DialogStartCaptur.ui \ view/MainWindow.ui diff --git a/gui/view/AdvancedFilterDialog.cpp b/gui/view/AdvancedFilterDialog.cpp new file mode 100644 index 0000000..d9a860c --- /dev/null +++ b/gui/view/AdvancedFilterDialog.cpp @@ -0,0 +1,65 @@ +#include "AdvancedFilterDialog.h" +#include "ui_AdvancedFilterDialog.h" + +AdvancedFilterDialog::AdvancedFilterDialog(QWidget* parent) : + QDialog(parent), + ui(new Ui::AdvancedFilterDialog) +{ + ui->setupUi(this); + makeConnections(); +} + +AdvancedFilterDialog::~AdvancedFilterDialog() +{ + delete ui; +} + +/*************************************************************************************************/ +void AdvancedFilterDialog::setActiveScopes(QMap options) +{ + QMap::const_iterator i; + for(i = options.constBegin(); i != options.constEnd(); i++) + { + auto item = new QListWidgetItem(i.key(), ui->listWidget); + item->setCheckState(i.value() ? Qt::Checked : Qt::Unchecked); + ui->listWidget->addItem(item); + } +} + +/*************************************************************************************************/ +QMap AdvancedFilterDialog::getActiveScopes() const +{ + QMap options; + for(int i = 0; i < ui->listWidget->count(); ++i) + { + QListWidgetItem* item = ui->listWidget->item(i); + options[item->text()] = item->checkState() == Qt::Checked; + } + + return options; +} + +/*************************************************************************************************/ +void AdvancedFilterDialog::checkAll() +{ + for(int i = 0; i < ui->listWidget->count(); ++i) + { + ui->listWidget->item(i)->setCheckState(Qt::Checked); + } +} + +/*************************************************************************************************/ +void AdvancedFilterDialog::uncheckAll() +{ + for(int i = 0; i < ui->listWidget->count(); ++i) + { + ui->listWidget->item(i)->setCheckState(Qt::Unchecked); + } +} + +/*************************************************************************************************/ +void AdvancedFilterDialog::makeConnections() +{ + connect(ui->checkAllButton, &QPushButton::clicked, this, &AdvancedFilterDialog::checkAll); + connect(ui->uncheckAllButton, &QPushButton::clicked, this, &AdvancedFilterDialog::uncheckAll); +} diff --git a/gui/view/AdvancedFilterDialog.h b/gui/view/AdvancedFilterDialog.h new file mode 100644 index 0000000..eca06da --- /dev/null +++ b/gui/view/AdvancedFilterDialog.h @@ -0,0 +1,33 @@ +#ifndef ADVANCEDFILTERDIALOG_H +#define ADVANCEDFILTERDIALOG_H + +#include + +namespace Ui { +class AdvancedFilterDialog; +} + +class AdvancedFilterDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AdvancedFilterDialog(QWidget* parent = nullptr); + ~AdvancedFilterDialog(); + + void setActiveScopes(QMap options); + QMap getActiveScopes() const; + +//uncrustify off +public slots: +//uncrustify on + void checkAll(); + void uncheckAll(); + +private: + Ui::AdvancedFilterDialog* ui; + + void makeConnections(); +}; + +#endif //ADVANCEDFILTERDIALOG_H diff --git a/gui/view/AdvancedFilterDialog.ui b/gui/view/AdvancedFilterDialog.ui new file mode 100644 index 0000000..f2ebad8 --- /dev/null +++ b/gui/view/AdvancedFilterDialog.ui @@ -0,0 +1,104 @@ + + + AdvancedFilterDialog + + + + 0 + 0 + 630 + 527 + + + + Dialog + + + + + + 0 + + + + Active Scopes + + + + + + + + + + + Check All + + + + + + + Uncheck All + + + + + + + + + + TODO + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AdvancedFilterDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AdvancedFilterDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/view/MainWindow.cpp b/gui/view/MainWindow.cpp index 944e1a2..70f53fe 100644 --- a/gui/view/MainWindow.cpp +++ b/gui/view/MainWindow.cpp @@ -5,14 +5,15 @@ #include #include "view/DialogStartCaptur.h" +#include "view/AdvancedFilterDialog.h" -#include "viewmodel/table/ELogColumn.h" #include "viewmodel/tree/LogTreeModel.h" #include "viewmodel/table/LogTableModel.h" #include "viewmodel/displayString/SimpleDisplayProviderCreator.h" #include "data/filter/PrefixFilterFormatCreator.h" #include "provider/NetworkProvider.h" #include "parser/JsonParser.h" +#include "loggerV2/type/ELogScope.h" /*************************************************************************************************/ MainWindow::MainWindow(QWidget* parent) @@ -23,6 +24,7 @@ MainWindow::MainWindow(QWidget* parent) prepareTableView(); prepareTreeView(); createConnections(); + prepareAdvancedFilters(); } /*************************************************************************************************/ @@ -42,6 +44,12 @@ void MainWindow::setTable(QAbstractItemModel* model) &MainWindow::onTableRowClicked); } +/*************************************************************************************************/ +void MainWindow::setDefaultAdvancedFilters(AdvancedFilterDto dto) +{ + _aFDto = dto; +} + /*************************************************************************************************/ void MainWindow::onTableRowClicked(const QModelIndex& current, const QModelIndex& previous) { @@ -93,6 +101,22 @@ void MainWindow::onFilterTextSubmitted() handleFilterChange(); } +/*************************************************************************************************/ +void MainWindow::onAdvancedFilterRequested() +{ + AdvancedFilterDialog af; + af.setActiveScopes(_aFDto._activeScopes); + + af.setModal(true); + int isOk = af.exec(); + + if(isOk) + { + _aFDto._activeScopes = af.getActiveScopes(); + _dataManager.setAdvancedFilters(_aFDto); + } +} + /*************************************************************************************************/ void MainWindow::onFilterError(QString msg) { @@ -140,10 +164,27 @@ void MainWindow::createConnections() connect(ui->filterEdit, &QLineEdit::textChanged, this, &MainWindow::onFilterTextChanged); connect(ui->filterEdit, &QLineEdit::returnPressed, this, &MainWindow::onFilterTextSubmitted); + connect(ui->filterSubmit, &QPushButton::clicked, this, &MainWindow::onFilterTextSubmitted); + connect(ui->advancedButton, &QPushButton::clicked, this, + &MainWindow::onAdvancedFilterRequested); + connect(&_dataManager, &DataManager::badFilterRequested, this, &MainWindow::onFilterError); } +/*************************************************************************************************/ +void MainWindow::prepareAdvancedFilters() +{ + QMetaEnum e = QMetaEnum::fromType(); + QMap scopeFilters; + for(int k = 0; k < e.keyCount(); k++) + { + scopeFilters[e.key(k)] = true; + } + + setDefaultAdvancedFilters(AdvancedFilterDto{scopeFilters}); +} + /*************************************************************************************************/ QString MainWindow::getCurrentFilter() { diff --git a/gui/view/MainWindow.h b/gui/view/MainWindow.h index 6111fc2..242ac37 100644 --- a/gui/view/MainWindow.h +++ b/gui/view/MainWindow.h @@ -7,6 +7,7 @@ #include "data/DataManager.h" #include "provider/IProvider.h" +#include "type/AdvancedFilterDto.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; @@ -21,6 +22,7 @@ public: MainWindow(QWidget* parent = nullptr); ~MainWindow(); void setTable(QAbstractItemModel* model); + void setDefaultAdvancedFilters(AdvancedFilterDto dto); //uncrustify off private slots: @@ -29,6 +31,7 @@ private slots: void onActionStartCapture(bool trigered); void onFilterTextSubmitted(); + void onAdvancedFilterRequested(); void onFilterError(QString msg); void onFilterTextChanged(); //uncrustify on @@ -37,6 +40,7 @@ private: void prepareTableView(); void prepareTreeView(); void createConnections(); + void prepareAdvancedFilters(); QString getCurrentFilter(); void handleFilterChange(); @@ -46,6 +50,7 @@ private: DataManager _dataManager; DataProvider_ptr _dataProvider; Ui::MainWindow* ui; + AdvancedFilterDto _aFDto; }; #endif //MAINWINDOW_H diff --git a/gui/viewmodel/tree/util/Log2TreeItemConverter.cpp b/gui/viewmodel/tree/util/Log2TreeItemConverter.cpp index 8e6dca8..8a37bcc 100644 --- a/gui/viewmodel/tree/util/Log2TreeItemConverter.cpp +++ b/gui/viewmodel/tree/util/Log2TreeItemConverter.cpp @@ -72,6 +72,8 @@ void SimpleLog2TreeItemConverter::addMsgItem(const Log_ptr log, const ILog2TreeItemConvertor::TMap& translatorMap, TreeItem* parent) const { + Q_UNUSED(translatorMap) + if(log->msg.has_value()) { auto msgRoot = std::make_unique(QVariantList{"Message", ""}); diff --git a/logger b/logger index 20bb40c..5d8ca71 160000 --- a/logger +++ b/logger @@ -1 +1 @@ -Subproject commit 20bb40c9e53a350e237a6b436a69a3e578e4f39b +Subproject commit 5d8ca71f73c1f80326dbdfaafb6a8a6d3a74bf40 diff --git a/model/include/data/DataManager.h b/model/include/data/DataManager.h index 65aec75..6102cd9 100644 --- a/model/include/data/DataManager.h +++ b/model/include/data/DataManager.h @@ -4,6 +4,7 @@ #include #include "data/filter/FilterParser.h" +#include "type/AdvancedFilterDto.h" #include "data/filter/IFilter.h" #include "LogWarehouse.h" @@ -16,6 +17,7 @@ public: void clearLogs(); void setFilter(QString filter); + void setAdvancedFilters(AdvancedFilterDto dto); signals: void badFilterRequested(QString message); @@ -30,9 +32,11 @@ public slots: private: void resetView(); void setFilter(std::shared_ptr > filter); + bool isLogAccepted(const Log_ptr& log); LogWarehouse_ptr _warehouse; std::shared_ptr > _filter; + std::shared_ptr > _advancedFilter; FilterParser _filterParser; }; diff --git a/model/include/data/filter/AdvancedFilter.h b/model/include/data/filter/AdvancedFilter.h new file mode 100644 index 0000000..8028a3b --- /dev/null +++ b/model/include/data/filter/AdvancedFilter.h @@ -0,0 +1,23 @@ +#ifndef ADVANCEDFILTER_H +#define ADVANCEDFILTER_H + +#include "type/Log.h" +#include "data/filter/IFilter.h" +#include "type/AdvancedFilterDto.h" + +class AdvancedFilter : public IFilter +{ +public: + AdvancedFilter(AdvancedFilterDto dto); + ~AdvancedFilter() override; + + bool isAccepted(Log_ptr input) const override; + +private: + QList _acceptedScopes; + + void initAcceptedScopes(const QMap& acceptanceMap); + bool isScopesAccepted(const Log_ptr& input) const; +}; + +#endif //AdvancedFilter_H diff --git a/model/include/type/AdvancedFilterDto.h b/model/include/type/AdvancedFilterDto.h new file mode 100644 index 0000000..562c11d --- /dev/null +++ b/model/include/type/AdvancedFilterDto.h @@ -0,0 +1,12 @@ +#ifndef ADVANCEDFILTERDTO_H +#define ADVANCEDFILTERDTO_H + +#include +#include + +struct AdvancedFilterDto +{ + QMap _activeScopes; +}; + +#endif // ADVANCEDFILTERDTO_H diff --git a/model/model.pro b/model/model.pro index af21743..e5b9a16 100644 --- a/model/model.pro +++ b/model/model.pro @@ -9,6 +9,7 @@ HEADERS += \ include/LogWarehouse.h \ include/conf/Strings.h \ include/data/DataManager.h \ + include/data/filter/AdvancedFilter.h \ include/data/filter/BypassFilter.h \ include/data/filter/CommandFilter.h \ include/data/filter/FilterAnd.h \ @@ -23,6 +24,7 @@ HEADERS += \ include/parser/JsonParser.h \ include/provider/IProvider.h \ include/provider/NetworkProvider.h \ + include/type/AdvancedFilterDto.h \ include/type/Log.h \ include/type/ELogLevel.h \ include/type/MessagePart.h \ @@ -33,6 +35,7 @@ HEADERS += \ SOURCES += \ src/LogWarehouse.cpp \ src/data/DataManager.cpp \ + src/data/filter/AdvancedFilter.cpp \ src/data/filter/BypassFilter.cpp \ src/data/filter/CommandFilter.cpp \ src/data/filter/FilterAnd.cpp \ diff --git a/model/src/data/DataManager.cpp b/model/src/data/DataManager.cpp index a0f7c07..f9d7b09 100644 --- a/model/src/data/DataManager.cpp +++ b/model/src/data/DataManager.cpp @@ -1,12 +1,13 @@ #include "data/DataManager.h" #include "data/filter/BypassFilter.h" -#include "data/filter/PrefixFilterFormatCreator.h" +#include "data/filter/AdvancedFilter.h" /*************************************************************************************************/ DataManager::DataManager(FilterCreator_ptr filterCreator) : _filterParser(filterCreator) { _filter = std::make_shared >(); + _advancedFilter = std::make_shared >(); _warehouse = std::make_shared(); } @@ -23,18 +24,25 @@ void DataManager::setFilter(QString filter) try { setFilter(_filterParser.parse(filter)); } - catch(std::runtime_error e) + catch(std::runtime_error& e) { setFilter(std::make_shared >()); emit badFilterRequested(e.what()); } } +/*************************************************************************************************/ +void DataManager::setAdvancedFilters(AdvancedFilterDto dto) +{ + _advancedFilter = std::make_shared(dto); + resetView(); +} + /*************************************************************************************************/ void DataManager::onLogProvided(const Log_ptr log) { _warehouse->addData(log); - if(_filter->isAccepted(log)) + if(isLogAccepted(log)) { emit logAdded(log); } @@ -47,7 +55,7 @@ void DataManager::resetView() for(int i = 0; i < _warehouse->getLength(); i++) { auto log = _warehouse->getItem(i); - if(_filter->isAccepted(log)) + if(isLogAccepted(log)) { logs.append(log); } @@ -69,3 +77,9 @@ void DataManager::setFilter(std::shared_ptr > filter) resetView(); } } + +/*************************************************************************************************/ +bool DataManager::isLogAccepted(const Log_ptr& log) +{ + return _filter->isAccepted(log) and _advancedFilter->isAccepted(log); +} diff --git a/model/src/data/filter/AdvancedFilter.cpp b/model/src/data/filter/AdvancedFilter.cpp new file mode 100644 index 0000000..378c61f --- /dev/null +++ b/model/src/data/filter/AdvancedFilter.cpp @@ -0,0 +1,41 @@ +#include "data/filter/AdvancedFilter.h" + +/*************************************************************************************************/ +AdvancedFilter::AdvancedFilter(AdvancedFilterDto dto) +{ + initAcceptedScopes(dto._activeScopes); +} + +/*************************************************************************************************/ +AdvancedFilter::~AdvancedFilter() +{ +} + +/*************************************************************************************************/ +bool AdvancedFilter::isAccepted(Log_ptr input) const +{ + bool isPassed = true; + + isPassed &= isScopesAccepted(input); + + return isPassed; +} + +/*************************************************************************************************/ +void AdvancedFilter::initAcceptedScopes(const QMap& acceptanceMap) +{ + QMap::const_iterator i; + for(i = acceptanceMap.constBegin(); i != acceptanceMap.constEnd(); i++) + { + if(i.value()) + { + _acceptedScopes.append(i.key()); + } + } +} + +/*************************************************************************************************/ +bool AdvancedFilter::isScopesAccepted(const Log_ptr& input) const +{ + return _acceptedScopes.contains(input->scope.value_or("")); +} diff --git a/model/src/provider/NetworkProvider.cpp b/model/src/provider/NetworkProvider.cpp index cbddd76..c66a7be 100644 --- a/model/src/provider/NetworkProvider.cpp +++ b/model/src/provider/NetworkProvider.cpp @@ -2,7 +2,6 @@ #include #include -#include "parser/JsonParser.h" #include #include @@ -13,21 +12,6 @@ NetworkProvider::NetworkProvider(QHostAddress hostAddress, quint16 port) _port = port; _isRunning = false; initServer(); - -//connect(&_timer, &QTimer::timeout, -//[this](){ -//QString jsonString = -//R"( -//{"id":"stderr","level":1,"location":{"file":"../../../host-projects/sono/logic/src/viewModel/factory/ApplicationStarter.cpp","func":"init","lineno":69},"msg":["Lanat\n"],"scope":"global","threadId":124330260010752,"timestamp":1716911725703} -//)"; -//Log_ptr log = JsonParser().parse(jsonString); -//static int a = 69; -//log->src->lineNumner = a++; - -//emit provided(log); -//}); - -//_timer.start(1000); } /*************************************************************************************************/ @@ -60,6 +44,7 @@ void NetworkProvider::stopServer() /*************************************************************************************************/ void NetworkProvider::onErrorOccured(QAbstractSocket::SocketError error) { + Q_UNUSED(error) //Handle Error } @@ -78,7 +63,7 @@ void NetworkProvider::createNewConnection() emit provided(log); } } - catch(std::exception e) + catch(std::exception& e) { } }