Additional work on new sniffer bitfield view.
This commit is contained in:
@@ -8,9 +8,9 @@ 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));
|
||||
redBrush = QBrush(Qt::red);
|
||||
greenBrush = QBrush(Qt::green);
|
||||
grayBrush = QBrush(QColor(230,230,230));
|
||||
mainFont.setPointSize(10);
|
||||
mainFontInfo = new QFontInfo(mainFont);
|
||||
}
|
||||
@@ -29,7 +29,11 @@ void SnifferDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
|
||||
|
||||
int x, y;
|
||||
SnifferItem *item = static_cast<SnifferItem*>(index.internalPointer());
|
||||
int val = item->getData(index.column() - 2);
|
||||
int idx = index.column() - 2;
|
||||
int val = item->getData(idx);
|
||||
int prevVal = item->getLastData(idx);
|
||||
int notchPattern = item->getNotchPattern(idx);
|
||||
int maskPattern;
|
||||
if (val < 0) return;
|
||||
|
||||
QRect viewport = option.rect;
|
||||
@@ -40,23 +44,50 @@ void SnifferDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
|
||||
//qDebug() << "XSpan" << xSpan << " YSpan " << ySpan;
|
||||
|
||||
int xSector = xSpan / 8;
|
||||
|
||||
painter->setPen(QPen(Qt::black));
|
||||
painter->setFont(mainFont);
|
||||
int v = item->getSeqInterval(index.column() - 2) * 10;
|
||||
if (v > 225) v = 225;
|
||||
if (v < 0) v = 0;
|
||||
|
||||
for (x = 0; x < 8; x++)
|
||||
{
|
||||
if (val & (1 << x))
|
||||
maskPattern = 1 << (7-x);
|
||||
//We look to see if each bit has changed since the last update or not. If not we
|
||||
//straight draw it black if set or white if unset. If it changed then draw it green if it is newly set
|
||||
//and red if newly unset
|
||||
//But also, if a bit is notched we just plain draw it gray no matter what it's doing
|
||||
if (notchPattern & maskPattern)
|
||||
{
|
||||
painter->setBrush(blackBrush);
|
||||
painter->setBrush(grayBrush);
|
||||
}
|
||||
else
|
||||
else if ( (val & maskPattern) == (prevVal & maskPattern) ) //wasn't notched so has it changed? No? Then...
|
||||
{
|
||||
painter->setBrush(whiteBrush);
|
||||
if (val & maskPattern)
|
||||
{
|
||||
painter->setBrush(blackBrush);
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->setBrush(whiteBrush);
|
||||
}
|
||||
}
|
||||
else //wasn't notched and did change since last time.
|
||||
{
|
||||
if (val & maskPattern)
|
||||
{
|
||||
painter->setBrush(greenBrush);
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->setBrush(redBrush);
|
||||
}
|
||||
}
|
||||
painter->setOpacity((255 - v) / 255.0);
|
||||
painter->drawRect(viewport.left() + x * xSector, viewport.top(), xSector, xSector);
|
||||
}
|
||||
|
||||
//painter->setPen(QPen(QColor(v,v,v,255)));
|
||||
painter->setPen(Qt::black);
|
||||
painter->setFont(mainFont);
|
||||
painter->drawText(QRect(viewport.left(), viewport.top() + xSector, xSpan, mainFontInfo->pixelSize()), Qt::AlignCenter, Utility::formatNumber(val));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ signals:
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QBrush blackBrush, whiteBrush;//, redBrush, greenBrush, grayBrush;
|
||||
QBrush blackBrush, whiteBrush, redBrush, greenBrush, grayBrush;
|
||||
QFont mainFont;
|
||||
QFontInfo* mainFontInfo;
|
||||
};
|
||||
|
||||
@@ -42,11 +42,26 @@ int SnifferItem::getData(uchar i) const
|
||||
return (i >= mCurrent.len) ? -1 : mCurrent.data[i];
|
||||
}
|
||||
|
||||
quint8 SnifferItem::getNotchPattern(uchar i) const
|
||||
{
|
||||
return (i >= mCurrent.len) ? -1 : mNotch[i];
|
||||
}
|
||||
|
||||
quint8 SnifferItem::getLastData(uchar i) const
|
||||
{
|
||||
return (i >= mLast.len) ? -1 : mLast.data[i];
|
||||
}
|
||||
|
||||
quint32 SnifferItem::getDataTimestamp(uchar i) const
|
||||
{
|
||||
return (i >= mCurrent.len) ? 0 : mCurrent.dataTimestamp[i];
|
||||
}
|
||||
|
||||
quint32 SnifferItem::getSeqInterval(uchar i) const
|
||||
{
|
||||
return mCurrSeqVal - getDataTimestamp(i);
|
||||
}
|
||||
|
||||
//Return whether a given data byte (by index 0-7) has incremented, deincremented, or stayed the same
|
||||
//since the last message
|
||||
//The If checks first that we aren't past the actual data length
|
||||
@@ -95,6 +110,7 @@ void SnifferItem::update(const CANFrame& pFrame, quint32 timeSeq, bool mute)
|
||||
/* copy current to last */
|
||||
mLast = mCurrent;
|
||||
mLastTime = mCurrentTime;
|
||||
mCurrSeqVal = timeSeq;
|
||||
|
||||
/* copy new value */
|
||||
for (int i = 0; i < 8; i++)
|
||||
|
||||
@@ -29,7 +29,10 @@ public:
|
||||
quint64 getId() const;
|
||||
float getDelta() const;
|
||||
int getData(uchar i) const;
|
||||
quint8 getNotchPattern(uchar i) const;
|
||||
quint8 getLastData(uchar i) const;
|
||||
quint32 getDataTimestamp(uchar i) const;
|
||||
quint32 getSeqInterval(uchar i) const;
|
||||
dc dataChange(uchar) const;
|
||||
int elapsed() const;
|
||||
void update(const CANFrame& pFrame, quint32 timeSeq, bool mute);
|
||||
@@ -45,6 +48,7 @@ private:
|
||||
quint8 mNotch[8];
|
||||
quint64 mLastTime;
|
||||
quint64 mCurrentTime;
|
||||
quint64 mCurrSeqVal;
|
||||
|
||||
QTime mTime;
|
||||
};
|
||||
|
||||
@@ -70,7 +70,7 @@ QVariant SnifferModel::data(const QModelIndex &index, int role) const
|
||||
case Qt::ForegroundRole:
|
||||
{
|
||||
if (!mFadeInactive || col < 2) return QBrush(Qt::black);
|
||||
int v = (mTimeSequence - item->getDataTimestamp(col - 2)) * 10;
|
||||
int v = item->getSeqInterval(col - 2) * 10;
|
||||
//qDebug() << "mTS: " << mTimeSequence << " gDT(" << (col - 2) << ") " << item->getDataTimestamp(col - 2);
|
||||
if (v > 225) v = 225;
|
||||
if (v < 0) v = 0;
|
||||
|
||||
Reference in New Issue
Block a user