You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
214 lines
7.2 KiB
214 lines
7.2 KiB
#include "MainWindow.h"
|
|
#include "ui_MainWindow.h"
|
|
|
|
#include <QDebug>
|
|
#include <QCompleter>
|
|
|
|
#include "view/DialogStartCaptur.h"
|
|
#include "view/AdvancedFilterDialog.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)
|
|
: QMainWindow(parent), _dataManager(std::make_shared<PrefixFilterFormatCreator>())
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
prepareTableView();
|
|
prepareTreeView();
|
|
createConnections();
|
|
prepareAdvancedFilters();
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void MainWindow::setTable(QAbstractItemModel* model)
|
|
{
|
|
ui->tableView->setModel(model);
|
|
|
|
connect(ui->tableView->selectionModel(),
|
|
&QItemSelectionModel::currentChanged,
|
|
this,
|
|
&MainWindow::onTableRowClicked);
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void MainWindow::setDefaultAdvancedFilters(AdvancedFilterDto dto)
|
|
{
|
|
_aFDto = dto;
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void MainWindow::onTableRowClicked(const QModelIndex& current, const QModelIndex& previous)
|
|
{
|
|
Q_UNUSED(previous)
|
|
|
|
QAbstractItemModel* abstractModel = ui->tableView->model();
|
|
LogTableModel* tablemodel = dynamic_cast<LogTableModel*>(abstractModel);
|
|
|
|
if(current.isValid())
|
|
{
|
|
auto log = tablemodel->data(current, Qt::UserRole).value<Log_ptr>();
|
|
|
|
QAbstractItemModel* treeAbstractModel = ui->treeView->model();
|
|
TreeModel* treemodel = dynamic_cast<TreeModel*>(treeAbstractModel);
|
|
treemodel->showSelectedLog(log);
|
|
}
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void MainWindow::onTableDeselected()
|
|
{
|
|
QAbstractItemModel* treeAbstractModel = ui->treeView->model();
|
|
TreeModel* treemodel = dynamic_cast<TreeModel*>(treeAbstractModel);
|
|
treemodel->clearView();
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void MainWindow::onActionStartCapture(bool trigered)
|
|
{
|
|
Q_UNUSED(trigered)
|
|
|
|
DialogStartCaptur capture;
|
|
|
|
capture.setModal(true);
|
|
int isOk = capture.exec();
|
|
|
|
if(isOk)
|
|
{
|
|
auto port = capture.getPort();
|
|
auto address = capture.getAddress();
|
|
qDebug() << address << port;
|
|
useNetworkProvider(address, port);
|
|
}
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
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)
|
|
{
|
|
ui->filterEdit->setStyleSheet("QLineEdit { background-color: #EF9A9A; }");
|
|
ui->statusbar->showMessage(msg, 5000);
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void MainWindow::onFilterTextChanged()
|
|
{
|
|
ui->filterEdit->setStyleSheet("");
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void MainWindow::prepareTableView()
|
|
{
|
|
ui->tableView->verticalHeader()->setVisible(false);
|
|
ui->tableView->horizontalHeader()->setSectionResizeMode(
|
|
QHeaderView::ResizeMode::ResizeToContents);
|
|
ui->tableView->horizontalHeader()->setStretchLastSection(true);
|
|
ui->tableView->horizontalHeader()->setSectionsMovable(true);
|
|
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
LogTableModel* tableModel = new LogTableModel();
|
|
tableModel->setDisplayProviderCreator(std::make_shared<SimpleDisplayProviderCreator>());
|
|
setTable(tableModel);
|
|
|
|
connect(&_dataManager, &DataManager::logAdded, tableModel, &LogTableModel::onLogAdded);
|
|
connect(&_dataManager, &DataManager::logsReseted, tableModel, &LogTableModel::onLogsChanged);
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void MainWindow::prepareTreeView()
|
|
{
|
|
ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
auto tm = new TreeModel();
|
|
ui->treeView->setModel(tm);
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void MainWindow::createConnections()
|
|
{
|
|
connect(ui->actionStart_Capture, &QAction::triggered, this, &MainWindow::onActionStartCapture);
|
|
|
|
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()
|
|
{
|
|
return ui->filterEdit->text();
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void MainWindow::handleFilterChange()
|
|
{
|
|
auto filter = getCurrentFilter();
|
|
_dataManager.setFilter(filter);
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void MainWindow::useNetworkProvider(QString address, quint16 port)
|
|
{
|
|
auto netProv = std::make_shared<NetworkProvider>(QHostAddress(address), port);
|
|
netProv->setParser(std::make_shared<JsonParser>());
|
|
|
|
_dataProvider = netProv;
|
|
connect(dynamic_cast<QObject*>(_dataProvider.get()),
|
|
SIGNAL(provided(const Log_ptr)),
|
|
&_dataManager,
|
|
SLOT(onLogProvided(const Log_ptr)));
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
|