LogsWindow: Add basic UI and infra
This commit is contained in:
parent
9a4e7e7550
commit
d0def8a0ec
138
client/logsmodel.cpp
Normal file
138
client/logsmodel.cpp
Normal file
@ -0,0 +1,138 @@
|
||||
/*
|
||||
Copyright (C) 2018 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "logsmodel.h"
|
||||
|
||||
#include <QBrush>
|
||||
|
||||
// XXX: Keep the enum in sync with it's string
|
||||
enum {
|
||||
kTimeStamp,
|
||||
kLogLevel,
|
||||
kPort,
|
||||
kMessage,
|
||||
kFieldCount
|
||||
};
|
||||
static QStringList columnTitles = QStringList()
|
||||
<< "Timestamp"
|
||||
<< "Level"
|
||||
<< "Port"
|
||||
<< "Message";
|
||||
|
||||
static QStringList levelTitles = QStringList()
|
||||
<< "Error"
|
||||
<< "Warning"
|
||||
<< "Info";
|
||||
|
||||
LogsModel::LogsModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
// FIXME: test only
|
||||
log(kInfo, QString("--"), QString("Welcome to Ostinato!"));
|
||||
log(kWarning, QString("--"), QString("This is a sample warning!"));
|
||||
log(kError, QString("--"), QString("This is a sample error!"));
|
||||
}
|
||||
|
||||
int LogsModel::rowCount(const QModelIndex &/*parent*/) const
|
||||
{
|
||||
return logs_.size();
|
||||
}
|
||||
|
||||
int LogsModel::columnCount(const QModelIndex &/*parent*/) const
|
||||
{
|
||||
if (!logs_.size())
|
||||
return 0;
|
||||
|
||||
return kFieldCount;
|
||||
}
|
||||
|
||||
QVariant LogsModel::headerData(
|
||||
int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
switch (orientation) {
|
||||
case Qt::Horizontal: // Column Header
|
||||
return columnTitles.at(section);
|
||||
case Qt::Vertical: // Row Header
|
||||
return QVariant();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant LogsModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::ForegroundRole) {
|
||||
switch(logs_.at(index.row()).logLevel) {
|
||||
case kError:
|
||||
return QBrush(QColor("darkred"));
|
||||
case kWarning:
|
||||
return QBrush(QColor("orangered"));
|
||||
case kInfo:
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
switch (index.column()) {
|
||||
case kTimeStamp:
|
||||
return logs_.at(index.row()).timeStamp.toString();
|
||||
case kLogLevel:
|
||||
return levelTitles.at(logs_.at(index.row()).logLevel);
|
||||
case kPort:
|
||||
return logs_.at(index.row()).port;
|
||||
case kMessage:
|
||||
return logs_.at(index.row()).message;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// --------------------------------------------- //
|
||||
// Slots
|
||||
// --------------------------------------------- //
|
||||
void LogsModel::clear()
|
||||
{
|
||||
beginResetModel();
|
||||
logs_.clear();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void LogsModel::log(int logLevel,QString port, QString message)
|
||||
{
|
||||
// TODO: discard logs older than some threshold
|
||||
|
||||
//qDebug("adding log %u %s", logs_.size(), qPrintable(message));
|
||||
beginInsertRows(QModelIndex(), logs_.size(), logs_.size());
|
||||
Log l;
|
||||
logs_.append(l);
|
||||
logs_.last().timeStamp = QTime::currentTime();
|
||||
logs_.last().logLevel = logLevel;
|
||||
logs_.last().port = port;
|
||||
logs_.last().message = message;
|
||||
endInsertRows();
|
||||
}
|
60
client/logsmodel.h
Normal file
60
client/logsmodel.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
Copyright (C) 2018 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _LOGS_MODEL_H
|
||||
#define _LOGS_MODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QTime>
|
||||
|
||||
class LogsModel: public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum LogLevel { // FIXME: use enum class?
|
||||
kError,
|
||||
kWarning,
|
||||
kInfo
|
||||
};
|
||||
|
||||
public:
|
||||
LogsModel(QObject *parent = 0);
|
||||
|
||||
int rowCount(const QModelIndex &parent=QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent=QModelIndex()) const;
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
void log(int logLevel,QString port, QString message);
|
||||
|
||||
private:
|
||||
struct Log {
|
||||
QTime timeStamp;
|
||||
int logLevel;
|
||||
QString port;
|
||||
QString message;
|
||||
};
|
||||
QVector<Log> logs_;
|
||||
};
|
||||
#endif
|
||||
|
45
client/logswindow.cpp
Normal file
45
client/logswindow.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright (C) 2018 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "logswindow.h"
|
||||
|
||||
#include "logsmodel.h"
|
||||
|
||||
#include <QHeaderView>
|
||||
|
||||
LogsWindow::LogsWindow(LogsModel *model, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
logs->verticalHeader()->setHighlightSections(false);
|
||||
logs->verticalHeader()->setDefaultSectionSize(
|
||||
logs->verticalHeader()->minimumSectionSize());
|
||||
logs->setShowGrid(false);
|
||||
logs->setAlternatingRowColors(true);
|
||||
logs->setModel(model);
|
||||
logs->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch);
|
||||
|
||||
//FIXME: connect(clear, SIGNAL(clicked()), model, SLOT(clear()));
|
||||
}
|
||||
|
||||
LogsWindow::~LogsWindow()
|
||||
{
|
||||
}
|
||||
|
36
client/logswindow.h
Normal file
36
client/logswindow.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright (C) 2018 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _LOGS_WINDOW_H
|
||||
#define _LOGS_WINDOW_H
|
||||
|
||||
#include "ui_logswindow.h"
|
||||
|
||||
class LogsModel;
|
||||
|
||||
class LogsWindow: public QWidget, private Ui::LogsWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LogsWindow(LogsModel *model, QWidget *parent = 0);
|
||||
~LogsWindow();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
104
client/logswindow.ui
Normal file
104
client/logswindow.ui
Normal file
@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LogsWindow</class>
|
||||
<widget class="QWidget" name="LogsWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>693</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Level</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>level</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="level">
|
||||
<property name="toolTip">
|
||||
<string>Log Level</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>Select the desired logging level</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>429</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="clear">
|
||||
<property name="toolTip">
|
||||
<string>Clear Logs</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>Clear Logs</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Clear</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="ostinato.qrc">
|
||||
<normaloff>:/icons/portstats_clear_all.png</normaloff>:/icons/portstats_clear_all.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="XTableView" name="logs">
|
||||
<property name="whatsThis">
|
||||
<string>Ostinato application logs are displayed here</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>XTableView</class>
|
||||
<extends>QTableView</extends>
|
||||
<header>xtableview.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>level</tabstop>
|
||||
<tabstop>clear</tabstop>
|
||||
<tabstop>logs</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="ostinato.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
@ -24,6 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#endif
|
||||
|
||||
#include "jumpurl.h"
|
||||
#include "logsmodel.h"
|
||||
#include "logswindow.h"
|
||||
#include "params.h"
|
||||
#include "portgrouplist.h"
|
||||
#include "portstatswindow.h"
|
||||
@ -56,6 +58,7 @@ extern const char* version;
|
||||
extern const char* revision;
|
||||
|
||||
PortGroupList *pgl;
|
||||
LogsModel *appLogs;
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow (parent)
|
||||
@ -89,24 +92,39 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
localServer_ = NULL;
|
||||
|
||||
pgl = new PortGroupList;
|
||||
appLogs = new LogsModel(this);
|
||||
|
||||
portsWindow = new PortsWindow(pgl, this);
|
||||
statsWindow = new PortStatsWindow(pgl, this);
|
||||
logsWindow_ = new LogsWindow(appLogs, this);
|
||||
|
||||
portsDock = new QDockWidget(tr("Ports and Streams"), this);
|
||||
portsDock->setObjectName("portsDock");
|
||||
portsDock->setFeatures(
|
||||
portsDock->features() & ~QDockWidget::DockWidgetClosable);
|
||||
|
||||
statsDock = new QDockWidget(tr("Port Statistics"), this);
|
||||
statsDock->setObjectName("statsDock");
|
||||
statsDock->setFeatures(
|
||||
statsDock->features() & ~QDockWidget::DockWidgetClosable);
|
||||
|
||||
logsDock_ = new QDockWidget(tr("Logs"), this);
|
||||
logsDock_->setObjectName("logsDock");
|
||||
logsDock_->setFeatures(
|
||||
logsDock_->features() & ~QDockWidget::DockWidgetClosable);
|
||||
|
||||
setupUi(this);
|
||||
|
||||
menuFile->insertActions(menuFile->actions().at(3), portsWindow->actions());
|
||||
|
||||
statsDock->setWidget(statsWindow);
|
||||
addDockWidget(Qt::BottomDockWidgetArea, statsDock);
|
||||
logsDock_->setWidget(logsWindow_);
|
||||
addDockWidget(Qt::BottomDockWidgetArea, logsDock_);
|
||||
tabifyDockWidget(statsDock, logsDock_);
|
||||
statsDock->show();
|
||||
statsDock->raise();
|
||||
|
||||
portsDock->setWidget(portsWindow);
|
||||
addDockWidget(Qt::TopDockWidgetArea, portsDock);
|
||||
|
||||
|
@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include <QMainWindow>
|
||||
#include <QProcess>
|
||||
|
||||
class LogsWindow;
|
||||
class PortsWindow;
|
||||
class PortStatsWindow;
|
||||
|
||||
@ -41,8 +42,10 @@ private:
|
||||
QProcess *localServer_;
|
||||
PortsWindow *portsWindow;
|
||||
PortStatsWindow *statsWindow;
|
||||
LogsWindow *logsWindow_;
|
||||
QDockWidget *portsDock;
|
||||
QDockWidget *statsDock;
|
||||
QDockWidget *logsDock_;
|
||||
|
||||
QRect defaultGeometry_;
|
||||
QByteArray defaultLayout_;
|
||||
|
@ -41,6 +41,8 @@ HEADERS += \
|
||||
deviceswidget.h \
|
||||
dumpview.h \
|
||||
hexlineedit.h \
|
||||
logsmodel.h \
|
||||
logswindow.h \
|
||||
mainwindow.h \
|
||||
ndpstatusmodel.h \
|
||||
packetmodel.h \
|
||||
@ -68,6 +70,7 @@ FORMS += \
|
||||
about.ui \
|
||||
devicegroupdialog.ui \
|
||||
deviceswidget.ui \
|
||||
logswindow.ui \
|
||||
mainwindow.ui \
|
||||
portconfigdialog.ui \
|
||||
portstatsfilter.ui \
|
||||
@ -87,6 +90,8 @@ SOURCES += \
|
||||
dumpview.cpp \
|
||||
stream.cpp \
|
||||
hexlineedit.cpp \
|
||||
logsmodel.cpp \
|
||||
logswindow.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
ndpstatusmodel.cpp \
|
||||
|
Loading…
Reference in New Issue
Block a user