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);
187 void MainWindow::newTraceFile(const QString &fileName)
189 qDebug()<< "Loading : " <<fileName;
191 m_progressBar->setValue(0);
192 m_trace->setFileName(fileName);
194 if (fileName.isEmpty()) {
195 m_ui.actionReplay->setEnabled(false);
196 m_ui.actionLookupState->setEnabled(false);
197 setWindowTitle(tr("QApiTrace"));
199 QFileInfo info(fileName);
200 m_ui.actionReplay->setEnabled(true);
201 m_ui.actionLookupState->setEnabled(true);
203 tr("QApiTrace - %1").arg(info.fileName()));
206 // force initial capture of thumbnails
207 replayTrace(false, true);
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);
216 m_progressBar->hide();
217 if (output.length() < 80) {
218 statusBar()->showMessage(output);
221 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
222 m_ui.errorsDock->setVisible(m_trace->hasErrors());
223 if (!m_trace->hasErrors()) {
224 m_ui.errorsTreeWidget->clear();
227 statusBar()->showMessage(
228 tr("Replaying finished!"), 2000);
231 void MainWindow::replayError(const QString &message)
233 m_ui.actionStop->setEnabled(false);
234 m_ui.actionReplay->setEnabled(true);
235 m_ui.actionLookupState->setEnabled(true);
237 m_nonDefaultsLookupEvent = 0;
239 m_progressBar->hide();
240 statusBar()->showMessage(
241 tr("Replaying unsuccessful."), 2000);
242 QMessageBox::warning(
243 this, tr("Replay Failed"), message);
246 void MainWindow::startedLoadingTrace()
249 m_progressBar->show();
250 QFileInfo info(m_trace->fileName());
251 statusBar()->showMessage(
252 tr("Loading %1...").arg(info.fileName()));
255 void MainWindow::finishedLoadingTrace()
257 m_progressBar->hide();
261 QFileInfo info(m_trace->fileName());
262 statusBar()->showMessage(
263 tr("Loaded %1").arg(info.fileName()), 3000);
264 if (m_initalCallNum >= 0) {
265 m_trace->findCallIndex(m_initalCallNum);
266 m_initalCallNum = -1;
270 void MainWindow::replayTrace(bool dumpState, bool dumpThumbnails)
272 if (m_trace->fileName().isEmpty()) {
276 m_retracer->setFileName(m_trace->fileName());
277 m_retracer->setAPI(m_api);
278 m_retracer->setCaptureState(dumpState);
279 m_retracer->setCaptureThumbnails(dumpThumbnails);
280 if (m_retracer->captureState() && m_selectedEvent) {
282 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
283 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
284 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
285 ApiTraceFrame *frame =
286 static_cast<ApiTraceFrame*>(m_selectedEvent);
287 if (frame->isEmpty()) {
288 //XXX i guess we could still get the current state
289 qDebug()<<"tried to get a state for an empty frame";
292 index = frame->lastCallIndex();
294 qDebug()<<"Unknown event type";
297 m_retracer->setCaptureAtCallNumber(index);
301 m_ui.actionStop->setEnabled(true);
302 m_progressBar->show();
303 if (dumpState || dumpThumbnails) {
304 if (dumpState && dumpThumbnails) {
305 statusBar()->showMessage(
306 tr("Looking up the state and capturing thumbnails..."));
307 } else if (dumpState) {
308 statusBar()->showMessage(
309 tr("Looking up the state..."));
310 } else if (dumpThumbnails) {
311 statusBar()->showMessage(
312 tr("Capturing thumbnails..."));
315 statusBar()->showMessage(
316 tr("Replaying the trace file..."));
320 void MainWindow::lookupState()
322 if (!m_selectedEvent) {
323 QMessageBox::warning(
324 this, tr("Unknown Event"),
325 tr("To inspect the state select an event in the event list."));
328 if (m_trace->isSaving()) {
329 QMessageBox::warning(
332 tr("QApiTrace is currently saving the edited trace file. "
333 "Please wait until it finishes and try again."));
336 m_stateEvent = m_selectedEvent;
337 replayTrace(true, false);
340 MainWindow::~MainWindow()
350 variantToString(const QVariant &var, QString &str)
352 if (var.type() == QVariant::List) {
353 QVector<QVariant> lst = var.toList().toVector();
354 str += QLatin1String("[");
355 for (int i = 0; i < lst.count(); ++i) {
356 QVariant val = lst[i];
357 variantToString(val, str);
358 if (i < lst.count() - 1)
359 str += QLatin1String(", ");
361 str += QLatin1String("]");
362 } else if (var.type() == QVariant::Map) {
363 Q_ASSERT(!"unsupported state type");
364 } else if (var.type() == QVariant::Hash) {
365 Q_ASSERT(!"unsupported state type");
367 str += var.toString();
371 static QTreeWidgetItem *
372 variantToItem(const QString &key, const QVariant &var,
373 const QVariant &defaultVar);
376 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap,
377 QList<QTreeWidgetItem *> &items)
379 QVariantMap::const_iterator itr;
380 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
381 QString key = itr.key();
382 QVariant var = itr.value();
383 QVariant defaultVar = defaultMap[key];
385 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
393 variantListToItems(const QVector<QVariant> &lst,
394 const QVector<QVariant> &defaultLst,
395 QList<QTreeWidgetItem *> &items)
397 for (int i = 0; i < lst.count(); ++i) {
398 QString key = QString::number(i);
399 QVariant var = lst[i];
402 if (i < defaultLst.count()) {
403 defaultVar = defaultLst[i];
406 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
414 isVariantDeep(const QVariant &var)
416 if (var.type() == QVariant::List) {
417 QVector<QVariant> lst = var.toList().toVector();
418 for (int i = 0; i < lst.count(); ++i) {
419 if (isVariantDeep(lst[i])) {
424 } else if (var.type() == QVariant::Map) {
426 } else if (var.type() == QVariant::Hash) {
433 static QTreeWidgetItem *
434 variantToItem(const QString &key, const QVariant &var,
435 const QVariant &defaultVar)
437 if (var == defaultVar) {
443 bool deep = isVariantDeep(var);
445 variantToString(var, val);
448 //qDebug()<<"key = "<<key;
449 //qDebug()<<"val = "<<val;
454 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
457 QList<QTreeWidgetItem *> children;
458 if (var.type() == QVariant::Map) {
459 QVariantMap map = var.toMap();
460 QVariantMap defaultMap = defaultVar.toMap();
461 variantMapToItems(map, defaultMap, children);
463 if (var.type() == QVariant::List) {
464 QVector<QVariant> lst = var.toList().toVector();
465 QVector<QVariant> defaultLst = defaultVar.toList().toVector();
466 variantListToItems(lst, defaultLst, children);
468 item->addChildren(children);
474 static void addSurfaceItem(const ApiSurface &surface,
475 const QString &label,
476 QTreeWidgetItem *parent,
479 QIcon icon(QPixmap::fromImage(surface.thumb()));
480 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
481 item->setIcon(0, icon);
483 int width = surface.size().width();
484 int height = surface.size().height();
486 QString::fromLatin1("%1, %2, %3 x %4")
488 .arg(surface.formatName())
492 //item->setText(1, descr);
493 QLabel *l = new QLabel(descr, tree);
494 l->setWordWrap(true);
495 tree->setItemWidget(item, 1, l);
497 item->setData(0, Qt::UserRole, surface.image());
500 void MainWindow::fillStateForFrame()
502 if (!m_selectedEvent || !m_selectedEvent->hasState()) {
506 if (m_nonDefaultsLookupEvent) {
507 m_ui.nonDefaultsCB->blockSignals(true);
508 m_ui.nonDefaultsCB->setChecked(true);
509 m_ui.nonDefaultsCB->blockSignals(false);
512 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
513 QVariantMap defaultParams;
515 ApiTraceState defaultState = m_trace->defaultState();
516 defaultParams = defaultState.parameters();
519 const ApiTraceState &state = *m_selectedEvent->state();
520 m_ui.stateTreeWidget->clear();
521 QList<QTreeWidgetItem *> items;
522 variantMapToItems(state.parameters(), defaultParams, items);
523 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
525 QMap<QString, QString> shaderSources = state.shaderSources();
526 if (shaderSources.isEmpty()) {
527 m_sourcesWidget->setShaders(shaderSources);
529 m_sourcesWidget->setShaders(shaderSources);
532 m_ui.uniformsTreeWidget->clear();
533 QList<QTreeWidgetItem *> uniformsItems;
534 variantMapToItems(state.uniforms(), QVariantMap(), uniformsItems);
535 m_ui.uniformsTreeWidget->insertTopLevelItems(0, uniformsItems);
537 const QList<ApiTexture> &textures =
539 const QList<ApiFramebuffer> &fbos =
540 state.framebuffers();
542 m_ui.surfacesTreeWidget->clear();
543 if (textures.isEmpty() && fbos.isEmpty()) {
544 m_ui.surfacesTab->setDisabled(false);
546 m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
547 if (!textures.isEmpty()) {
548 QTreeWidgetItem *textureItem =
549 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
550 textureItem->setText(0, tr("Textures"));
551 if (textures.count() <= 6) {
552 textureItem->setExpanded(true);
555 for (int i = 0; i < textures.count(); ++i) {
556 const ApiTexture &texture =
558 addSurfaceItem(texture, texture.label(),
560 m_ui.surfacesTreeWidget);
563 if (!fbos.isEmpty()) {
564 QTreeWidgetItem *fboItem =
565 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
566 fboItem->setText(0, tr("Framebuffers"));
567 if (fbos.count() <= 6) {
568 fboItem->setExpanded(true);
571 for (int i = 0; i < fbos.count(); ++i) {
572 const ApiFramebuffer &fbo =
574 addSurfaceItem(fbo, fbo.type(),
576 m_ui.surfacesTreeWidget);
579 m_ui.surfacesTab->setEnabled(true);
581 m_ui.stateDock->show();
584 void MainWindow::showSettings()
586 SettingsDialog dialog;
587 dialog.setAPI(m_api);
588 dialog.setFilterModel(m_proxyModel);
592 m_api = dialog.getAPI();
595 void MainWindow::openHelp(const QUrl &url)
597 QDesktopServices::openUrl(url);
600 void MainWindow::showSurfacesMenu(const QPoint &pos)
602 QTreeWidget *tree = m_ui.surfacesTreeWidget;
603 QTreeWidgetItem *item = tree->itemAt(pos);
608 QMenu menu(tr("Surfaces"), this);
610 QAction *act = menu.addAction(tr("View Image"));
611 act->setStatusTip(tr("View the currently selected surface"));
612 connect(act, SIGNAL(triggered()),
613 SLOT(showSelectedSurface()));
615 act = menu.addAction(tr("Save Image"));
616 act->setStatusTip(tr("Save the currently selected surface"));
617 connect(act, SIGNAL(triggered()),
618 SLOT(saveSelectedSurface()));
620 menu.exec(tree->viewport()->mapToGlobal(pos));
623 void MainWindow::showSelectedSurface()
625 QTreeWidgetItem *item =
626 m_ui.surfacesTreeWidget->currentItem();
632 ImageViewer *viewer = new ImageViewer(this);
635 if (selectedCall()) {
636 title = tr("QApiTrace - Surface at %1 (%2)")
637 .arg(selectedCall()->name())
638 .arg(selectedCall()->index());
640 title = tr("QApiTrace - Surface Viewer");
642 viewer->setWindowTitle(title);
644 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
646 QVariant var = item->data(0, Qt::UserRole);
647 QImage img = var.value<QImage>();
648 viewer->setImage(img);
652 viewer->activateWindow();
655 void MainWindow::initObjects()
657 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
658 m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder);
660 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
661 QVBoxLayout *layout = new QVBoxLayout;
662 layout->addWidget(m_sourcesWidget);
663 m_ui.shadersTab->setLayout(layout);
665 m_trace = new ApiTrace();
666 m_retracer = new Retracer(this);
668 m_vdataInterpreter = new VertexDataInterpreter(this);
669 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
670 m_vdataInterpreter->setStride(
671 m_ui.vertexStrideSB->value());
672 m_vdataInterpreter->setComponents(
673 m_ui.vertexComponentsSB->value());
674 m_vdataInterpreter->setStartingOffset(
675 m_ui.startingOffsetSB->value());
676 m_vdataInterpreter->setTypeFromString(
677 m_ui.vertexTypeCB->currentText());
679 m_model = new ApiTraceModel();
680 m_model->setApiTrace(m_trace);
681 m_proxyModel = new ApiTraceFilter();
682 m_proxyModel->setSourceModel(m_model);
683 m_ui.callView->setModel(m_proxyModel);
684 m_ui.callView->setItemDelegate(
685 new ApiCallDelegate(m_ui.callView));
686 m_ui.callView->resizeColumnToContents(0);
687 m_ui.callView->header()->swapSections(0, 1);
688 m_ui.callView->setColumnWidth(1, 42);
689 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
691 m_progressBar = new QProgressBar();
692 m_progressBar->setRange(0, 100);
693 statusBar()->addPermanentWidget(m_progressBar);
694 m_progressBar->hide();
696 m_argsEditor = new ArgumentsEditor(this);
698 m_ui.detailsDock->hide();
699 m_ui.errorsDock->hide();
700 m_ui.vertexDataDock->hide();
701 m_ui.stateDock->hide();
702 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
704 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
705 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
707 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
709 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
710 QWebPage::DelegateExternalLinks);
712 m_jumpWidget = new JumpWidget(this);
713 m_ui.centralLayout->addWidget(m_jumpWidget);
714 m_jumpWidget->hide();
716 m_searchWidget = new SearchWidget(this);
717 m_ui.centralLayout->addWidget(m_searchWidget);
718 m_searchWidget->hide();
720 m_traceProcess = new TraceProcess(this);
723 void MainWindow::initConnections()
725 connect(m_trace, SIGNAL(startedLoadingTrace()),
726 this, SLOT(startedLoadingTrace()));
727 connect(m_trace, SIGNAL(loaded(int)),
728 this, SLOT(loadProgess(int)));
729 connect(m_trace, SIGNAL(finishedLoadingTrace()),
730 this, SLOT(finishedLoadingTrace()));
731 connect(m_trace, SIGNAL(startedSaving()),
732 this, SLOT(slotStartedSaving()));
733 connect(m_trace, SIGNAL(saved()),
734 this, SLOT(slotSaved()));
735 connect(m_trace, SIGNAL(changed(ApiTraceCall*)),
736 this, SLOT(slotTraceChanged(ApiTraceCall*)));
737 connect(m_trace, SIGNAL(findResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)),
738 this, SLOT(slotSearchResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)));
739 connect(m_trace, SIGNAL(foundFrameStart(ApiTraceFrame*)),
740 this, SLOT(slotFoundFrameStart(ApiTraceFrame*)));
741 connect(m_trace, SIGNAL(foundFrameEnd(ApiTraceFrame*)),
742 this, SLOT(slotFoundFrameEnd(ApiTraceFrame*)));
743 connect(m_trace, SIGNAL(foundCallIndex(ApiTraceCall*)),
744 this, SLOT(slotJumpToResult(ApiTraceCall*)));
746 connect(m_retracer, SIGNAL(finished(const QString&)),
747 this, SLOT(replayFinished(const QString&)));
748 connect(m_retracer, SIGNAL(error(const QString&)),
749 this, SLOT(replayError(const QString&)));
750 connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
751 this, SLOT(replayStateFound(ApiTraceState*)));
752 connect(m_retracer, SIGNAL(foundThumbnails(const QList<QImage>&)),
753 this, SLOT(replayThumbnailsFound(const QList<QImage>&)));
754 connect(m_retracer, SIGNAL(retraceErrors(const QList<ApiTraceError>&)),
755 this, SLOT(slotRetraceErrors(const QList<ApiTraceError>&)));
757 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
758 m_vdataInterpreter, SLOT(interpretData()));
759 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
760 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
761 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
762 m_vdataInterpreter, SLOT(setStride(int)));
763 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
764 m_vdataInterpreter, SLOT(setComponents(int)));
765 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
766 m_vdataInterpreter, SLOT(setStartingOffset(int)));
769 connect(m_ui.actionNew, SIGNAL(triggered()),
770 this, SLOT(createTrace()));
771 connect(m_ui.actionOpen, SIGNAL(triggered()),
772 this, SLOT(openTrace()));
773 connect(m_ui.actionQuit, SIGNAL(triggered()),
774 this, SLOT(close()));
776 connect(m_ui.actionFind, SIGNAL(triggered()),
777 this, SLOT(slotSearch()));
778 connect(m_ui.actionGo, SIGNAL(triggered()),
779 this, SLOT(slotGoTo()));
780 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
781 this, SLOT(slotGoFrameStart()));
782 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
783 this, SLOT(slotGoFrameEnd()));
785 connect(m_ui.actionReplay, SIGNAL(triggered()),
786 this, SLOT(replayStart()));
787 connect(m_ui.actionStop, SIGNAL(triggered()),
788 this, SLOT(replayStop()));
789 connect(m_ui.actionLookupState, SIGNAL(triggered()),
790 this, SLOT(lookupState()));
791 connect(m_ui.actionOptions, SIGNAL(triggered()),
792 this, SLOT(showSettings()));
794 connect(m_ui.callView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
795 this, SLOT(callItemSelected(const QModelIndex &)));
796 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
797 this, SLOT(customContextMenuRequested(QPoint)));
799 connect(m_ui.surfacesTreeWidget,
800 SIGNAL(customContextMenuRequested(const QPoint &)),
801 SLOT(showSurfacesMenu(const QPoint &)));
802 connect(m_ui.surfacesTreeWidget,
803 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
804 SLOT(showSelectedSurface()));
806 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
807 this, SLOT(openHelp(const QUrl&)));
809 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
810 this, SLOT(fillState(bool)));
812 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
813 SLOT(slotJumpTo(int)));
815 connect(m_searchWidget,
816 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
817 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
818 connect(m_searchWidget,
819 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
820 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
822 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
823 SLOT(createdTrace(const QString&)));
824 connect(m_traceProcess, SIGNAL(error(const QString&)),
825 SLOT(traceError(const QString&)));
827 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
828 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
829 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
830 m_ui.errorsDock, SLOT(setVisible(bool)));
831 connect(m_ui.errorsTreeWidget,
832 SIGNAL(itemActivated(QTreeWidgetItem*, int)),
833 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
836 void MainWindow::replayStateFound(ApiTraceState *state)
838 m_stateEvent->setState(state);
839 m_model->stateSetOnEvent(m_stateEvent);
840 if (m_selectedEvent == m_stateEvent ||
841 m_nonDefaultsLookupEvent == m_selectedEvent) {
844 m_ui.stateDock->hide();
846 m_nonDefaultsLookupEvent = 0;
849 void MainWindow::replayThumbnailsFound(const QList<QImage> &thumbnails)
851 m_thumbnails = thumbnails;
854 void MainWindow::slotGoTo()
856 m_searchWidget->hide();
857 m_jumpWidget->show();
860 void MainWindow::slotJumpTo(int callNum)
862 m_trace->findCallIndex(callNum);
865 void MainWindow::createdTrace(const QString &path)
867 qDebug()<<"Done tracing "<<path;
871 void MainWindow::traceError(const QString &msg)
873 QMessageBox::warning(
879 void MainWindow::slotSearch()
881 m_jumpWidget->hide();
882 m_searchWidget->show();
885 void MainWindow::slotSearchNext(const QString &str,
886 Qt::CaseSensitivity sensitivity)
888 ApiTraceCall *call = currentCall();
889 ApiTraceFrame *frame = currentFrame();
891 Q_ASSERT(call || frame);
893 frame = call->parentFrame();
897 m_trace->findNext(frame, call, str, sensitivity);
900 void MainWindow::slotSearchPrev(const QString &str,
901 Qt::CaseSensitivity sensitivity)
903 ApiTraceCall *call = currentCall();
904 ApiTraceFrame *frame = currentFrame();
906 Q_ASSERT(call || frame);
908 frame = call->parentFrame();
912 m_trace->findPrev(frame, call, str, sensitivity);
915 void MainWindow::fillState(bool nonDefaults)
918 ApiTraceState defaultState = m_trace->defaultState();
919 if (defaultState.isEmpty()) {
920 m_ui.nonDefaultsCB->blockSignals(true);
921 m_ui.nonDefaultsCB->setChecked(false);
922 m_ui.nonDefaultsCB->blockSignals(false);
923 ApiTraceFrame *firstFrame =
928 if (!firstFrame->isLoaded()) {
929 m_trace->loadFrame(firstFrame);
932 ApiTraceCall *firstCall = firstFrame->calls().first();
933 ApiTraceEvent *oldSelected = m_selectedEvent;
934 m_nonDefaultsLookupEvent = m_selectedEvent;
935 m_selectedEvent = firstCall;
937 m_selectedEvent = oldSelected;
943 void MainWindow::customContextMenuRequested(QPoint pos)
945 QModelIndex index = m_ui.callView->indexAt(pos);
947 callItemSelected(index);
948 if (!index.isValid()) {
952 ApiTraceEvent *event =
953 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
959 menu.addAction(QIcon(":/resources/media-record.png"),
960 tr("Lookup state"), this, SLOT(lookupState()));
961 if (event->type() == ApiTraceEvent::Call) {
962 menu.addAction(tr("Edit"), this, SLOT(editCall()));
965 menu.exec(QCursor::pos());
968 void MainWindow::editCall()
970 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
971 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
972 m_argsEditor->setCall(call);
973 m_argsEditor->show();
977 void MainWindow::slotStartedSaving()
979 m_progressBar->show();
980 statusBar()->showMessage(
981 tr("Saving to %1").arg(m_trace->fileName()));
984 void MainWindow::slotSaved()
986 statusBar()->showMessage(
987 tr("Saved to %1").arg(m_trace->fileName()), 2000);
988 m_progressBar->hide();
991 void MainWindow::slotGoFrameStart()
993 ApiTraceFrame *frame = currentFrame();
994 ApiTraceCall *call = currentCall();
996 if (!frame && call) {
997 frame = call->parentFrame();
1000 m_trace->findFrameStart(frame);
1003 void MainWindow::slotGoFrameEnd()
1005 ApiTraceFrame *frame = currentFrame();
1006 ApiTraceCall *call = currentCall();
1008 if (!frame && call) {
1009 frame = call->parentFrame();
1012 m_trace->findFrameEnd(frame);
1015 ApiTraceFrame * MainWindow::selectedFrame() const
1017 if (m_selectedEvent) {
1018 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
1019 return static_cast<ApiTraceFrame*>(m_selectedEvent);
1021 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1022 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1023 return call->parentFrame();
1029 void MainWindow::slotTraceChanged(ApiTraceCall *call)
1032 if (call == m_selectedEvent) {
1033 m_ui.detailsWebView->setHtml(call->toHtml());
1037 void MainWindow::slotRetraceErrors(const QList<ApiTraceError> &errors)
1039 m_ui.errorsTreeWidget->clear();
1041 foreach(ApiTraceError error, errors) {
1042 m_trace->setCallError(error);
1044 QTreeWidgetItem *item =
1045 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1046 item->setData(0, Qt::DisplayRole, error.callIndex);
1047 item->setData(0, Qt::UserRole, error.callIndex);
1048 QString type = error.type;
1049 type[0] = type[0].toUpper();
1050 item->setData(1, Qt::DisplayRole, type);
1051 item->setData(2, Qt::DisplayRole, error.message);
1055 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1059 current->data(0, Qt::UserRole).toInt();
1060 m_trace->findCallIndex(callIndex);
1064 ApiTraceCall * MainWindow::selectedCall() const
1066 if (m_selectedEvent &&
1067 m_selectedEvent->type() == ApiTraceEvent::Call) {
1068 return static_cast<ApiTraceCall*>(m_selectedEvent);
1073 void MainWindow::saveSelectedSurface()
1075 QTreeWidgetItem *item =
1076 m_ui.surfacesTreeWidget->currentItem();
1078 if (!item || !m_trace) {
1082 QVariant var = item->data(0, Qt::UserRole);
1083 QImage img = var.value<QImage>();
1086 if (selectedCall()) {
1087 imageIndex = tr("_call_%1")
1088 .arg(selectedCall()->index());
1089 } else if (selectedFrame()) {
1090 ApiTraceCall *firstCall = selectedFrame()->call(0);
1092 imageIndex = tr("_frame_%1")
1093 .arg(firstCall->index());
1095 qDebug()<<"unknown frame number";
1096 imageIndex = tr("_frame_%1")
1097 .arg(firstCall->index());
1101 //which of the surfaces are we saving
1102 QTreeWidgetItem *parent = item->parent();
1104 m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent);
1105 if (parentIndex < 0) {
1110 childIndex = parent->indexOfChild(item);
1112 childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item);
1117 tr("%1%2-%3_%4.png")
1118 .arg(m_trace->fileName())
1122 //qDebug()<<"save "<<fileName;
1123 img.save(fileName, "PNG");
1124 statusBar()->showMessage( tr("Saved '%1'").arg(fileName), 5000);
1127 void MainWindow::loadProgess(int percent)
1129 m_progressBar->setValue(percent);
1132 void MainWindow::slotSearchResult(const ApiTrace::SearchRequest &request,
1133 ApiTrace::SearchResult result,
1137 case ApiTrace::SearchResult_NotFound:
1138 m_searchWidget->setFound(false);
1140 case ApiTrace::SearchResult_Found: {
1141 QModelIndex index = m_proxyModel->indexForCall(call);
1143 if (index.isValid()) {
1144 m_ui.callView->setCurrentIndex(index);
1145 m_searchWidget->setFound(true);
1147 //call is filtered out, so continue searching but from the
1150 qDebug()<<"Error: search success with no call";
1153 // qDebug()<<"filtered! search from "<<call->searchText()
1154 // <<", call idx = "<<call->index();
1156 if (request.direction == ApiTrace::SearchRequest::Next) {
1157 m_trace->findNext(call->parentFrame(), call,
1158 request.text, request.cs);
1160 m_trace->findNext(call->parentFrame(), call,
1161 request.text, request.cs);
1166 case ApiTrace::SearchResult_Wrapped:
1167 m_searchWidget->setFound(false);
1172 ApiTraceFrame * MainWindow::currentFrame() const
1174 QModelIndex index = m_ui.callView->currentIndex();
1175 ApiTraceEvent *event = 0;
1177 if (!index.isValid()) {
1178 index = m_proxyModel->index(0, 0, QModelIndex());
1179 if (!index.isValid()) {
1180 qDebug()<<"no currently valid index";
1185 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1191 ApiTraceFrame *frame = 0;
1192 if (event->type() == ApiTraceCall::Frame) {
1193 frame = static_cast<ApiTraceFrame*>(event);
1198 ApiTraceCall * MainWindow::currentCall() const
1200 QModelIndex index = m_ui.callView->currentIndex();
1201 ApiTraceEvent *event = 0;
1203 if (!index.isValid()) {
1204 index = m_proxyModel->index(0, 0, QModelIndex());
1205 if (!index.isValid()) {
1206 qDebug()<<"no currently valid index";
1211 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1217 ApiTraceCall *call = 0;
1218 if (event->type() == ApiTraceCall::Call) {
1219 call = static_cast<ApiTraceCall*>(event);
1226 void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame)
1228 Q_ASSERT(frame->isLoaded());
1229 if (!frame || frame->isEmpty()) {
1233 QVector<ApiTraceCall*>::const_iterator itr;
1234 QVector<ApiTraceCall*> calls = frame->calls();
1236 itr = calls.constBegin();
1237 while (itr != calls.constEnd()) {
1238 ApiTraceCall *call = *itr;
1239 QModelIndex idx = m_proxyModel->indexForCall(call);
1240 if (idx.isValid()) {
1241 m_ui.callView->setCurrentIndex(idx);
1248 void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame)
1250 Q_ASSERT(frame->isLoaded());
1251 if (!frame || frame->isEmpty()) {
1254 QVector<ApiTraceCall*>::const_iterator itr;
1255 QVector<ApiTraceCall*> calls = frame->calls();
1257 itr = calls.constEnd();
1260 ApiTraceCall *call = *itr;
1261 QModelIndex idx = m_proxyModel->indexForCall(call);
1262 if (idx.isValid()) {
1263 m_ui.callView->setCurrentIndex(idx);
1266 } while (itr != calls.constBegin());
1269 void MainWindow::slotJumpToResult(ApiTraceCall *call)
1271 QModelIndex index = m_proxyModel->indexForCall(call);
1272 if (index.isValid()) {
1273 m_ui.callView->setCurrentIndex(index);
1275 statusBar()->showMessage(tr("Call has been filtered out."));
1279 #include "mainwindow.moc"