Files
DRAMSys/analyzer/analyzer/presentation/debugmessagetreewidget.cpp
2014-07-11 09:22:34 +02:00

91 lines
2.6 KiB
C++

#include "debugmessagetreewidget.h"
#include <QGuiApplication>
#include <qtooltip.h>
using namespace std;
void DebugMessageTreeWidget::init(TraceNavigator *navigator, TracePlot *traceplot)
{
Q_ASSERT(isInitialized == false);
isInitialized = true;
arrangeUiSettings();
connect(navigator,SIGNAL(currentTraceTimeChanged()),this,SLOT(currentTraceTimeChanged()));
connect(navigator,SIGNAL(selectedTransactionsChanged()),this,SLOT(selectedTransactionChanged()));
this->traceplot = traceplot;
this->navigator = navigator;
currentTraceTimeChanged();
}
void DebugMessageTreeWidget::arrangeUiSettings()
{
QFont font = QGuiApplication::font();
font.setPointSize(10);
this->setFont(font);
setColumnCount(2);
setHeaderLabels(QStringList({"Time", "Message"}));
}
void DebugMessageTreeWidget::selectedTransactionChanged()
{
if(navigator->hasSelectedTransactions())
{
Timespan span = navigator->getSpanCoveredBySelectedTransaction();
showDebugMessages(navigator->TraceFile().getDebugMessagesInTimespan(span));
}
else
{
showDebugMessages(navigator->TraceFile().getDebugMessagesInTimespan(traceplot->GetCurrentTimespan()));
}
}
void DebugMessageTreeWidget::currentTraceTimeChanged()
{
if(!navigator->hasSelectedTransactions())
showDebugMessages(navigator->TraceFile().getDebugMessagesInTimespan(traceplot->GetCurrentTimespan()));
}
void DebugMessageTreeWidget::showDebugMessages(const vector<Comment>& comments)
{
clear();
if(comments.empty())
return;
traceTime currentTime = -1;
for(Comment comment: comments)
{
if(currentTime != comment.Time())
{
addTopLevelItem(new QTreeWidgetItem({prettyFormatTime(comment.Time()), formatDebugMessage(comment.Text())}));
currentTime = comment.Time();
}
else
{
addTopLevelItem(new QTreeWidgetItem({"", formatDebugMessage(comment.Text())}));
}
}
this->resizeColumnToContents(0);
this->scrollToTop();
}
QString DebugMessageTreeWidget::formatDebugMessage(const QString &message)
{
QString formattedMessage = message;
formattedMessage.replace(hexAdressMatcher,"");
formattedMessage.replace(timeAnnotationMatcher,"");
formattedMessage.replace("\t"," ");
return formattedMessage;
}
void DebugMessageTreeWidget::mousePressEvent(QMouseEvent *event)
{
QTreeWidgetItem* itemUnderCursor = itemAt(event->pos());
if(itemUnderCursor != NULL)
{
QToolTip::showText(this->mapToGlobal(event->pos()), itemUnderCursor->text(1));
}
}