|
|
|
#include "MainWindow.h"
|
|
|
|
#include "ui_MainWindow.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include "view/DialogStartCaptur.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"
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
MainWindow::MainWindow(QWidget* parent)
|
|
|
|
: QMainWindow(parent), _dataManager(std::make_shared<PrefixFilterFormatCreator>())
|
|
|
|
, ui(new Ui::MainWindow)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
prepareTableView();
|
|
|
|
prepareTreeView();
|
|
|
|
createConnections();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
void MainWindow::setTable(QAbstractItemModel* model)
|
|
|
|
{
|
|
|
|
ui->tableView->setModel(model);
|
|
|
|
|
|
|
|
connect(ui->tableView->selectionModel(),
|
|
|
|
&QItemSelectionModel::currentChanged,
|
|
|
|
this,
|
|
|
|
&MainWindow::onTableRowClicked);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
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::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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************************************/
|
|
|
|
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)));
|
|
|
|
}
|