]> git.cworth.org Git - apitrace/blob - gui/apitracecall.cpp
bdf55919334b9a149ae8263b9eeee68b7ca7a4fa
[apitrace] / gui / apitracecall.cpp
1 #include "apitracecall.h"
2
3 #include "apitrace.h"
4 #include "trace_model.hpp"
5
6 #include <QDebug>
7 #include <QLocale>
8 #include <QObject>
9 #define QT_USE_FAST_OPERATOR_PLUS
10 #include <QStringBuilder>
11 #include <QTextDocument>
12
13 const char * const styleSheet =
14     ".call {\n"
15     "    font-weight:bold;\n"
16     // text shadow looks great but doesn't work well in qtwebkit 4.7
17     "    /*text-shadow: 0px 2px 3px #555;*/\n"
18     "    font-size: 1.2em;\n"
19     "}\n"
20     ".arg-name {\n"
21     "    border: 1px solid rgb(238,206,0);\n"
22     "    border-radius: 4px;\n"
23     "    background: yellow;\n"
24     "    padding: 2px;\n"
25     "    box-shadow: 0px 1px 3px dimgrey;\n"
26     "    -webkit-transition: background 1s linear;\n"
27     "}\n"
28     ".arg-name:hover {\n"
29     "    background: white;\n"
30     "}\n"
31     ".arg-value {\n"
32     "    color: #0000ff;\n"
33     "}\n"
34     ".error {\n"
35     "    border: 1px solid rgb(255,0,0);\n"
36     "    margin: 10px;\n"
37     "    padding: 1;\n"
38     "    border-radius: 4px;\n"
39     // also looks great but qtwebkit doesn't support it
40     //"    background: #6fb2e5;\n"
41     //"    box-shadow: 0 1px 5px #0061aa, inset 0 10px 20px #b6f9ff;\n"
42     //"    -o-box-shadow: 0 1px 5px #0061aa, inset 0 10px 20px #b6f9ff;\n"
43     //"    -webkit-box-shadow: 0 1px 5px #0061aa, inset 0 10px 20px #b6f9ff;\n"
44     //"    -moz-box-shadow: 0 1px 5px #0061aa, inset 0 10px 20px #b6f9ff;\n"
45     "}\n";
46
47
48 // Qt::convertFromPlainText doesn't do precisely what we want
49 static QString
50 plainTextToHTML(const QString & plain, bool multiLine)
51 {
52     int col = 0;
53     bool quote = false;
54     QString rich;
55     for (int i = 0; i < plain.length(); ++i) {
56         if (plain[i] == QLatin1Char('\n')){
57             if (multiLine) {
58                 rich += QLatin1String("<br>\n");
59             } else {
60                 rich += QLatin1String("\\n");
61             }
62             col = 0;
63             quote = true;
64         } else {
65             if (plain[i] == QLatin1Char('\t')){
66                 if (multiLine) {
67                     rich += QChar(0x00a0U);
68                     ++col;
69                     while (col % 8) {
70                         rich += QChar(0x00a0U);
71                         ++col;
72                     }
73                 } else {
74                     rich += QLatin1String("\\t");
75                 }
76                 quote = true;
77             } else if (plain[i].isSpace()) {
78                 rich += QChar(0x00a0U);
79                 quote = true;
80             } else if (plain[i] == QLatin1Char('<')) {
81                 rich += QLatin1String("&lt;");
82             } else if (plain[i] == QLatin1Char('>')) {
83                 rich += QLatin1String("&gt;");
84             } else if (plain[i] == QLatin1Char('&')) {
85                 rich += QLatin1String("&amp;");
86             } else {
87                 rich += plain[i];
88             }
89             ++col;
90         }
91     }
92
93     if (quote) {
94         return QLatin1Literal("\"") + rich + QLatin1Literal("\"");
95     }
96
97     return rich;
98 }
99
100 QString
101 apiVariantToString(const QVariant &variant, bool multiLine)
102 {
103     if (variant.userType() == QVariant::Double) {
104         return QString::number(variant.toFloat());
105     }
106     if (variant.userType() == QVariant::ByteArray) {
107         if (variant.toByteArray().size() < 1024) {
108             int bytes = variant.toByteArray().size();
109             return QObject::tr("[binary data, size = %1 bytes]").arg(bytes);
110         } else {
111             float kb = variant.toByteArray().size()/1024.;
112             return QObject::tr("[binary data, size = %1 kb]").arg(kb);
113         }
114     }
115
116     if (variant.userType() == QVariant::String) {
117         return plainTextToHTML(variant.toString(), multiLine);
118     }
119
120     if (variant.userType() < QVariant::UserType) {
121         return variant.toString();
122     }
123
124     if (variant.canConvert<ApiPointer>()) {
125         return variant.value<ApiPointer>().toString();
126     }
127     if (variant.canConvert<ApiBitmask>()) {
128         return variant.value<ApiBitmask>().toString();
129     }
130     if (variant.canConvert<ApiStruct>()) {
131         return variant.value<ApiStruct>().toString();
132     }
133     if (variant.canConvert<ApiArray>()) {
134         return variant.value<ApiArray>().toString();
135     }
136     if (variant.canConvert<ApiEnum>()) {
137         return variant.value<ApiEnum>().toString();
138     }
139
140     return QString();
141 }
142
143
144 void VariantVisitor::visit(Trace::Null *)
145 {
146     m_variant = QVariant::fromValue(ApiPointer(0));
147 }
148
149 void VariantVisitor::visit(Trace::Bool *node)
150 {
151     m_variant = QVariant(node->value);
152 }
153
154 void VariantVisitor::visit(Trace::SInt *node)
155 {
156     m_variant = QVariant(node->value);
157 }
158
159 void VariantVisitor::visit(Trace::UInt *node)
160 {
161     m_variant = QVariant(node->value);
162 }
163
164 void VariantVisitor::visit(Trace::Float *node)
165 {
166     m_variant = QVariant(node->value);
167 }
168
169 void VariantVisitor::visit(Trace::String *node)
170 {
171     m_variant = QVariant(QString::fromStdString(node->value));
172 }
173
174 void VariantVisitor::visit(Trace::Enum *e)
175 {
176     ApiTraceEnumSignature *sig = 0;
177
178     if (m_trace) {
179         sig = m_trace->enumSignature(e->sig->id);
180     }
181     if (!sig) {
182         sig = new ApiTraceEnumSignature(
183             QString::fromStdString(e->sig->name),
184             QVariant(e->sig->value));
185         if (m_trace) {
186             m_trace->addEnumSignature(e->sig->id, sig);
187         }
188     }
189
190     m_variant = QVariant::fromValue(ApiEnum(sig));
191 }
192
193 void VariantVisitor::visit(Trace::Bitmask *bitmask)
194 {
195     m_variant = QVariant::fromValue(ApiBitmask(bitmask));
196 }
197
198 void VariantVisitor::visit(Trace::Struct *str)
199 {
200     m_variant = QVariant::fromValue(ApiStruct(str));
201 }
202
203 void VariantVisitor::visit(Trace::Array *array)
204 {
205     m_variant = QVariant::fromValue(ApiArray(array));
206 }
207
208 void VariantVisitor::visit(Trace::Blob *blob)
209 {
210     //XXX
211     //FIXME: this is a nasty hack. Trace::Blob's can't
212     //   delete the contents in the destructor because
213     //   the data is being used by other calls. We piggy back
214     //   on that assumption and don't deep copy the data. If
215     //   Blob's will start deleting the data we will need to
216     //   start deep copying it or switch to using something like
217     //   Boost's shared_ptr or Qt's QSharedPointer to handle it
218     QByteArray barray = QByteArray::fromRawData(blob->buf, blob->size);
219     m_variant = QVariant(barray);
220 }
221
222 void VariantVisitor::visit(Trace::Pointer *ptr)
223 {
224     m_variant = QVariant::fromValue(ApiPointer(ptr->value));
225 }
226
227
228 ApiEnum::ApiEnum(ApiTraceEnumSignature *sig)
229     : m_sig(sig)
230 {
231 }
232
233 QString ApiEnum::toString() const
234 {
235     if (m_sig) {
236         return m_sig->name();
237     }
238     Q_ASSERT(!"should never happen");
239     return QString();
240 }
241
242 QVariant ApiEnum::value() const
243 {
244     if (m_sig) {
245         return m_sig->value();
246     }
247     Q_ASSERT(!"should never happen");
248     return QVariant();
249 }
250
251 QString ApiEnum::name() const
252 {
253     if (m_sig) {
254         return m_sig->name();
255     }
256     Q_ASSERT(!"should never happen");
257     return QString();
258 }
259
260 unsigned long long ApiBitmask::value() const
261 {
262     return m_value;
263 }
264
265 ApiBitmask::Signature ApiBitmask::signature() const
266 {
267     return m_sig;
268 }
269
270 ApiStruct::Signature ApiStruct::signature() const
271 {
272     return m_sig;
273 }
274
275 QList<QVariant> ApiStruct::values() const
276 {
277     return m_members;
278 }
279
280 ApiPointer::ApiPointer(unsigned long long val)
281     : m_value(val)
282 {
283 }
284
285
286 unsigned long long ApiPointer::value() const
287 {
288     return m_value;
289 }
290
291 QString ApiPointer::toString() const
292 {
293     if (m_value)
294         return QString("0x%1").arg(m_value, 0, 16);
295     else
296         return QLatin1String("NULL");
297 }
298
299 ApiBitmask::ApiBitmask(const Trace::Bitmask *bitmask)
300     : m_value(0)
301 {
302     init(bitmask);
303 }
304
305 void ApiBitmask::init(const Trace::Bitmask *bitmask)
306 {
307     if (!bitmask)
308         return;
309
310     m_value = bitmask->value;
311     for (const Trace::BitmaskFlag *it = bitmask->sig->flags;
312          it != bitmask->sig->flags + bitmask->sig->num_flags; ++it) {
313         assert(it->value);
314         QPair<QString, unsigned long long> pair;
315
316         pair.first = QString::fromStdString(it->name);
317         pair.second = it->value;
318
319         m_sig.append(pair);
320     }
321 }
322
323 QString ApiBitmask::toString() const
324 {
325     QString str;
326     unsigned long long value = m_value;
327     bool first = true;
328     for (Signature::const_iterator it = m_sig.begin();
329          value != 0 && it != m_sig.end(); ++it) {
330         Q_ASSERT(it->second);
331         if ((value & it->second) == it->second) {
332             if (!first) {
333                 str += QLatin1String(" | ");
334             }
335             str += it->first;
336             value &= ~it->second;
337             first = false;
338         }
339     }
340     if (value || first) {
341         if (!first) {
342             str += QLatin1String(" | ");
343         }
344         str += QString::fromLatin1("0x%1").arg(value, 0, 16);
345     }
346     return str;
347 }
348
349 ApiStruct::ApiStruct(const Trace::Struct *s)
350 {
351     init(s);
352 }
353
354 QString ApiStruct::toString() const
355 {
356     QString str;
357
358     str += QLatin1String("{");
359     for (unsigned i = 0; i < m_members.count(); ++i) {
360         str += m_sig.memberNames[i] %
361                QLatin1Literal(" = ") %
362                apiVariantToString(m_members[i]);
363         if (i < m_members.count() - 1)
364             str += QLatin1String(", ");
365     }
366     str += QLatin1String("}");
367
368     return str;
369 }
370
371 void ApiStruct::init(const Trace::Struct *s)
372 {
373     if (!s)
374         return;
375
376     m_sig.name = QString::fromStdString(s->sig->name);
377     for (unsigned i = 0; i < s->sig->num_members; ++i) {
378         VariantVisitor vis(0);
379         m_sig.memberNames.append(
380             QString::fromStdString(s->sig->member_names[i]));
381         s->members[i]->visit(vis);
382         m_members.append(vis.variant());
383     }
384 }
385
386 ApiArray::ApiArray(const Trace::Array *arr)
387 {
388     init(arr);
389 }
390
391 ApiArray::ApiArray(const QList<QVariant> &vals)
392     : m_array(vals)
393 {
394 }
395
396 QList<QVariant> ApiArray::values() const
397 {
398     return m_array;
399 }
400
401 QString ApiArray::toString() const
402 {
403     QString str;
404     str += QLatin1String("[");
405     for(int i = 0; i < m_array.count(); ++i) {
406         const QVariant &var = m_array[i];
407         str += apiVariantToString(var);
408         if (i < m_array.count() - 1)
409             str += QLatin1String(", ");
410     }
411     str += QLatin1String("]");
412
413     return str;
414 }
415
416 void ApiArray::init(const Trace::Array *arr)
417 {
418     if (!arr)
419         return;
420
421     m_array.reserve(arr->values.size());
422     for (int i = 0; i < arr->values.size(); ++i) {
423         VariantVisitor vis(0);
424         arr->values[i]->visit(vis);
425
426         m_array.append(vis.variant());
427     }
428 }
429
430 ApiTraceState::ApiTraceState()
431 {
432 }
433
434 ApiTraceState::ApiTraceState(const QVariantMap &parsedJson)
435 {
436     m_parameters = parsedJson[QLatin1String("parameters")].toMap();
437     QVariantMap attachedShaders =
438         parsedJson[QLatin1String("shaders")].toMap();
439     QVariantMap::const_iterator itr;
440
441
442     for (itr = attachedShaders.constBegin(); itr != attachedShaders.constEnd();
443          ++itr) {
444         QString type = itr.key();
445         QString source = itr.value().toString();
446         m_shaderSources[type] = source;
447     }
448
449     m_uniforms = parsedJson[QLatin1String("uniforms")].toMap();
450
451     QVariantMap textures =
452         parsedJson[QLatin1String("textures")].toMap();
453     for (itr = textures.constBegin(); itr != textures.constEnd(); ++itr) {
454         QVariantMap image = itr.value().toMap();
455         QSize size(image[QLatin1String("__width__")].toInt(),
456                    image[QLatin1String("__height__")].toInt());
457         QString cls = image[QLatin1String("__class__")].toString();
458         QString type = image[QLatin1String("__type__")].toString();
459         bool normalized =
460             image[QLatin1String("__normalized__")].toBool();
461         int numChannels =
462             image[QLatin1String("__channels__")].toInt();
463
464         Q_ASSERT(type == QLatin1String("uint8"));
465         Q_ASSERT(normalized == true);
466         Q_UNUSED(normalized);
467
468         QByteArray dataArray =
469             image[QLatin1String("__data__")].toByteArray();
470
471         ApiTexture tex;
472         tex.setSize(size);
473         tex.setNumChannels(numChannels);
474         tex.setLabel(itr.key());
475         tex.contentsFromBase64(dataArray);
476
477         m_textures.append(tex);
478     }
479
480     QVariantMap fbos =
481         parsedJson[QLatin1String("framebuffer")].toMap();
482     for (itr = fbos.constBegin(); itr != fbos.constEnd(); ++itr) {
483         QVariantMap buffer = itr.value().toMap();
484         QSize size(buffer[QLatin1String("__width__")].toInt(),
485                    buffer[QLatin1String("__height__")].toInt());
486         QString cls = buffer[QLatin1String("__class__")].toString();
487         QString type = buffer[QLatin1String("__type__")].toString();
488         bool normalized = buffer[QLatin1String("__normalized__")].toBool();
489         int numChannels = buffer[QLatin1String("__channels__")].toInt();
490
491         Q_ASSERT(type == QLatin1String("uint8"));
492         Q_ASSERT(normalized == true);
493         Q_UNUSED(normalized);
494
495         QByteArray dataArray =
496             buffer[QLatin1String("__data__")].toByteArray();
497
498         ApiFramebuffer fbo;
499         fbo.setSize(size);
500         fbo.setNumChannels(numChannels);
501         fbo.setType(itr.key());
502         fbo.contentsFromBase64(dataArray);
503         m_framebuffers.append(fbo);
504     }
505 }
506
507 const QVariantMap & ApiTraceState::parameters() const
508 {
509     return m_parameters;
510 }
511
512 const QMap<QString, QString> & ApiTraceState::shaderSources() const
513 {
514     return m_shaderSources;
515 }
516
517 const QVariantMap & ApiTraceState::uniforms() const
518 {
519     return m_uniforms;
520 }
521
522 bool ApiTraceState::isEmpty() const
523 {
524     return m_parameters.isEmpty();
525 }
526
527 const QList<ApiTexture> & ApiTraceState::textures() const
528 {
529     return m_textures;
530 }
531
532 const QList<ApiFramebuffer> & ApiTraceState::framebuffers() const
533 {
534     return m_framebuffers;
535 }
536
537 ApiTraceCallSignature::ApiTraceCallSignature(const QString &name,
538                                              const QStringList &argNames)
539     : m_name(name),
540       m_argNames(argNames)
541 {
542 }
543
544 ApiTraceCallSignature::~ApiTraceCallSignature()
545 {
546 }
547
548 QUrl ApiTraceCallSignature::helpUrl() const
549 {
550     return m_helpUrl;
551 }
552
553 void ApiTraceCallSignature::setHelpUrl(const QUrl &url)
554 {
555     m_helpUrl = url;
556 }
557
558 ApiTraceEvent::ApiTraceEvent()
559     : m_type(ApiTraceEvent::None),
560       m_hasBinaryData(false),
561       m_binaryDataIndex(0),
562       m_state(0),
563       m_staticText(0)
564 {
565 }
566
567 ApiTraceEvent::ApiTraceEvent(Type t)
568     : m_type(t),
569       m_hasBinaryData(false),
570       m_binaryDataIndex(0),
571       m_state(0),
572       m_staticText(0)
573 {
574 }
575
576 ApiTraceEvent::~ApiTraceEvent()
577 {
578     delete m_state;
579     delete m_staticText;
580 }
581
582 QVariantMap ApiTraceEvent::stateParameters() const
583 {
584     if (m_state) {
585         return m_state->parameters();
586     } else {
587         return QVariantMap();
588     }
589 }
590
591 ApiTraceState *ApiTraceEvent::state() const
592 {
593     return m_state;
594 }
595
596 void ApiTraceEvent::setState(ApiTraceState *state)
597 {
598     m_state = state;
599 }
600
601 ApiTraceCall::ApiTraceCall(ApiTraceFrame *parentFrame, const Trace::Call *call)
602     : ApiTraceEvent(ApiTraceEvent::Call),
603       m_parentFrame(parentFrame)
604 {
605     ApiTrace *trace = parentTrace();
606
607     Q_ASSERT(trace);
608
609     m_index = call->no;
610
611     m_signature = trace->signature(call->sig->id);
612
613     if (!m_signature) {
614         QString name = QString::fromStdString(call->sig->name);
615         QStringList argNames;
616         argNames.reserve(call->sig->num_args);
617         for (int i = 0; i < call->sig->num_args; ++i) {
618             argNames += QString::fromStdString(call->sig->arg_names[i]);
619         }
620         m_signature = new ApiTraceCallSignature(name, argNames);
621         trace->addSignature(call->sig->id, m_signature);
622     }
623     if (call->ret) {
624         VariantVisitor retVisitor(trace);
625         call->ret->visit(retVisitor);
626         m_returnValue = retVisitor.variant();
627     }
628     m_argValues.reserve(call->args.size());
629     for (int i = 0; i < call->args.size(); ++i) {
630         VariantVisitor argVisitor(trace);
631         call->args[i]->visit(argVisitor);
632         m_argValues.append(argVisitor.variant());
633         if (m_argValues[i].type() == QVariant::ByteArray) {
634             m_hasBinaryData = true;
635             m_binaryDataIndex = i;
636         }
637     }
638 }
639
640 ApiTraceCall::~ApiTraceCall()
641 {
642 }
643
644
645 bool ApiTraceCall::hasError() const
646 {
647     return !m_error.isEmpty();
648 }
649
650 QString ApiTraceCall::error() const
651 {
652     return m_error;
653 }
654
655 void ApiTraceCall::setError(const QString &msg)
656 {
657     if (m_error != msg) {
658         ApiTrace *trace = parentTrace();
659         m_error = msg;
660         m_richText = QString();
661         if (trace)
662             trace->callError(this);
663     }
664 }
665
666 ApiTrace * ApiTraceCall::parentTrace() const
667 {
668     if (m_parentFrame)
669         return m_parentFrame->parentTrace();
670     return NULL;
671 }
672
673 QVariantList ApiTraceCall::originalValues() const
674 {
675     return m_argValues;
676 }
677
678 void ApiTraceCall::setEditedValues(const QVariantList &lst)
679 {
680     ApiTrace *trace = parentTrace();
681
682     m_editedValues = lst;
683     //lets regenerate data
684     m_richText = QString();
685     m_searchText = QString();
686     delete m_staticText;
687     m_staticText = 0;
688
689     if (trace) {
690         if (!lst.isEmpty()) {
691             trace->callEdited(this);
692         } else {
693             trace->callReverted(this);
694         }
695     }
696 }
697
698 QVariantList ApiTraceCall::editedValues() const
699 {
700     return m_editedValues;
701 }
702
703 bool ApiTraceCall::edited() const
704 {
705     return !m_editedValues.isEmpty();
706 }
707
708 void ApiTraceCall::revert()
709 {
710     setEditedValues(QVariantList());
711 }
712
713 void ApiTraceCall::setHelpUrl(const QUrl &url)
714 {
715     m_signature->setHelpUrl(url);
716 }
717
718 void ApiTraceCall::setParentFrame(ApiTraceFrame *frame)
719 {
720     m_parentFrame = frame;
721 }
722
723 ApiTraceFrame * ApiTraceCall::parentFrame()const
724 {
725     return m_parentFrame;
726 }
727
728 int ApiTraceCall::index() const
729 {
730     return m_index;
731 }
732
733 QString ApiTraceCall::name() const
734 {
735     return m_signature->name();
736 }
737
738 QStringList ApiTraceCall::argNames() const
739 {
740     return m_signature->argNames();
741 }
742
743 QVariantList ApiTraceCall::arguments() const
744 {
745     if (m_editedValues.isEmpty())
746         return m_argValues;
747     else
748         return m_editedValues;
749 }
750
751 QVariant ApiTraceCall::returnValue() const
752 {
753     return m_returnValue;
754 }
755
756 QUrl ApiTraceCall::helpUrl() const
757 {
758     return m_signature->helpUrl();
759 }
760
761 bool ApiTraceCall::hasBinaryData() const
762 {
763     return m_hasBinaryData;
764 }
765
766 int ApiTraceCall::binaryDataIndex() const
767 {
768     return m_binaryDataIndex;
769 }
770
771 QStaticText ApiTraceCall::staticText() const
772 {
773     if (m_staticText && !m_staticText->text().isEmpty())
774         return *m_staticText;
775
776     QVariantList argValues = arguments();
777
778     QString richText = QString::fromLatin1(
779         "<span style=\"font-weight:bold\">%1</span>(").arg(
780             m_signature->name());
781     QStringList argNames = m_signature->argNames();
782     for (int i = 0; i < argNames.count(); ++i) {
783         richText += QLatin1String("<span style=\"color:#0000ff\">");
784         QString argText = apiVariantToString(argValues[i]);
785
786         //if arguments are really long (e.g. shader text), cut them
787         // and elide it
788         if (argText.length() > 40) {
789             QString shortened = argText.mid(0, 40);
790             shortened[argText.length() - 5] = '.';
791             shortened[argText.length() - 4] = '.';
792             shortened[argText.length() - 3] = '.';
793             shortened[argText.length() - 2] = argText.at(argText.length() - 2);
794             shortened[argText.length() - 1] = argText.at(argText.length() - 1);
795             richText += shortened;
796         } else {
797             richText += argText;
798         }
799         richText += QLatin1String("</span>");
800         if (i < argNames.count() - 1)
801             richText += QLatin1String(", ");
802     }
803     richText += QLatin1String(")");
804     if (m_returnValue.isValid()) {
805         richText +=
806             QLatin1Literal(" = ") %
807             QLatin1Literal("<span style=\"color:#0000ff\">") %
808             apiVariantToString(m_returnValue) %
809             QLatin1Literal("</span>");
810     }
811
812     if (!m_staticText)
813         m_staticText = new QStaticText(richText);
814     else
815         m_staticText->setText(richText);
816     QTextOption opt;
817     opt.setWrapMode(QTextOption::NoWrap);
818     m_staticText->setTextOption(opt);
819     m_staticText->prepare();
820
821     return *m_staticText;
822 }
823
824 QString ApiTraceCall::toHtml() const
825 {
826     if (!m_richText.isEmpty())
827         return m_richText;
828
829     m_richText = QLatin1String("<div class=\"call\">");
830
831     QUrl helpUrl = m_signature->helpUrl();
832     if (helpUrl.isEmpty()) {
833         m_richText += QString::fromLatin1(
834             "%1) <span class=\"callName\">%2</span>(")
835                       .arg(m_index)
836                       .arg(m_signature->name());
837     } else {
838         m_richText += QString::fromLatin1(
839             "%1) <span class=\"callName\"><a href=\"%2\">%3</a></span>(")
840                       .arg(m_index)
841                       .arg(helpUrl.toString())
842                       .arg(m_signature->name());
843     }
844
845     QVariantList argValues = arguments();
846     QStringList argNames = m_signature->argNames();
847     for (int i = 0; i < argNames.count(); ++i) {
848         m_richText +=
849             QLatin1String("<span class=\"arg-name\">") +
850             argNames[i] +
851             QLatin1String("</span>") +
852             QLatin1Literal(" = ") +
853             QLatin1Literal("<span class=\"arg-value\">") +
854             apiVariantToString(argValues[i], true) +
855             QLatin1Literal("</span>");
856         if (i < argNames.count() - 1)
857             m_richText += QLatin1String(", ");
858     }
859     m_richText += QLatin1String(")");
860
861     if (m_returnValue.isValid()) {
862         m_richText +=
863             QLatin1String(" = ") +
864             QLatin1String("<span style=\"color:#0000ff\">") +
865             apiVariantToString(m_returnValue, true) +
866             QLatin1String("</span>");
867     }
868     m_richText += QLatin1String("</div>");
869
870     if (hasError()) {
871         QString errorStr =
872             QString::fromLatin1(
873                 "<div class=\"error\">%1</div>")
874             .arg(m_error);
875         m_richText += errorStr;
876     }
877
878     m_richText =
879         QString::fromLatin1(
880             "<html><head><style type=\"text/css\" media=\"all\">"
881             "%1</style></head><body>%2</body></html>")
882         .arg(styleSheet)
883         .arg(m_richText);
884     m_richText.squeeze();
885
886     //qDebug()<<m_richText;
887     return m_richText;
888 }
889
890 QString ApiTraceCall::searchText() const
891 {
892     if (!m_searchText.isEmpty())
893         return m_searchText;
894
895     QVariantList argValues = arguments();
896     m_searchText = m_signature->name() + QLatin1Literal("(");
897     QStringList argNames = m_signature->argNames();
898     for (int i = 0; i < argNames.count(); ++i) {
899         m_searchText += argNames[i] +
900                         QLatin1Literal(" = ") +
901                         apiVariantToString(argValues[i]);
902         if (i < argNames.count() - 1)
903             m_searchText += QLatin1String(", ");
904     }
905     m_searchText += QLatin1String(")");
906
907     if (m_returnValue.isValid()) {
908         m_searchText += QLatin1Literal(" = ") +
909                         apiVariantToString(m_returnValue);
910     }
911     m_searchText.squeeze();
912     return m_searchText;
913 }
914
915 int ApiTraceCall::numChildren() const
916 {
917     return 0;
918 }
919
920 ApiTraceFrame::ApiTraceFrame(ApiTrace *parentTrace)
921     : ApiTraceEvent(ApiTraceEvent::Frame),
922       m_parentTrace(parentTrace),
923       m_binaryDataSize(0)
924 {
925 }
926
927 QStaticText ApiTraceFrame::staticText() const
928 {
929     if (m_staticText && !m_staticText->text().isEmpty())
930         return *m_staticText;
931
932     QString richText;
933
934     //mark the frame if it uploads more than a meg a frame
935     if (m_binaryDataSize > (1024*1024)) {
936         richText =
937             QObject::tr(
938                 "<span style=\"font-weight:bold;\">"
939                 "Frame&nbsp;%1</span>"
940                 "<span style=\"font-style:italic;\">"
941                 "&nbsp;&nbsp;&nbsp;&nbsp;(%2MB)</span>")
942             .arg(number)
943             .arg(double(m_binaryDataSize / (1024.*1024.)), 0, 'g', 2);
944     } else {
945         richText =
946             QObject::tr(
947                 "<span style=\"font-weight:bold\">Frame %1</span>")
948             .arg(number);
949     }
950
951     if (!m_staticText)
952         m_staticText = new QStaticText(richText);
953
954     QTextOption opt;
955     opt.setWrapMode(QTextOption::NoWrap);
956     m_staticText->setTextOption(opt);
957     m_staticText->prepare();
958
959     return *m_staticText;
960 }
961
962 int ApiTraceFrame::numChildren() const
963 {
964     return m_calls.count();
965 }
966
967 ApiTrace * ApiTraceFrame::parentTrace() const
968 {
969     return m_parentTrace;
970 }
971
972 void ApiTraceFrame::addCall(ApiTraceCall *call)
973 {
974     m_calls.append(call);
975     if (call->hasBinaryData()) {
976         QByteArray data =
977             call->arguments()[call->binaryDataIndex()].toByteArray();
978         m_binaryDataSize += data.size();
979     }
980 }
981
982 QVector<ApiTraceCall*> ApiTraceFrame::calls() const
983 {
984     return m_calls;
985 }
986
987 ApiTraceCall * ApiTraceFrame::call(int idx) const
988 {
989     return m_calls.value(idx);
990 }
991
992 int ApiTraceFrame::callIndex(ApiTraceCall *call) const
993 {
994     return m_calls.indexOf(call);
995 }
996
997 bool ApiTraceFrame::isEmpty() const
998 {
999     return m_calls.isEmpty();
1000 }
1001
1002 int ApiTraceFrame::binaryDataSize() const
1003 {
1004     return m_binaryDataSize;
1005 }
1006
1007 void ApiTraceFrame::setCalls(const QVector<ApiTraceCall*> &calls,
1008                              quint64 binaryDataSize)
1009 {
1010     m_calls = calls;
1011     m_binaryDataSize = binaryDataSize;
1012 }