set(qapitrace_SRCS
+ apicalldelegate.cpp
apitracecall.cpp
apitracefilter.cpp
apitracemodel.cpp
--- /dev/null
+#include "apicalldelegate.h"
+
+#include "apitracecall.h"
+
+#include <QDebug>
+#include <QPainter>
+#include <QStaticText>
+
+ApiCallDelegate::ApiCallDelegate(QWidget *parent)
+ : QStyledItemDelegate(parent)
+{
+}
+
+void ApiCallDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ ApiTraceCall *call = static_cast<ApiTraceCall*>(index.internalPointer());
+ if (call) {
+ QStaticText text = call->staticText();
+ //text.setTextWidth(option.rect.width());
+ painter->drawStaticText(option.rect.topLeft(), text);
+ } else{
+ QStyledItemDelegate::paint(painter, option, index);
+ }
+}
+
+QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ ApiTraceCall *call = static_cast<ApiTraceCall*>(index.internalPointer());
+ if (call) {
+ QStaticText text = call->staticText();
+ //text.setTextWidth(option.rect.width());
+ return text.size().toSize();
+ }
+ return QStyledItemDelegate::sizeHint(option, index);
+}
+
+
+#include "apicalldelegate.moc"
--- /dev/null
+#ifndef APICALLDELEGATE_H
+#define APICALLDELEGATE_H
+
+
+
+#include <QStyledItemDelegate>
+
+class ApiCallDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+
+public:
+ ApiCallDelegate(QWidget *parent = 0);
+
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const;
+ QSize sizeHint(const QStyleOptionViewItem &option,
+ const QModelIndex &index) const;
+};
+
+#endif
m_array.append(vis.variant());
}
}
+
+QStaticText ApiTraceCall::staticText() const
+{
+ if (!m_richText.isEmpty())
+ return m_staticText;
+
+ m_richText = QString::fromLatin1("<span style=\"font-weight:bold\">%1</span>(").arg(name);
+ for (int i = 0; i < argNames.count(); ++i) {
+ m_richText += argNames[i];
+ m_richText += QString::fromLatin1(" = ");
+ m_richText += QLatin1String("<span style=\"color:#0000ff\">");
+ m_richText += apiVariantToString(argValues[i]);
+ m_richText += QLatin1String("</span>");
+ if (i < argNames.count() - 1)
+ m_richText += QString::fromLatin1(", ");
+ }
+ m_richText += QLatin1String(")");
+
+ if (returnValue.isValid()) {
+ m_richText += QLatin1String(" = ");
+ m_richText += QLatin1String("<span style=\"color:#0000ff\">");
+ m_richText += apiVariantToString(returnValue);
+ m_richText += QLatin1String("</span>");
+ }
+
+ m_staticText.setText(m_richText);
+ QTextOption opt;
+ opt.setWrapMode(QTextOption::NoWrap);
+ m_staticText.setTextOption(opt);
+ m_staticText.prepare();
+
+ return m_staticText;
+}
+
+QString ApiTraceCall::richText() const
+{
+ staticText();
+ return m_richText;
+}
#ifndef APITRACECALL_H
#define APITRACECALL_H
+#include <QStaticText>
#include <QStringList>
#include <QVariant>
QStringList argNames;
QVariantList argValues;
QVariant returnValue;
+
+ QString richText() const;
+ QStaticText staticText() const;
+private:
+ mutable QString m_richText;
+ mutable QStaticText m_staticText;
};
#endif
switch (index.column()) {
case 0: {
- QString str;
- str += QString::number(index.row());
- str += QLatin1String(") ");
- str += item->name;
- str += QLatin1String("(");
- for (int i = 0; i < item->argNames.count(); ++i) {
- str += item->argNames[i];
- str += QString::fromLatin1(" = ");
- str += apiVariantToString(item->argValues[i]);
- if (i < item->argNames.count() - 1)
- str += QString::fromLatin1(", ");
- }
- str += QLatin1String(")");
-
- if (item->returnValue.isValid()) {
- str += QLatin1String(" = ");
- str += apiVariantToString(item->returnValue);
- }
- return str;
+ return item->richText();
}
default:
return QVariant();
#include "mainwindow.h"
+#include "apicalldelegate.h"
#include "apitracemodel.h"
#include "apitracefilter.h"
m_proxyModel = new ApiTraceFilter();
m_proxyModel->setSourceModel(m_model);
m_ui.callView->setModel(m_model);
+ m_ui.callView->setItemDelegate(new ApiCallDelegate);
for (int column = 0; column < m_model->columnCount(); ++column)
m_ui.callView->resizeColumnToContents(column);