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>
31 #include <QVBoxLayout>
36 MainWindow::MainWindow()
46 void MainWindow::createTrace()
50 if (!m_traceProcess->canTrace()) {
54 tr("Current configuration doesn't support tracing."));
58 if (dialog.exec() == QDialog::Accepted) {
59 qDebug()<< "App : " <<dialog.applicationPath();
60 qDebug()<< " Arguments: "<<dialog.arguments();
61 m_traceProcess->setExecutablePath(dialog.applicationPath());
62 m_traceProcess->setArguments(dialog.arguments());
63 m_traceProcess->start();
67 void MainWindow::openTrace()
70 QFileDialog::getOpenFileName(
74 tr("Trace Files (*.trace)"));
76 qDebug()<< "File name : " <<fileName;
78 newTraceFile(fileName);
81 void MainWindow::loadTrace(const QString &fileName)
83 if (!QFile::exists(fileName)) {
84 QMessageBox::warning(this, tr("File Missing"),
85 tr("File '%1' doesn't exist.").arg(fileName));
88 qDebug()<< "Loading : " <<fileName;
90 m_progressBar->setValue(0);
91 newTraceFile(fileName);
94 void MainWindow::callItemSelected(const QModelIndex &index)
96 ApiTraceEvent *event =
97 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
99 if (event && event->type() == ApiTraceEvent::Call) {
100 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
101 m_ui.detailsWebView->setHtml(call->toHtml());
102 m_ui.detailsDock->show();
103 if (call->hasBinaryData()) {
105 call->arguments()[call->binaryDataIndex()].toByteArray();
106 m_vdataInterpreter->setData(data);
107 QVariantList args = call->arguments();
109 for (int i = 0; i < call->argNames().count(); ++i) {
110 QString name = call->argNames()[i];
111 if (name == QLatin1String("stride")) {
112 int stride = args[i].toInt();
113 m_ui.vertexStrideSB->setValue(stride);
114 } else if (name == QLatin1String("size")) {
115 int components = args[i].toInt();
116 m_ui.vertexComponentsSB->setValue(components);
117 } else if (name == QLatin1String("type")) {
118 QString val = args[i].toString();
119 int textIndex = m_ui.vertexTypeCB->findText(val);
121 m_ui.vertexTypeCB->setCurrentIndex(textIndex);
125 m_ui.vertexDataDock->setVisible(call->hasBinaryData());
126 m_selectedEvent = call;
128 if (event && event->type() == ApiTraceEvent::Frame) {
129 m_selectedEvent = static_cast<ApiTraceFrame*>(event);
132 m_ui.detailsDock->hide();
133 m_ui.vertexDataDock->hide();
135 if (m_selectedEvent && !m_selectedEvent->state().isEmpty()) {
138 m_ui.stateDock->hide();
141 void MainWindow::replayStart()
143 if (m_trace->isSaving()) {
144 QMessageBox::warning(
147 tr("QApiTrace is currently saving the edited trace file. "
148 "Please wait until it finishes and try again."));
152 Ui_RetracerDialog dlgUi;
155 dlgUi.doubleBufferingCB->setChecked(
156 m_retracer->isDoubleBuffered());
157 dlgUi.benchmarkCB->setChecked(
158 m_retracer->isBenchmarking());
160 if (dlg.exec() == QDialog::Accepted) {
161 m_retracer->setDoubleBuffered(
162 dlgUi.doubleBufferingCB->isChecked());
163 m_retracer->setBenchmarking(
164 dlgUi.benchmarkCB->isChecked());
169 void MainWindow::replayStop()
172 m_ui.actionStop->setEnabled(false);
173 m_ui.actionReplay->setEnabled(true);
174 m_ui.actionLookupState->setEnabled(true);
177 void MainWindow::newTraceFile(const QString &fileName)
179 m_trace->setFileName(fileName);
181 if (fileName.isEmpty()) {
182 m_ui.actionReplay->setEnabled(false);
183 m_ui.actionLookupState->setEnabled(false);
184 setWindowTitle(tr("QApiTrace"));
186 QFileInfo info(fileName);
187 m_ui.actionReplay->setEnabled(true);
188 m_ui.actionLookupState->setEnabled(true);
190 tr("QApiTrace - %1").arg(info.fileName()));
194 void MainWindow::replayFinished(const QString &output)
196 m_ui.actionStop->setEnabled(false);
197 m_ui.actionReplay->setEnabled(true);
198 m_ui.actionLookupState->setEnabled(true);
200 m_progressBar->hide();
201 if (output.length() < 80) {
202 statusBar()->showMessage(output);
205 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
206 m_ui.errorsDock->setVisible(m_trace->hasErrors());
208 statusBar()->showMessage(
209 tr("Replaying finished!"), 2000);
212 void MainWindow::replayError(const QString &message)
214 m_ui.actionStop->setEnabled(false);
215 m_ui.actionReplay->setEnabled(true);
216 m_ui.actionLookupState->setEnabled(true);
219 m_progressBar->hide();
220 statusBar()->showMessage(
221 tr("Replaying unsuccessful."), 2000);
222 QMessageBox::warning(
223 this, tr("Replay Failed"), message);
226 void MainWindow::startedLoadingTrace()
229 m_progressBar->show();
230 QFileInfo info(m_trace->fileName());
231 statusBar()->showMessage(
232 tr("Loading %1...").arg(info.fileName()));
235 void MainWindow::finishedLoadingTrace()
237 m_progressBar->hide();
241 QFileInfo info(m_trace->fileName());
242 statusBar()->showMessage(
243 tr("Loaded %1").arg(info.fileName()), 3000);
246 void MainWindow::replayTrace(bool dumpState)
248 if (m_trace->fileName().isEmpty())
251 m_retracer->setFileName(m_trace->fileName());
252 m_retracer->setCaptureState(dumpState);
253 if (m_retracer->captureState() && m_selectedEvent) {
255 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
256 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
257 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
258 ApiTraceFrame *frame =
259 static_cast<ApiTraceFrame*>(m_selectedEvent);
260 if (frame->calls.isEmpty()) {
261 //XXX i guess we could still get the current state
262 qDebug()<<"tried to get a state for an empty frame";
265 index = frame->calls.first()->index();
267 qDebug()<<"Unknown event type";
270 m_retracer->setCaptureAtCallNumber(index);
274 m_ui.actionStop->setEnabled(true);
275 m_progressBar->show();
277 statusBar()->showMessage(
278 tr("Looking up the state..."));
280 statusBar()->showMessage(
281 tr("Replaying the trace file..."));
284 void MainWindow::lookupState()
286 if (!m_selectedEvent) {
287 QMessageBox::warning(
288 this, tr("Unknown Event"),
289 tr("To inspect the state select an event in the event list."));
292 if (m_trace->isSaving()) {
293 QMessageBox::warning(
296 tr("QApiTrace is currently saving the edited trace file. "
297 "Please wait until it finishes and try again."));
300 m_stateEvent = m_selectedEvent;
304 MainWindow::~MainWindow()
309 variantToString(const QVariant &var, QString &str)
311 if (var.type() == QVariant::List) {
312 QVariantList lst = var.toList();
313 str += QLatin1String("[");
314 for (int i = 0; i < lst.count(); ++i) {
315 QVariant val = lst[i];
316 variantToString(val, str);
317 if (i < lst.count() - 1)
318 str += QLatin1String(", ");
320 str += QLatin1String("]");
321 } else if (var.type() == QVariant::Map) {
322 Q_ASSERT(!"unsupported state type");
323 } else if (var.type() == QVariant::Hash) {
324 Q_ASSERT(!"unsupported state type");
326 str += var.toString();
330 static QTreeWidgetItem *
331 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar);
334 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap, QList<QTreeWidgetItem *> &items)
336 QVariantMap::const_iterator itr;
337 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
338 QString key = itr.key();
339 QVariant var = itr.value();
340 QVariant defaultVar = defaultMap[key];
342 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
350 variantListToItems(const QVariantList &lst, const QVariantList &defaultLst, QList<QTreeWidgetItem *> &items)
352 for (int i = 0; i < lst.count(); ++i) {
353 QString key = QString::number(i);
354 QVariant var = lst[i];
357 if (i < defaultLst.count()) {
358 defaultVar = defaultLst[i];
361 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
369 isVariantDeep(const QVariant &var)
371 if (var.type() == QVariant::List) {
372 QVariantList lst = var.toList();
373 for (int i = 0; i < lst.count(); ++i) {
374 if (isVariantDeep(lst[i])) {
379 } else if (var.type() == QVariant::Map) {
381 } else if (var.type() == QVariant::Hash) {
388 static QTreeWidgetItem *
389 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar)
391 if (var == defaultVar) {
397 bool deep = isVariantDeep(var);
399 variantToString(var, val);
402 //qDebug()<<"key = "<<key;
403 //qDebug()<<"val = "<<val;
408 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
411 QList<QTreeWidgetItem *> children;
412 if (var.type() == QVariant::Map) {
413 QVariantMap map = var.toMap();
414 QVariantMap defaultMap = defaultVar.toMap();
415 variantMapToItems(map, defaultMap, children);
417 if (var.type() == QVariant::List) {
418 QVariantList lst = var.toList();
419 QVariantList defaultLst = defaultVar.toList();
420 variantListToItems(lst, defaultLst, children);
422 item->addChildren(children);
428 void MainWindow::fillStateForFrame()
432 if (!m_selectedEvent || m_selectedEvent->state().isEmpty())
435 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
436 QVariantMap defaultParams;
438 ApiTraceState defaultState = m_trace->defaultState();
439 defaultParams = defaultState.parameters();
442 const ApiTraceState &state = m_selectedEvent->state();
443 m_ui.stateTreeWidget->clear();
444 params = state.parameters();
445 QList<QTreeWidgetItem *> items;
446 variantMapToItems(params, defaultParams, items);
447 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
449 QMap<QString, QString> shaderSources = state.shaderSources();
450 if (shaderSources.isEmpty()) {
451 m_sourcesWidget->setShaders(shaderSources);
453 m_sourcesWidget->setShaders(shaderSources);
456 const QList<ApiTexture> &textures =
458 const QList<ApiFramebuffer> &fbos =
459 state.framebuffers();
461 m_ui.surfacesTreeWidget->clear();
462 if (textures.isEmpty() && fbos.isEmpty()) {
463 m_ui.surfacesTab->setDisabled(false);
465 m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
466 if (!textures.isEmpty()) {
467 QTreeWidgetItem *textureItem =
468 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
469 textureItem->setText(0, tr("Textures"));
470 if (textures.count() <= 6)
471 textureItem->setExpanded(true);
473 for (int i = 0; i < textures.count(); ++i) {
474 const ApiTexture &texture =
476 QIcon icon(QPixmap::fromImage(texture.thumb()));
477 QTreeWidgetItem *item = new QTreeWidgetItem(textureItem);
478 item->setIcon(0, icon);
479 int width = texture.size().width();
480 int height = texture.size().height();
482 QString::fromLatin1("%1, %2 x %3")
483 .arg(texture.target())
486 item->setText(1, descr);
488 item->setData(0, Qt::UserRole,
492 if (!fbos.isEmpty()) {
493 QTreeWidgetItem *fboItem =
494 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
495 fboItem->setText(0, tr("Framebuffers"));
496 if (fbos.count() <= 6)
497 fboItem->setExpanded(true);
499 for (int i = 0; i < fbos.count(); ++i) {
500 const ApiFramebuffer &fbo =
502 QIcon icon(QPixmap::fromImage(fbo.thumb()));
503 QTreeWidgetItem *item = new QTreeWidgetItem(fboItem);
504 item->setIcon(0, icon);
505 int width = fbo.size().width();
506 int height = fbo.size().height();
508 QString::fromLatin1("%1, %2 x %3")
512 item->setText(1, descr);
514 item->setData(0, Qt::UserRole,
518 m_ui.surfacesTab->setEnabled(true);
520 m_ui.stateDock->show();
523 void MainWindow::showSettings()
525 SettingsDialog dialog;
526 dialog.setFilterModel(m_proxyModel);
531 void MainWindow::openHelp(const QUrl &url)
533 QDesktopServices::openUrl(url);
536 void MainWindow::showSurfacesMenu(const QPoint &pos)
538 QTreeWidget *tree = m_ui.surfacesTreeWidget;
539 QTreeWidgetItem *item = tree->itemAt(pos);
543 QMenu menu(tr("Surfaces"), this);
545 QAction *act = menu.addAction(tr("View Image"));
546 act->setStatusTip(tr("View the currently selected surface"));
547 connect(act, SIGNAL(triggered()),
548 SLOT(showSelectedSurface()));
550 menu.exec(tree->viewport()->mapToGlobal(pos));
553 void MainWindow::showSelectedSurface()
555 QTreeWidgetItem *item =
556 m_ui.surfacesTreeWidget->currentItem();
561 QVariant var = item->data(0, Qt::UserRole);
562 m_imageViewer->setImage(var.value<QImage>());
563 m_imageViewer->show();
564 m_imageViewer->raise();
565 m_imageViewer->activateWindow();
568 void MainWindow::initObjects()
570 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
572 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
573 QVBoxLayout *layout = new QVBoxLayout;
574 layout->addWidget(m_sourcesWidget);
575 m_ui.shadersTab->setLayout(layout);
577 m_trace = new ApiTrace();
578 m_retracer = new Retracer(this);
580 m_vdataInterpreter = new VertexDataInterpreter(this);
581 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
582 m_vdataInterpreter->setStride(
583 m_ui.vertexStrideSB->value());
584 m_vdataInterpreter->setComponents(
585 m_ui.vertexComponentsSB->value());
586 m_vdataInterpreter->setStartingOffset(
587 m_ui.startingOffsetSB->value());
588 m_vdataInterpreter->setTypeFromString(
589 m_ui.vertexTypeCB->currentText());
591 m_imageViewer = new ImageViewer(this);
593 m_model = new ApiTraceModel();
594 m_model->setApiTrace(m_trace);
595 m_proxyModel = new ApiTraceFilter();
596 m_proxyModel->setSourceModel(m_model);
597 m_ui.callView->setModel(m_proxyModel);
598 m_ui.callView->setItemDelegate(new ApiCallDelegate);
599 m_ui.callView->resizeColumnToContents(0);
600 m_ui.callView->header()->swapSections(0, 1);
601 m_ui.callView->setColumnWidth(1, 42);
602 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
604 m_progressBar = new QProgressBar();
605 m_progressBar->setRange(0, 0);
606 statusBar()->addPermanentWidget(m_progressBar);
607 m_progressBar->hide();
609 m_argsEditor = new ArgumentsEditor(this);
611 m_ui.detailsDock->hide();
612 m_ui.errorsDock->hide();
613 m_ui.vertexDataDock->hide();
614 m_ui.stateDock->hide();
615 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
617 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
618 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
620 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
622 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
623 QWebPage::DelegateExternalLinks);
625 m_jumpWidget = new JumpWidget(this);
626 m_ui.centralLayout->addWidget(m_jumpWidget);
627 m_jumpWidget->hide();
629 m_searchWidget = new SearchWidget(this);
630 m_ui.centralLayout->addWidget(m_searchWidget);
631 m_searchWidget->hide();
633 m_traceProcess = new TraceProcess(this);
635 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_G),
636 this, SLOT(slotGoTo()));
637 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F),
638 this, SLOT(slotSearch()));
641 void MainWindow::initConnections()
643 connect(m_trace, SIGNAL(startedLoadingTrace()),
644 this, SLOT(startedLoadingTrace()));
645 connect(m_trace, SIGNAL(finishedLoadingTrace()),
646 this, SLOT(finishedLoadingTrace()));
647 connect(m_trace, SIGNAL(startedSaving()),
648 this, SLOT(slotStartedSaving()));
649 connect(m_trace, SIGNAL(saved()),
650 this, SLOT(slotSaved()));
651 connect(m_trace, SIGNAL(changed(ApiTraceCall*)),
652 this, SLOT(slotTraceChanged(ApiTraceCall*)));
654 connect(m_retracer, SIGNAL(finished(const QString&)),
655 this, SLOT(replayFinished(const QString&)));
656 connect(m_retracer, SIGNAL(error(const QString&)),
657 this, SLOT(replayError(const QString&)));
658 connect(m_retracer, SIGNAL(foundState(const ApiTraceState&)),
659 this, SLOT(replayStateFound(const ApiTraceState&)));
660 connect(m_retracer, SIGNAL(retraceErrors(const QList<RetraceError>&)),
661 this, SLOT(slotRetraceErrors(const QList<RetraceError>&)));
663 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
664 m_vdataInterpreter, SLOT(interpretData()));
665 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
666 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
667 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
668 m_vdataInterpreter, SLOT(setStride(int)));
669 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
670 m_vdataInterpreter, SLOT(setComponents(int)));
671 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
672 m_vdataInterpreter, SLOT(setStartingOffset(int)));
675 connect(m_ui.actionNew, SIGNAL(triggered()),
676 this, SLOT(createTrace()));
677 connect(m_ui.actionOpen, SIGNAL(triggered()),
678 this, SLOT(openTrace()));
679 connect(m_ui.actionQuit, SIGNAL(triggered()),
680 this, SLOT(close()));
682 connect(m_ui.actionFind, SIGNAL(triggered()),
683 this, SLOT(slotSearch()));
684 connect(m_ui.actionGo, SIGNAL(triggered()),
685 this, SLOT(slotGoTo()));
686 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
687 this, SLOT(slotGoFrameStart()));
688 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
689 this, SLOT(slotGoFrameEnd()));
691 connect(m_ui.actionReplay, SIGNAL(triggered()),
692 this, SLOT(replayStart()));
693 connect(m_ui.actionStop, SIGNAL(triggered()),
694 this, SLOT(replayStop()));
695 connect(m_ui.actionLookupState, SIGNAL(triggered()),
696 this, SLOT(lookupState()));
697 connect(m_ui.actionOptions, SIGNAL(triggered()),
698 this, SLOT(showSettings()));
700 connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
701 this, SLOT(callItemSelected(const QModelIndex &)));
702 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
703 this, SLOT(customContextMenuRequested(QPoint)));
705 connect(m_ui.surfacesTreeWidget,
706 SIGNAL(customContextMenuRequested(const QPoint &)),
707 SLOT(showSurfacesMenu(const QPoint &)));
708 connect(m_ui.surfacesTreeWidget,
709 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
710 SLOT(showSelectedSurface()));
712 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
713 this, SLOT(openHelp(const QUrl&)));
715 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
716 this, SLOT(fillState(bool)));
718 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
719 SLOT(slotJumpTo(int)));
721 connect(m_searchWidget,
722 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
723 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
724 connect(m_searchWidget,
725 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
726 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
728 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
729 SLOT(createdTrace(const QString&)));
730 connect(m_traceProcess, SIGNAL(error(const QString&)),
731 SLOT(traceError(const QString&)));
733 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
734 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
735 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
736 m_ui.errorsDock, SLOT(setVisible(bool)));
737 connect(m_ui.errorsTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
738 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
741 void MainWindow::replayStateFound(const ApiTraceState &state)
743 m_stateEvent->setState(state);
744 m_model->stateSetOnEvent(m_stateEvent);
745 if (m_selectedEvent == m_stateEvent) {
748 m_ui.stateDock->hide();
752 void MainWindow::slotGoTo()
754 m_searchWidget->hide();
755 m_jumpWidget->show();
758 void MainWindow::slotJumpTo(int callNum)
760 QModelIndex index = m_proxyModel->callIndex(callNum);
761 if (index.isValid()) {
762 m_ui.callView->setCurrentIndex(index);
766 void MainWindow::createdTrace(const QString &path)
768 qDebug()<<"Done tracing "<<path;
772 void MainWindow::traceError(const QString &msg)
774 QMessageBox::warning(
780 void MainWindow::slotSearch()
782 m_jumpWidget->hide();
783 m_searchWidget->show();
786 void MainWindow::slotSearchNext(const QString &str, Qt::CaseSensitivity sensitivity)
788 QModelIndex index = m_ui.callView->currentIndex();
789 ApiTraceEvent *event = 0;
792 if (!index.isValid()) {
793 index = m_proxyModel->index(0, 0, QModelIndex());
794 if (!index.isValid()) {
795 qDebug()<<"no currently valid index";
796 m_searchWidget->setFound(false);
801 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
802 ApiTraceCall *call = 0;
804 if (event->type() == ApiTraceCall::Call)
805 call = static_cast<ApiTraceCall*>(event);
807 Q_ASSERT(event->type() == ApiTraceCall::Frame);
808 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
809 call = frame->calls.value(0);
813 m_searchWidget->setFound(false);
816 const QList<ApiTraceCall*> &calls = m_trace->calls();
817 int callNum = calls.indexOf(call);
819 for (int i = callNum + 1; i < calls.count(); ++i) {
820 ApiTraceCall *testCall = calls[i];
821 QString txt = testCall->filterText();
822 if (txt.contains(str, sensitivity)) {
823 QModelIndex index = m_proxyModel->indexForCall(testCall);
824 /* if it's not valid it means that the proxy model has already
826 if (index.isValid()) {
827 m_ui.callView->setCurrentIndex(index);
828 m_searchWidget->setFound(true);
833 m_searchWidget->setFound(false);
836 void MainWindow::slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitivity)
838 QModelIndex index = m_ui.callView->currentIndex();
839 ApiTraceEvent *event = 0;
842 if (!index.isValid()) {
843 index = m_proxyModel->index(0, 0, QModelIndex());
844 if (!index.isValid()) {
845 qDebug()<<"no currently valid index";
846 m_searchWidget->setFound(false);
851 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
852 ApiTraceCall *call = 0;
854 if (event->type() == ApiTraceCall::Call)
855 call = static_cast<ApiTraceCall*>(event);
857 Q_ASSERT(event->type() == ApiTraceCall::Frame);
858 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
859 call = frame->calls.value(0);
863 m_searchWidget->setFound(false);
866 const QList<ApiTraceCall*> &calls = m_trace->calls();
867 int callNum = calls.indexOf(call);
869 for (int i = callNum - 1; i >= 0; --i) {
870 ApiTraceCall *testCall = calls[i];
871 QString txt = testCall->filterText();
872 if (txt.contains(str, sensitivity)) {
873 QModelIndex index = m_proxyModel->indexForCall(testCall);
874 /* if it's not valid it means that the proxy model has already
876 if (index.isValid()) {
877 m_ui.callView->setCurrentIndex(index);
878 m_searchWidget->setFound(true);
883 m_searchWidget->setFound(false);
886 void MainWindow::fillState(bool nonDefaults)
889 ApiTraceState defaultState = m_trace->defaultState();
890 if (defaultState.isEmpty()) {
891 m_ui.nonDefaultsCB->blockSignals(true);
892 m_ui.nonDefaultsCB->setChecked(false);
893 m_ui.nonDefaultsCB->blockSignals(false);
894 int ret = QMessageBox::question(
895 this, tr("Empty Default State"),
896 tr("The applcation needs to figure out the "
897 "default state for the current trace. "
898 "This only has to be done once and "
899 "afterwards you will be able to enable "
900 "displaying of non default state for all calls."
901 "\nDo you want to lookup the default state now?"),
902 QMessageBox::Yes | QMessageBox::No);
903 if (ret != QMessageBox::Yes)
905 ApiTraceFrame *firstFrame =
907 ApiTraceEvent *oldSelected = m_selectedEvent;
910 m_selectedEvent = firstFrame;
912 m_selectedEvent = oldSelected;
918 void MainWindow::customContextMenuRequested(QPoint pos)
921 QModelIndex index = m_ui.callView->indexAt(pos);
923 callItemSelected(index);
924 if (!index.isValid())
927 ApiTraceEvent *event =
928 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
929 if (!event || event->type() != ApiTraceEvent::Call)
932 menu.addAction(QIcon(":/resources/media-record.png"),
933 tr("Lookup state"), this, SLOT(lookupState()));
934 menu.addAction(tr("Edit"), this, SLOT(editCall()));
936 menu.exec(QCursor::pos());
939 void MainWindow::editCall()
941 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
942 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
943 m_argsEditor->setCall(call);
944 m_argsEditor->show();
948 void MainWindow::slotStartedSaving()
950 m_progressBar->show();
951 statusBar()->showMessage(
952 tr("Saving to %1").arg(m_trace->fileName()));
955 void MainWindow::slotSaved()
957 statusBar()->showMessage(
958 tr("Saved to %1").arg(m_trace->fileName()), 2000);
959 m_progressBar->hide();
962 void MainWindow::slotGoFrameStart()
964 ApiTraceFrame *frame = currentFrame();
965 if (!frame || frame->calls.isEmpty()) {
969 QList<ApiTraceCall*>::const_iterator itr;
971 itr = frame->calls.constBegin();
972 while (itr != frame->calls.constEnd()) {
973 ApiTraceCall *call = *itr;
974 QModelIndex idx = m_proxyModel->indexForCall(call);
976 m_ui.callView->setCurrentIndex(idx);
983 void MainWindow::slotGoFrameEnd()
985 ApiTraceFrame *frame = currentFrame();
986 if (!frame || frame->calls.isEmpty()) {
989 QList<ApiTraceCall*>::const_iterator itr;
991 itr = frame->calls.constEnd();
994 ApiTraceCall *call = *itr;
995 QModelIndex idx = m_proxyModel->indexForCall(call);
997 m_ui.callView->setCurrentIndex(idx);
1000 } while (itr != frame->calls.constBegin());
1003 ApiTraceFrame * MainWindow::currentFrame() const
1005 if (m_selectedEvent) {
1006 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
1007 return static_cast<ApiTraceFrame*>(m_selectedEvent);
1009 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1010 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1011 return call->parentFrame();
1017 void MainWindow::slotTraceChanged(ApiTraceCall *call)
1020 if (call == m_selectedEvent) {
1021 m_ui.detailsWebView->setHtml(call->toHtml());
1025 void MainWindow::slotRetraceErrors(const QList<RetraceError> &errors)
1027 m_ui.errorsTreeWidget->clear();
1029 foreach(RetraceError error, errors) {
1030 ApiTraceCall *call = m_trace->callWithIndex(error.callIndex);
1033 call->setError(error.message);
1035 QTreeWidgetItem *item =
1036 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1037 item->setData(0, Qt::DisplayRole, error.callIndex);
1038 item->setData(0, Qt::UserRole, QVariant::fromValue(call));
1039 QString type = error.type;
1040 type[0] = type[0].toUpper();
1041 item->setData(1, Qt::DisplayRole, type);
1042 item->setData(2, Qt::DisplayRole, error.message);
1046 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1049 ApiTraceCall *call =
1050 current->data(0, Qt::UserRole).value<ApiTraceCall*>();
1052 QModelIndex index = m_proxyModel->indexForCall(call);
1053 if (index.isValid()) {
1054 m_ui.callView->setCurrentIndex(index);
1056 statusBar()->showMessage(tr("Call has been filtered out."));
1061 #include "mainwindow.moc"