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"
21 #include <QApplication>
23 #include <QDesktopServices>
24 #include <QDesktopWidget>
26 #include <QFileDialog>
28 #include <QMessageBox>
29 #include <QProgressBar>
32 #include <QVBoxLayout>
37 MainWindow::MainWindow()
47 void MainWindow::createTrace()
51 if (!m_traceProcess->canTrace()) {
55 tr("Current configuration doesn't support tracing."));
59 if (dialog.exec() == QDialog::Accepted) {
60 qDebug()<< "App : " <<dialog.applicationPath();
61 qDebug()<< " Arguments: "<<dialog.arguments();
62 m_traceProcess->setExecutablePath(dialog.applicationPath());
63 m_traceProcess->setArguments(dialog.arguments());
64 m_traceProcess->start();
68 void MainWindow::openTrace()
71 QFileDialog::getOpenFileName(
75 tr("Trace Files (*.trace)"));
77 qDebug()<< "File name : " <<fileName;
79 newTraceFile(fileName);
82 void MainWindow::loadTrace(const QString &fileName)
84 if (!QFile::exists(fileName)) {
85 QMessageBox::warning(this, tr("File Missing"),
86 tr("File '%1' doesn't exist.").arg(fileName));
89 qDebug()<< "Loading : " <<fileName;
91 m_progressBar->setValue(0);
92 newTraceFile(fileName);
95 void MainWindow::callItemSelected(const QModelIndex &index)
97 ApiTraceEvent *event =
98 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
100 if (event && event->type() == ApiTraceEvent::Call) {
101 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
102 m_ui.detailsWebView->setHtml(call->toHtml());
103 m_ui.detailsDock->show();
104 if (call->hasBinaryData()) {
106 call->arguments()[call->binaryDataIndex()].toByteArray();
107 m_vdataInterpreter->setData(data);
108 QVariantList args = call->arguments();
110 for (int i = 0; i < call->argNames().count(); ++i) {
111 QString name = call->argNames()[i];
112 if (name == QLatin1String("stride")) {
113 int stride = args[i].toInt();
114 m_ui.vertexStrideSB->setValue(stride);
115 } else if (name == QLatin1String("size")) {
116 int components = args[i].toInt();
117 m_ui.vertexComponentsSB->setValue(components);
118 } else if (name == QLatin1String("type")) {
119 QString val = args[i].toString();
120 int textIndex = m_ui.vertexTypeCB->findText(val);
122 m_ui.vertexTypeCB->setCurrentIndex(textIndex);
126 m_ui.vertexDataDock->setVisible(call->hasBinaryData());
127 m_selectedEvent = call;
129 if (event && event->type() == ApiTraceEvent::Frame) {
130 m_selectedEvent = static_cast<ApiTraceFrame*>(event);
133 m_ui.detailsDock->hide();
134 m_ui.vertexDataDock->hide();
136 if (m_selectedEvent && !m_selectedEvent->state().isEmpty()) {
139 m_ui.stateDock->hide();
142 void MainWindow::replayStart()
144 if (m_trace->isSaving()) {
145 QMessageBox::warning(
148 tr("QApiTrace is currently saving the edited trace file. "
149 "Please wait until it finishes and try again."));
153 Ui_RetracerDialog dlgUi;
156 dlgUi.doubleBufferingCB->setChecked(
157 m_retracer->isDoubleBuffered());
158 dlgUi.errorCheckCB->setChecked(
159 !m_retracer->isBenchmarking());
161 if (dlg.exec() == QDialog::Accepted) {
162 m_retracer->setDoubleBuffered(
163 dlgUi.doubleBufferingCB->isChecked());
164 m_retracer->setBenchmarking(
165 !dlgUi.errorCheckCB->isChecked());
170 void MainWindow::replayStop()
173 m_ui.actionStop->setEnabled(false);
174 m_ui.actionReplay->setEnabled(true);
175 m_ui.actionLookupState->setEnabled(true);
178 void MainWindow::newTraceFile(const QString &fileName)
180 m_trace->setFileName(fileName);
182 if (fileName.isEmpty()) {
183 m_ui.actionReplay->setEnabled(false);
184 m_ui.actionLookupState->setEnabled(false);
185 setWindowTitle(tr("QApiTrace"));
187 QFileInfo info(fileName);
188 m_ui.actionReplay->setEnabled(true);
189 m_ui.actionLookupState->setEnabled(true);
191 tr("QApiTrace - %1").arg(info.fileName()));
195 void MainWindow::replayFinished(const QString &output)
197 m_ui.actionStop->setEnabled(false);
198 m_ui.actionReplay->setEnabled(true);
199 m_ui.actionLookupState->setEnabled(true);
201 m_progressBar->hide();
202 if (output.length() < 80) {
203 statusBar()->showMessage(output);
206 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
207 m_ui.errorsDock->setVisible(m_trace->hasErrors());
208 if (!m_trace->hasErrors())
209 m_ui.errorsTreeWidget->clear();
211 statusBar()->showMessage(
212 tr("Replaying finished!"), 2000);
215 void MainWindow::replayError(const QString &message)
217 m_ui.actionStop->setEnabled(false);
218 m_ui.actionReplay->setEnabled(true);
219 m_ui.actionLookupState->setEnabled(true);
222 m_progressBar->hide();
223 statusBar()->showMessage(
224 tr("Replaying unsuccessful."), 2000);
225 QMessageBox::warning(
226 this, tr("Replay Failed"), message);
229 void MainWindow::startedLoadingTrace()
232 m_progressBar->show();
233 QFileInfo info(m_trace->fileName());
234 statusBar()->showMessage(
235 tr("Loading %1...").arg(info.fileName()));
238 void MainWindow::finishedLoadingTrace()
240 m_progressBar->hide();
244 QFileInfo info(m_trace->fileName());
245 statusBar()->showMessage(
246 tr("Loaded %1").arg(info.fileName()), 3000);
249 void MainWindow::replayTrace(bool dumpState)
251 if (m_trace->fileName().isEmpty())
254 m_retracer->setFileName(m_trace->fileName());
255 m_retracer->setCaptureState(dumpState);
256 if (m_retracer->captureState() && m_selectedEvent) {
258 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
259 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
260 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
261 ApiTraceFrame *frame =
262 static_cast<ApiTraceFrame*>(m_selectedEvent);
263 if (frame->calls.isEmpty()) {
264 //XXX i guess we could still get the current state
265 qDebug()<<"tried to get a state for an empty frame";
268 index = frame->calls.first()->index();
270 qDebug()<<"Unknown event type";
273 m_retracer->setCaptureAtCallNumber(index);
277 m_ui.actionStop->setEnabled(true);
278 m_progressBar->show();
280 statusBar()->showMessage(
281 tr("Looking up the state..."));
283 statusBar()->showMessage(
284 tr("Replaying the trace file..."));
287 void MainWindow::lookupState()
289 if (!m_selectedEvent) {
290 QMessageBox::warning(
291 this, tr("Unknown Event"),
292 tr("To inspect the state select an event in the event list."));
295 if (m_trace->isSaving()) {
296 QMessageBox::warning(
299 tr("QApiTrace is currently saving the edited trace file. "
300 "Please wait until it finishes and try again."));
303 m_stateEvent = m_selectedEvent;
307 MainWindow::~MainWindow()
312 variantToString(const QVariant &var, QString &str)
314 if (var.type() == QVariant::List) {
315 QVariantList lst = var.toList();
316 str += QLatin1String("[");
317 for (int i = 0; i < lst.count(); ++i) {
318 QVariant val = lst[i];
319 variantToString(val, str);
320 if (i < lst.count() - 1)
321 str += QLatin1String(", ");
323 str += QLatin1String("]");
324 } else if (var.type() == QVariant::Map) {
325 Q_ASSERT(!"unsupported state type");
326 } else if (var.type() == QVariant::Hash) {
327 Q_ASSERT(!"unsupported state type");
329 str += var.toString();
333 static QTreeWidgetItem *
334 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar);
337 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap, QList<QTreeWidgetItem *> &items)
339 QVariantMap::const_iterator itr;
340 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
341 QString key = itr.key();
342 QVariant var = itr.value();
343 QVariant defaultVar = defaultMap[key];
345 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
353 variantListToItems(const QVariantList &lst, const QVariantList &defaultLst, QList<QTreeWidgetItem *> &items)
355 for (int i = 0; i < lst.count(); ++i) {
356 QString key = QString::number(i);
357 QVariant var = lst[i];
360 if (i < defaultLst.count()) {
361 defaultVar = defaultLst[i];
364 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
372 isVariantDeep(const QVariant &var)
374 if (var.type() == QVariant::List) {
375 QVariantList lst = var.toList();
376 for (int i = 0; i < lst.count(); ++i) {
377 if (isVariantDeep(lst[i])) {
382 } else if (var.type() == QVariant::Map) {
384 } else if (var.type() == QVariant::Hash) {
391 static QTreeWidgetItem *
392 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar)
394 if (var == defaultVar) {
400 bool deep = isVariantDeep(var);
402 variantToString(var, val);
405 //qDebug()<<"key = "<<key;
406 //qDebug()<<"val = "<<val;
411 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
414 QList<QTreeWidgetItem *> children;
415 if (var.type() == QVariant::Map) {
416 QVariantMap map = var.toMap();
417 QVariantMap defaultMap = defaultVar.toMap();
418 variantMapToItems(map, defaultMap, children);
420 if (var.type() == QVariant::List) {
421 QVariantList lst = var.toList();
422 QVariantList defaultLst = defaultVar.toList();
423 variantListToItems(lst, defaultLst, children);
425 item->addChildren(children);
431 void MainWindow::fillStateForFrame()
435 if (!m_selectedEvent || m_selectedEvent->state().isEmpty())
438 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
439 QVariantMap defaultParams;
441 ApiTraceState defaultState = m_trace->defaultState();
442 defaultParams = defaultState.parameters();
445 const ApiTraceState &state = m_selectedEvent->state();
446 m_ui.stateTreeWidget->clear();
447 params = state.parameters();
448 QList<QTreeWidgetItem *> items;
449 variantMapToItems(params, defaultParams, items);
450 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
452 QMap<QString, QString> shaderSources = state.shaderSources();
453 if (shaderSources.isEmpty()) {
454 m_sourcesWidget->setShaders(shaderSources);
456 m_sourcesWidget->setShaders(shaderSources);
459 const QList<ApiTexture> &textures =
461 const QList<ApiFramebuffer> &fbos =
462 state.framebuffers();
464 m_ui.surfacesTreeWidget->clear();
465 if (textures.isEmpty() && fbos.isEmpty()) {
466 m_ui.surfacesTab->setDisabled(false);
468 m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
469 if (!textures.isEmpty()) {
470 QTreeWidgetItem *textureItem =
471 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
472 textureItem->setText(0, tr("Textures"));
473 if (textures.count() <= 6)
474 textureItem->setExpanded(true);
476 for (int i = 0; i < textures.count(); ++i) {
477 const ApiTexture &texture =
479 QIcon icon(QPixmap::fromImage(texture.thumb()));
480 QTreeWidgetItem *item = new QTreeWidgetItem(textureItem);
481 item->setIcon(0, icon);
482 int width = texture.size().width();
483 int height = texture.size().height();
485 QString::fromLatin1("%1, %2 x %3")
486 .arg(texture.target())
489 item->setText(1, descr);
491 item->setData(0, Qt::UserRole,
495 if (!fbos.isEmpty()) {
496 QTreeWidgetItem *fboItem =
497 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
498 fboItem->setText(0, tr("Framebuffers"));
499 if (fbos.count() <= 6)
500 fboItem->setExpanded(true);
502 for (int i = 0; i < fbos.count(); ++i) {
503 const ApiFramebuffer &fbo =
505 QIcon icon(QPixmap::fromImage(fbo.thumb()));
506 QTreeWidgetItem *item = new QTreeWidgetItem(fboItem);
507 item->setIcon(0, icon);
508 int width = fbo.size().width();
509 int height = fbo.size().height();
511 QString::fromLatin1("%1, %2 x %3")
515 item->setText(1, descr);
517 item->setData(0, Qt::UserRole,
521 m_ui.surfacesTab->setEnabled(true);
523 m_ui.stateDock->show();
526 void MainWindow::showSettings()
528 SettingsDialog dialog;
529 dialog.setFilterModel(m_proxyModel);
534 void MainWindow::openHelp(const QUrl &url)
536 QDesktopServices::openUrl(url);
539 void MainWindow::showSurfacesMenu(const QPoint &pos)
541 QTreeWidget *tree = m_ui.surfacesTreeWidget;
542 QTreeWidgetItem *item = tree->itemAt(pos);
546 QMenu menu(tr("Surfaces"), this);
548 QAction *act = menu.addAction(tr("View Image"));
549 act->setStatusTip(tr("View the currently selected surface"));
550 connect(act, SIGNAL(triggered()),
551 SLOT(showSelectedSurface()));
553 menu.exec(tree->viewport()->mapToGlobal(pos));
556 void MainWindow::showSelectedSurface()
558 QTreeWidgetItem *item =
559 m_ui.surfacesTreeWidget->currentItem();
564 QVariant var = item->data(0, Qt::UserRole);
565 QImage img = var.value<QImage>();
566 ImageViewer *viewer = new ImageViewer(this);
567 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
568 viewer->setImage(img);
569 QRect screenRect = QApplication::desktop()->availableGeometry();
570 viewer->resize(qMin(int(0.75 * screenRect.width()), img.width()) + 40,
571 qMin(int(0.75 * screenRect.height()), img.height()) + 40);
574 viewer->activateWindow();
577 void MainWindow::initObjects()
579 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
581 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
582 QVBoxLayout *layout = new QVBoxLayout;
583 layout->addWidget(m_sourcesWidget);
584 m_ui.shadersTab->setLayout(layout);
586 m_trace = new ApiTrace();
587 m_retracer = new Retracer(this);
589 m_vdataInterpreter = new VertexDataInterpreter(this);
590 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
591 m_vdataInterpreter->setStride(
592 m_ui.vertexStrideSB->value());
593 m_vdataInterpreter->setComponents(
594 m_ui.vertexComponentsSB->value());
595 m_vdataInterpreter->setStartingOffset(
596 m_ui.startingOffsetSB->value());
597 m_vdataInterpreter->setTypeFromString(
598 m_ui.vertexTypeCB->currentText());
600 m_model = new ApiTraceModel();
601 m_model->setApiTrace(m_trace);
602 m_proxyModel = new ApiTraceFilter();
603 m_proxyModel->setSourceModel(m_model);
604 m_ui.callView->setModel(m_proxyModel);
605 m_ui.callView->setItemDelegate(new ApiCallDelegate);
606 m_ui.callView->resizeColumnToContents(0);
607 m_ui.callView->header()->swapSections(0, 1);
608 m_ui.callView->setColumnWidth(1, 42);
609 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
611 m_progressBar = new QProgressBar();
612 m_progressBar->setRange(0, 0);
613 statusBar()->addPermanentWidget(m_progressBar);
614 m_progressBar->hide();
616 m_argsEditor = new ArgumentsEditor(this);
618 m_ui.detailsDock->hide();
619 m_ui.errorsDock->hide();
620 m_ui.vertexDataDock->hide();
621 m_ui.stateDock->hide();
622 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
624 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
625 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
627 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
629 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
630 QWebPage::DelegateExternalLinks);
632 m_jumpWidget = new JumpWidget(this);
633 m_ui.centralLayout->addWidget(m_jumpWidget);
634 m_jumpWidget->hide();
636 m_searchWidget = new SearchWidget(this);
637 m_ui.centralLayout->addWidget(m_searchWidget);
638 m_searchWidget->hide();
640 m_traceProcess = new TraceProcess(this);
643 void MainWindow::initConnections()
645 connect(m_trace, SIGNAL(startedLoadingTrace()),
646 this, SLOT(startedLoadingTrace()));
647 connect(m_trace, SIGNAL(finishedLoadingTrace()),
648 this, SLOT(finishedLoadingTrace()));
649 connect(m_trace, SIGNAL(startedSaving()),
650 this, SLOT(slotStartedSaving()));
651 connect(m_trace, SIGNAL(saved()),
652 this, SLOT(slotSaved()));
653 connect(m_trace, SIGNAL(changed(ApiTraceCall*)),
654 this, SLOT(slotTraceChanged(ApiTraceCall*)));
656 connect(m_retracer, SIGNAL(finished(const QString&)),
657 this, SLOT(replayFinished(const QString&)));
658 connect(m_retracer, SIGNAL(error(const QString&)),
659 this, SLOT(replayError(const QString&)));
660 connect(m_retracer, SIGNAL(foundState(const ApiTraceState&)),
661 this, SLOT(replayStateFound(const ApiTraceState&)));
662 connect(m_retracer, SIGNAL(retraceErrors(const QList<RetraceError>&)),
663 this, SLOT(slotRetraceErrors(const QList<RetraceError>&)));
665 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
666 m_vdataInterpreter, SLOT(interpretData()));
667 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
668 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
669 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
670 m_vdataInterpreter, SLOT(setStride(int)));
671 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
672 m_vdataInterpreter, SLOT(setComponents(int)));
673 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
674 m_vdataInterpreter, SLOT(setStartingOffset(int)));
677 connect(m_ui.actionNew, SIGNAL(triggered()),
678 this, SLOT(createTrace()));
679 connect(m_ui.actionOpen, SIGNAL(triggered()),
680 this, SLOT(openTrace()));
681 connect(m_ui.actionQuit, SIGNAL(triggered()),
682 this, SLOT(close()));
684 connect(m_ui.actionFind, SIGNAL(triggered()),
685 this, SLOT(slotSearch()));
686 connect(m_ui.actionGo, SIGNAL(triggered()),
687 this, SLOT(slotGoTo()));
688 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
689 this, SLOT(slotGoFrameStart()));
690 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
691 this, SLOT(slotGoFrameEnd()));
693 connect(m_ui.actionReplay, SIGNAL(triggered()),
694 this, SLOT(replayStart()));
695 connect(m_ui.actionStop, SIGNAL(triggered()),
696 this, SLOT(replayStop()));
697 connect(m_ui.actionLookupState, SIGNAL(triggered()),
698 this, SLOT(lookupState()));
699 connect(m_ui.actionOptions, SIGNAL(triggered()),
700 this, SLOT(showSettings()));
702 connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
703 this, SLOT(callItemSelected(const QModelIndex &)));
704 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
705 this, SLOT(customContextMenuRequested(QPoint)));
707 connect(m_ui.surfacesTreeWidget,
708 SIGNAL(customContextMenuRequested(const QPoint &)),
709 SLOT(showSurfacesMenu(const QPoint &)));
710 connect(m_ui.surfacesTreeWidget,
711 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
712 SLOT(showSelectedSurface()));
714 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
715 this, SLOT(openHelp(const QUrl&)));
717 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
718 this, SLOT(fillState(bool)));
720 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
721 SLOT(slotJumpTo(int)));
723 connect(m_searchWidget,
724 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
725 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
726 connect(m_searchWidget,
727 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
728 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
730 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
731 SLOT(createdTrace(const QString&)));
732 connect(m_traceProcess, SIGNAL(error(const QString&)),
733 SLOT(traceError(const QString&)));
735 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
736 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
737 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
738 m_ui.errorsDock, SLOT(setVisible(bool)));
739 connect(m_ui.errorsTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
740 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
743 void MainWindow::replayStateFound(const ApiTraceState &state)
745 m_stateEvent->setState(state);
746 m_model->stateSetOnEvent(m_stateEvent);
747 if (m_selectedEvent == m_stateEvent) {
750 m_ui.stateDock->hide();
754 void MainWindow::slotGoTo()
756 m_searchWidget->hide();
757 m_jumpWidget->show();
760 void MainWindow::slotJumpTo(int callNum)
762 QModelIndex index = m_proxyModel->callIndex(callNum);
763 if (index.isValid()) {
764 m_ui.callView->setCurrentIndex(index);
768 void MainWindow::createdTrace(const QString &path)
770 qDebug()<<"Done tracing "<<path;
774 void MainWindow::traceError(const QString &msg)
776 QMessageBox::warning(
782 void MainWindow::slotSearch()
784 m_jumpWidget->hide();
785 m_searchWidget->show();
788 void MainWindow::slotSearchNext(const QString &str, Qt::CaseSensitivity sensitivity)
790 QModelIndex index = m_ui.callView->currentIndex();
791 ApiTraceEvent *event = 0;
794 if (!index.isValid()) {
795 index = m_proxyModel->index(0, 0, QModelIndex());
796 if (!index.isValid()) {
797 qDebug()<<"no currently valid index";
798 m_searchWidget->setFound(false);
803 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
804 ApiTraceCall *call = 0;
806 if (event->type() == ApiTraceCall::Call)
807 call = static_cast<ApiTraceCall*>(event);
809 Q_ASSERT(event->type() == ApiTraceCall::Frame);
810 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
811 call = frame->calls.value(0);
815 m_searchWidget->setFound(false);
818 const QList<ApiTraceCall*> &calls = m_trace->calls();
819 int callNum = calls.indexOf(call);
821 for (int i = callNum + 1; i < calls.count(); ++i) {
822 ApiTraceCall *testCall = calls[i];
823 QString txt = testCall->filterText();
824 if (txt.contains(str, sensitivity)) {
825 QModelIndex index = m_proxyModel->indexForCall(testCall);
826 /* if it's not valid it means that the proxy model has already
828 if (index.isValid()) {
829 m_ui.callView->setCurrentIndex(index);
830 m_searchWidget->setFound(true);
835 m_searchWidget->setFound(false);
838 void MainWindow::slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitivity)
840 QModelIndex index = m_ui.callView->currentIndex();
841 ApiTraceEvent *event = 0;
844 if (!index.isValid()) {
845 index = m_proxyModel->index(0, 0, QModelIndex());
846 if (!index.isValid()) {
847 qDebug()<<"no currently valid index";
848 m_searchWidget->setFound(false);
853 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
854 ApiTraceCall *call = 0;
856 if (event->type() == ApiTraceCall::Call)
857 call = static_cast<ApiTraceCall*>(event);
859 Q_ASSERT(event->type() == ApiTraceCall::Frame);
860 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
861 call = frame->calls.value(0);
865 m_searchWidget->setFound(false);
868 const QList<ApiTraceCall*> &calls = m_trace->calls();
869 int callNum = calls.indexOf(call);
871 for (int i = callNum - 1; i >= 0; --i) {
872 ApiTraceCall *testCall = calls[i];
873 QString txt = testCall->filterText();
874 if (txt.contains(str, sensitivity)) {
875 QModelIndex index = m_proxyModel->indexForCall(testCall);
876 /* if it's not valid it means that the proxy model has already
878 if (index.isValid()) {
879 m_ui.callView->setCurrentIndex(index);
880 m_searchWidget->setFound(true);
885 m_searchWidget->setFound(false);
888 void MainWindow::fillState(bool nonDefaults)
891 ApiTraceState defaultState = m_trace->defaultState();
892 if (defaultState.isEmpty()) {
893 m_ui.nonDefaultsCB->blockSignals(true);
894 m_ui.nonDefaultsCB->setChecked(false);
895 m_ui.nonDefaultsCB->blockSignals(false);
896 int ret = QMessageBox::question(
897 this, tr("Empty Default State"),
898 tr("The applcation needs to figure out the "
899 "default state for the current trace. "
900 "This only has to be done once and "
901 "afterwards you will be able to enable "
902 "displaying of non default state for all calls."
903 "\nDo you want to lookup the default state now?"),
904 QMessageBox::Yes | QMessageBox::No);
905 if (ret != QMessageBox::Yes)
907 ApiTraceFrame *firstFrame =
909 ApiTraceEvent *oldSelected = m_selectedEvent;
912 m_selectedEvent = firstFrame;
914 m_selectedEvent = oldSelected;
920 void MainWindow::customContextMenuRequested(QPoint pos)
923 QModelIndex index = m_ui.callView->indexAt(pos);
925 callItemSelected(index);
926 if (!index.isValid())
929 ApiTraceEvent *event =
930 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
931 if (!event || event->type() != ApiTraceEvent::Call)
934 menu.addAction(QIcon(":/resources/media-record.png"),
935 tr("Lookup state"), this, SLOT(lookupState()));
936 menu.addAction(tr("Edit"), this, SLOT(editCall()));
938 menu.exec(QCursor::pos());
941 void MainWindow::editCall()
943 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
944 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
945 m_argsEditor->setCall(call);
946 m_argsEditor->show();
950 void MainWindow::slotStartedSaving()
952 m_progressBar->show();
953 statusBar()->showMessage(
954 tr("Saving to %1").arg(m_trace->fileName()));
957 void MainWindow::slotSaved()
959 statusBar()->showMessage(
960 tr("Saved to %1").arg(m_trace->fileName()), 2000);
961 m_progressBar->hide();
964 void MainWindow::slotGoFrameStart()
966 ApiTraceFrame *frame = currentFrame();
967 if (!frame || frame->calls.isEmpty()) {
971 QList<ApiTraceCall*>::const_iterator itr;
973 itr = frame->calls.constBegin();
974 while (itr != frame->calls.constEnd()) {
975 ApiTraceCall *call = *itr;
976 QModelIndex idx = m_proxyModel->indexForCall(call);
978 m_ui.callView->setCurrentIndex(idx);
985 void MainWindow::slotGoFrameEnd()
987 ApiTraceFrame *frame = currentFrame();
988 if (!frame || frame->calls.isEmpty()) {
991 QList<ApiTraceCall*>::const_iterator itr;
993 itr = frame->calls.constEnd();
996 ApiTraceCall *call = *itr;
997 QModelIndex idx = m_proxyModel->indexForCall(call);
999 m_ui.callView->setCurrentIndex(idx);
1002 } while (itr != frame->calls.constBegin());
1005 ApiTraceFrame * MainWindow::currentFrame() const
1007 if (m_selectedEvent) {
1008 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
1009 return static_cast<ApiTraceFrame*>(m_selectedEvent);
1011 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1012 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1013 return call->parentFrame();
1019 void MainWindow::slotTraceChanged(ApiTraceCall *call)
1022 if (call == m_selectedEvent) {
1023 m_ui.detailsWebView->setHtml(call->toHtml());
1027 void MainWindow::slotRetraceErrors(const QList<RetraceError> &errors)
1029 m_ui.errorsTreeWidget->clear();
1031 foreach(RetraceError error, errors) {
1032 ApiTraceCall *call = m_trace->callWithIndex(error.callIndex);
1035 call->setError(error.message);
1037 QTreeWidgetItem *item =
1038 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1039 item->setData(0, Qt::DisplayRole, error.callIndex);
1040 item->setData(0, Qt::UserRole, QVariant::fromValue(call));
1041 QString type = error.type;
1042 type[0] = type[0].toUpper();
1043 item->setData(1, Qt::DisplayRole, type);
1044 item->setData(2, Qt::DisplayRole, error.message);
1048 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1051 ApiTraceCall *call =
1052 current->data(0, Qt::UserRole).value<ApiTraceCall*>();
1054 QModelIndex index = m_proxyModel->indexForCall(call);
1055 if (index.isValid()) {
1056 m_ui.callView->setCurrentIndex(index);
1058 statusBar()->showMessage(tr("Call has been filtered out."));
1063 #include "mainwindow.moc"