]> git.cworth.org Git - apitrace/blob - gui/mainwindow.cpp
Implement state diffing.
[apitrace] / gui / mainwindow.cpp
1 #include "mainwindow.h"
2
3 #include "apitrace.h"
4 #include "apitracecall.h"
5 #include "apicalldelegate.h"
6 #include "apitracemodel.h"
7 #include "apitracefilter.h"
8 #include "imageviewer.h"
9 #include "jumpwidget.h"
10 #include "retracer.h"
11 #include "searchwidget.h"
12 #include "settingsdialog.h"
13 #include "shaderssourcewidget.h"
14 #include "tracedialog.h"
15 #include "traceprocess.h"
16 #include "ui_retracerdialog.h"
17 #include "vertexdatainterpreter.h"
18
19 #include <QAction>
20 #include <QDebug>
21 #include <QDesktopServices>
22 #include <QDir>
23 #include <QFileDialog>
24 #include <QLineEdit>
25 #include <QMessageBox>
26 #include <QProgressBar>
27 #include <QShortcut>
28 #include <QToolBar>
29 #include <QUrl>
30 #include <QVBoxLayout>
31 #include <QWebPage>
32 #include <QWebView>
33
34
35 MainWindow::MainWindow()
36     : QMainWindow(),
37       m_selectedEvent(0),
38       m_stateEvent(0)
39 {
40     m_ui.setupUi(this);
41     initObjects();
42     initConnections();
43 }
44
45 void MainWindow::createTrace()
46 {
47     TraceDialog dialog;
48
49     if (!m_traceProcess->canTrace()) {
50         QMessageBox::warning(
51             this,
52             tr("Unsupported"),
53             tr("Current configuration doesn't support tracing."));
54         return;
55     }
56
57     if (dialog.exec() == QDialog::Accepted) {
58         qDebug()<< "App : " <<dialog.applicationPath();
59         qDebug()<< "  Arguments: "<<dialog.arguments();
60         m_traceProcess->setExecutablePath(dialog.applicationPath());
61         m_traceProcess->setArguments(dialog.arguments());
62         m_traceProcess->start();
63     }
64 }
65
66 void MainWindow::openTrace()
67 {
68     QString fileName =
69         QFileDialog::getOpenFileName(
70             this,
71             tr("Open Trace"),
72             QDir::homePath(),
73             tr("Trace Files (*.trace)"));
74
75     qDebug()<< "File name : " <<fileName;
76
77     newTraceFile(fileName);
78 }
79
80 void MainWindow::loadTrace(const QString &fileName)
81 {
82     if (!QFile::exists(fileName)) {
83         QMessageBox::warning(this, tr("File Missing"),
84                              tr("File '%1' doesn't exist.").arg(fileName));
85         return;
86     }
87     qDebug()<< "Loading  : " <<fileName;
88
89     m_progressBar->setValue(0);
90     newTraceFile(fileName);
91 }
92
93 void MainWindow::callItemSelected(const QModelIndex &index)
94 {
95     ApiTraceEvent *event =
96         index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
97
98     if (event && event->type() == ApiTraceEvent::Call) {
99         ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
100         m_ui.detailsWebView->setHtml(call->toHtml());
101         m_ui.detailsDock->show();
102         if (call->hasBinaryData()) {
103             QByteArray data =
104                 call->argValues[call->binaryDataIndex()].toByteArray();
105             m_vdataInterpreter->setData(data);
106
107             for (int i = 0; i < call->argNames.count(); ++i) {
108                 QString name = call->argNames[i];
109                 if (name == QLatin1String("stride")) {
110                     int stride = call->argValues[i].toInt();
111                     m_ui.vertexStrideSB->setValue(stride);
112                 } else if (name == QLatin1String("size")) {
113                     int components = call->argValues[i].toInt();
114                     m_ui.vertexComponentsSB->setValue(components);
115                 } else if (name == QLatin1String("type")) {
116                     QString val = call->argValues[i].toString();
117                     int textIndex = m_ui.vertexTypeCB->findText(val);
118                     if (textIndex >= 0)
119                         m_ui.vertexTypeCB->setCurrentIndex(textIndex);
120                 }
121             }
122         }
123         m_ui.vertexDataDock->setVisible(call->hasBinaryData());
124         m_selectedEvent = call;
125     } else {
126         if (event && event->type() == ApiTraceEvent::Frame) {
127             m_selectedEvent = static_cast<ApiTraceFrame*>(event);
128         } else
129             m_selectedEvent = 0;
130         m_ui.detailsDock->hide();
131         m_ui.vertexDataDock->hide();
132     }
133     if (m_selectedEvent && !m_selectedEvent->state().isEmpty()) {
134         fillStateForFrame();
135     } else
136         m_ui.stateDock->hide();
137 }
138
139 void MainWindow::replayStart()
140 {
141     QDialog dlg;
142     Ui_RetracerDialog dlgUi;
143     dlgUi.setupUi(&dlg);
144
145     dlgUi.doubleBufferingCB->setChecked(
146         m_retracer->isDoubleBuffered());
147     dlgUi.benchmarkCB->setChecked(
148         m_retracer->isBenchmarking());
149
150     if (dlg.exec() == QDialog::Accepted) {
151         m_retracer->setDoubleBuffered(
152             dlgUi.doubleBufferingCB->isChecked());
153         m_retracer->setBenchmarking(
154             dlgUi.benchmarkCB->isChecked());
155         replayTrace(false);
156     }
157 }
158
159 void MainWindow::replayStop()
160 {
161     m_retracer->quit();
162     m_ui.actionStop->setEnabled(false);
163     m_ui.actionReplay->setEnabled(true);
164     m_ui.actionLookupState->setEnabled(true);
165 }
166
167 void MainWindow::newTraceFile(const QString &fileName)
168 {
169     m_traceFileName = fileName;
170     m_trace->setFileName(fileName);
171
172     if (m_traceFileName.isEmpty()) {
173         m_ui.actionReplay->setEnabled(false);
174         m_ui.actionLookupState->setEnabled(false);
175         setWindowTitle(tr("QApiTrace"));
176     } else {
177         QFileInfo info(fileName);
178         m_ui.actionReplay->setEnabled(true);
179         m_ui.actionLookupState->setEnabled(true);
180         setWindowTitle(
181             tr("QApiTrace - %1").arg(info.fileName()));
182     }
183 }
184
185 void MainWindow::replayFinished(const QString &output)
186 {
187     m_ui.actionStop->setEnabled(false);
188     m_ui.actionReplay->setEnabled(true);
189     m_ui.actionLookupState->setEnabled(true);
190
191     m_progressBar->hide();
192     if (output.length() < 80) {
193         statusBar()->showMessage(output);
194     }
195     m_stateEvent = 0;
196     statusBar()->showMessage(
197         tr("Replaying finished!"), 2000);
198 }
199
200 void MainWindow::replayError(const QString &message)
201 {
202     m_ui.actionStop->setEnabled(false);
203     m_ui.actionReplay->setEnabled(true);
204     m_ui.actionLookupState->setEnabled(true);
205     m_stateEvent = 0;
206
207     m_progressBar->hide();
208     statusBar()->showMessage(
209         tr("Replaying unsuccessful."), 2000);
210     QMessageBox::warning(
211         this, tr("Replay Failed"), message);
212 }
213
214 void MainWindow::startedLoadingTrace()
215 {
216     Q_ASSERT(m_trace);
217     m_progressBar->show();
218     QFileInfo info(m_trace->fileName());
219     statusBar()->showMessage(
220         tr("Loading %1...").arg(info.fileName()));
221 }
222
223 void MainWindow::finishedLoadingTrace()
224 {
225     m_progressBar->hide();
226     if (!m_trace) {
227         return;
228     }
229     QFileInfo info(m_trace->fileName());
230     statusBar()->showMessage(
231         tr("Loaded %1").arg(info.fileName()), 3000);
232 }
233
234 void MainWindow::replayTrace(bool dumpState)
235 {
236     if (m_traceFileName.isEmpty())
237         return;
238
239     m_retracer->setFileName(m_traceFileName);
240     m_retracer->setCaptureState(dumpState);
241     if (m_retracer->captureState() && m_selectedEvent) {
242         int index = 0;
243         if (m_selectedEvent->type() == ApiTraceEvent::Call) {
244             index = static_cast<ApiTraceCall*>(m_selectedEvent)->index;
245         } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
246             ApiTraceFrame *frame =
247                 static_cast<ApiTraceFrame*>(m_selectedEvent);
248             if (frame->calls.isEmpty()) {
249                 //XXX i guess we could still get the current state
250                 qDebug()<<"tried to get a state for an empty frame";
251                 return;
252             }
253             index = frame->calls.first()->index;
254         } else {
255             qDebug()<<"Unknown event type";
256             return;
257         }
258         m_retracer->setCaptureAtCallNumber(index);
259     }
260     m_retracer->start();
261
262     m_ui.actionStop->setEnabled(true);
263     m_progressBar->show();
264     if (dumpState)
265         statusBar()->showMessage(
266             tr("Looking up the state..."));
267     else
268         statusBar()->showMessage(
269             tr("Replaying the trace file..."));
270 }
271
272 void MainWindow::lookupState()
273 {
274     if (!m_selectedEvent) {
275         QMessageBox::warning(
276             this, tr("Unknown Event"),
277             tr("To inspect the state select an event in the event list."));
278         return;
279     }
280     m_stateEvent = m_selectedEvent;
281     replayTrace(true);
282 }
283
284 MainWindow::~MainWindow()
285 {
286 }
287
288 static void
289 variantToString(const QVariant &var, QString &str)
290 {
291     if (var.type() == QVariant::List) {
292         QVariantList lst = var.toList();
293         str += QLatin1String("[");
294         for (int i = 0; i < lst.count(); ++i) {
295             QVariant val = lst[i];
296             variantToString(val, str);
297             if (i < lst.count() - 1)
298                 str += QLatin1String(", ");
299         }
300         str += QLatin1String("]");
301     } else if (var.type() == QVariant::Map) {
302         Q_ASSERT(!"unsupported state type");
303     } else if (var.type() == QVariant::Hash) {
304         Q_ASSERT(!"unsupported state type");
305     } else {
306         str += var.toString();
307     }
308 }
309
310 void MainWindow::fillStateForFrame()
311 {
312     QVariantMap::const_iterator itr;
313     QVariantMap params;
314
315     if (!m_selectedEvent || m_selectedEvent->state().isEmpty())
316         return;
317
318     bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
319     ApiTraceState defaultState = m_trace->defaultState();
320     QVariantMap defaultParams = defaultState.parameters();
321
322     const ApiTraceState &state = m_selectedEvent->state();
323     m_ui.stateTreeWidget->clear();
324     params = state.parameters();
325     QList<QTreeWidgetItem *> items;
326     for (itr = params.constBegin(); itr != params.constEnd(); ++itr) {
327         QString key = itr.key();
328         QString val;
329
330         variantToString(itr.value(), val);
331         if (nonDefaults) {
332             QString defaultValue;
333             variantToString(defaultParams[key], defaultValue);
334             if (defaultValue == val)
335                 continue;
336         }
337         //qDebug()<<"key = "<<key;
338         //qDebug()<<"val = "<<val;
339         QStringList lst;
340         lst += key;
341         lst += val;
342         items.append(new QTreeWidgetItem((QTreeWidget*)0, lst));
343     }
344     m_ui.stateTreeWidget->insertTopLevelItems(0, items);
345
346     QStringList shaderSources = state.shaderSources();
347     if (shaderSources.isEmpty()) {
348         m_sourcesWidget->setShaders(shaderSources);
349     } else {
350         m_sourcesWidget->setShaders(shaderSources);
351     }
352
353     const QList<ApiTexture> &textures =
354         state.textures();
355     const QList<ApiFramebuffer> &fbos =
356         state.framebuffers();
357
358     m_ui.surfacesTreeWidget->clear();
359     if (textures.isEmpty() && fbos.isEmpty()) {
360         m_ui.surfacesTab->setDisabled(false);
361     } else {
362         m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
363         if (!textures.isEmpty()) {
364             QTreeWidgetItem *textureItem =
365                 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
366             textureItem->setText(0, tr("Textures"));
367             if (textures.count() <= 6)
368                 textureItem->setExpanded(true);
369
370             for (int i = 0; i < textures.count(); ++i) {
371                 const ApiTexture &texture =
372                     textures[i];
373                 QIcon icon(QPixmap::fromImage(texture.thumb()));
374                 QTreeWidgetItem *item = new QTreeWidgetItem(textureItem);
375                 item->setIcon(0, icon);
376                 int width = texture.size().width();
377                 int height = texture.size().height();
378                 QString descr =
379                     QString::fromLatin1("%1, %2 x %3")
380                     .arg(texture.target())
381                     .arg(width)
382                     .arg(height);
383                 item->setText(1, descr);
384
385                 item->setData(0, Qt::UserRole,
386                               texture.image());
387             }
388         }
389         if (!fbos.isEmpty()) {
390             QTreeWidgetItem *fboItem =
391                 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
392             fboItem->setText(0, tr("Framebuffers"));
393             if (fbos.count() <= 6)
394                 fboItem->setExpanded(true);
395
396             for (int i = 0; i < fbos.count(); ++i) {
397                 const ApiFramebuffer &fbo =
398                     fbos[i];
399                 QIcon icon(QPixmap::fromImage(fbo.thumb()));
400                 QTreeWidgetItem *item = new QTreeWidgetItem(fboItem);
401                 item->setIcon(0, icon);
402                 int width = fbo.size().width();
403                 int height = fbo.size().height();
404                 QString descr =
405                     QString::fromLatin1("%1, %2 x %3")
406                     .arg(fbo.type())
407                     .arg(width)
408                     .arg(height);
409                 item->setText(1, descr);
410
411                 item->setData(0, Qt::UserRole,
412                               fbo.image());
413             }
414         }
415         m_ui.surfacesTab->setEnabled(true);
416     }
417     m_ui.stateDock->show();
418 }
419
420 void MainWindow::showSettings()
421 {
422     SettingsDialog dialog;
423     dialog.setFilterModel(m_proxyModel);
424
425     dialog.exec();
426 }
427
428 void MainWindow::openHelp(const QUrl &url)
429 {
430     QDesktopServices::openUrl(url);
431 }
432
433 void MainWindow::showSurfacesMenu(const QPoint &pos)
434 {
435     QTreeWidget *tree = m_ui.surfacesTreeWidget;
436     QTreeWidgetItem *item = tree->itemAt(pos);
437     if (!item)
438         return;
439
440     QMenu menu(tr("Surfaces"), this);
441     //add needed actions
442     QAction *act = menu.addAction(tr("View Image"));
443     act->setStatusTip(tr("View the currently selected surface"));
444     connect(act, SIGNAL(triggered()),
445             SLOT(showSelectedSurface()));
446
447     menu.exec(tree->viewport()->mapToGlobal(pos));
448 }
449
450 void MainWindow::showSelectedSurface()
451 {
452     QTreeWidgetItem *item =
453         m_ui.surfacesTreeWidget->currentItem();
454
455     if (!item)
456         return;
457
458     QVariant var = item->data(0, Qt::UserRole);
459     m_imageViewer->setImage(var.value<QImage>());
460     m_imageViewer->show();
461     m_imageViewer->raise();
462     m_imageViewer->activateWindow();
463 }
464
465 void MainWindow::initObjects()
466 {
467     m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
468
469     m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
470     QVBoxLayout *layout = new QVBoxLayout;
471     layout->addWidget(m_sourcesWidget);
472     m_ui.shadersTab->setLayout(layout);
473
474     m_trace = new ApiTrace();
475     m_retracer = new Retracer(this);
476
477     m_vdataInterpreter = new VertexDataInterpreter(this);
478     m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
479     m_vdataInterpreter->setStride(
480         m_ui.vertexStrideSB->value());
481     m_vdataInterpreter->setComponents(
482         m_ui.vertexComponentsSB->value());
483     m_vdataInterpreter->setStartingOffset(
484         m_ui.startingOffsetSB->value());
485     m_vdataInterpreter->setTypeFromString(
486         m_ui.vertexTypeCB->currentText());
487
488     m_imageViewer = new ImageViewer(this);
489
490     m_model = new ApiTraceModel();
491     m_model->setApiTrace(m_trace);
492     m_proxyModel = new ApiTraceFilter();
493     m_proxyModel->setSourceModel(m_model);
494     m_ui.callView->setModel(m_proxyModel);
495     m_ui.callView->setItemDelegate(new ApiCallDelegate);
496     m_ui.callView->resizeColumnToContents(0);
497     m_ui.callView->header()->swapSections(0, 1);
498     m_ui.callView->setColumnWidth(1, 42);
499
500     m_progressBar = new QProgressBar();
501     m_progressBar->setRange(0, 0);
502     statusBar()->addPermanentWidget(m_progressBar);
503     m_progressBar->hide();
504
505     m_ui.detailsDock->hide();
506     m_ui.vertexDataDock->hide();
507     m_ui.stateDock->hide();
508     setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
509
510     tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
511
512     m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
513
514     m_ui.detailsWebView->page()->setLinkDelegationPolicy(
515         QWebPage::DelegateExternalLinks);
516
517     m_jumpWidget = new JumpWidget(this);
518     m_ui.centralLayout->addWidget(m_jumpWidget);
519     m_jumpWidget->hide();
520
521     m_searchWidget = new SearchWidget(this);
522     m_ui.centralLayout->addWidget(m_searchWidget);
523     m_searchWidget->hide();
524
525     m_traceProcess = new TraceProcess(this);
526
527     new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_G),
528                   this, SLOT(slotGoTo()));
529     new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F),
530                   this, SLOT(slotSearch()));
531 }
532
533 void MainWindow::initConnections()
534 {
535     connect(m_trace, SIGNAL(startedLoadingTrace()),
536             this, SLOT(startedLoadingTrace()));
537     connect(m_trace, SIGNAL(finishedLoadingTrace()),
538             this, SLOT(finishedLoadingTrace()));
539
540     connect(m_retracer, SIGNAL(finished(const QString&)),
541             this, SLOT(replayFinished(const QString&)));
542     connect(m_retracer, SIGNAL(error(const QString&)),
543             this, SLOT(replayError(const QString&)));
544     connect(m_retracer, SIGNAL(foundState(const ApiTraceState&)),
545             this, SLOT(replayStateFound(const ApiTraceState&)));
546
547     connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
548             m_vdataInterpreter, SLOT(interpretData()));
549     connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
550             m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
551     connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
552             m_vdataInterpreter, SLOT(setStride(int)));
553     connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
554             m_vdataInterpreter, SLOT(setComponents(int)));
555     connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
556             m_vdataInterpreter, SLOT(setStartingOffset(int)));
557
558
559     connect(m_ui.actionNew, SIGNAL(triggered()),
560             this, SLOT(createTrace()));
561     connect(m_ui.actionOpen, SIGNAL(triggered()),
562             this, SLOT(openTrace()));
563     connect(m_ui.actionQuit, SIGNAL(triggered()),
564             this, SLOT(close()));
565
566     connect(m_ui.actionReplay, SIGNAL(triggered()),
567             this, SLOT(replayStart()));
568     connect(m_ui.actionStop, SIGNAL(triggered()),
569             this, SLOT(replayStop()));
570     connect(m_ui.actionLookupState, SIGNAL(triggered()),
571             this, SLOT(lookupState()));
572     connect(m_ui.actionOptions, SIGNAL(triggered()),
573             this, SLOT(showSettings()));
574
575     connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
576             this, SLOT(callItemSelected(const QModelIndex &)));
577
578     connect(m_ui.surfacesTreeWidget,
579             SIGNAL(customContextMenuRequested(const QPoint &)),
580             SLOT(showSurfacesMenu(const QPoint &)));
581     connect(m_ui.surfacesTreeWidget,
582             SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
583             SLOT(showSelectedSurface()));
584
585     connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
586             this, SLOT(openHelp(const QUrl&)));
587
588     connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
589             this, SLOT(fillState(bool)));
590
591     connect(m_jumpWidget, SIGNAL(jumpTo(int)),
592             SLOT(slotJumpTo(int)));
593
594     connect(m_searchWidget,
595             SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
596             SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
597     connect(m_searchWidget,
598             SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
599             SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
600
601     connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
602             SLOT(createdTrace(const QString&)));
603     connect(m_traceProcess, SIGNAL(error(const QString&)),
604             SLOT(traceError(const QString&)));
605 }
606
607 void MainWindow::replayStateFound(const ApiTraceState &state)
608 {
609     m_stateEvent->setState(state);
610     m_model->stateSetOnEvent(m_stateEvent);
611     if (m_selectedEvent == m_stateEvent) {
612         fillStateForFrame();
613     } else {
614         m_ui.stateDock->hide();
615     }
616 }
617
618 void MainWindow::slotGoTo()
619 {
620     m_searchWidget->hide();
621     m_jumpWidget->show();
622 }
623
624 void MainWindow::slotJumpTo(int callNum)
625 {
626     QModelIndex index = m_proxyModel->callIndex(callNum);
627     if (index.isValid()) {
628         m_ui.callView->setCurrentIndex(index);
629     }
630 }
631
632 void MainWindow::createdTrace(const QString &path)
633 {
634     qDebug()<<"Done tracing "<<path;
635     newTraceFile(path);
636 }
637
638 void MainWindow::traceError(const QString &msg)
639 {
640     QMessageBox::warning(
641             this,
642             tr("Tracing Error"),
643             msg);
644 }
645
646 void MainWindow::slotSearch()
647 {
648     m_jumpWidget->hide();
649     m_searchWidget->show();
650 }
651
652 void MainWindow::slotSearchNext(const QString &str, Qt::CaseSensitivity sensitivity)
653 {
654     QModelIndex index = m_ui.callView->currentIndex();
655     ApiTraceEvent *event = 0;
656
657
658     if (!index.isValid()) {
659         index = m_proxyModel->index(0, 0, QModelIndex());
660         if (!index.isValid()) {
661             qDebug()<<"no currently valid index";
662             m_searchWidget->setFound(false);
663             return;
664         }
665     }
666
667     event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
668     ApiTraceCall *call = 0;
669
670     if (event->type() == ApiTraceCall::Call)
671         call = static_cast<ApiTraceCall*>(event);
672     else {
673         Q_ASSERT(event->type() == ApiTraceCall::Frame);
674         ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
675         call = frame->calls.value(0);
676     }
677
678     if (!call) {
679         m_searchWidget->setFound(false);
680         return;
681     }
682     const QList<ApiTraceCall*> &calls = m_trace->calls();
683     int callNum = calls.indexOf(call);
684
685     for (int i = callNum + 1; i < calls.count(); ++i) {
686         ApiTraceCall *testCall = calls[i];
687         QString txt = testCall->filterText();
688         if (txt.contains(str, sensitivity)) {
689             QModelIndex index = m_proxyModel->indexForCall(testCall);
690             /* if it's not valid it means that the proxy model has already
691              * filtered it out */
692             if (index.isValid()) {
693                 m_ui.callView->setCurrentIndex(index);
694                 m_searchWidget->setFound(true);
695                 return;
696             }
697         }
698     }
699     m_searchWidget->setFound(false);
700 }
701
702 void MainWindow::slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitivity)
703 {
704     QModelIndex index = m_ui.callView->currentIndex();
705     ApiTraceEvent *event = 0;
706
707
708     if (!index.isValid()) {
709         index = m_proxyModel->index(0, 0, QModelIndex());
710         if (!index.isValid()) {
711             qDebug()<<"no currently valid index";
712             m_searchWidget->setFound(false);
713             return;
714         }
715     }
716
717     event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
718     ApiTraceCall *call = 0;
719
720     if (event->type() == ApiTraceCall::Call)
721         call = static_cast<ApiTraceCall*>(event);
722     else {
723         Q_ASSERT(event->type() == ApiTraceCall::Frame);
724         ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
725         call = frame->calls.value(0);
726     }
727
728     if (!call) {
729         m_searchWidget->setFound(false);
730         return;
731     }
732     const QList<ApiTraceCall*> &calls = m_trace->calls();
733     int callNum = calls.indexOf(call);
734
735     for (int i = callNum - 1; i >= 0; --i) {
736         ApiTraceCall *testCall = calls[i];
737         QString txt = testCall->filterText();
738         if (txt.contains(str, sensitivity)) {
739             QModelIndex index = m_proxyModel->indexForCall(testCall);
740             /* if it's not valid it means that the proxy model has already
741              * filtered it out */
742             if (index.isValid()) {
743                 m_ui.callView->setCurrentIndex(index);
744                 m_searchWidget->setFound(true);
745                 return;
746             }
747         }
748     }
749     m_searchWidget->setFound(false);
750 }
751
752 void MainWindow::fillState(bool nonDefaults)
753 {
754     if (nonDefaults) {
755         ApiTraceState defaultState = m_trace->defaultState();
756         if (defaultState.isEmpty()) {
757             m_ui.nonDefaultsCB->blockSignals(true);
758             m_ui.nonDefaultsCB->setChecked(false);
759             m_ui.nonDefaultsCB->blockSignals(false);
760             int ret = QMessageBox::question(
761                 this, tr("Empty Default State"),
762                 tr("The applcation needs to figure out the "
763                    "default state for the current trace. "
764                    "This only has to be done once and "
765                    "afterwards you will be able to enable "
766                    "displaying of non default state for all calls."
767                    "\nDo you want to lookup the default state now?"),
768                 QMessageBox::Yes | QMessageBox::No);
769             if (ret != QMessageBox::Yes)
770                 return;
771             ApiTraceFrame *firstFrame =
772                 m_trace->frameAt(0);
773             ApiTraceEvent *oldSelected = m_selectedEvent;
774             if (!firstFrame)
775                 return;
776             m_selectedEvent = firstFrame;
777             lookupState();
778             m_selectedEvent = oldSelected;
779         }
780     }
781     fillStateForFrame();
782 }
783
784 #include "mainwindow.moc"