1 #include "mainwindow.h"
4 #include "apitracecall.h"
5 #include "apicalldelegate.h"
6 #include "apitracemodel.h"
7 #include "apitracefilter.h"
8 #include "argumentseditor.h"
9 #include "imageviewer.h"
10 #include "jumpwidget.h"
12 #include "searchwidget.h"
13 #include "settingsdialog.h"
14 #include "shaderssourcewidget.h"
15 #include "tracedialog.h"
16 #include "traceprocess.h"
17 #include "ui_retracerdialog.h"
18 #include "vertexdatainterpreter.h"
22 #include <QDesktopServices>
24 #include <QFileDialog>
26 #include <QMessageBox>
27 #include <QProgressBar>
30 #include <QVBoxLayout>
35 MainWindow::MainWindow()
45 void MainWindow::createTrace()
49 if (!m_traceProcess->canTrace()) {
53 tr("Current configuration doesn't support tracing."));
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();
66 void MainWindow::openTrace()
69 QFileDialog::getOpenFileName(
73 tr("Trace Files (*.trace)"));
75 qDebug()<< "File name : " <<fileName;
77 newTraceFile(fileName);
80 void MainWindow::loadTrace(const QString &fileName)
82 if (!QFile::exists(fileName)) {
83 QMessageBox::warning(this, tr("File Missing"),
84 tr("File '%1' doesn't exist.").arg(fileName));
87 qDebug()<< "Loading : " <<fileName;
89 m_progressBar->setValue(0);
90 newTraceFile(fileName);
93 void MainWindow::callItemSelected(const QModelIndex &index)
95 ApiTraceEvent *event =
96 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
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()) {
104 call->arguments()[call->binaryDataIndex()].toByteArray();
105 m_vdataInterpreter->setData(data);
106 QVariantList args = call->arguments();
108 for (int i = 0; i < call->argNames().count(); ++i) {
109 QString name = call->argNames()[i];
110 if (name == QLatin1String("stride")) {
111 int stride = args[i].toInt();
112 m_ui.vertexStrideSB->setValue(stride);
113 } else if (name == QLatin1String("size")) {
114 int components = args[i].toInt();
115 m_ui.vertexComponentsSB->setValue(components);
116 } else if (name == QLatin1String("type")) {
117 QString val = args[i].toString();
118 int textIndex = m_ui.vertexTypeCB->findText(val);
120 m_ui.vertexTypeCB->setCurrentIndex(textIndex);
124 m_ui.vertexDataDock->setVisible(call->hasBinaryData());
125 m_selectedEvent = call;
127 if (event && event->type() == ApiTraceEvent::Frame) {
128 m_selectedEvent = static_cast<ApiTraceFrame*>(event);
131 m_ui.detailsDock->hide();
132 m_ui.vertexDataDock->hide();
134 if (m_selectedEvent && !m_selectedEvent->state().isEmpty()) {
137 m_ui.stateDock->hide();
140 void MainWindow::replayStart()
142 if (m_trace->isSaving()) {
143 QMessageBox::warning(
146 tr("QApiTrace is currently saving the edited trace file. "
147 "Please wait until it finishes and try again."));
151 Ui_RetracerDialog dlgUi;
154 dlgUi.doubleBufferingCB->setChecked(
155 m_retracer->isDoubleBuffered());
156 dlgUi.errorCheckCB->setChecked(
157 !m_retracer->isBenchmarking());
159 if (dlg.exec() == QDialog::Accepted) {
160 m_retracer->setDoubleBuffered(
161 dlgUi.doubleBufferingCB->isChecked());
162 m_retracer->setBenchmarking(
163 !dlgUi.errorCheckCB->isChecked());
168 void MainWindow::replayStop()
171 m_ui.actionStop->setEnabled(false);
172 m_ui.actionReplay->setEnabled(true);
173 m_ui.actionLookupState->setEnabled(true);
176 void MainWindow::newTraceFile(const QString &fileName)
178 m_trace->setFileName(fileName);
180 if (fileName.isEmpty()) {
181 m_ui.actionReplay->setEnabled(false);
182 m_ui.actionLookupState->setEnabled(false);
183 setWindowTitle(tr("QApiTrace"));
185 QFileInfo info(fileName);
186 m_ui.actionReplay->setEnabled(true);
187 m_ui.actionLookupState->setEnabled(true);
189 tr("QApiTrace - %1").arg(info.fileName()));
193 void MainWindow::replayFinished(const QString &output)
195 m_ui.actionStop->setEnabled(false);
196 m_ui.actionReplay->setEnabled(true);
197 m_ui.actionLookupState->setEnabled(true);
199 m_progressBar->hide();
200 if (output.length() < 80) {
201 statusBar()->showMessage(output);
204 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
205 m_ui.errorsDock->setVisible(m_trace->hasErrors());
206 if (!m_trace->hasErrors())
207 m_ui.errorsTreeWidget->clear();
209 statusBar()->showMessage(
210 tr("Replaying finished!"), 2000);
213 void MainWindow::replayError(const QString &message)
215 m_ui.actionStop->setEnabled(false);
216 m_ui.actionReplay->setEnabled(true);
217 m_ui.actionLookupState->setEnabled(true);
220 m_progressBar->hide();
221 statusBar()->showMessage(
222 tr("Replaying unsuccessful."), 2000);
223 QMessageBox::warning(
224 this, tr("Replay Failed"), message);
227 void MainWindow::startedLoadingTrace()
230 m_progressBar->show();
231 QFileInfo info(m_trace->fileName());
232 statusBar()->showMessage(
233 tr("Loading %1...").arg(info.fileName()));
236 void MainWindow::finishedLoadingTrace()
238 m_progressBar->hide();
242 QFileInfo info(m_trace->fileName());
243 statusBar()->showMessage(
244 tr("Loaded %1").arg(info.fileName()), 3000);
247 void MainWindow::replayTrace(bool dumpState)
249 if (m_trace->fileName().isEmpty())
252 m_retracer->setFileName(m_trace->fileName());
253 m_retracer->setCaptureState(dumpState);
254 if (m_retracer->captureState() && m_selectedEvent) {
256 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
257 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
258 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
259 ApiTraceFrame *frame =
260 static_cast<ApiTraceFrame*>(m_selectedEvent);
261 if (frame->calls.isEmpty()) {
262 //XXX i guess we could still get the current state
263 qDebug()<<"tried to get a state for an empty frame";
266 index = frame->calls.first()->index();
268 qDebug()<<"Unknown event type";
271 m_retracer->setCaptureAtCallNumber(index);
275 m_ui.actionStop->setEnabled(true);
276 m_progressBar->show();
278 statusBar()->showMessage(
279 tr("Looking up the state..."));
281 statusBar()->showMessage(
282 tr("Replaying the trace file..."));
285 void MainWindow::lookupState()
287 if (!m_selectedEvent) {
288 QMessageBox::warning(
289 this, tr("Unknown Event"),
290 tr("To inspect the state select an event in the event list."));
293 if (m_trace->isSaving()) {
294 QMessageBox::warning(
297 tr("QApiTrace is currently saving the edited trace file. "
298 "Please wait until it finishes and try again."));
301 m_stateEvent = m_selectedEvent;
305 MainWindow::~MainWindow()
310 variantToString(const QVariant &var, QString &str)
312 if (var.type() == QVariant::List) {
313 QVariantList lst = var.toList();
314 str += QLatin1String("[");
315 for (int i = 0; i < lst.count(); ++i) {
316 QVariant val = lst[i];
317 variantToString(val, str);
318 if (i < lst.count() - 1)
319 str += QLatin1String(", ");
321 str += QLatin1String("]");
322 } else if (var.type() == QVariant::Map) {
323 Q_ASSERT(!"unsupported state type");
324 } else if (var.type() == QVariant::Hash) {
325 Q_ASSERT(!"unsupported state type");
327 str += var.toString();
331 static QTreeWidgetItem *
332 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar);
335 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap, QList<QTreeWidgetItem *> &items)
337 QVariantMap::const_iterator itr;
338 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
339 QString key = itr.key();
340 QVariant var = itr.value();
341 QVariant defaultVar = defaultMap[key];
343 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
351 variantListToItems(const QVariantList &lst, const QVariantList &defaultLst, QList<QTreeWidgetItem *> &items)
353 for (int i = 0; i < lst.count(); ++i) {
354 QString key = QString::number(i);
355 QVariant var = lst[i];
358 if (i < defaultLst.count()) {
359 defaultVar = defaultLst[i];
362 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
370 isVariantDeep(const QVariant &var)
372 if (var.type() == QVariant::List) {
373 QVariantList lst = var.toList();
374 for (int i = 0; i < lst.count(); ++i) {
375 if (isVariantDeep(lst[i])) {
380 } else if (var.type() == QVariant::Map) {
382 } else if (var.type() == QVariant::Hash) {
389 static QTreeWidgetItem *
390 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar)
392 if (var == defaultVar) {
398 bool deep = isVariantDeep(var);
400 variantToString(var, val);
403 //qDebug()<<"key = "<<key;
404 //qDebug()<<"val = "<<val;
409 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
412 QList<QTreeWidgetItem *> children;
413 if (var.type() == QVariant::Map) {
414 QVariantMap map = var.toMap();
415 QVariantMap defaultMap = defaultVar.toMap();
416 variantMapToItems(map, defaultMap, children);
418 if (var.type() == QVariant::List) {
419 QVariantList lst = var.toList();
420 QVariantList defaultLst = defaultVar.toList();
421 variantListToItems(lst, defaultLst, children);
423 item->addChildren(children);
429 void MainWindow::fillStateForFrame()
433 if (!m_selectedEvent || m_selectedEvent->state().isEmpty())
436 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
437 QVariantMap defaultParams;
439 ApiTraceState defaultState = m_trace->defaultState();
440 defaultParams = defaultState.parameters();
443 const ApiTraceState &state = m_selectedEvent->state();
444 m_ui.stateTreeWidget->clear();
445 params = state.parameters();
446 QList<QTreeWidgetItem *> items;
447 variantMapToItems(params, defaultParams, items);
448 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
450 QMap<QString, QString> shaderSources = state.shaderSources();
451 if (shaderSources.isEmpty()) {
452 m_sourcesWidget->setShaders(shaderSources);
454 m_sourcesWidget->setShaders(shaderSources);
457 const QList<ApiTexture> &textures =
459 const QList<ApiFramebuffer> &fbos =
460 state.framebuffers();
462 m_ui.surfacesTreeWidget->clear();
463 if (textures.isEmpty() && fbos.isEmpty()) {
464 m_ui.surfacesTab->setDisabled(false);
466 m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
467 if (!textures.isEmpty()) {
468 QTreeWidgetItem *textureItem =
469 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
470 textureItem->setText(0, tr("Textures"));
471 if (textures.count() <= 6)
472 textureItem->setExpanded(true);
474 for (int i = 0; i < textures.count(); ++i) {
475 const ApiTexture &texture =
477 QIcon icon(QPixmap::fromImage(texture.thumb()));
478 QTreeWidgetItem *item = new QTreeWidgetItem(textureItem);
479 item->setIcon(0, icon);
480 int width = texture.size().width();
481 int height = texture.size().height();
483 QString::fromLatin1("%1, %2 x %3")
484 .arg(texture.target())
487 item->setText(1, descr);
489 item->setData(0, Qt::UserRole,
493 if (!fbos.isEmpty()) {
494 QTreeWidgetItem *fboItem =
495 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
496 fboItem->setText(0, tr("Framebuffers"));
497 if (fbos.count() <= 6)
498 fboItem->setExpanded(true);
500 for (int i = 0; i < fbos.count(); ++i) {
501 const ApiFramebuffer &fbo =
503 QIcon icon(QPixmap::fromImage(fbo.thumb()));
504 QTreeWidgetItem *item = new QTreeWidgetItem(fboItem);
505 item->setIcon(0, icon);
506 int width = fbo.size().width();
507 int height = fbo.size().height();
509 QString::fromLatin1("%1, %2 x %3")
513 item->setText(1, descr);
515 item->setData(0, Qt::UserRole,
519 m_ui.surfacesTab->setEnabled(true);
521 m_ui.stateDock->show();
524 void MainWindow::showSettings()
526 SettingsDialog dialog;
527 dialog.setFilterModel(m_proxyModel);
532 void MainWindow::openHelp(const QUrl &url)
534 QDesktopServices::openUrl(url);
537 void MainWindow::showSurfacesMenu(const QPoint &pos)
539 QTreeWidget *tree = m_ui.surfacesTreeWidget;
540 QTreeWidgetItem *item = tree->itemAt(pos);
544 QMenu menu(tr("Surfaces"), this);
546 QAction *act = menu.addAction(tr("View Image"));
547 act->setStatusTip(tr("View the currently selected surface"));
548 connect(act, SIGNAL(triggered()),
549 SLOT(showSelectedSurface()));
551 menu.exec(tree->viewport()->mapToGlobal(pos));
554 void MainWindow::showSelectedSurface()
556 QTreeWidgetItem *item =
557 m_ui.surfacesTreeWidget->currentItem();
562 QVariant var = item->data(0, Qt::UserRole);
563 m_imageViewer->setImage(var.value<QImage>());
564 m_imageViewer->show();
565 m_imageViewer->raise();
566 m_imageViewer->activateWindow();
569 void MainWindow::initObjects()
571 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
573 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
574 QVBoxLayout *layout = new QVBoxLayout;
575 layout->addWidget(m_sourcesWidget);
576 m_ui.shadersTab->setLayout(layout);
578 m_trace = new ApiTrace();
579 m_retracer = new Retracer(this);
581 m_vdataInterpreter = new VertexDataInterpreter(this);
582 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
583 m_vdataInterpreter->setStride(
584 m_ui.vertexStrideSB->value());
585 m_vdataInterpreter->setComponents(
586 m_ui.vertexComponentsSB->value());
587 m_vdataInterpreter->setStartingOffset(
588 m_ui.startingOffsetSB->value());
589 m_vdataInterpreter->setTypeFromString(
590 m_ui.vertexTypeCB->currentText());
592 m_imageViewer = new ImageViewer(this);
594 m_model = new ApiTraceModel();
595 m_model->setApiTrace(m_trace);
596 m_proxyModel = new ApiTraceFilter();
597 m_proxyModel->setSourceModel(m_model);
598 m_ui.callView->setModel(m_proxyModel);
599 m_ui.callView->setItemDelegate(new ApiCallDelegate);
600 m_ui.callView->resizeColumnToContents(0);
601 m_ui.callView->header()->swapSections(0, 1);
602 m_ui.callView->setColumnWidth(1, 42);
603 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
605 m_progressBar = new QProgressBar();
606 m_progressBar->setRange(0, 0);
607 statusBar()->addPermanentWidget(m_progressBar);
608 m_progressBar->hide();
610 m_argsEditor = new ArgumentsEditor(this);
612 m_ui.detailsDock->hide();
613 m_ui.errorsDock->hide();
614 m_ui.vertexDataDock->hide();
615 m_ui.stateDock->hide();
616 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
618 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
619 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
621 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
623 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
624 QWebPage::DelegateExternalLinks);
626 m_jumpWidget = new JumpWidget(this);
627 m_ui.centralLayout->addWidget(m_jumpWidget);
628 m_jumpWidget->hide();
630 m_searchWidget = new SearchWidget(this);
631 m_ui.centralLayout->addWidget(m_searchWidget);
632 m_searchWidget->hide();
634 m_traceProcess = new TraceProcess(this);
637 void MainWindow::initConnections()
639 connect(m_trace, SIGNAL(startedLoadingTrace()),
640 this, SLOT(startedLoadingTrace()));
641 connect(m_trace, SIGNAL(finishedLoadingTrace()),
642 this, SLOT(finishedLoadingTrace()));
643 connect(m_trace, SIGNAL(startedSaving()),
644 this, SLOT(slotStartedSaving()));
645 connect(m_trace, SIGNAL(saved()),
646 this, SLOT(slotSaved()));
647 connect(m_trace, SIGNAL(changed(ApiTraceCall*)),
648 this, SLOT(slotTraceChanged(ApiTraceCall*)));
650 connect(m_retracer, SIGNAL(finished(const QString&)),
651 this, SLOT(replayFinished(const QString&)));
652 connect(m_retracer, SIGNAL(error(const QString&)),
653 this, SLOT(replayError(const QString&)));
654 connect(m_retracer, SIGNAL(foundState(const ApiTraceState&)),
655 this, SLOT(replayStateFound(const ApiTraceState&)));
656 connect(m_retracer, SIGNAL(retraceErrors(const QList<RetraceError>&)),
657 this, SLOT(slotRetraceErrors(const QList<RetraceError>&)));
659 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
660 m_vdataInterpreter, SLOT(interpretData()));
661 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
662 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
663 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
664 m_vdataInterpreter, SLOT(setStride(int)));
665 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
666 m_vdataInterpreter, SLOT(setComponents(int)));
667 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
668 m_vdataInterpreter, SLOT(setStartingOffset(int)));
671 connect(m_ui.actionNew, SIGNAL(triggered()),
672 this, SLOT(createTrace()));
673 connect(m_ui.actionOpen, SIGNAL(triggered()),
674 this, SLOT(openTrace()));
675 connect(m_ui.actionQuit, SIGNAL(triggered()),
676 this, SLOT(close()));
678 connect(m_ui.actionFind, SIGNAL(triggered()),
679 this, SLOT(slotSearch()));
680 connect(m_ui.actionGo, SIGNAL(triggered()),
681 this, SLOT(slotGoTo()));
682 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
683 this, SLOT(slotGoFrameStart()));
684 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
685 this, SLOT(slotGoFrameEnd()));
687 connect(m_ui.actionReplay, SIGNAL(triggered()),
688 this, SLOT(replayStart()));
689 connect(m_ui.actionStop, SIGNAL(triggered()),
690 this, SLOT(replayStop()));
691 connect(m_ui.actionLookupState, SIGNAL(triggered()),
692 this, SLOT(lookupState()));
693 connect(m_ui.actionOptions, SIGNAL(triggered()),
694 this, SLOT(showSettings()));
696 connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
697 this, SLOT(callItemSelected(const QModelIndex &)));
698 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
699 this, SLOT(customContextMenuRequested(QPoint)));
701 connect(m_ui.surfacesTreeWidget,
702 SIGNAL(customContextMenuRequested(const QPoint &)),
703 SLOT(showSurfacesMenu(const QPoint &)));
704 connect(m_ui.surfacesTreeWidget,
705 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
706 SLOT(showSelectedSurface()));
708 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
709 this, SLOT(openHelp(const QUrl&)));
711 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
712 this, SLOT(fillState(bool)));
714 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
715 SLOT(slotJumpTo(int)));
717 connect(m_searchWidget,
718 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
719 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
720 connect(m_searchWidget,
721 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
722 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
724 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
725 SLOT(createdTrace(const QString&)));
726 connect(m_traceProcess, SIGNAL(error(const QString&)),
727 SLOT(traceError(const QString&)));
729 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
730 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
731 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
732 m_ui.errorsDock, SLOT(setVisible(bool)));
733 connect(m_ui.errorsTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
734 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
737 void MainWindow::replayStateFound(const ApiTraceState &state)
739 m_stateEvent->setState(state);
740 m_model->stateSetOnEvent(m_stateEvent);
741 if (m_selectedEvent == m_stateEvent) {
744 m_ui.stateDock->hide();
748 void MainWindow::slotGoTo()
750 m_searchWidget->hide();
751 m_jumpWidget->show();
754 void MainWindow::slotJumpTo(int callNum)
756 QModelIndex index = m_proxyModel->callIndex(callNum);
757 if (index.isValid()) {
758 m_ui.callView->setCurrentIndex(index);
762 void MainWindow::createdTrace(const QString &path)
764 qDebug()<<"Done tracing "<<path;
768 void MainWindow::traceError(const QString &msg)
770 QMessageBox::warning(
776 void MainWindow::slotSearch()
778 m_jumpWidget->hide();
779 m_searchWidget->show();
782 void MainWindow::slotSearchNext(const QString &str, Qt::CaseSensitivity sensitivity)
784 QModelIndex index = m_ui.callView->currentIndex();
785 ApiTraceEvent *event = 0;
788 if (!index.isValid()) {
789 index = m_proxyModel->index(0, 0, QModelIndex());
790 if (!index.isValid()) {
791 qDebug()<<"no currently valid index";
792 m_searchWidget->setFound(false);
797 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
798 ApiTraceCall *call = 0;
800 if (event->type() == ApiTraceCall::Call)
801 call = static_cast<ApiTraceCall*>(event);
803 Q_ASSERT(event->type() == ApiTraceCall::Frame);
804 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
805 call = frame->calls.value(0);
809 m_searchWidget->setFound(false);
812 const QList<ApiTraceCall*> &calls = m_trace->calls();
813 int callNum = calls.indexOf(call);
815 for (int i = callNum + 1; i < calls.count(); ++i) {
816 ApiTraceCall *testCall = calls[i];
817 QString txt = testCall->filterText();
818 if (txt.contains(str, sensitivity)) {
819 QModelIndex index = m_proxyModel->indexForCall(testCall);
820 /* if it's not valid it means that the proxy model has already
822 if (index.isValid()) {
823 m_ui.callView->setCurrentIndex(index);
824 m_searchWidget->setFound(true);
829 m_searchWidget->setFound(false);
832 void MainWindow::slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitivity)
834 QModelIndex index = m_ui.callView->currentIndex();
835 ApiTraceEvent *event = 0;
838 if (!index.isValid()) {
839 index = m_proxyModel->index(0, 0, QModelIndex());
840 if (!index.isValid()) {
841 qDebug()<<"no currently valid index";
842 m_searchWidget->setFound(false);
847 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
848 ApiTraceCall *call = 0;
850 if (event->type() == ApiTraceCall::Call)
851 call = static_cast<ApiTraceCall*>(event);
853 Q_ASSERT(event->type() == ApiTraceCall::Frame);
854 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
855 call = frame->calls.value(0);
859 m_searchWidget->setFound(false);
862 const QList<ApiTraceCall*> &calls = m_trace->calls();
863 int callNum = calls.indexOf(call);
865 for (int i = callNum - 1; i >= 0; --i) {
866 ApiTraceCall *testCall = calls[i];
867 QString txt = testCall->filterText();
868 if (txt.contains(str, sensitivity)) {
869 QModelIndex index = m_proxyModel->indexForCall(testCall);
870 /* if it's not valid it means that the proxy model has already
872 if (index.isValid()) {
873 m_ui.callView->setCurrentIndex(index);
874 m_searchWidget->setFound(true);
879 m_searchWidget->setFound(false);
882 void MainWindow::fillState(bool nonDefaults)
885 ApiTraceState defaultState = m_trace->defaultState();
886 if (defaultState.isEmpty()) {
887 m_ui.nonDefaultsCB->blockSignals(true);
888 m_ui.nonDefaultsCB->setChecked(false);
889 m_ui.nonDefaultsCB->blockSignals(false);
890 int ret = QMessageBox::question(
891 this, tr("Empty Default State"),
892 tr("The applcation needs to figure out the "
893 "default state for the current trace. "
894 "This only has to be done once and "
895 "afterwards you will be able to enable "
896 "displaying of non default state for all calls."
897 "\nDo you want to lookup the default state now?"),
898 QMessageBox::Yes | QMessageBox::No);
899 if (ret != QMessageBox::Yes)
901 ApiTraceFrame *firstFrame =
903 ApiTraceEvent *oldSelected = m_selectedEvent;
906 m_selectedEvent = firstFrame;
908 m_selectedEvent = oldSelected;
914 void MainWindow::customContextMenuRequested(QPoint pos)
917 QModelIndex index = m_ui.callView->indexAt(pos);
919 callItemSelected(index);
920 if (!index.isValid())
923 ApiTraceEvent *event =
924 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
925 if (!event || event->type() != ApiTraceEvent::Call)
928 menu.addAction(QIcon(":/resources/media-record.png"),
929 tr("Lookup state"), this, SLOT(lookupState()));
930 menu.addAction(tr("Edit"), this, SLOT(editCall()));
932 menu.exec(QCursor::pos());
935 void MainWindow::editCall()
937 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
938 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
939 m_argsEditor->setCall(call);
940 m_argsEditor->show();
944 void MainWindow::slotStartedSaving()
946 m_progressBar->show();
947 statusBar()->showMessage(
948 tr("Saving to %1").arg(m_trace->fileName()));
951 void MainWindow::slotSaved()
953 statusBar()->showMessage(
954 tr("Saved to %1").arg(m_trace->fileName()), 2000);
955 m_progressBar->hide();
958 void MainWindow::slotGoFrameStart()
960 ApiTraceFrame *frame = currentFrame();
961 if (!frame || frame->calls.isEmpty()) {
965 QList<ApiTraceCall*>::const_iterator itr;
967 itr = frame->calls.constBegin();
968 while (itr != frame->calls.constEnd()) {
969 ApiTraceCall *call = *itr;
970 QModelIndex idx = m_proxyModel->indexForCall(call);
972 m_ui.callView->setCurrentIndex(idx);
979 void MainWindow::slotGoFrameEnd()
981 ApiTraceFrame *frame = currentFrame();
982 if (!frame || frame->calls.isEmpty()) {
985 QList<ApiTraceCall*>::const_iterator itr;
987 itr = frame->calls.constEnd();
990 ApiTraceCall *call = *itr;
991 QModelIndex idx = m_proxyModel->indexForCall(call);
993 m_ui.callView->setCurrentIndex(idx);
996 } while (itr != frame->calls.constBegin());
999 ApiTraceFrame * MainWindow::currentFrame() const
1001 if (m_selectedEvent) {
1002 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
1003 return static_cast<ApiTraceFrame*>(m_selectedEvent);
1005 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1006 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1007 return call->parentFrame();
1013 void MainWindow::slotTraceChanged(ApiTraceCall *call)
1016 if (call == m_selectedEvent) {
1017 m_ui.detailsWebView->setHtml(call->toHtml());
1021 void MainWindow::slotRetraceErrors(const QList<RetraceError> &errors)
1023 m_ui.errorsTreeWidget->clear();
1025 foreach(RetraceError error, errors) {
1026 ApiTraceCall *call = m_trace->callWithIndex(error.callIndex);
1029 call->setError(error.message);
1031 QTreeWidgetItem *item =
1032 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1033 item->setData(0, Qt::DisplayRole, error.callIndex);
1034 item->setData(0, Qt::UserRole, QVariant::fromValue(call));
1035 QString type = error.type;
1036 type[0] = type[0].toUpper();
1037 item->setData(1, Qt::DisplayRole, type);
1038 item->setData(2, Qt::DisplayRole, error.message);
1042 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1045 ApiTraceCall *call =
1046 current->data(0, Qt::UserRole).value<ApiTraceCall*>();
1048 QModelIndex index = m_proxyModel->indexForCall(call);
1049 if (index.isValid()) {
1050 m_ui.callView->setCurrentIndex(index);
1052 statusBar()->showMessage(tr("Call has been filtered out."));
1057 #include "mainwindow.moc"