Ali Hatami Tajik
5 months ago
22 changed files with 523 additions and 89 deletions
@ -0,0 +1,26 @@ |
|||
#include "DialogStartCaptur.h" |
|||
#include "ui_DialogStartCaptur.h" |
|||
|
|||
DialogStartCaptur::DialogStartCaptur(QWidget* parent) : |
|||
QDialog(parent), |
|||
ui(new Ui::DialogStartCaptur) |
|||
{ |
|||
ui->setupUi(this); |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
quint16 DialogStartCaptur::getPort() |
|||
{ |
|||
return static_cast<quint16>(ui->spinBox->value()); |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
QString DialogStartCaptur::getAddress() |
|||
{ |
|||
return ui->lineEdit->text(); |
|||
} |
|||
|
|||
DialogStartCaptur::~DialogStartCaptur() |
|||
{ |
|||
delete ui; |
|||
} |
@ -0,0 +1,24 @@ |
|||
#ifndef DIALOGSTARTCAPTUR_H |
|||
#define DIALOGSTARTCAPTUR_H |
|||
|
|||
#include <QDialog> |
|||
|
|||
namespace Ui { |
|||
class DialogStartCaptur; |
|||
} |
|||
|
|||
class DialogStartCaptur : public QDialog |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
explicit DialogStartCaptur(QWidget* parent = nullptr); |
|||
quint16 getPort(); |
|||
QString getAddress(); |
|||
~DialogStartCaptur(); |
|||
|
|||
private: |
|||
Ui::DialogStartCaptur* ui; |
|||
}; |
|||
|
|||
#endif //DIALOGSTARTCAPTUR_H
|
@ -0,0 +1,105 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<ui version="4.0"> |
|||
<class>DialogStartCaptur</class> |
|||
<widget class="QDialog" name="DialogStartCaptur"> |
|||
<property name="geometry"> |
|||
<rect> |
|||
<x>0</x> |
|||
<y>0</y> |
|||
<width>270</width> |
|||
<height>170</height> |
|||
</rect> |
|||
</property> |
|||
<property name="windowTitle"> |
|||
<string>Dialog</string> |
|||
</property> |
|||
<layout class="QVBoxLayout" name="verticalLayout"> |
|||
<item> |
|||
<widget class="QLineEdit" name="lineEdit"> |
|||
<property name="placeholderText"> |
|||
<string>Address</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<layout class="QHBoxLayout" name="horizontalLayout"> |
|||
<item> |
|||
<widget class="QLabel" name="label"> |
|||
<property name="text"> |
|||
<string>Port:</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<widget class="QSpinBox" name="spinBox"> |
|||
<property name="maximum"> |
|||
<number>65535</number> |
|||
</property> |
|||
<property name="value"> |
|||
<number>12345</number> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
</layout> |
|||
</item> |
|||
<item> |
|||
<spacer name="verticalSpacer"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Vertical</enum> |
|||
</property> |
|||
<property name="sizeHint" stdset="0"> |
|||
<size> |
|||
<width>20</width> |
|||
<height>40</height> |
|||
</size> |
|||
</property> |
|||
</spacer> |
|||
</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>DialogStartCaptur</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>DialogStartCaptur</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> |
@ -0,0 +1,38 @@ |
|||
#ifndef DATAMANAGER_H |
|||
#define DATAMANAGER_H |
|||
|
|||
#include <QObject> |
|||
|
|||
#include "data/filter/FilterParser.h" |
|||
#include "data/filter/IFilter.h" |
|||
#include "LogWarehouse.h" |
|||
|
|||
class DataManager : public QObject |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
DataManager(FilterCreator_ptr<Log_ptr> filterCreator); |
|||
|
|||
void clearLogs(); |
|||
void setFilter(QString filter); |
|||
|
|||
signals: |
|||
void badFilterRequested(QString message); |
|||
void logAdded(const Log_ptr log); |
|||
void logsReseted(QList<Log_ptr> logs); |
|||
|
|||
//uncrustify off
|
|||
public slots: |
|||
//uncrustify on
|
|||
void onLogProvided(Log_ptr log); |
|||
|
|||
private: |
|||
void resetView(); |
|||
|
|||
LogWarehouse_ptr _warehouse; |
|||
std::shared_ptr<IFilter<Log_ptr> > _filter; |
|||
FilterParser<Log_ptr> _parser; |
|||
}; |
|||
|
|||
#endif //DATAMANAGER_H
|
@ -0,0 +1,18 @@ |
|||
#ifndef MESSAGEFILTER |
|||
#define MESSAGEFILTER |
|||
|
|||
#include "type/Log.h" |
|||
#include "data/filter/IFilter.h" |
|||
|
|||
class MessageFilter : public IFilter<Log_ptr> |
|||
{ |
|||
public: |
|||
MessageFilter(QString filter); |
|||
|
|||
bool isAccepted(Log_ptr input) const override; |
|||
|
|||
private: |
|||
QString _filter; |
|||
}; |
|||
|
|||
#endif //MESSAGEFILTER
|
@ -0,0 +1,58 @@ |
|||
#include "data/DataManager.h" |
|||
|
|||
#include "data/filter/BypassFilter.h" |
|||
#include "data/filter/PrefixFilterFormatCreator.h" |
|||
|
|||
/*************************************************************************************************/ |
|||
DataManager::DataManager(FilterCreator_ptr<Log_ptr> filterCreator) : _parser(filterCreator) |
|||
{ |
|||
_filter = std::make_shared<BypassFilter>(); |
|||
_warehouse = std::make_shared<LogWarehouse>(); |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void DataManager::clearLogs() |
|||
{ |
|||
emit logsReseted({}); |
|||
_warehouse->clear(); |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void DataManager::setFilter(QString filter) |
|||
{ |
|||
try { |
|||
_filter = _parser.parse(filter); |
|||
resetView(); |
|||
} |
|||
catch(std::runtime_error e) |
|||
{ |
|||
_filter = std::make_shared<BypassFilter>(); |
|||
emit badFilterRequested(e.what()); |
|||
} |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void DataManager::onLogProvided(const Log_ptr log) |
|||
{ |
|||
_warehouse->addData(log); |
|||
if(_filter->isAccepted(log)) |
|||
{ |
|||
emit logAdded(log); |
|||
} |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void DataManager::resetView() |
|||
{ |
|||
QList<Log_ptr> logs; |
|||
for(int i = 0; i < _warehouse->getLength(); i++) |
|||
{ |
|||
auto log = _warehouse->getItem(i); |
|||
if(_filter->isAccepted(log)) |
|||
{ |
|||
logs.append(logs); |
|||
} |
|||
} |
|||
|
|||
emit logsReseted(logs); |
|||
} |
@ -0,0 +1,27 @@ |
|||
#include "data/filter/MessageFilter.h" |
|||
|
|||
/*************************************************************************************************/ |
|||
MessageFilter::MessageFilter(QString filter) |
|||
{ |
|||
_filter = filter; |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
bool MessageFilter::isAccepted(Log_ptr input) const |
|||
{ |
|||
if(input->msg.has_value()) |
|||
{ |
|||
for(auto& part : input->msg.value()) |
|||
{ |
|||
if(part.string.has_value()) |
|||
{ |
|||
if(part.string.value().contains(_filter)) |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
Loading…
Reference in new issue