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()
43 m_nonDefaultsLookupEvent(0)
50 void MainWindow::createTrace()
52 if (!m_traceProcess->canTrace()) {
56 tr("Current configuration doesn't support tracing."));
61 if (dialog.exec() == QDialog::Accepted) {
62 qDebug()<< "App : " <<dialog.applicationPath();
63 qDebug()<< " Arguments: "<<dialog.arguments();
64 m_traceProcess->setApi(dialog.api());
65 m_traceProcess->setExecutablePath(dialog.applicationPath());
66 m_traceProcess->setArguments(dialog.arguments());
67 m_traceProcess->start();
71 void MainWindow::openTrace()
74 QFileDialog::getOpenFileName(
78 tr("Trace Files (*.trace)"));
80 if (!fileName.isEmpty() && QFile::exists(fileName)) {
81 newTraceFile(fileName);
85 void MainWindow::loadTrace(const QString &fileName, int callNum)
87 if (!QFile::exists(fileName)) {
88 QMessageBox::warning(this, tr("File Missing"),
89 tr("File '%1' doesn't exist.").arg(fileName));
93 m_initalCallNum = callNum;
94 newTraceFile(fileName);
97 void MainWindow::callItemSelected(const QModelIndex &index)
99 ApiTraceEvent *event =
100 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
102 if (event && event->type() == ApiTraceEvent::Call) {
103 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
104 m_ui.detailsDock->setWindowTitle(
105 tr("Details View. Frame %1, Call %2")
106 .arg(call->parentFrame() ? call->parentFrame()->number : 0)
107 .arg(call->index()));
108 m_ui.detailsWebView->setHtml(call->toHtml());
109 m_ui.detailsDock->show();
110 if (call->hasBinaryData()) {
112 call->arguments()[call->binaryDataIndex()].toByteArray();
113 m_vdataInterpreter->setData(data);
115 QVector<QVariant> args = call->arguments();
116 for (int i = 0; i < call->argNames().count(); ++i) {
117 QString name = call->argNames()[i];
118 if (name == QLatin1String("stride")) {
119 int stride = args[i].toInt();
120 m_ui.vertexStrideSB->setValue(stride);
121 } else if (name == QLatin1String("size")) {
122 int components = args[i].toInt();
123 m_ui.vertexComponentsSB->setValue(components);
124 } else if (name == QLatin1String("type")) {
125 QString val = args[i].toString();
126 int textIndex = m_ui.vertexTypeCB->findText(val);
127 if (textIndex >= 0) {
128 m_ui.vertexTypeCB->setCurrentIndex(textIndex);
133 m_ui.vertexDataDock->setVisible(call->hasBinaryData());
134 m_selectedEvent = call;
136 if (event && event->type() == ApiTraceEvent::Frame) {
137 m_selectedEvent = static_cast<ApiTraceFrame*>(event);
141 m_ui.detailsDock->hide();
142 m_ui.vertexDataDock->hide();
144 if (m_selectedEvent && m_selectedEvent->hasState()) {
147 m_ui.stateDock->hide();
151 void MainWindow::replayStart()
153 if (m_trace->isSaving()) {
154 QMessageBox::warning(
157 tr("QApiTrace is currently saving the edited trace file. "
158 "Please wait until it finishes and try again."));
162 Ui_RetracerDialog dlgUi;
165 dlgUi.doubleBufferingCB->setChecked(
166 m_retracer->isDoubleBuffered());
167 dlgUi.errorCheckCB->setChecked(
168 !m_retracer->isBenchmarking());
170 if (dlg.exec() == QDialog::Accepted) {
171 m_retracer->setDoubleBuffered(
172 dlgUi.doubleBufferingCB->isChecked());
173 m_retracer->setBenchmarking(
174 !dlgUi.errorCheckCB->isChecked());
175 replayTrace(false, true);
179 void MainWindow::replayStop()
182 m_ui.actionStop->setEnabled(false);
183 m_ui.actionReplay->setEnabled(true);
184 m_ui.actionLookupState->setEnabled(true);
185 m_ui.actionShowThumbnails->setEnabled(true);
188 void MainWindow::newTraceFile(const QString &fileName)
190 qDebug()<< "Loading : " <<fileName;
192 m_progressBar->setValue(0);
193 m_trace->setFileName(fileName);
195 if (fileName.isEmpty()) {
196 m_ui.actionReplay->setEnabled(false);
197 m_ui.actionLookupState->setEnabled(false);
198 m_ui.actionShowThumbnails->setEnabled(false);
199 setWindowTitle(tr("QApiTrace"));
201 QFileInfo info(fileName);
202 m_ui.actionReplay->setEnabled(true);
203 m_ui.actionLookupState->setEnabled(true);
204 m_ui.actionShowThumbnails->setEnabled(true);
206 tr("QApiTrace - %1").arg(info.fileName()));
210 void MainWindow::replayFinished(const QString &output)
212 m_ui.actionStop->setEnabled(false);
213 m_ui.actionReplay->setEnabled(true);
214 m_ui.actionLookupState->setEnabled(true);
215 m_ui.actionShowThumbnails->setEnabled(true);
217 m_progressBar->hide();
218 if (output.length() < 80) {
219 statusBar()->showMessage(output);
222 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
223 m_ui.errorsDock->setVisible(m_trace->hasErrors());
224 if (!m_trace->hasErrors()) {
225 m_ui.errorsTreeWidget->clear();
228 statusBar()->showMessage(
229 tr("Replaying finished!"), 2000);
232 void MainWindow::replayError(const QString &message)
234 m_ui.actionStop->setEnabled(false);
235 m_ui.actionReplay->setEnabled(true);
236 m_ui.actionLookupState->setEnabled(true);
237 m_ui.actionShowThumbnails->setEnabled(true);
239 m_nonDefaultsLookupEvent = 0;
241 m_progressBar->hide();
242 statusBar()->showMessage(
243 tr("Replaying unsuccessful."), 2000);
244 QMessageBox::warning(
245 this, tr("Replay Failed"), message);
248 void MainWindow::startedLoadingTrace()
251 m_progressBar->show();
252 QFileInfo info(m_trace->fileName());
253 statusBar()->showMessage(
254 tr("Loading %1...").arg(info.fileName()));
257 void MainWindow::finishedLoadingTrace()
259 m_progressBar->hide();
263 QFileInfo info(m_trace->fileName());
264 statusBar()->showMessage(
265 tr("Loaded %1").arg(info.fileName()), 3000);
266 if (m_initalCallNum >= 0) {
267 m_trace->findCallIndex(m_initalCallNum);
268 m_initalCallNum = -1;
272 void MainWindow::replayTrace(bool dumpState, bool dumpThumbnails)
274 if (m_trace->fileName().isEmpty()) {
278 m_retracer->setFileName(m_trace->fileName());
279 m_retracer->setAPI(m_api);
280 m_retracer->setCaptureState(dumpState);
281 m_retracer->setCaptureThumbnails(dumpThumbnails);
282 if (m_retracer->captureState() && m_selectedEvent) {
284 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
285 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
286 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
287 ApiTraceFrame *frame =
288 static_cast<ApiTraceFrame*>(m_selectedEvent);
289 if (frame->isEmpty()) {
290 //XXX i guess we could still get the current state
291 qDebug()<<"tried to get a state for an empty frame";
294 index = frame->lastCallIndex();
296 qDebug()<<"Unknown event type";
299 m_retracer->setCaptureAtCallNumber(index);
303 m_ui.actionStop->setEnabled(true);
304 m_progressBar->show();
305 if (dumpState || dumpThumbnails) {
306 if (dumpState && dumpThumbnails) {
307 statusBar()->showMessage(
308 tr("Looking up the state and capturing thumbnails..."));
309 } else if (dumpState) {
310 statusBar()->showMessage(
311 tr("Looking up the state..."));
312 } else if (dumpThumbnails) {
313 statusBar()->showMessage(
314 tr("Capturing thumbnails..."));
317 statusBar()->showMessage(
318 tr("Replaying the trace file..."));
322 void MainWindow::lookupState()
324 if (!m_selectedEvent) {
325 QMessageBox::warning(
326 this, tr("Unknown Event"),
327 tr("To inspect the state select an event in the event list."));
330 if (m_trace->isSaving()) {
331 QMessageBox::warning(
334 tr("QApiTrace is currently saving the edited trace file. "
335 "Please wait until it finishes and try again."));
338 m_stateEvent = m_selectedEvent;
339 replayTrace(true, false);
342 void MainWindow::showThumbnails()
344 replayTrace(false, true);
347 MainWindow::~MainWindow()
357 variantToString(const QVariant &var, QString &str)
359 if (var.type() == QVariant::List) {
360 QVector<QVariant> lst = var.toList().toVector();
361 str += QLatin1String("[");
362 for (int i = 0; i < lst.count(); ++i) {
363 QVariant val = lst[i];
364 variantToString(val, str);
365 if (i < lst.count() - 1)
366 str += QLatin1String(", ");
368 str += QLatin1String("]");
369 } else if (var.type() == QVariant::Map) {
370 Q_ASSERT(!"unsupported state type");
371 } else if (var.type() == QVariant::Hash) {
372 Q_ASSERT(!"unsupported state type");
374 str += var.toString();
378 static QTreeWidgetItem *
379 variantToItem(const QString &key, const QVariant &var,
380 const QVariant &defaultVar);
383 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap,
384 QList<QTreeWidgetItem *> &items)
386 QVariantMap::const_iterator itr;
387 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
388 QString key = itr.key();
389 QVariant var = itr.value();
390 QVariant defaultVar = defaultMap[key];
392 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
400 variantListToItems(const QVector<QVariant> &lst,
401 const QVector<QVariant> &defaultLst,
402 QList<QTreeWidgetItem *> &items)
404 for (int i = 0; i < lst.count(); ++i) {
405 QString key = QString::number(i);
406 QVariant var = lst[i];
409 if (i < defaultLst.count()) {
410 defaultVar = defaultLst[i];
413 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
421 isVariantDeep(const QVariant &var)
423 if (var.type() == QVariant::List) {
424 QVector<QVariant> lst = var.toList().toVector();
425 for (int i = 0; i < lst.count(); ++i) {
426 if (isVariantDeep(lst[i])) {
431 } else if (var.type() == QVariant::Map) {
433 } else if (var.type() == QVariant::Hash) {
440 static QTreeWidgetItem *
441 variantToItem(const QString &key, const QVariant &var,
442 const QVariant &defaultVar)
444 if (var == defaultVar) {
450 bool deep = isVariantDeep(var);
452 variantToString(var, val);
455 //qDebug()<<"key = "<<key;
456 //qDebug()<<"val = "<<val;
461 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
464 QList<QTreeWidgetItem *> children;
465 if (var.type() == QVariant::Map) {
466 QVariantMap map = var.toMap();
467 QVariantMap defaultMap = defaultVar.toMap();
468 variantMapToItems(map, defaultMap, children);
470 if (var.type() == QVariant::List) {
471 QVector<QVariant> lst = var.toList().toVector();
472 QVector<QVariant> defaultLst = defaultVar.toList().toVector();
473 variantListToItems(lst, defaultLst, children);
475 item->addChildren(children);
481 static void addSurfaceItem(const ApiSurface &surface,
482 const QString &label,
483 QTreeWidgetItem *parent,
486 QIcon icon(QPixmap::fromImage(surface.thumb()));
487 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
488 item->setIcon(0, icon);
490 int width = surface.size().width();
491 int height = surface.size().height();
493 QString::fromLatin1("%1, %2, %3 x %4")
495 .arg(surface.formatName())
499 //item->setText(1, descr);
500 QLabel *l = new QLabel(descr, tree);
501 l->setWordWrap(true);
502 tree->setItemWidget(item, 1, l);
504 item->setData(0, Qt::UserRole, surface.image());
507 void MainWindow::fillStateForFrame()
509 if (!m_selectedEvent || !m_selectedEvent->hasState()) {
513 if (m_nonDefaultsLookupEvent) {
514 m_ui.nonDefaultsCB->blockSignals(true);
515 m_ui.nonDefaultsCB->setChecked(true);
516 m_ui.nonDefaultsCB->blockSignals(false);
519 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
520 QVariantMap defaultParams;
522 ApiTraceState defaultState = m_trace->defaultState();
523 defaultParams = defaultState.parameters();
526 const ApiTraceState &state = *m_selectedEvent->state();
527 m_ui.stateTreeWidget->clear();
528 QList<QTreeWidgetItem *> items;
529 variantMapToItems(state.parameters(), defaultParams, items);
530 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
532 QMap<QString, QString> shaderSources = state.shaderSources();
533 if (shaderSources.isEmpty()) {
534 m_sourcesWidget->setShaders(shaderSources);
536 m_sourcesWidget->setShaders(shaderSources);
539 m_ui.uniformsTreeWidget->clear();
540 QList<QTreeWidgetItem *> uniformsItems;
541 variantMapToItems(state.uniforms(), QVariantMap(), uniformsItems);
542 m_ui.uniformsTreeWidget->insertTopLevelItems(0, uniformsItems);
544 const QList<ApiTexture> &textures =
546 const QList<ApiFramebuffer> &fbos =
547 state.framebuffers();
549 m_ui.surfacesTreeWidget->clear();
550 if (textures.isEmpty() && fbos.isEmpty()) {
551 m_ui.surfacesTab->setDisabled(false);
553 m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
554 if (!textures.isEmpty()) {
555 QTreeWidgetItem *textureItem =
556 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
557 textureItem->setText(0, tr("Textures"));
558 if (textures.count() <= 6) {
559 textureItem->setExpanded(true);
562 for (int i = 0; i < textures.count(); ++i) {
563 const ApiTexture &texture =
565 addSurfaceItem(texture, texture.label(),
567 m_ui.surfacesTreeWidget);
570 if (!fbos.isEmpty()) {
571 QTreeWidgetItem *fboItem =
572 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
573 fboItem->setText(0, tr("Framebuffers"));
574 if (fbos.count() <= 6) {
575 fboItem->setExpanded(true);
578 for (int i = 0; i < fbos.count(); ++i) {
579 const ApiFramebuffer &fbo =
581 addSurfaceItem(fbo, fbo.type(),
583 m_ui.surfacesTreeWidget);
586 m_ui.surfacesTab->setEnabled(true);
588 m_ui.stateDock->show();
591 void MainWindow::showSettings()
593 SettingsDialog dialog;
594 dialog.setAPI(m_api);
595 dialog.setFilterModel(m_proxyModel);
599 m_api = dialog.getAPI();
602 void MainWindow::openHelp(const QUrl &url)
604 QDesktopServices::openUrl(url);
607 void MainWindow::showSurfacesMenu(const QPoint &pos)
609 QTreeWidget *tree = m_ui.surfacesTreeWidget;
610 QTreeWidgetItem *item = tree->itemAt(pos);
615 QMenu menu(tr("Surfaces"), this);
617 QAction *act = menu.addAction(tr("View Image"));
618 act->setStatusTip(tr("View the currently selected surface"));
619 connect(act, SIGNAL(triggered()),
620 SLOT(showSelectedSurface()));
622 act = menu.addAction(tr("Save Image"));
623 act->setStatusTip(tr("Save the currently selected surface"));
624 connect(act, SIGNAL(triggered()),
625 SLOT(saveSelectedSurface()));
627 menu.exec(tree->viewport()->mapToGlobal(pos));
630 void MainWindow::showSelectedSurface()
632 QTreeWidgetItem *item =
633 m_ui.surfacesTreeWidget->currentItem();
639 ImageViewer *viewer = new ImageViewer(this);
642 if (selectedCall()) {
643 title = tr("QApiTrace - Surface at %1 (%2)")
644 .arg(selectedCall()->name())
645 .arg(selectedCall()->index());
647 title = tr("QApiTrace - Surface Viewer");
649 viewer->setWindowTitle(title);
651 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
653 QVariant var = item->data(0, Qt::UserRole);
654 QImage img = var.value<QImage>();
655 viewer->setImage(img);
659 viewer->activateWindow();
662 void MainWindow::initObjects()
664 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
665 m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder);
667 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
668 QVBoxLayout *layout = new QVBoxLayout;
669 layout->addWidget(m_sourcesWidget);
670 m_ui.shadersTab->setLayout(layout);
672 m_trace = new ApiTrace();
673 m_retracer = new Retracer(this);
675 m_vdataInterpreter = new VertexDataInterpreter(this);
676 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
677 m_vdataInterpreter->setStride(
678 m_ui.vertexStrideSB->value());
679 m_vdataInterpreter->setComponents(
680 m_ui.vertexComponentsSB->value());
681 m_vdataInterpreter->setStartingOffset(
682 m_ui.startingOffsetSB->value());
683 m_vdataInterpreter->setTypeFromString(
684 m_ui.vertexTypeCB->currentText());
686 m_model = new ApiTraceModel();
687 m_model->setApiTrace(m_trace);
688 m_proxyModel = new ApiTraceFilter();
689 m_proxyModel->setSourceModel(m_model);
690 m_ui.callView->setModel(m_proxyModel);
691 m_ui.callView->setItemDelegate(
692 new ApiCallDelegate(m_ui.callView));
693 m_ui.callView->resizeColumnToContents(0);
694 m_ui.callView->header()->swapSections(0, 1);
695 m_ui.callView->setColumnWidth(1, 42);
696 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
698 m_progressBar = new QProgressBar();
699 m_progressBar->setRange(0, 100);
700 statusBar()->addPermanentWidget(m_progressBar);
701 m_progressBar->hide();
703 m_argsEditor = new ArgumentsEditor(this);
705 m_ui.detailsDock->hide();
706 m_ui.errorsDock->hide();
707 m_ui.vertexDataDock->hide();
708 m_ui.stateDock->hide();
709 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
711 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
712 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
714 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
716 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
717 QWebPage::DelegateExternalLinks);
719 m_jumpWidget = new JumpWidget(this);
720 m_ui.centralLayout->addWidget(m_jumpWidget);
721 m_jumpWidget->hide();
723 m_searchWidget = new SearchWidget(this);
724 m_ui.centralLayout->addWidget(m_searchWidget);
725 m_searchWidget->hide();
727 m_traceProcess = new TraceProcess(this);
730 void MainWindow::initConnections()
732 connect(m_trace, SIGNAL(startedLoadingTrace()),
733 this, SLOT(startedLoadingTrace()));
734 connect(m_trace, SIGNAL(loaded(int)),
735 this, SLOT(loadProgess(int)));
736 connect(m_trace, SIGNAL(finishedLoadingTrace()),
737 this, SLOT(finishedLoadingTrace()));
738 connect(m_trace, SIGNAL(startedSaving()),
739 this, SLOT(slotStartedSaving()));
740 connect(m_trace, SIGNAL(saved()),
741 this, SLOT(slotSaved()));
742 connect(m_trace, SIGNAL(changed(ApiTraceEvent*)),
743 this, SLOT(slotTraceChanged(ApiTraceEvent*)));
744 connect(m_trace, SIGNAL(findResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)),
745 this, SLOT(slotSearchResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)));
746 connect(m_trace, SIGNAL(foundFrameStart(ApiTraceFrame*)),
747 this, SLOT(slotFoundFrameStart(ApiTraceFrame*)));
748 connect(m_trace, SIGNAL(foundFrameEnd(ApiTraceFrame*)),
749 this, SLOT(slotFoundFrameEnd(ApiTraceFrame*)));
750 connect(m_trace, SIGNAL(foundCallIndex(ApiTraceCall*)),
751 this, SLOT(slotJumpToResult(ApiTraceCall*)));
753 connect(m_retracer, SIGNAL(finished(const QString&)),
754 this, SLOT(replayFinished(const QString&)));
755 connect(m_retracer, SIGNAL(error(const QString&)),
756 this, SLOT(replayError(const QString&)));
757 connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
758 this, SLOT(replayStateFound(ApiTraceState*)));
759 connect(m_retracer, SIGNAL(foundThumbnails(const QList<QImage>&)),
760 this, SLOT(replayThumbnailsFound(const QList<QImage>&)));
761 connect(m_retracer, SIGNAL(retraceErrors(const QList<ApiTraceError>&)),
762 this, SLOT(slotRetraceErrors(const QList<ApiTraceError>&)));
764 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
765 m_vdataInterpreter, SLOT(interpretData()));
766 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
767 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
768 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
769 m_vdataInterpreter, SLOT(setStride(int)));
770 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
771 m_vdataInterpreter, SLOT(setComponents(int)));
772 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
773 m_vdataInterpreter, SLOT(setStartingOffset(int)));
776 connect(m_ui.actionNew, SIGNAL(triggered()),
777 this, SLOT(createTrace()));
778 connect(m_ui.actionOpen, SIGNAL(triggered()),
779 this, SLOT(openTrace()));
780 connect(m_ui.actionQuit, SIGNAL(triggered()),
781 this, SLOT(close()));
783 connect(m_ui.actionFind, SIGNAL(triggered()),
784 this, SLOT(slotSearch()));
785 connect(m_ui.actionGo, SIGNAL(triggered()),
786 this, SLOT(slotGoTo()));
787 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
788 this, SLOT(slotGoFrameStart()));
789 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
790 this, SLOT(slotGoFrameEnd()));
792 connect(m_ui.actionReplay, SIGNAL(triggered()),
793 this, SLOT(replayStart()));
794 connect(m_ui.actionStop, SIGNAL(triggered()),
795 this, SLOT(replayStop()));
796 connect(m_ui.actionLookupState, SIGNAL(triggered()),
797 this, SLOT(lookupState()));
798 connect(m_ui.actionShowThumbnails, SIGNAL(triggered()),
799 this, SLOT(showThumbnails()));
800 connect(m_ui.actionOptions, SIGNAL(triggered()),
801 this, SLOT(showSettings()));
803 connect(m_ui.callView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
804 this, SLOT(callItemSelected(const QModelIndex &)));
805 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
806 this, SLOT(customContextMenuRequested(QPoint)));
808 connect(m_ui.surfacesTreeWidget,
809 SIGNAL(customContextMenuRequested(const QPoint &)),
810 SLOT(showSurfacesMenu(const QPoint &)));
811 connect(m_ui.surfacesTreeWidget,
812 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
813 SLOT(showSelectedSurface()));
815 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
816 this, SLOT(openHelp(const QUrl&)));
818 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
819 this, SLOT(fillState(bool)));
821 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
822 SLOT(slotJumpTo(int)));
824 connect(m_searchWidget,
825 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
826 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
827 connect(m_searchWidget,
828 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
829 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
831 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
832 SLOT(createdTrace(const QString&)));
833 connect(m_traceProcess, SIGNAL(error(const QString&)),
834 SLOT(traceError(const QString&)));
836 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
837 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
838 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
839 m_ui.errorsDock, SLOT(setVisible(bool)));
840 connect(m_ui.errorsTreeWidget,
841 SIGNAL(itemActivated(QTreeWidgetItem*, int)),
842 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
845 void MainWindow::replayStateFound(ApiTraceState *state)
847 m_stateEvent->setState(state);
848 m_model->stateSetOnEvent(m_stateEvent);
849 if (m_selectedEvent == m_stateEvent ||
850 m_nonDefaultsLookupEvent == m_selectedEvent) {
853 m_ui.stateDock->hide();
855 m_nonDefaultsLookupEvent = 0;
858 void MainWindow::replayThumbnailsFound(const QList<QImage> &thumbnails)
860 m_trace->bindThumbnailsToFrames(thumbnails);
863 void MainWindow::slotGoTo()
865 m_searchWidget->hide();
866 m_jumpWidget->show();
869 void MainWindow::slotJumpTo(int callNum)
871 m_trace->findCallIndex(callNum);
874 void MainWindow::createdTrace(const QString &path)
876 qDebug()<<"Done tracing "<<path;
880 void MainWindow::traceError(const QString &msg)
882 QMessageBox::warning(
888 void MainWindow::slotSearch()
890 m_jumpWidget->hide();
891 m_searchWidget->show();
894 void MainWindow::slotSearchNext(const QString &str,
895 Qt::CaseSensitivity sensitivity)
897 ApiTraceCall *call = currentCall();
898 ApiTraceFrame *frame = currentFrame();
900 Q_ASSERT(call || frame);
902 frame = call->parentFrame();
906 m_trace->findNext(frame, call, str, sensitivity);
909 void MainWindow::slotSearchPrev(const QString &str,
910 Qt::CaseSensitivity sensitivity)
912 ApiTraceCall *call = currentCall();
913 ApiTraceFrame *frame = currentFrame();
915 Q_ASSERT(call || frame);
917 frame = call->parentFrame();
921 m_trace->findPrev(frame, call, str, sensitivity);
924 void MainWindow::fillState(bool nonDefaults)
927 ApiTraceState defaultState = m_trace->defaultState();
928 if (defaultState.isEmpty()) {
929 m_ui.nonDefaultsCB->blockSignals(true);
930 m_ui.nonDefaultsCB->setChecked(false);
931 m_ui.nonDefaultsCB->blockSignals(false);
932 ApiTraceFrame *firstFrame =
937 if (!firstFrame->isLoaded()) {
938 m_trace->loadFrame(firstFrame);
941 ApiTraceCall *firstCall = firstFrame->calls().first();
942 ApiTraceEvent *oldSelected = m_selectedEvent;
943 m_nonDefaultsLookupEvent = m_selectedEvent;
944 m_selectedEvent = firstCall;
946 m_selectedEvent = oldSelected;
952 void MainWindow::customContextMenuRequested(QPoint pos)
954 QModelIndex index = m_ui.callView->indexAt(pos);
956 callItemSelected(index);
957 if (!index.isValid()) {
961 ApiTraceEvent *event =
962 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
968 menu.addAction(QIcon(":/resources/media-record.png"),
969 tr("Lookup state"), this, SLOT(lookupState()));
970 if (event->type() == ApiTraceEvent::Call) {
971 menu.addAction(tr("Edit"), this, SLOT(editCall()));
974 menu.exec(QCursor::pos());
977 void MainWindow::editCall()
979 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
980 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
981 m_argsEditor->setCall(call);
982 m_argsEditor->show();
986 void MainWindow::slotStartedSaving()
988 m_progressBar->show();
989 statusBar()->showMessage(
990 tr("Saving to %1").arg(m_trace->fileName()));
993 void MainWindow::slotSaved()
995 statusBar()->showMessage(
996 tr("Saved to %1").arg(m_trace->fileName()), 2000);
997 m_progressBar->hide();
1000 void MainWindow::slotGoFrameStart()
1002 ApiTraceFrame *frame = currentFrame();
1003 ApiTraceCall *call = currentCall();
1005 if (!frame && call) {
1006 frame = call->parentFrame();
1009 m_trace->findFrameStart(frame);
1012 void MainWindow::slotGoFrameEnd()
1014 ApiTraceFrame *frame = currentFrame();
1015 ApiTraceCall *call = currentCall();
1017 if (!frame && call) {
1018 frame = call->parentFrame();
1021 m_trace->findFrameEnd(frame);
1024 ApiTraceFrame * MainWindow::selectedFrame() const
1026 if (m_selectedEvent) {
1027 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
1028 return static_cast<ApiTraceFrame*>(m_selectedEvent);
1030 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1031 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1032 return call->parentFrame();
1038 void MainWindow::slotTraceChanged(ApiTraceEvent *event)
1041 if (event == m_selectedEvent) {
1042 if (event->type() == ApiTraceEvent::Call) {
1043 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
1044 m_ui.detailsWebView->setHtml(call->toHtml());
1049 void MainWindow::slotRetraceErrors(const QList<ApiTraceError> &errors)
1051 m_ui.errorsTreeWidget->clear();
1053 foreach(ApiTraceError error, errors) {
1054 m_trace->setCallError(error);
1056 QTreeWidgetItem *item =
1057 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1058 item->setData(0, Qt::DisplayRole, error.callIndex);
1059 item->setData(0, Qt::UserRole, error.callIndex);
1060 QString type = error.type;
1061 type[0] = type[0].toUpper();
1062 item->setData(1, Qt::DisplayRole, type);
1063 item->setData(2, Qt::DisplayRole, error.message);
1067 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1071 current->data(0, Qt::UserRole).toInt();
1072 m_trace->findCallIndex(callIndex);
1076 ApiTraceCall * MainWindow::selectedCall() const
1078 if (m_selectedEvent &&
1079 m_selectedEvent->type() == ApiTraceEvent::Call) {
1080 return static_cast<ApiTraceCall*>(m_selectedEvent);
1085 void MainWindow::saveSelectedSurface()
1087 QTreeWidgetItem *item =
1088 m_ui.surfacesTreeWidget->currentItem();
1090 if (!item || !m_trace) {
1094 QVariant var = item->data(0, Qt::UserRole);
1095 QImage img = var.value<QImage>();
1098 if (selectedCall()) {
1099 imageIndex = tr("_call_%1")
1100 .arg(selectedCall()->index());
1101 } else if (selectedFrame()) {
1102 ApiTraceCall *firstCall = selectedFrame()->call(0);
1104 imageIndex = tr("_frame_%1")
1105 .arg(firstCall->index());
1107 qDebug()<<"unknown frame number";
1108 imageIndex = tr("_frame_%1")
1109 .arg(firstCall->index());
1113 //which of the surfaces are we saving
1114 QTreeWidgetItem *parent = item->parent();
1116 m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent);
1117 if (parentIndex < 0) {
1122 childIndex = parent->indexOfChild(item);
1124 childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item);
1129 tr("%1%2-%3_%4.png")
1130 .arg(m_trace->fileName())
1134 //qDebug()<<"save "<<fileName;
1135 img.save(fileName, "PNG");
1136 statusBar()->showMessage( tr("Saved '%1'").arg(fileName), 5000);
1139 void MainWindow::loadProgess(int percent)
1141 m_progressBar->setValue(percent);
1144 void MainWindow::slotSearchResult(const ApiTrace::SearchRequest &request,
1145 ApiTrace::SearchResult result,
1149 case ApiTrace::SearchResult_NotFound:
1150 m_searchWidget->setFound(false);
1152 case ApiTrace::SearchResult_Found: {
1153 QModelIndex index = m_proxyModel->indexForCall(call);
1155 if (index.isValid()) {
1156 m_ui.callView->setCurrentIndex(index);
1157 m_searchWidget->setFound(true);
1159 //call is filtered out, so continue searching but from the
1162 qDebug()<<"Error: search success with no call";
1165 // qDebug()<<"filtered! search from "<<call->searchText()
1166 // <<", call idx = "<<call->index();
1168 if (request.direction == ApiTrace::SearchRequest::Next) {
1169 m_trace->findNext(call->parentFrame(), call,
1170 request.text, request.cs);
1172 m_trace->findNext(call->parentFrame(), call,
1173 request.text, request.cs);
1178 case ApiTrace::SearchResult_Wrapped:
1179 m_searchWidget->setFound(false);
1184 ApiTraceFrame * MainWindow::currentFrame() const
1186 QModelIndex index = m_ui.callView->currentIndex();
1187 ApiTraceEvent *event = 0;
1189 if (!index.isValid()) {
1190 index = m_proxyModel->index(0, 0, QModelIndex());
1191 if (!index.isValid()) {
1192 qDebug()<<"no currently valid index";
1197 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1203 ApiTraceFrame *frame = 0;
1204 if (event->type() == ApiTraceCall::Frame) {
1205 frame = static_cast<ApiTraceFrame*>(event);
1210 ApiTraceCall * MainWindow::currentCall() const
1212 QModelIndex index = m_ui.callView->currentIndex();
1213 ApiTraceEvent *event = 0;
1215 if (!index.isValid()) {
1216 index = m_proxyModel->index(0, 0, QModelIndex());
1217 if (!index.isValid()) {
1218 qDebug()<<"no currently valid index";
1223 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1229 ApiTraceCall *call = 0;
1230 if (event->type() == ApiTraceCall::Call) {
1231 call = static_cast<ApiTraceCall*>(event);
1238 void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame)
1240 Q_ASSERT(frame->isLoaded());
1241 if (!frame || frame->isEmpty()) {
1245 QVector<ApiTraceCall*>::const_iterator itr;
1246 QVector<ApiTraceCall*> calls = frame->calls();
1248 itr = calls.constBegin();
1249 while (itr != calls.constEnd()) {
1250 ApiTraceCall *call = *itr;
1251 QModelIndex idx = m_proxyModel->indexForCall(call);
1252 if (idx.isValid()) {
1253 m_ui.callView->setCurrentIndex(idx);
1260 void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame)
1262 Q_ASSERT(frame->isLoaded());
1263 if (!frame || frame->isEmpty()) {
1266 QVector<ApiTraceCall*>::const_iterator itr;
1267 QVector<ApiTraceCall*> calls = frame->calls();
1269 itr = calls.constEnd();
1272 ApiTraceCall *call = *itr;
1273 QModelIndex idx = m_proxyModel->indexForCall(call);
1274 if (idx.isValid()) {
1275 m_ui.callView->setCurrentIndex(idx);
1278 } while (itr != calls.constBegin());
1281 void MainWindow::slotJumpToResult(ApiTraceCall *call)
1283 QModelIndex index = m_proxyModel->indexForCall(call);
1284 if (index.isValid()) {
1285 m_ui.callView->setCurrentIndex(index);
1287 statusBar()->showMessage(tr("Call has been filtered out."));
1291 #include "mainwindow.moc"