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"
11 #include "profiledialog.h"
13 #include "searchwidget.h"
14 #include "settingsdialog.h"
15 #include "shaderssourcewidget.h"
16 #include "tracedialog.h"
17 #include "traceprocess.h"
18 #include "trimprocess.h"
19 #include "thumbnail.h"
20 #include "ui_retracerdialog.h"
21 #include "ui_profilereplaydialog.h"
22 #include "vertexdatainterpreter.h"
23 #include "trace_profiler.hpp"
26 #include <QApplication>
28 #include <QDesktopServices>
29 #include <QDesktopWidget>
31 #include <QFileDialog>
33 #include <QMessageBox>
34 #include <QProgressBar>
37 #include <QVBoxLayout>
42 MainWindow::MainWindow()
48 m_nonDefaultsLookupEvent(0)
51 updateActionsState(false);
56 MainWindow::~MainWindow()
65 void MainWindow::createTrace()
67 if (!m_traceProcess->canTrace()) {
71 tr("Current configuration doesn't support tracing."));
76 if (dialog.exec() == QDialog::Accepted) {
77 qDebug()<< "App : " <<dialog.applicationPath();
78 qDebug()<< " Arguments: "<<dialog.arguments();
79 m_traceProcess->setApi(dialog.api());
80 m_traceProcess->setExecutablePath(dialog.applicationPath());
81 m_traceProcess->setArguments(dialog.arguments());
82 m_traceProcess->start();
86 void MainWindow::openTrace()
89 QFileDialog::getOpenFileName(
93 tr("Trace Files (*.trace)"));
95 if (!fileName.isEmpty() && QFile::exists(fileName)) {
96 newTraceFile(fileName);
100 void MainWindow::loadTrace(const QString &fileName, int callNum)
102 if (!QFile::exists(fileName)) {
103 QMessageBox::warning(this, tr("File Missing"),
104 tr("File '%1' doesn't exist.").arg(fileName));
108 m_initalCallNum = callNum;
109 newTraceFile(fileName);
112 void MainWindow::setRemoteTarget(const QString &host)
114 m_retracer->setRemoteTarget(host);
117 void MainWindow::callItemSelected(const QModelIndex &index)
119 ApiTraceEvent *event =
120 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
122 if (event && event->type() == ApiTraceEvent::Call) {
123 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
124 m_ui.detailsDock->setWindowTitle(
125 tr("Details View. Frame %1, Call %2")
126 .arg(call->parentFrame() ? call->parentFrame()->number : 0)
127 .arg(call->index()));
128 m_ui.detailsWebView->setHtml(call->toHtml());
129 m_ui.detailsDock->show();
130 if (call->hasBinaryData()) {
132 call->arguments()[call->binaryDataIndex()].toByteArray();
133 m_vdataInterpreter->setData(data);
135 QVector<QVariant> args = call->arguments();
136 for (int i = 0; i < call->argNames().count(); ++i) {
137 QString name = call->argNames()[i];
138 if (name == QLatin1String("stride")) {
139 int stride = args[i].toInt();
140 m_ui.vertexStrideSB->setValue(stride);
141 } else if (name == QLatin1String("size")) {
142 int components = args[i].toInt();
143 m_ui.vertexComponentsSB->setValue(components);
144 } else if (name == QLatin1String("type")) {
145 QString val = args[i].toString();
146 int textIndex = m_ui.vertexTypeCB->findText(val);
147 if (textIndex >= 0) {
148 m_ui.vertexTypeCB->setCurrentIndex(textIndex);
153 m_ui.vertexDataDock->setVisible(call->hasBinaryData());
154 m_selectedEvent = call;
156 if (event && event->type() == ApiTraceEvent::Frame) {
157 m_selectedEvent = static_cast<ApiTraceFrame*>(event);
161 m_ui.detailsDock->hide();
162 m_ui.vertexDataDock->hide();
164 if (m_selectedEvent && m_selectedEvent->hasState()) {
167 m_ui.stateDock->hide();
171 void MainWindow::callItemActivated(const QModelIndex &index) {
175 void MainWindow::replayStart()
177 if (m_trace->isSaving()) {
178 QMessageBox::warning(
181 tr("QApiTrace is currently saving the edited trace file. "
182 "Please wait until it finishes and try again."));
187 Ui_RetracerDialog dlgUi;
190 dlgUi.doubleBufferingCB->setChecked(
191 m_retracer->isDoubleBuffered());
193 dlgUi.errorCheckCB->setChecked(
194 !m_retracer->isBenchmarking());
196 if (dlg.exec() == QDialog::Accepted) {
197 m_retracer->setDoubleBuffered(
198 dlgUi.doubleBufferingCB->isChecked());
200 m_retracer->setBenchmarking(
201 !dlgUi.errorCheckCB->isChecked());
203 m_retracer->setProfiling(false, false, false);
205 replayTrace(false, false);
209 void MainWindow::replayProfile()
211 if (m_trace->isSaving()) {
212 QMessageBox::warning(
215 tr("QApiTrace is currently saving the edited trace file. "
216 "Please wait until it finishes and try again."));
221 Ui_ProfileReplayDialog dlgUi;
224 if (dlg.exec() == QDialog::Accepted) {
225 m_retracer->setProfiling(
226 dlgUi.gpuTimesCB->isChecked(),
227 dlgUi.cpuTimesCB->isChecked(),
228 dlgUi.pixelsDrawnCB->isChecked());
230 replayTrace(false, false);
234 void MainWindow::replayStop()
237 updateActionsState(true, true);
240 void MainWindow::newTraceFile(const QString &fileName)
242 qDebug()<< "Loading : " <<fileName;
244 m_progressBar->setValue(0);
245 m_trace->setFileName(fileName);
247 if (fileName.isEmpty()) {
248 updateActionsState(false);
249 setWindowTitle(tr("QApiTrace"));
251 updateActionsState(true);
252 QFileInfo info(fileName);
254 tr("QApiTrace - %1").arg(info.fileName()));
258 void MainWindow::replayFinished(const QString &message)
260 updateActionsState(true);
261 m_progressBar->hide();
262 statusBar()->showMessage(message, 2000);
264 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
265 m_ui.errorsDock->setVisible(m_trace->hasErrors());
266 if (!m_trace->hasErrors()) {
267 m_ui.errorsTreeWidget->clear();
271 void MainWindow::replayError(const QString &message)
273 updateActionsState(true);
275 m_nonDefaultsLookupEvent = 0;
277 m_progressBar->hide();
278 statusBar()->showMessage(
279 tr("Replaying unsuccessful."), 2000);
280 QMessageBox::warning(
281 this, tr("Replay Failed"), message);
284 void MainWindow::startedLoadingTrace()
287 m_progressBar->show();
288 QFileInfo info(m_trace->fileName());
289 statusBar()->showMessage(
290 tr("Loading %1...").arg(info.fileName()));
293 void MainWindow::finishedLoadingTrace()
295 m_progressBar->hide();
299 m_api = m_trace->api();
300 QFileInfo info(m_trace->fileName());
301 statusBar()->showMessage(
302 tr("Loaded %1").arg(info.fileName()), 3000);
303 if (m_initalCallNum >= 0) {
304 m_trace->findCallIndex(m_initalCallNum);
305 m_initalCallNum = -1;
309 void MainWindow::replayTrace(bool dumpState, bool dumpThumbnails)
311 if (m_trace->fileName().isEmpty()) {
315 m_retracer->setFileName(m_trace->fileName());
316 m_retracer->setAPI(m_api);
317 m_retracer->setCaptureState(dumpState);
318 m_retracer->setCaptureThumbnails(dumpThumbnails);
319 if (m_retracer->captureState() && m_selectedEvent) {
321 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
322 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
323 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
324 ApiTraceFrame *frame =
325 static_cast<ApiTraceFrame*>(m_selectedEvent);
326 if (frame->isEmpty()) {
327 //XXX i guess we could still get the current state
328 qDebug()<<"tried to get a state for an empty frame";
331 index = frame->lastCallIndex();
333 qDebug()<<"Unknown event type";
336 m_retracer->setCaptureAtCallNumber(index);
340 m_ui.actionStop->setEnabled(true);
341 m_progressBar->show();
342 if (dumpState || dumpThumbnails) {
343 if (dumpState && dumpThumbnails) {
344 statusBar()->showMessage(
345 tr("Looking up the state and capturing thumbnails..."));
346 } else if (dumpState) {
347 statusBar()->showMessage(
348 tr("Looking up the state..."));
349 } else if (dumpThumbnails) {
350 statusBar()->showMessage(
351 tr("Capturing thumbnails..."));
353 } else if (m_retracer->isProfiling()) {
354 statusBar()->showMessage(
355 tr("Profiling draw calls in trace file..."));
357 statusBar()->showMessage(
358 tr("Replaying the trace file..."));
362 void MainWindow::trimEvent()
366 if (m_trimEvent->type() == ApiTraceEvent::Call) {
367 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_trimEvent);
368 trimIndex = call->index();
369 } else if (m_trimEvent->type() == ApiTraceEvent::Frame) {
370 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(m_trimEvent);
371 const QList<ApiTraceFrame*> frames = m_trace->frames();
372 trimIndex = frame->lastCallIndex();
375 m_trimProcess->setTracePath(m_trace->fileName());
376 m_trimProcess->setTrimIndex(trimIndex);
378 m_trimProcess->start();
381 void MainWindow::lookupState()
383 if (!m_selectedEvent) {
384 QMessageBox::warning(
385 this, tr("Unknown Event"),
386 tr("To inspect the state select an event in the event list."));
389 if (m_trace->isSaving()) {
390 QMessageBox::warning(
393 tr("QApiTrace is currently saving the edited trace file. "
394 "Please wait until it finishes and try again."));
397 m_stateEvent = m_selectedEvent;
398 replayTrace(true, false);
401 void MainWindow::showThumbnails()
403 replayTrace(false, true);
406 void MainWindow::trim()
408 if (!m_selectedEvent) {
409 QMessageBox::warning(
410 this, tr("Unknown Event"),
411 tr("To trim select a frame or an event in the event list."));
414 m_trimEvent = m_selectedEvent;
419 variantToString(const QVariant &var, QString &str)
421 if (var.type() == QVariant::List) {
422 QVector<QVariant> lst = var.toList().toVector();
423 str += QLatin1String("[");
424 for (int i = 0; i < lst.count(); ++i) {
425 QVariant val = lst[i];
426 variantToString(val, str);
427 if (i < lst.count() - 1)
428 str += QLatin1String(", ");
430 str += QLatin1String("]");
431 } else if (var.type() == QVariant::Map) {
432 Q_ASSERT(!"unsupported state type");
433 } else if (var.type() == QVariant::Hash) {
434 Q_ASSERT(!"unsupported state type");
436 str += var.toString();
440 static QTreeWidgetItem *
441 variantToItem(const QString &key, const QVariant &var,
442 const QVariant &defaultVar);
445 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap,
446 QList<QTreeWidgetItem *> &items)
448 QVariantMap::const_iterator itr;
449 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
450 QString key = itr.key();
451 QVariant var = itr.value();
452 QVariant defaultVar = defaultMap[key];
454 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
462 variantListToItems(const QVector<QVariant> &lst,
463 const QVector<QVariant> &defaultLst,
464 QList<QTreeWidgetItem *> &items)
466 for (int i = 0; i < lst.count(); ++i) {
467 QString key = QString::number(i);
468 QVariant var = lst[i];
471 if (i < defaultLst.count()) {
472 defaultVar = defaultLst[i];
475 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
483 isVariantDeep(const QVariant &var)
485 if (var.type() == QVariant::List) {
486 QVector<QVariant> lst = var.toList().toVector();
487 for (int i = 0; i < lst.count(); ++i) {
488 if (isVariantDeep(lst[i])) {
493 } else if (var.type() == QVariant::Map) {
495 } else if (var.type() == QVariant::Hash) {
502 static QTreeWidgetItem *
503 variantToItem(const QString &key, const QVariant &var,
504 const QVariant &defaultVar)
506 if (var == defaultVar) {
512 bool deep = isVariantDeep(var);
514 variantToString(var, val);
517 //qDebug()<<"key = "<<key;
518 //qDebug()<<"val = "<<val;
523 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
526 QList<QTreeWidgetItem *> children;
527 if (var.type() == QVariant::Map) {
528 QVariantMap map = var.toMap();
529 QVariantMap defaultMap = defaultVar.toMap();
530 variantMapToItems(map, defaultMap, children);
532 if (var.type() == QVariant::List) {
533 QVector<QVariant> lst = var.toList().toVector();
534 QVector<QVariant> defaultLst = defaultVar.toList().toVector();
535 variantListToItems(lst, defaultLst, children);
537 item->addChildren(children);
543 static void addSurfaceItem(const ApiSurface &surface,
544 const QString &label,
545 QTreeWidgetItem *parent,
548 QIcon icon(QPixmap::fromImage(surface.thumb()));
549 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
550 item->setIcon(0, icon);
552 int width = surface.size().width();
553 int height = surface.size().height();
555 QString::fromLatin1("%1, %2, %3 x %4")
557 .arg(surface.formatName())
561 //item->setText(1, descr);
562 QLabel *l = new QLabel(descr, tree);
563 l->setWordWrap(true);
564 tree->setItemWidget(item, 1, l);
566 item->setData(0, Qt::UserRole, surface.image());
569 void MainWindow::fillStateForFrame()
571 if (!m_selectedEvent || !m_selectedEvent->hasState()) {
575 if (m_nonDefaultsLookupEvent) {
576 m_ui.nonDefaultsCB->blockSignals(true);
577 m_ui.nonDefaultsCB->setChecked(true);
578 m_ui.nonDefaultsCB->blockSignals(false);
581 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
582 QVariantMap defaultParams;
584 ApiTraceState defaultState = m_trace->defaultState();
585 defaultParams = defaultState.parameters();
588 const ApiTraceState &state = *m_selectedEvent->state();
589 m_ui.stateTreeWidget->clear();
590 QList<QTreeWidgetItem *> items;
591 variantMapToItems(state.parameters(), defaultParams, items);
592 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
594 QMap<QString, QString> shaderSources = state.shaderSources();
595 if (shaderSources.isEmpty()) {
596 m_sourcesWidget->setShaders(shaderSources);
598 m_sourcesWidget->setShaders(shaderSources);
601 m_ui.uniformsTreeWidget->clear();
602 QList<QTreeWidgetItem *> uniformsItems;
603 variantMapToItems(state.uniforms(), QVariantMap(), uniformsItems);
604 m_ui.uniformsTreeWidget->insertTopLevelItems(0, uniformsItems);
606 const QList<ApiTexture> &textures =
608 const QList<ApiFramebuffer> &fbos =
609 state.framebuffers();
611 m_ui.surfacesTreeWidget->clear();
612 if (textures.isEmpty() && fbos.isEmpty()) {
613 m_ui.surfacesTab->setDisabled(false);
615 m_ui.surfacesTreeWidget->setIconSize(QSize(THUMBNAIL_SIZE, THUMBNAIL_SIZE));
616 if (!textures.isEmpty()) {
617 QTreeWidgetItem *textureItem =
618 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
619 textureItem->setText(0, tr("Textures"));
620 if (textures.count() <= 6) {
621 textureItem->setExpanded(true);
624 for (int i = 0; i < textures.count(); ++i) {
625 const ApiTexture &texture =
627 addSurfaceItem(texture, texture.label(),
629 m_ui.surfacesTreeWidget);
632 if (!fbos.isEmpty()) {
633 QTreeWidgetItem *fboItem =
634 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
635 fboItem->setText(0, tr("Framebuffers"));
636 if (fbos.count() <= 6) {
637 fboItem->setExpanded(true);
640 for (int i = 0; i < fbos.count(); ++i) {
641 const ApiFramebuffer &fbo =
643 addSurfaceItem(fbo, fbo.type(),
645 m_ui.surfacesTreeWidget);
648 m_ui.surfacesTab->setEnabled(true);
650 m_ui.stateDock->show();
653 void MainWindow::showSettings()
655 SettingsDialog dialog;
656 dialog.setFilterModel(m_proxyModel);
661 void MainWindow::openHelp(const QUrl &url)
663 QDesktopServices::openUrl(url);
666 void MainWindow::showSurfacesMenu(const QPoint &pos)
668 QTreeWidget *tree = m_ui.surfacesTreeWidget;
669 QTreeWidgetItem *item = tree->itemAt(pos);
674 QMenu menu(tr("Surfaces"), this);
676 QAction *act = menu.addAction(tr("View Image"));
677 act->setStatusTip(tr("View the currently selected surface"));
678 connect(act, SIGNAL(triggered()),
679 SLOT(showSelectedSurface()));
681 act = menu.addAction(tr("Save Image"));
682 act->setStatusTip(tr("Save the currently selected surface"));
683 connect(act, SIGNAL(triggered()),
684 SLOT(saveSelectedSurface()));
686 menu.exec(tree->viewport()->mapToGlobal(pos));
689 void MainWindow::showSelectedSurface()
691 QTreeWidgetItem *item =
692 m_ui.surfacesTreeWidget->currentItem();
698 ImageViewer *viewer = new ImageViewer(this);
701 if (selectedCall()) {
702 title = tr("QApiTrace - Surface at %1 (%2)")
703 .arg(selectedCall()->name())
704 .arg(selectedCall()->index());
706 title = tr("QApiTrace - Surface Viewer");
708 viewer->setWindowTitle(title);
710 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
712 QVariant var = item->data(0, Qt::UserRole);
713 QImage img = var.value<QImage>();
714 viewer->setImage(img);
718 viewer->activateWindow();
721 void MainWindow::initObjects()
723 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
724 m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder);
726 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
727 QVBoxLayout *layout = new QVBoxLayout;
728 layout->addWidget(m_sourcesWidget);
729 m_ui.shadersTab->setLayout(layout);
731 m_trace = new ApiTrace();
732 m_retracer = new Retracer(this);
734 m_vdataInterpreter = new VertexDataInterpreter(this);
735 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
736 m_vdataInterpreter->setStride(
737 m_ui.vertexStrideSB->value());
738 m_vdataInterpreter->setComponents(
739 m_ui.vertexComponentsSB->value());
740 m_vdataInterpreter->setStartingOffset(
741 m_ui.startingOffsetSB->value());
742 m_vdataInterpreter->setTypeFromString(
743 m_ui.vertexTypeCB->currentText());
745 m_model = new ApiTraceModel();
746 m_model->setApiTrace(m_trace);
747 m_proxyModel = new ApiTraceFilter();
748 m_proxyModel->setSourceModel(m_model);
749 m_ui.callView->setModel(m_proxyModel);
750 m_ui.callView->setItemDelegate(
751 new ApiCallDelegate(m_ui.callView));
752 m_ui.callView->resizeColumnToContents(0);
753 m_ui.callView->header()->swapSections(0, 1);
754 m_ui.callView->setColumnWidth(1, 42);
755 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
757 m_progressBar = new QProgressBar();
758 m_progressBar->setRange(0, 100);
759 statusBar()->addPermanentWidget(m_progressBar);
760 m_progressBar->hide();
762 m_argsEditor = new ArgumentsEditor(this);
764 m_ui.detailsDock->hide();
765 m_ui.errorsDock->hide();
766 m_ui.vertexDataDock->hide();
767 m_ui.stateDock->hide();
768 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
770 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
771 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
773 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
775 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
776 QWebPage::DelegateExternalLinks);
778 m_jumpWidget = new JumpWidget(this);
779 m_ui.centralLayout->addWidget(m_jumpWidget);
780 m_jumpWidget->hide();
782 m_searchWidget = new SearchWidget(this);
783 m_ui.centralLayout->addWidget(m_searchWidget);
784 m_searchWidget->hide();
786 m_traceProcess = new TraceProcess(this);
787 m_trimProcess = new TrimProcess(this);
789 m_profileDialog = new ProfileDialog();
792 void MainWindow::initConnections()
794 connect(m_trace, SIGNAL(startedLoadingTrace()),
795 this, SLOT(startedLoadingTrace()));
796 connect(m_trace, SIGNAL(loaded(int)),
797 this, SLOT(loadProgess(int)));
798 connect(m_trace, SIGNAL(finishedLoadingTrace()),
799 this, SLOT(finishedLoadingTrace()));
800 connect(m_trace, SIGNAL(startedSaving()),
801 this, SLOT(slotStartedSaving()));
802 connect(m_trace, SIGNAL(saved()),
803 this, SLOT(slotSaved()));
804 connect(m_trace, SIGNAL(changed(ApiTraceEvent*)),
805 this, SLOT(slotTraceChanged(ApiTraceEvent*)));
806 connect(m_trace, SIGNAL(findResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)),
807 this, SLOT(slotSearchResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)));
808 connect(m_trace, SIGNAL(foundFrameStart(ApiTraceFrame*)),
809 this, SLOT(slotFoundFrameStart(ApiTraceFrame*)));
810 connect(m_trace, SIGNAL(foundFrameEnd(ApiTraceFrame*)),
811 this, SLOT(slotFoundFrameEnd(ApiTraceFrame*)));
812 connect(m_trace, SIGNAL(foundCallIndex(ApiTraceCall*)),
813 this, SLOT(slotJumpToResult(ApiTraceCall*)));
815 connect(m_retracer, SIGNAL(finished(const QString&)),
816 this, SLOT(replayFinished(const QString&)));
817 connect(m_retracer, SIGNAL(error(const QString&)),
818 this, SLOT(replayError(const QString&)));
819 connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
820 this, SLOT(replayStateFound(ApiTraceState*)));
821 connect(m_retracer, SIGNAL(foundProfile(trace::Profile*)),
822 this, SLOT(replayProfileFound(trace::Profile*)));
823 connect(m_retracer, SIGNAL(foundThumbnails(const QList<QImage>&)),
824 this, SLOT(replayThumbnailsFound(const QList<QImage>&)));
825 connect(m_retracer, SIGNAL(retraceErrors(const QList<ApiTraceError>&)),
826 this, SLOT(slotRetraceErrors(const QList<ApiTraceError>&)));
828 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
829 m_vdataInterpreter, SLOT(interpretData()));
830 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
831 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
832 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
833 m_vdataInterpreter, SLOT(setStride(int)));
834 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
835 m_vdataInterpreter, SLOT(setComponents(int)));
836 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
837 m_vdataInterpreter, SLOT(setStartingOffset(int)));
840 connect(m_ui.actionNew, SIGNAL(triggered()),
841 this, SLOT(createTrace()));
842 connect(m_ui.actionOpen, SIGNAL(triggered()),
843 this, SLOT(openTrace()));
844 connect(m_ui.actionQuit, SIGNAL(triggered()),
845 this, SLOT(close()));
847 connect(m_ui.actionFind, SIGNAL(triggered()),
848 this, SLOT(slotSearch()));
849 connect(m_ui.actionGo, SIGNAL(triggered()),
850 this, SLOT(slotGoTo()));
851 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
852 this, SLOT(slotGoFrameStart()));
853 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
854 this, SLOT(slotGoFrameEnd()));
856 connect(m_ui.actionReplay, SIGNAL(triggered()),
857 this, SLOT(replayStart()));
858 connect(m_ui.actionProfile, SIGNAL(triggered()),
859 this, SLOT(replayProfile()));
860 connect(m_ui.actionStop, SIGNAL(triggered()),
861 this, SLOT(replayStop()));
862 connect(m_ui.actionLookupState, SIGNAL(triggered()),
863 this, SLOT(lookupState()));
864 connect(m_ui.actionTrim, SIGNAL(triggered()),
866 connect(m_ui.actionShowThumbnails, SIGNAL(triggered()),
867 this, SLOT(showThumbnails()));
868 connect(m_ui.actionOptions, SIGNAL(triggered()),
869 this, SLOT(showSettings()));
871 connect(m_ui.callView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
872 this, SLOT(callItemSelected(const QModelIndex &)));
873 connect(m_ui.callView, SIGNAL(doubleClicked(const QModelIndex &)),
874 this, SLOT(callItemActivated(const QModelIndex &)));
875 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
876 this, SLOT(customContextMenuRequested(QPoint)));
878 connect(m_ui.surfacesTreeWidget,
879 SIGNAL(customContextMenuRequested(const QPoint &)),
880 SLOT(showSurfacesMenu(const QPoint &)));
881 connect(m_ui.surfacesTreeWidget,
882 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
883 SLOT(showSelectedSurface()));
885 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
886 this, SLOT(openHelp(const QUrl&)));
888 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
889 this, SLOT(fillState(bool)));
891 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
892 SLOT(slotJumpTo(int)));
894 connect(m_searchWidget,
895 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
896 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
897 connect(m_searchWidget,
898 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
899 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
901 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
902 SLOT(createdTrace(const QString&)));
903 connect(m_traceProcess, SIGNAL(error(const QString&)),
904 SLOT(traceError(const QString&)));
906 connect(m_trimProcess, SIGNAL(trimmedFile(const QString&)),
907 SLOT(createdTrim(const QString&)));
908 connect(m_trimProcess, SIGNAL(error(const QString&)),
909 SLOT(trimError(const QString&)));
911 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
912 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
913 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
914 m_ui.errorsDock, SLOT(setVisible(bool)));
915 connect(m_ui.errorsTreeWidget,
916 SIGNAL(itemActivated(QTreeWidgetItem*, int)),
917 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
919 connect(m_ui.actionShowProfileDialog, SIGNAL(triggered(bool)),
920 m_profileDialog, SLOT(show()));
921 connect(m_profileDialog, SIGNAL(jumpToCall(int)),
922 this, SLOT(slotJumpTo(int)));
925 void MainWindow::updateActionsState(bool traceLoaded, bool stopped)
929 m_ui.actionFind ->setEnabled(true);
930 m_ui.actionGo ->setEnabled(true);
931 m_ui.actionGoFrameStart ->setEnabled(true);
932 m_ui.actionGoFrameEnd ->setEnabled(true);
936 m_ui.actionStop->setEnabled(false);
937 m_ui.actionReplay->setEnabled(true);
940 m_ui.actionStop->setEnabled(true);
941 m_ui.actionReplay->setEnabled(false);
944 m_ui.actionProfile ->setEnabled(true);
945 m_ui.actionLookupState ->setEnabled(true);
946 m_ui.actionShowThumbnails->setEnabled(true);
947 m_ui.actionTrim ->setEnabled(true);
951 m_ui.actionFind ->setEnabled(false);
952 m_ui.actionGo ->setEnabled(false);
953 m_ui.actionGoFrameStart ->setEnabled(false);
954 m_ui.actionGoFrameEnd ->setEnabled(false);
957 m_ui.actionReplay ->setEnabled(false);
958 m_ui.actionProfile ->setEnabled(false);
959 m_ui.actionStop ->setEnabled(false);
960 m_ui.actionLookupState ->setEnabled(false);
961 m_ui.actionShowThumbnails->setEnabled(false);
962 m_ui.actionTrim ->setEnabled(false);
966 void MainWindow::closeEvent(QCloseEvent * event)
968 m_profileDialog->close();
969 QMainWindow::closeEvent(event);
972 void MainWindow::replayProfileFound(trace::Profile *profile)
974 m_ui.actionShowProfileDialog->setEnabled(true);
975 m_profileDialog->setProfile(profile);
976 m_profileDialog->show();
977 m_profileDialog->activateWindow();
978 m_profileDialog->setFocus();
981 void MainWindow::replayStateFound(ApiTraceState *state)
983 m_stateEvent->setState(state);
984 m_model->stateSetOnEvent(m_stateEvent);
985 if (m_selectedEvent == m_stateEvent ||
986 m_nonDefaultsLookupEvent == m_selectedEvent) {
989 m_ui.stateDock->hide();
991 m_nonDefaultsLookupEvent = 0;
994 void MainWindow::replayThumbnailsFound(const QList<QImage> &thumbnails)
996 m_ui.callView->setUniformRowHeights(false);
997 m_trace->bindThumbnailsToFrames(thumbnails);
1000 void MainWindow::slotGoTo()
1002 m_searchWidget->hide();
1003 m_jumpWidget->show();
1006 void MainWindow::slotJumpTo(int callNum)
1008 m_trace->findCallIndex(callNum);
1011 void MainWindow::createdTrace(const QString &path)
1013 qDebug()<<"Done tracing "<<path;
1017 void MainWindow::traceError(const QString &msg)
1019 QMessageBox::warning(
1021 tr("Tracing Error"),
1025 void MainWindow::createdTrim(const QString &path)
1027 qDebug()<<"Done trimming "<<path;
1032 void MainWindow::trimError(const QString &msg)
1034 QMessageBox::warning(
1040 void MainWindow::slotSearch()
1042 m_jumpWidget->hide();
1043 m_searchWidget->show();
1046 void MainWindow::slotSearchNext(const QString &str,
1047 Qt::CaseSensitivity sensitivity)
1049 ApiTraceCall *call = currentCall();
1050 ApiTraceFrame *frame = currentFrame();
1052 Q_ASSERT(call || frame);
1054 frame = call->parentFrame();
1058 m_trace->findNext(frame, call, str, sensitivity);
1061 void MainWindow::slotSearchPrev(const QString &str,
1062 Qt::CaseSensitivity sensitivity)
1064 ApiTraceCall *call = currentCall();
1065 ApiTraceFrame *frame = currentFrame();
1067 Q_ASSERT(call || frame);
1069 frame = call->parentFrame();
1073 m_trace->findPrev(frame, call, str, sensitivity);
1076 void MainWindow::fillState(bool nonDefaults)
1079 ApiTraceState defaultState = m_trace->defaultState();
1080 if (defaultState.isEmpty()) {
1081 m_ui.nonDefaultsCB->blockSignals(true);
1082 m_ui.nonDefaultsCB->setChecked(false);
1083 m_ui.nonDefaultsCB->blockSignals(false);
1084 ApiTraceFrame *firstFrame =
1085 m_trace->frameAt(0);
1089 if (!firstFrame->isLoaded()) {
1090 m_trace->loadFrame(firstFrame);
1093 ApiTraceCall *firstCall = firstFrame->calls().first();
1094 ApiTraceEvent *oldSelected = m_selectedEvent;
1095 m_nonDefaultsLookupEvent = m_selectedEvent;
1096 m_selectedEvent = firstCall;
1098 m_selectedEvent = oldSelected;
1101 fillStateForFrame();
1104 void MainWindow::customContextMenuRequested(QPoint pos)
1106 QModelIndex index = m_ui.callView->indexAt(pos);
1108 callItemSelected(index);
1109 if (!index.isValid()) {
1113 ApiTraceEvent *event =
1114 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1120 menu.addAction(QIcon(":/resources/media-record.png"),
1121 tr("Lookup state"), this, SLOT(lookupState()));
1122 if (event->type() == ApiTraceEvent::Call) {
1123 menu.addAction(tr("Edit"), this, SLOT(editCall()));
1126 menu.exec(QCursor::pos());
1129 void MainWindow::editCall()
1131 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
1132 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1133 m_argsEditor->setCall(call);
1134 m_argsEditor->show();
1138 void MainWindow::slotStartedSaving()
1140 m_progressBar->show();
1141 statusBar()->showMessage(
1142 tr("Saving to %1").arg(m_trace->fileName()));
1145 void MainWindow::slotSaved()
1147 statusBar()->showMessage(
1148 tr("Saved to %1").arg(m_trace->fileName()), 2000);
1149 m_progressBar->hide();
1152 void MainWindow::slotGoFrameStart()
1154 ApiTraceFrame *frame = currentFrame();
1155 ApiTraceCall *call = currentCall();
1157 if (!frame && call) {
1158 frame = call->parentFrame();
1161 m_trace->findFrameStart(frame);
1164 void MainWindow::slotGoFrameEnd()
1166 ApiTraceFrame *frame = currentFrame();
1167 ApiTraceCall *call = currentCall();
1169 if (!frame && call) {
1170 frame = call->parentFrame();
1173 m_trace->findFrameEnd(frame);
1176 ApiTraceFrame * MainWindow::selectedFrame() const
1178 if (m_selectedEvent) {
1179 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
1180 return static_cast<ApiTraceFrame*>(m_selectedEvent);
1182 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1183 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1184 return call->parentFrame();
1190 void MainWindow::slotTraceChanged(ApiTraceEvent *event)
1193 if (event == m_selectedEvent) {
1194 if (event->type() == ApiTraceEvent::Call) {
1195 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
1196 m_ui.detailsWebView->setHtml(call->toHtml());
1201 void MainWindow::slotRetraceErrors(const QList<ApiTraceError> &errors)
1203 m_ui.errorsTreeWidget->clear();
1205 foreach(ApiTraceError error, errors) {
1206 m_trace->setCallError(error);
1208 QTreeWidgetItem *item =
1209 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1210 item->setData(0, Qt::DisplayRole, error.callIndex);
1211 item->setData(0, Qt::UserRole, error.callIndex);
1212 QString type = error.type;
1213 type[0] = type[0].toUpper();
1214 item->setData(1, Qt::DisplayRole, type);
1215 item->setData(2, Qt::DisplayRole, error.message);
1219 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1223 current->data(0, Qt::UserRole).toInt();
1224 m_trace->findCallIndex(callIndex);
1228 ApiTraceCall * MainWindow::selectedCall() const
1230 if (m_selectedEvent &&
1231 m_selectedEvent->type() == ApiTraceEvent::Call) {
1232 return static_cast<ApiTraceCall*>(m_selectedEvent);
1237 void MainWindow::saveSelectedSurface()
1239 QTreeWidgetItem *item =
1240 m_ui.surfacesTreeWidget->currentItem();
1242 if (!item || !m_trace) {
1246 QVariant var = item->data(0, Qt::UserRole);
1247 QImage img = var.value<QImage>();
1250 if (selectedCall()) {
1251 imageIndex = tr("_call_%1")
1252 .arg(selectedCall()->index());
1253 } else if (selectedFrame()) {
1254 ApiTraceCall *firstCall = selectedFrame()->call(0);
1256 imageIndex = tr("_frame_%1")
1257 .arg(firstCall->index());
1259 qDebug()<<"unknown frame number";
1260 imageIndex = tr("_frame_%1")
1261 .arg(firstCall->index());
1265 //which of the surfaces are we saving
1266 QTreeWidgetItem *parent = item->parent();
1268 m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent);
1269 if (parentIndex < 0) {
1274 childIndex = parent->indexOfChild(item);
1276 childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item);
1281 tr("%1%2-%3_%4.png")
1282 .arg(m_trace->fileName())
1286 //qDebug()<<"save "<<fileName;
1287 img.save(fileName, "PNG");
1288 statusBar()->showMessage( tr("Saved '%1'").arg(fileName), 5000);
1291 void MainWindow::loadProgess(int percent)
1293 m_progressBar->setValue(percent);
1296 void MainWindow::slotSearchResult(const ApiTrace::SearchRequest &request,
1297 ApiTrace::SearchResult result,
1301 case ApiTrace::SearchResult_NotFound:
1302 m_searchWidget->setFound(false);
1304 case ApiTrace::SearchResult_Found: {
1305 QModelIndex index = m_proxyModel->indexForCall(call);
1307 if (index.isValid()) {
1308 m_ui.callView->setCurrentIndex(index);
1309 m_searchWidget->setFound(true);
1311 //call is filtered out, so continue searching but from the
1314 qDebug()<<"Error: search success with no call";
1317 // qDebug()<<"filtered! search from "<<call->searchText()
1318 // <<", call idx = "<<call->index();
1320 if (request.direction == ApiTrace::SearchRequest::Next) {
1321 m_trace->findNext(call->parentFrame(), call,
1322 request.text, request.cs);
1324 m_trace->findNext(call->parentFrame(), call,
1325 request.text, request.cs);
1330 case ApiTrace::SearchResult_Wrapped:
1331 m_searchWidget->setFound(false);
1336 ApiTraceFrame * MainWindow::currentFrame() const
1338 QModelIndex index = m_ui.callView->currentIndex();
1339 ApiTraceEvent *event = 0;
1341 if (!index.isValid()) {
1342 index = m_proxyModel->index(0, 0, QModelIndex());
1343 if (!index.isValid()) {
1344 qDebug()<<"no currently valid index";
1349 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1355 ApiTraceFrame *frame = 0;
1356 if (event->type() == ApiTraceCall::Frame) {
1357 frame = static_cast<ApiTraceFrame*>(event);
1362 ApiTraceCall * MainWindow::currentCall() const
1364 QModelIndex index = m_ui.callView->currentIndex();
1365 ApiTraceEvent *event = 0;
1367 if (!index.isValid()) {
1368 index = m_proxyModel->index(0, 0, QModelIndex());
1369 if (!index.isValid()) {
1370 qDebug()<<"no currently valid index";
1375 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1381 ApiTraceCall *call = 0;
1382 if (event->type() == ApiTraceCall::Call) {
1383 call = static_cast<ApiTraceCall*>(event);
1390 void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame)
1392 Q_ASSERT(frame->isLoaded());
1393 if (!frame || frame->isEmpty()) {
1397 QVector<ApiTraceCall*>::const_iterator itr;
1398 QVector<ApiTraceCall*> calls = frame->calls();
1400 itr = calls.constBegin();
1401 while (itr != calls.constEnd()) {
1402 ApiTraceCall *call = *itr;
1403 QModelIndex idx = m_proxyModel->indexForCall(call);
1404 if (idx.isValid()) {
1405 m_ui.callView->setCurrentIndex(idx);
1406 m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtTop);
1413 void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame)
1415 Q_ASSERT(frame->isLoaded());
1416 if (!frame || frame->isEmpty()) {
1419 QVector<ApiTraceCall*>::const_iterator itr;
1420 QVector<ApiTraceCall*> calls = frame->calls();
1422 itr = calls.constEnd();
1425 ApiTraceCall *call = *itr;
1426 QModelIndex idx = m_proxyModel->indexForCall(call);
1427 if (idx.isValid()) {
1428 m_ui.callView->setCurrentIndex(idx);
1429 m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtBottom);
1432 } while (itr != calls.constBegin());
1435 void MainWindow::slotJumpToResult(ApiTraceCall *call)
1437 QModelIndex idx = m_proxyModel->indexForCall(call);
1438 if (idx.isValid()) {
1440 m_ui.callView->setFocus();
1441 m_ui.callView->setCurrentIndex(idx);
1442 m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
1444 statusBar()->showMessage(tr("Call has been filtered out."));
1448 #include "mainwindow.moc"