319 lines
12 KiB
C++
Executable File
319 lines
12 KiB
C++
Executable File
/*
|
|
* @RDE_HEADER@
|
|
* <short description>
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Malte Schröder, SLSE, 2016-07-14
|
|
*/
|
|
|
|
#include "mainwindow.h"
|
|
#include "cmbfilterwidget.h"
|
|
#include "sortfiltermodel.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include <QtWidgets/QFileDialog>
|
|
#include <QtCore/QDateTime>
|
|
#include <QtCore/QSortFilterProxyModel>
|
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
#include <QtWidgets/QMessageBox>
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, m_ui(new Ui::MainWindow)
|
|
, m_logfileModel(new LogViewTableModel(this))
|
|
, m_dateFilter(new DateFilterWidget())
|
|
, m_levelFilter(new LevelFilterWidget())
|
|
, m_loggerFilter(new LoggerFilterWidget())
|
|
, m_dataFilter(new DataFilterWidget())
|
|
, m_locationFilter(new LocationFilterWidget())
|
|
, m_filterProxyModel(new SortFilterModel(this))
|
|
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("MainWindow"))
|
|
, m_lbItemCount(new QLabel(this))
|
|
, m_lbCoords(new QLabel(this))
|
|
{
|
|
m_ui->setupUi(this);
|
|
m_filterProxyModel->setSourceModel(m_logfileModel);
|
|
m_ui->tvContent->setModel(m_filterProxyModel);
|
|
m_ui->tvContent->resizeColumnsToContents();
|
|
m_ui->tvContent->horizontalHeader()->setStretchLastSection(true);
|
|
m_lbItemCount->setText(tr("Items: \t0"));
|
|
m_lbCoords->setText(QLatin1String("x: \ty:"));
|
|
m_ui->statusBar->addPermanentWidget(m_lbItemCount, 2);
|
|
m_ui->statusBar->addPermanentWidget(m_lbCoords, 2);
|
|
this->setWindowState(Qt::WindowMaximized);
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete m_ui;
|
|
delete m_logfileModel;
|
|
delete m_filterProxyModel;
|
|
delete m_lbItemCount;
|
|
delete m_dateFilter;
|
|
delete m_levelFilter;
|
|
delete m_loggerFilter;
|
|
delete m_dataFilter;
|
|
delete m_locationFilter;
|
|
delete m_lbCoords;
|
|
}
|
|
|
|
bool MainWindow::init()
|
|
{
|
|
connect(m_ui->actionOpen, &QAction::triggered, this, &MainWindow::onActionOpen);
|
|
connect(m_ui->actionReset, &QAction::triggered, this, &MainWindow::onActionReset);
|
|
connect(m_ui->actionExit, &QAction::triggered, this, &MainWindow::close);
|
|
connect(m_ui->tvContent, &LogViewTableView::cellColorIsAboutToChange, m_logfileModel, &LogViewTableModel::adjustCellColor);
|
|
connect(m_ui->tvContent, &LogViewTableView::fontColorIsAboutToChange, m_logfileModel, &LogViewTableModel::adjustFontColor);
|
|
connect(m_ui->tvContent, &LogViewTableView::mouseMoved, this, &MainWindow::showPosition);
|
|
connect(m_dateFilter, &DateFilterWidget::dateStartFilterChanged, m_filterProxyModel, &SortFilterModel::setStartDateFilter);
|
|
connect(m_dateFilter, &DateFilterWidget::dateEndFilterChanged, m_filterProxyModel, &SortFilterModel::setEndDateFilter);
|
|
connect(m_ui->tvContent, &LogViewTableView::resetAllFilter, this, &MainWindow::onActionResetFilter);
|
|
|
|
connect(m_ui->tvContent, &LogViewTableView::whichFilterAreActivated, m_filterProxyModel, &SortFilterModel::figureFilterOut);
|
|
connect(m_filterProxyModel, &SortFilterModel::theseFilterAreActivated, m_ui->tvContent, &LogViewTableView::showActivatedFilter);
|
|
|
|
connect(m_dateFilter, &DateFilterWidget::setStartDateTime, m_logfileModel, &LogViewTableModel::startDateTime);
|
|
connect(m_logfileModel, &LogViewTableModel::startTimeSetted, m_dateFilter, &DateFilterWidget::setStartDateTimeValue);
|
|
|
|
connect(m_dateFilter, &DateFilterWidget::setEndDateTime, m_logfileModel, &LogViewTableModel::endDateTime);
|
|
connect(m_logfileModel, &LogViewTableModel::endTimeSetted, m_dateFilter, &DateFilterWidget::setEndDateTimeValue);
|
|
|
|
connect(m_ui->tvContent, &LogViewTableView::dateFilterIsAboutToChange, this, &MainWindow::setFilterDate);
|
|
connect(m_dateFilter, &DateFilterWidget::dateStartFilterChanged, m_ui->tvContent, &LogViewTableView::dateFilterIsAboutToChange);
|
|
|
|
connect(m_ui->tvContent, &LogViewTableView::dateFilterIsAboutToChange, this, &MainWindow::setFilterDate);
|
|
connect(m_dateFilter, &DateFilterWidget::dateEndFilterChanged, m_ui->tvContent, &LogViewTableView::dateFilterIsAboutToChange);
|
|
|
|
connect(m_ui->tvContent, &LogViewTableView::levelFilterIsAboutToChange, this, &MainWindow::setFilterLevel);
|
|
connect(m_levelFilter, &LevelFilterWidget::cmbTextChanged, m_ui->tvContent, &LogViewTableView::levelFilterIsAboutToChange);
|
|
|
|
connect(m_ui->tvContent, &LogViewTableView::loggerFilterIsAboutToChange, this, &MainWindow::setFilterLogger);
|
|
connect(m_loggerFilter, &LoggerFilterWidget::cmbTextChanged, m_ui->tvContent, &LogViewTableView::loggerFilterIsAboutToChange);
|
|
|
|
connect(m_ui->tvContent, &LogViewTableView::dataFilterIsAboutToChange, this, &MainWindow::setFilterData);
|
|
connect(m_dataFilter, &DataFilterWidget::contentTextChanged, m_ui->tvContent, &LogViewTableView::dataFilterIsAboutToChange);
|
|
|
|
connect(m_ui->tvContent, &LogViewTableView::locationFilterIsAboutToChange, this, &MainWindow::setFilterLocation);
|
|
connect(m_locationFilter, &LocationFilterWidget::contentTextChanged, m_ui->tvContent, &LogViewTableView::locationFilterIsAboutToChange);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
void MainWindow::onActionOpen()
|
|
{
|
|
const QString fileName = QFileDialog::getOpenFileName(this, tr("Open Logfile"), QString(), tr("Logfile (*.log) (*.log)"));
|
|
QFile file(fileName);
|
|
|
|
if (fileName.isEmpty())
|
|
return;
|
|
|
|
if (!file.exists() || !file.open(QIODevice::ReadOnly))
|
|
{
|
|
file.close();
|
|
return;
|
|
}
|
|
|
|
QByteArray ba = file.readAll();
|
|
file.close();
|
|
|
|
if (ba.isEmpty())
|
|
{
|
|
m_logfileModel->setData(QVector<LogViewTableModel::logInformation>());
|
|
return;
|
|
}
|
|
|
|
QString str(QString::fromUtf8(ba));
|
|
|
|
const QStringList strLines = str.split(QLatin1Char('\n'), QString::SkipEmptyParts);
|
|
for (const QString &tempLines : strLines)
|
|
{
|
|
const QStringList strWords = tempLines.split(QLatin1Char(' '), QString::SkipEmptyParts);
|
|
|
|
LogViewTableModel::logInformation li;
|
|
QDateTime firstDate;
|
|
|
|
// 2016-04-19 12:27:43,467 INFO zssiwi |#| Programm ist funktionsbereit (TDS-source-product/ZS/ZSSI/ZSSIWI/zssi_wi_Main.cpp:175)
|
|
for (int counter = 0; counter < strWords.size(); counter++)
|
|
{
|
|
if (counter >= 0 && counter <= 1) // 2016-04-19 12:27:43,467
|
|
{
|
|
if (firstDate.date().isNull())
|
|
{
|
|
if (counter == 0)
|
|
firstDate.setDate(QDate::fromString(strWords.at(counter), QLatin1String("yyyy-MM-dd")));
|
|
}
|
|
else
|
|
{
|
|
if (counter == 1)
|
|
{
|
|
firstDate.setTime(QTime::fromString(strWords.at(counter), QLatin1String("hh:mm:ss,zzz")));
|
|
li.date = firstDate;
|
|
}
|
|
}
|
|
}
|
|
else if (counter == 2) // INFO
|
|
li.level = strWords.at(counter);
|
|
else if (counter == 3) // zssiwi
|
|
li.logger = strWords.at(counter);
|
|
else // |#|
|
|
{
|
|
// |#| Programm ist funktionsbereit (TDS-source-product/ZS/ZSSI/ZSSIWI/zssi_wi_Main.cpp:175)
|
|
int index = tempLines.indexOf(QLatin1String("|#|"), 0) + 4;
|
|
|
|
if (index < 0)
|
|
return;
|
|
|
|
// Programm ist funktionsbereit (TDS-source-product/ZS/ZSSI/ZSSIWI/zssi_wi_Main.cpp:175)
|
|
QString subStrLines = tempLines.mid(index);
|
|
int lastOpenBracket = subStrLines.lastIndexOf(QLatin1Char('('));
|
|
|
|
if (lastOpenBracket < 0)
|
|
return;
|
|
|
|
QString debugStr = subStrLines.left(lastOpenBracket); // Programm ist funktionsbereit
|
|
QString fileLine = subStrLines.mid(lastOpenBracket + 1); // (TDS-source-product/ZS/ZSSI/ZSSIWI/zssi_wi_Main.cpp:175)
|
|
fileLine = fileLine.mid(0, fileLine.length() - 2);
|
|
|
|
li.data = debugStr;
|
|
li.location = fileLine;
|
|
}
|
|
}
|
|
m_logfileModel->addData(li);
|
|
}
|
|
|
|
m_ui->tvContent->setContentAvailable(true);
|
|
m_ui->actionReset->setEnabled(true);
|
|
m_ui->actionResetFilter->setEnabled(true);
|
|
m_ui->actionShowCurrentFilter->setEnabled(true);
|
|
m_ui->tvContent->resizeColumnsToContents();
|
|
m_ui->tvContent->horizontalHeader()->setStretchLastSection(true);
|
|
m_lbItemCount->setText(tr("Items: \t") + QString::number(m_logfileModel->rowCount(QModelIndex())));
|
|
}
|
|
|
|
|
|
void MainWindow::onActionReset()
|
|
{
|
|
int result = QMessageBox::critical(this, tr("Reset"), tr("Are you sure to reset the current view?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
|
|
if (result == QMessageBox::Yes)
|
|
{
|
|
m_logfileModel->reset();
|
|
m_lbItemCount->setText(tr("Items: \t") + QString::number(m_logfileModel->rowCount(QModelIndex())));
|
|
m_ui->actionReset->setEnabled(false);
|
|
m_ui->actionResetFilter->setEnabled(false);
|
|
m_ui->actionShowCurrentFilter->setEnabled(false);
|
|
m_ui->tvContent->setContentAvailable(false);
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::onActionResetFilter()
|
|
{
|
|
m_filterProxyModel->resetAllFilter();
|
|
m_lbItemCount->setText(tr("Items: \t") + QString::number(m_logfileModel->rowCount(QModelIndex())));
|
|
}
|
|
|
|
|
|
void MainWindow::showPosition(const QPoint &coords)
|
|
{
|
|
QString out;
|
|
out.append(tr("x: "));
|
|
out.append(QString::number(coords.x()));
|
|
out.append(QLatin1String("\ty: "));
|
|
out.append(QString::number(coords.y()));
|
|
m_lbCoords->setText(out);
|
|
}
|
|
|
|
|
|
void MainWindow::setFilterDate()
|
|
{
|
|
m_dateFilter->init();
|
|
m_filterProxyModel->setStartDateFilter(m_dateFilter->dtimeUp());
|
|
m_filterProxyModel->setEndDateFilter(m_dateFilter->dtimeTo());
|
|
m_filterProxyModel->setFilterKeyColumn(0);
|
|
|
|
m_filterProxyModel->invalidate();
|
|
m_lbItemCount->setText(tr("Items: \t") + QString::number(m_filterProxyModel->rowCount(QModelIndex())));
|
|
|
|
m_dateFilter->move(QCursor::pos() - QPoint(m_dateFilter->width() / 2, m_dateFilter->height() / 2));
|
|
m_dateFilter->show();
|
|
}
|
|
|
|
|
|
void MainWindow::setFilterLevel()
|
|
{
|
|
if (m_levelFilter->currentIndex() == 0)
|
|
m_filterProxyModel->setStringFilter(1, QString());
|
|
else
|
|
m_filterProxyModel->setStringFilter(1, m_levelFilter->currentText());
|
|
|
|
m_filterProxyModel->invalidate();
|
|
m_lbItemCount->setText(tr("Items: \t") + QString::number(m_filterProxyModel->rowCount(QModelIndex())));
|
|
|
|
if (!m_levelFilter->contentInside())
|
|
this->loadDataInCMB(1);
|
|
|
|
m_levelFilter->move(QCursor::pos() - QPoint(m_levelFilter->width() / 2, m_levelFilter->height() / 2));
|
|
m_levelFilter->show();
|
|
}
|
|
|
|
|
|
void MainWindow::setFilterLogger()
|
|
{
|
|
if (m_loggerFilter->currentIndex() == 0)
|
|
m_filterProxyModel->setStringFilter(2, QString());
|
|
else
|
|
m_filterProxyModel->setStringFilter(2, m_loggerFilter->currentText());
|
|
|
|
m_filterProxyModel->invalidate();
|
|
m_lbItemCount->setText(tr("Items: \t") + QString::number(m_filterProxyModel->rowCount(QModelIndex())));
|
|
|
|
if (!m_loggerFilter->contentInside())
|
|
this->loadDataInCMB(2);
|
|
|
|
m_loggerFilter->move(QCursor::pos() - QPoint(m_loggerFilter->width() / 2, m_loggerFilter->height() / 2));
|
|
m_loggerFilter->show();
|
|
}
|
|
|
|
|
|
void MainWindow::setFilterData()
|
|
{
|
|
m_filterProxyModel->setStringFilter(3, m_dataFilter->textContent());
|
|
m_filterProxyModel->invalidate();
|
|
m_lbItemCount->setText(tr("Items: \t") + QString::number(m_filterProxyModel->rowCount(QModelIndex())));
|
|
|
|
m_dataFilter->move(QCursor::pos() - QPoint(m_dataFilter->width() / 2, m_dataFilter->height() / 2));
|
|
m_dataFilter->show();
|
|
}
|
|
|
|
|
|
void MainWindow::setFilterLocation()
|
|
{
|
|
m_filterProxyModel->setStringFilter(4, m_locationFilter->textContent());
|
|
m_filterProxyModel->invalidate();
|
|
m_lbItemCount->setText(tr("Items: \t") + QString::number(m_filterProxyModel->rowCount(QModelIndex())));
|
|
|
|
m_locationFilter->move(QCursor::pos() - QPoint(m_locationFilter->width() / 2, m_locationFilter->height() / 2));
|
|
m_locationFilter->show();
|
|
}
|
|
|
|
|
|
void MainWindow::loadDataInCMB(int column)
|
|
{
|
|
QStringList strList;
|
|
strList.push_back(QLatin1String("- unfiltered -"));
|
|
strList.reserve(m_logfileModel->length());
|
|
for (int i = 0; i < m_logfileModel->length(); i++)
|
|
{
|
|
const QString val = m_logfileModel->itemAt(i, column);
|
|
if (!strList.contains(val))
|
|
strList.push_back(val);
|
|
}
|
|
|
|
if (column == 1)
|
|
m_levelFilter->addItems(strList);
|
|
else if (column == 2)
|
|
m_loggerFilter->addItems(strList);
|
|
}
|