Browse Source

Add active scope advanced search

basic-view
Ali Hatami Tajik 4 months ago
parent
commit
716ee90e42
  1. 3
      gui/gui.pro
  2. 65
      gui/view/AdvancedFilterDialog.cpp
  3. 33
      gui/view/AdvancedFilterDialog.h
  4. 104
      gui/view/AdvancedFilterDialog.ui
  5. 43
      gui/view/MainWindow.cpp
  6. 5
      gui/view/MainWindow.h
  7. 2
      gui/viewmodel/tree/util/Log2TreeItemConverter.cpp
  8. 2
      logger
  9. 4
      model/include/data/DataManager.h
  10. 23
      model/include/data/filter/AdvancedFilter.h
  11. 12
      model/include/type/AdvancedFilterDto.h
  12. 3
      model/model.pro
  13. 22
      model/src/data/DataManager.cpp
  14. 41
      model/src/data/filter/AdvancedFilter.cpp
  15. 19
      model/src/provider/NetworkProvider.cpp

3
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

65
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<QString, bool> options)
{
QMap<QString, bool>::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<QString, bool> AdvancedFilterDialog::getActiveScopes() const
{
QMap<QString, bool> 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);
}

33
gui/view/AdvancedFilterDialog.h

@ -0,0 +1,33 @@
#ifndef ADVANCEDFILTERDIALOG_H
#define ADVANCEDFILTERDIALOG_H
#include <QDialog>
namespace Ui {
class AdvancedFilterDialog;
}
class AdvancedFilterDialog : public QDialog
{
Q_OBJECT
public:
explicit AdvancedFilterDialog(QWidget* parent = nullptr);
~AdvancedFilterDialog();
void setActiveScopes(QMap<QString, bool> options);
QMap<QString, bool> getActiveScopes() const;
//uncrustify off
public slots:
//uncrustify on
void checkAll();
void uncheckAll();
private:
Ui::AdvancedFilterDialog* ui;
void makeConnections();
};
#endif //ADVANCEDFILTERDIALOG_H

104
gui/view/AdvancedFilterDialog.ui

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AdvancedFilterDialog</class>
<widget class="QDialog" name="AdvancedFilterDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>630</width>
<height>527</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Active Scopes</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="checkAllButton">
<property name="text">
<string>Check All</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="uncheckAllButton">
<property name="text">
<string>Uncheck All</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>TODO</string>
</attribute>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AdvancedFilterDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AdvancedFilterDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

43
gui/view/MainWindow.cpp

@ -5,14 +5,15 @@
#include <QCompleter>
#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<ELogScope>();
QMap<QString, bool> scopeFilters;
for(int k = 0; k < e.keyCount(); k++)
{
scopeFilters[e.key(k)] = true;
}
setDefaultAdvancedFilters(AdvancedFilterDto{scopeFilters});
}
/*************************************************************************************************/
QString MainWindow::getCurrentFilter()
{

5
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

2
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<TreeItem>(QVariantList{"Message", ""});

2
logger

@ -1 +1 @@
Subproject commit 20bb40c9e53a350e237a6b436a69a3e578e4f39b
Subproject commit 5d8ca71f73c1f80326dbdfaafb6a8a6d3a74bf40

4
model/include/data/DataManager.h

@ -4,6 +4,7 @@
#include <QObject>
#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<IFilter<Log_ptr> > filter);
bool isLogAccepted(const Log_ptr& log);
LogWarehouse_ptr _warehouse;
std::shared_ptr<IFilter<Log_ptr> > _filter;
std::shared_ptr<IFilter<Log_ptr> > _advancedFilter;
FilterParser<Log_ptr> _filterParser;
};

23
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<Log_ptr>
{
public:
AdvancedFilter(AdvancedFilterDto dto);
~AdvancedFilter() override;
bool isAccepted(Log_ptr input) const override;
private:
QList<QString> _acceptedScopes;
void initAcceptedScopes(const QMap<QString, bool>& acceptanceMap);
bool isScopesAccepted(const Log_ptr& input) const;
};
#endif //AdvancedFilter_H

12
model/include/type/AdvancedFilterDto.h

@ -0,0 +1,12 @@
#ifndef ADVANCEDFILTERDTO_H
#define ADVANCEDFILTERDTO_H
#include <QMap>
#include <QString>
struct AdvancedFilterDto
{
QMap<QString, bool> _activeScopes;
};
#endif // ADVANCEDFILTERDTO_H

3
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 \

22
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<Log_ptr> filterCreator) : _filterParser(filterCreator)
{
_filter = std::make_shared<BypassFilter<Log_ptr> >();
_advancedFilter = std::make_shared<BypassFilter<Log_ptr> >();
_warehouse = std::make_shared<LogWarehouse>();
}
@ -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<BypassFilter<Log_ptr> >());
emit badFilterRequested(e.what());
}
}
/*************************************************************************************************/
void DataManager::setAdvancedFilters(AdvancedFilterDto dto)
{
_advancedFilter = std::make_shared<AdvancedFilter>(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<IFilter<Log_ptr> > filter)
resetView();
}
}
/*************************************************************************************************/
bool DataManager::isLogAccepted(const Log_ptr& log)
{
return _filter->isAccepted(log) and _advancedFilter->isAccepted(log);
}

41
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<QString, bool>& acceptanceMap)
{
QMap<QString, bool>::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(""));
}

19
model/src/provider/NetworkProvider.cpp

@ -2,7 +2,6 @@
#include <QThread>
#include <QTimer>
#include "parser/JsonParser.h"
#include <QTcpSocket>
#include <QtConcurrent/QtConcurrent>
@ -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)
{
}
}

Loading…
Cancel
Save