#include "apicalldelegate.h"
#include "apitracecall.h"
+#include "apitracemodel.h"
+#include <QApplication>
#include <QDebug>
#include <QPainter>
#include <QStaticText>
#include <QStyle>
ApiCallDelegate::ApiCallDelegate(QWidget *parent)
- : QStyledItemDelegate(parent)
+ : QStyledItemDelegate(parent),
+ m_stateEmblem(":/resources/dialog-information.png")
{
}
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
- ApiTraceCall *call = index.data().value<ApiTraceCall*>();
- if (call) {
- QStaticText text = call->staticText();
+ QVariant var = index.data(ApiTraceModel::EventRole);
+ ApiTraceEvent *event = var.value<ApiTraceEvent*>();
+
+ Q_ASSERT(index.column() == 0);
+
+ if (event) {
+ QPoint offset;
+ QStaticText text = event->staticText();
//text.setTextWidth(option.rect.width());
- QStyledItemDelegate::paint(painter, option, index);
- painter->drawStaticText(option.rect.topLeft(), text);
- } else {
- ApiTraceFrame *frame = index.data().value<ApiTraceFrame*>();
- if (frame) {
- QStaticText text = frame->staticText();
- //text.setTextWidth(option.rect.width());
- QStyledItemDelegate::paint(painter, option, index);
- painter->drawStaticText(option.rect.topLeft(), text);
- } else {
- QStyledItemDelegate::paint(painter, option, index);
+ //QStyledItemDelegate::paint(painter, option, index);
+ QStyle *style = QApplication::style();
+ style->drawControl(QStyle::CE_ItemViewItem, &option, painter, 0);
+ if (!event->state().isEmpty()) {
+ QPixmap px = m_stateEmblem.pixmap(option.rect.height(), option.rect.height());
+ painter->drawPixmap(option.rect.topLeft(), px);
+ offset = QPoint(option.rect.height() + 5, 0);
}
+ painter->drawStaticText(option.rect.topLeft() + offset, text);
+ } else {
+ QStyledItemDelegate::paint(painter, option, index);
}
}
QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
- ApiTraceCall *call = index.data().value<ApiTraceCall*>();
- if (call) {
- QStaticText text = call->staticText();
+ ApiTraceEvent *event =
+ index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
+
+ Q_ASSERT(index.column() == 0);
+
+ if (event) {
+ QStaticText text = event->staticText();
//text.setTextWidth(option.rect.width());
+ //qDebug()<<"text size = "<<text.size();
return text.size().toSize();
- } else {
- ApiTraceFrame *frame = index.data().value<ApiTraceFrame*>();
- if (frame) {
- QStaticText text = frame->staticText();
- //text.setTextWidth(option.rect.width());
- return text.size().toSize();
- }
}
return QStyledItemDelegate::sizeHint(option, index);
}
const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const;
+
+private:
+ QIcon m_stateEmblem;
};
#endif
#include "apitracefilter.h"
#include "apitracecall.h"
+#include "apitracemodel.h"
#include <QDebug>
const QModelIndex &sourceParent) const
{
QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
- QVariant varientData = sourceModel()->data(index0);
- ApiTraceCall *call = varientData.value<ApiTraceCall*>();
+ QVariant varientData = sourceModel()->data(index0, ApiTraceModel::EventRole);
+ ApiTraceEvent *event = varientData.value<ApiTraceEvent*>();
- if (!call) {
- ApiTraceFrame *frame = varientData.value<ApiTraceFrame*>();
- return frame != 0;
+ Q_ASSERT(event);
+ if (!event)
+ return false;
+
+ //we don't filter frames
+ if (event->type() == ApiTraceEvent::Frame) {
+ return true;
}
+ ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
QString function = call->name;
if (!m_text.isEmpty()) {
#include "trace_parser.hpp"
#include <QDebug>
+#include <QImage>
#include <QVariant>
if (!index.isValid())
return QVariant();
- if (role != Qt::DisplayRole)
- return QVariant();
-
- //data only in the first column
if (index.column() != 0)
return QVariant();
ApiTraceEvent *itm = item(index);
- if (itm) {
- if (itm->type() == ApiTraceEvent::Frame) {
- ApiTraceFrame *frame =
- static_cast<ApiTraceFrame *>(itm);
- return QVariant::fromValue(frame);
- } else if (itm->type() == ApiTraceEvent::Call) {
- ApiTraceCall *call =
- static_cast<ApiTraceCall *>(itm);
- return QVariant::fromValue(call);
- }
+ if (!itm) {
+ return QVariant();
+ }
+
+ switch (role) {
+ case Qt::DisplayRole:
+ return itm->staticText().text();
+ case Qt::DecorationRole:
+ return QImage();
+ case ApiTraceModel::EventRole:
+ return QVariant::fromValue(itm);
}
return QVariant();
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) {
case 0:
- return tr("Event");
+ return tr("Events");
+ case 1:
+ return tr("Flags");
default:
//fall through
break;
if (parent.isValid() && parent.column() != 0)
return QModelIndex();
- if (parent.isValid()) {
- QVariant data = parent.data();
- ApiTraceFrame *frame = data.value<ApiTraceFrame*>();
- if (!frame) {
- qDebug()<<"got a valid parent but it's not a frame "<<data;
+ ApiTraceEvent *event = item(parent);
+ if (event) {
+ if (event->type() != ApiTraceEvent::Frame) {
+ qDebug()<<"got a valid parent but it's not a frame "<<event->type();
return QModelIndex();
}
+ ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
ApiTraceCall *call = frame->calls.value(row);
if (call)
return createIndex(row, column, call);
bool ApiTraceModel::hasChildren(const QModelIndex &parent) const
{
if (parent.isValid()) {
- ApiTraceFrame *frame = parent.data().value<ApiTraceFrame*>();
- if (frame)
+ ApiTraceEvent *event = item(parent);
+ if (event && event->type() == ApiTraceEvent::Frame) {
+ ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
return !frame->calls.isEmpty();
- else
+ } else
return false;
} else {
return (rowCount() > 0);
if (!index.isValid())
return QModelIndex();
- ApiTraceCall *call = index.data().value<ApiTraceCall*>();
- if (call) {
+ ApiTraceEvent *event = item(index);
+ if (event && event->type() == ApiTraceEvent::Call) {
+ ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
Q_ASSERT(call->parentFrame);
return createIndex(call->parentFrame->number,
0, call->parentFrame);
if (!parent.isValid())
return m_trace->numFrames();
- ApiTraceCall *call = parent.data().value<ApiTraceCall*>();
- if (call)
+ ApiTraceEvent *event = item(parent);
+ if (!event || event->type() == ApiTraceEvent::Call)
return 0;
- ApiTraceFrame *frame = parent.data().value<ApiTraceFrame*>();
+ ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
if (frame)
return frame->calls.count();
return 1;
}
-
bool ApiTraceModel::insertRows(int position, int rows,
const QModelIndex &parent)
{
void ApiTraceModel::appendFrames(int oldCount, int numAdded)
{
beginInsertRows(QModelIndex(), oldCount,
- oldCount + numAdded);
+ oldCount + numAdded - 1);
endInsertRows();
}
return static_cast<ApiTraceEvent*>(index.internalPointer());
}
+void ApiTraceModel::stateSetOnEvent(ApiTraceEvent *event)
+{
+ if (!event)
+ return;
+
+ if (event->type() == ApiTraceEvent::Call) {
+ ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
+ ApiTraceFrame *frame = call->parentFrame;
+ int row = frame->calls.indexOf(call);
+ QModelIndex index = createIndex(row, 0, call);
+ emit dataChanged(index, index);
+ } else if (event->type() == ApiTraceEvent::Frame) {
+ ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
+ const QList<ApiTraceFrame*> frames = m_trace->frames();
+ int row = frames.indexOf(frame);
+ QModelIndex index = createIndex(row, 0, frame);
+ emit dataChanged(index, index);
+ }
+}
+
#include "apitracemodel.moc"
{
Q_OBJECT
public:
+ enum Roles {
+ EventRole = Qt::UserRole + 1
+ };
+public:
ApiTraceModel(QObject *parent = 0);
~ApiTraceModel();
void setApiTrace(ApiTrace *trace);
const ApiTrace *apiTrace() const;
+ void stateSetOnEvent(ApiTraceEvent *event);
public:
/* QAbstractItemModel { */
m_proxyModel->setSourceModel(m_model);
m_ui.callView->setModel(m_proxyModel);
m_ui.callView->setItemDelegate(new ApiCallDelegate);
- for (int column = 0; column < m_model->columnCount(); ++column)
- m_ui.callView->resizeColumnToContents(column);
+ m_ui.callView->resizeColumnToContents(0);
+ m_ui.callView->header()->swapSections(0, 1);
+ m_ui.callView->setColumnWidth(1, 42);
QToolBar *toolBar = addToolBar(tr("Navigation"));
m_filterEdit = new QLineEdit(toolBar);
void MainWindow::callItemSelected(const QModelIndex &index)
{
- ApiTraceCall *call = index.data().value<ApiTraceCall*>();
- if (call) {
+ ApiTraceEvent *event =
+ index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
+
+ if (event && event->type() == ApiTraceEvent::Call) {
+ ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
m_ui.detailsWebView->setHtml(call->toHtml());
m_ui.detailsDock->show();
m_selectedEvent = call;
} else {
- m_selectedEvent = index.data().value<ApiTraceFrame*>();
+ if (event && event->type() == ApiTraceEvent::Frame) {
+ m_selectedEvent = static_cast<ApiTraceFrame*>(event);
+ } else
+ m_selectedEvent = 0;
m_ui.detailsDock->hide();
}
if (m_selectedEvent && !m_selectedEvent->state().isEmpty()) {
QVariantMap::const_iterator itr;
m_stateEvent->setState(params);
+ m_model->stateSetOnEvent(m_stateEvent);
if (m_selectedEvent == m_stateEvent) {
fillStateForFrame();
} else {