Skip to content

Commit

Permalink
Finalized the BarTree visualization. Several minor improvements, lead…
Browse files Browse the repository at this point in the history
…ing to a better whole.
  • Loading branch information
wimleers committed Jan 9, 2011
1 parent 1aeecb0 commit 30820dc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
26 changes: 19 additions & 7 deletions Visualizer/BarTreeVisualization.cpp
Expand Up @@ -5,10 +5,13 @@ BarTreeVisualization::BarTreeVisualization(QWidget *parent) : QWebView(parent) {
connect(this, SIGNAL(loadFinished(bool)), SLOT(loadHasFinished(bool)));

// See explanation at BarTreeVisualization::timerEvent().
startTimer(BARTREEVISUALIZATION_DATA_REFRESH_INTERVAL);
this->initialTimerID = this->startTimer(20);
this->firstRenderDone = false;

// Load the visualization in the web view.
this->load(QUrl("qrc:/BarTree/BarTree.html"));
this->nextEventSequence = NULL;
this->currentEventSequence = NULL;
}

void BarTreeVisualization::loadHasFinished(bool ok) {
Expand All @@ -21,10 +24,6 @@ void BarTreeVisualization::eventSequenceChanged(QVector<Event *> * events) {
this->mutex.unlock();
}

void BarTreeVisualization::highlightEventLocation(int msecs, const QString & eventType) {
qDebug() << eventType;
}

/**
* Periodically (BARTREEVISUALIZATION_DATA_REFRESH_INTERVAL intervals) poll
* to see if there's a new event sequence to draw. We do this using polling
Expand All @@ -37,6 +36,12 @@ void BarTreeVisualization::timerEvent(QTimerEvent *) {
if (!this->pageHasLoaded)
return;

if (!this->firstRenderDone) {
this->firstRenderDone = true;
this->killTimer(this->initialTimerID);
this->startTimer(BARTREEVISUALIZATION_DATA_REFRESH_INTERVAL);
}

// Make the next event sequence the current, if any, and send it to the
// web view.
if (this->nextEventSequence != NULL) {
Expand All @@ -61,6 +66,8 @@ void BarTreeVisualization::sendEventSequenceToWebView() {
QString inputType, eventType, modifier, details;
QStringList detailsList;
Event * event;
QTime timer;
timer.start();

// Count frequencies.
foreach (event, *this->currentEventSequence) {
Expand Down Expand Up @@ -217,9 +224,14 @@ void BarTreeVisualization::sendEventSequenceToWebView() {
}
data = level1;

qDebug() << "[BarTree] Calculated statistics in " << timer.elapsed() << "ms.";
timer.restart();
QString json = QxtJSON::stringify(data);
qDebug() << "Generated JSON:" << json;
qDebug() << "[BarTree] Generated JSON in " << timer.elapsed() << "ms.";
timer.restart();
this->mainFrame->evaluateJavaScript(QString("barTreeView.loadData(%1);").arg(json));
this->update();
qDebug() << "[BarTree] QWebView updated in " << timer.elapsed() << "ms.";
}

/**
Expand All @@ -230,7 +242,7 @@ double BarTreeVisualization::calcTotalFreq(const QMap<QString, int> & frequencie
static double totalFrequency;

totalFrequency = 0;
foreach(key, frequencies.keys()) {
foreach (key, frequencies.keys()) {
totalFrequency += frequencies[key];
}

Expand Down
4 changes: 3 additions & 1 deletion Visualizer/BarTreeVisualization.h
Expand Up @@ -11,6 +11,7 @@
#include <QMap>
#include <QMutex>
#include <QTimerEvent>
#include <QTime>
#include <QDebug>
#include "Event.h"

Expand All @@ -28,7 +29,6 @@ class BarTreeVisualization : public QWebView {
public slots:
void loadHasFinished(bool ok);
void eventSequenceChanged(QVector<Event *> * events);
void highlightEventLocation(int msecs, const QString & eventType);

protected:
void timerEvent(QTimerEvent *);
Expand All @@ -40,6 +40,8 @@ public slots:
QVector<Event *> * nextEventSequence;
QMutex mutex;
bool pageHasLoaded;
bool firstRenderDone;
int initialTimerID;
};

#endif // BARTREEVISUALIZATION_H
1 change: 0 additions & 1 deletion Visualizer/MainWindow.cpp
Expand Up @@ -28,7 +28,6 @@ void MainWindow::createContent() {

connect(timeLineVis, SIGNAL(timeSpanChanged(int, int)), database, SLOT(loadEvents(int, int)));
connect(timeLineVis, SIGNAL(onEventShapeClicked(int, const QString &)), heatMapVis, SLOT(highlightEventLocation(int)));
connect(timeLineVis, SIGNAL(onEventShapeClicked(int, const QString &)), barTreeVis, SLOT(highlightEventLocation(int, const QString &)));

vbox = new QVBoxLayout();
vbox->addWidget(heatMapVis);
Expand Down

0 comments on commit 30820dc

Please sign in to comment.