Add preliminary version of a new data visualization idea in the
sniffer window.
This commit is contained in:
+4
-2
@@ -65,7 +65,8 @@ SOURCES += main.cpp\
|
||||
jsedit.cpp \
|
||||
frameplaybackobject.cpp \
|
||||
helpwindow.cpp \
|
||||
blfhandler.cpp
|
||||
blfhandler.cpp \
|
||||
re/sniffer/SnifferDelegate.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
can_structs.h \
|
||||
@@ -121,7 +122,8 @@ HEADERS += mainwindow.h \
|
||||
jsedit.h \
|
||||
frameplaybackobject.h \
|
||||
helpwindow.h \
|
||||
blfhandler.h
|
||||
blfhandler.h \
|
||||
re/sniffer/SnifferDelegate.h
|
||||
|
||||
FORMS += ui/candatagrid.ui \
|
||||
ui/connectionwindow.ui \
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#include "SnifferDelegate.h"
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include "utility.h"
|
||||
#include "re/sniffer/snifferitem.h"
|
||||
|
||||
SnifferDelegate::SnifferDelegate(QWidget *parent) : QItemDelegate(parent)
|
||||
{
|
||||
blackBrush = QBrush(Qt::black);
|
||||
whiteBrush = QBrush(Qt::white);
|
||||
//redBrush = QBrush(Qt::red);
|
||||
//greenBrush = QBrush(Qt::green);
|
||||
//grayBrush = QBrush(QColor(230,230,230));
|
||||
mainFont.setPointSize(10);
|
||||
mainFontInfo = new QFontInfo(mainFont);
|
||||
}
|
||||
|
||||
void SnifferDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
//qDebug() << "SnifferDelegate Paint Event";
|
||||
|
||||
if (index.column() < 2)
|
||||
{
|
||||
QItemDelegate::paint(painter, option, index);
|
||||
return;
|
||||
}
|
||||
|
||||
if (index.column() > 9) return;
|
||||
|
||||
int x, y;
|
||||
SnifferItem *item = static_cast<SnifferItem*>(index.internalPointer());
|
||||
int val = item->getData(index.column() - 2);
|
||||
if (val < 0) return;
|
||||
|
||||
QRect viewport = option.rect;
|
||||
|
||||
int xSpan = viewport.right() - viewport.left();
|
||||
int ySpan = viewport.bottom() - viewport.top();
|
||||
|
||||
//qDebug() << "XSpan" << xSpan << " YSpan " << ySpan;
|
||||
|
||||
int xSector = xSpan / 8;
|
||||
|
||||
painter->setPen(QPen(Qt::black));
|
||||
painter->setFont(mainFont);
|
||||
|
||||
for (x = 0; x < 8; x++)
|
||||
{
|
||||
if (val & (1 << x))
|
||||
{
|
||||
painter->setBrush(blackBrush);
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->setBrush(whiteBrush);
|
||||
}
|
||||
painter->drawRect(viewport.left() + x * xSector, viewport.top(), xSector, xSector);
|
||||
}
|
||||
|
||||
painter->drawText(QRect(viewport.left(), viewport.top() + xSector, xSpan, mainFontInfo->pixelSize()), Qt::AlignCenter, Utility::formatNumber(val));
|
||||
}
|
||||
|
||||
QSize SnifferDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QSize origSize = QItemDelegate::sizeHint(option, index);
|
||||
origSize.setHeight(origSize.height() * 2.0);
|
||||
return origSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef SNIFFERDELEGATE_H
|
||||
#define SNIFFERDELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
|
||||
class SnifferDelegate : public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SnifferDelegate(QWidget *parent = nullptr);
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QBrush blackBrush, whiteBrush;//, redBrush, greenBrush, grayBrush;
|
||||
QFont mainFont;
|
||||
QFontInfo* mainFontInfo;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <QDebug>
|
||||
#include "sniffermodel.h"
|
||||
#include "snifferwindow.h"
|
||||
|
||||
#include "SnifferDelegate.h"
|
||||
|
||||
SnifferModel::SnifferModel(QObject *parent)
|
||||
: QAbstractItemModel(parent),
|
||||
@@ -60,8 +60,10 @@ QVariant SnifferModel::data(const QModelIndex &index, int role) const
|
||||
if(tc::DATA_0<=col && col <=tc::DATA_7)
|
||||
{
|
||||
int data = item->getData(col-tc::DATA_0);
|
||||
if(data>=0)
|
||||
if(data >= 0)
|
||||
{
|
||||
return QString("%1").arg(data, 2, 16, QLatin1Char('0')).toUpper();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "ui_snifferwindow.h"
|
||||
#include "helpwindow.h"
|
||||
#include "connections/canconmanager.h"
|
||||
#include "SnifferDelegate.h"
|
||||
|
||||
SnifferWindow::SnifferWindow(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
@@ -19,8 +20,10 @@ SnifferWindow::SnifferWindow(QWidget *parent) :
|
||||
ui->treeView->setColumnWidth(tc::ID, 50);
|
||||
ui->treeView->setColumnWidth(tc::LAST, 1);
|
||||
for(int i=tc::DATA_0 ; i<=tc::DATA_7 ; i++)
|
||||
ui->treeView->setColumnWidth(i, 30);
|
||||
ui->treeView->setColumnWidth(i, 95);
|
||||
ui->treeView->setUniformRowHeights(true);
|
||||
ui->treeView->header()->setDefaultAlignment(Qt::AlignCenter);
|
||||
ui->treeView->setItemDelegate(new SnifferDelegate());
|
||||
|
||||
/* activate sorting */
|
||||
ui->listWidget->setSortingEnabled(true);
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>710</width>
|
||||
<width>1097</width>
|
||||
<height>752</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
||||
Reference in New Issue
Block a user