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 "thumbnail.h"
18 #include "ui_retracerdialog.h"
19 #include "vertexdatainterpreter.h"
22 #include <QApplication>
24 #include <QDesktopServices>
25 #include <QDesktopWidget>
27 #include <QFileDialog>
29 #include <QMessageBox>
30 #include <QProgressBar>
33 #include <QVBoxLayout>
38 MainWindow::MainWindow()
44 m_nonDefaultsLookupEvent(0)
51 void MainWindow::createTrace()
53 if (!m_traceProcess->canTrace()) {
57 tr("Current configuration doesn't support tracing."));
62 if (dialog.exec() == QDialog::Accepted) {
63 qDebug()<< "App : " <<dialog.applicationPath();
64 qDebug()<< " Arguments: "<<dialog.arguments();
65 m_traceProcess->setApi(dialog.api());
66 m_traceProcess->setExecutablePath(dialog.applicationPath());
67 m_traceProcess->setArguments(dialog.arguments());
68 m_traceProcess->start();
72 void MainWindow::openTrace()
75 QFileDialog::getOpenFileName(
79 tr("Trace Files (*.trace)"));
81 if (!fileName.isEmpty() && QFile::exists(fileName)) {
82 newTraceFile(fileName);
86 void MainWindow::loadTrace(const QString &fileName, int callNum)
88 if (!QFile::exists(fileName)) {
89 QMessageBox::warning(this, tr("File Missing"),
90 tr("File '%1' doesn't exist.").arg(fileName));
94 m_initalCallNum = callNum;
95 newTraceFile(fileName);
98 void MainWindow::callItemSelected(const QModelIndex &index)
100 ApiTraceEvent *event =
101 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
103 if (event && event->type() == ApiTraceEvent::Call) {
104 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
105 m_ui.detailsDock->setWindowTitle(
106 tr("Details View. Frame %1, Call %2")
107 .arg(call->parentFrame() ? call->parentFrame()->number : 0)
108 .arg(call->index()));
109 m_ui.detailsWebView->setHtml(call->toHtml());
110 m_ui.detailsDock->show();
111 if (call->hasBinaryData()) {
113 call->arguments()[call->binaryDataIndex()].toByteArray();
114 m_vdataInterpreter->setData(data);
116 QVector<QVariant> args = call->arguments();
117 for (int i = 0; i < call->argNames().count(); ++i) {
118 QString name = call->argNames()[i];
119 if (name == QLatin1String("stride")) {
120 int stride = args[i].toInt();
121 m_ui.vertexStrideSB->setValue(stride);
122 } else if (name == QLatin1String("size")) {
123 int components = args[i].toInt();
124 m_ui.vertexComponentsSB->setValue(components);
125 } else if (name == QLatin1String("type")) {
126 QString val = args[i].toString();
127 int textIndex = m_ui.vertexTypeCB->findText(val);
128 if (textIndex >= 0) {
129 m_ui.vertexTypeCB->setCurrentIndex(textIndex);
134 m_ui.vertexDataDock->setVisible(call->hasBinaryData());
135 m_selectedEvent = call;
137 if (event && event->type() == ApiTraceEvent::Frame) {
138 m_selectedEvent = static_cast<ApiTraceFrame*>(event);
142 m_ui.detailsDock->hide();
143 m_ui.vertexDataDock->hide();
145 if (m_selectedEvent && m_selectedEvent->hasState()) {
148 m_ui.stateDock->hide();
152 void MainWindow::callItemActivated(const QModelIndex &index) {
156 void MainWindow::replayStart()
158 if (m_trace->isSaving()) {
159 QMessageBox::warning(
162 tr("QApiTrace is currently saving the edited trace file. "
163 "Please wait until it finishes and try again."));
167 Ui_RetracerDialog dlgUi;
170 dlgUi.doubleBufferingCB->setChecked(
171 m_retracer->isDoubleBuffered());
172 dlgUi.errorCheckCB->setChecked(
173 !m_retracer->isBenchmarking());
175 if (dlg.exec() == QDialog::Accepted) {
176 m_retracer->setDoubleBuffered(
177 dlgUi.doubleBufferingCB->isChecked());
178 m_retracer->setBenchmarking(
179 !dlgUi.errorCheckCB->isChecked());
180 replayTrace(false, true);
184 void MainWindow::replayStop()
187 m_ui.actionStop->setEnabled(false);
188 m_ui.actionReplay->setEnabled(true);
189 m_ui.actionLookupState->setEnabled(true);
190 m_ui.actionShowThumbnails->setEnabled(true);
193 void MainWindow::newTraceFile(const QString &fileName)
195 qDebug()<< "Loading : " <<fileName;
197 m_progressBar->setValue(0);
198 m_trace->setFileName(fileName);
200 if (fileName.isEmpty()) {
201 m_ui.actionReplay->setEnabled(false);
202 m_ui.actionLookupState->setEnabled(false);
203 m_ui.actionShowThumbnails->setEnabled(false);
204 setWindowTitle(tr("QApiTrace"));
206 QFileInfo info(fileName);
207 m_ui.actionReplay->setEnabled(true);
208 m_ui.actionLookupState->setEnabled(true);
209 m_ui.actionShowThumbnails->setEnabled(true);
211 tr("QApiTrace - %1").arg(info.fileName()));
215 void MainWindow::replayFinished(const QString &message)
217 m_ui.actionStop->setEnabled(false);
218 m_ui.actionReplay->setEnabled(true);
219 m_ui.actionLookupState->setEnabled(true);
220 m_ui.actionShowThumbnails->setEnabled(true);
222 m_progressBar->hide();
223 statusBar()->showMessage(message, 2000);
225 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
226 m_ui.errorsDock->setVisible(m_trace->hasErrors());
227 if (!m_trace->hasErrors()) {
228 m_ui.errorsTreeWidget->clear();
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 m_api = m_trace->api();
264 QFileInfo info(m_trace->fileName());
265 statusBar()->showMessage(
266 tr("Loaded %1").arg(info.fileName()), 3000);
267 if (m_initalCallNum >= 0) {
268 m_trace->findCallIndex(m_initalCallNum);
269 m_initalCallNum = -1;
273 void MainWindow::replayTrace(bool dumpState, bool dumpThumbnails)
275 if (m_trace->fileName().isEmpty()) {
279 m_retracer->setFileName(m_trace->fileName());
280 m_retracer->setAPI(m_api);
281 m_retracer->setCaptureState(dumpState);
282 m_retracer->setCaptureThumbnails(dumpThumbnails);
283 if (m_retracer->captureState() && m_selectedEvent) {
285 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
286 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
287 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
288 ApiTraceFrame *frame =
289 static_cast<ApiTraceFrame*>(m_selectedEvent);
290 if (frame->isEmpty()) {
291 //XXX i guess we could still get the current state
292 qDebug()<<"tried to get a state for an empty frame";
295 index = frame->lastCallIndex();
297 qDebug()<<"Unknown event type";
300 m_retracer->setCaptureAtCallNumber(index);
304 m_ui.actionStop->setEnabled(true);
305 m_progressBar->show();
306 if (dumpState || dumpThumbnails) {
307 if (dumpState && dumpThumbnails) {
308 statusBar()->showMessage(
309 tr("Looking up the state and capturing thumbnails..."));
310 } else if (dumpState) {
311 statusBar()->showMessage(
312 tr("Looking up the state..."));
313 } else if (dumpThumbnails) {
314 statusBar()->showMessage(
315 tr("Capturing thumbnails..."));
318 statusBar()->showMessage(
319 tr("Replaying the trace file..."));
323 void MainWindow::lookupState()
325 if (!m_selectedEvent) {
326 QMessageBox::warning(
327 this, tr("Unknown Event"),
328 tr("To inspect the state select an event in the event list."));
331 if (m_trace->isSaving()) {
332 QMessageBox::warning(
335 tr("QApiTrace is currently saving the edited trace file. "
336 "Please wait until it finishes and try again."));
339 m_stateEvent = m_selectedEvent;
340 replayTrace(true, false);
343 void MainWindow::showThumbnails()
345 replayTrace(false, true);
348 MainWindow::~MainWindow()
358 variantToString(const QVariant &var, QString &str)
360 if (var.type() == QVariant::List) {
361 QVector<QVariant> lst = var.toList().toVector();
362 str += QLatin1String("[");
363 for (int i = 0; i < lst.count(); ++i) {
364 QVariant val = lst[i];
365 variantToString(val, str);
366 if (i < lst.count() - 1)
367 str += QLatin1String(", ");
369 str += QLatin1String("]");
370 } else if (var.type() == QVariant::Map) {
371 Q_ASSERT(!"unsupported state type");
372 } else if (var.type() == QVariant::Hash) {
373 Q_ASSERT(!"unsupported state type");
375 str += var.toString();
379 static QTreeWidgetItem *
380 variantToItem(const QString &key, const QVariant &var,
381 const QVariant &defaultVar);
384 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap,
385 QList<QTreeWidgetItem *> &items)
387 QVariantMap::const_iterator itr;
388 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
389 QString key = itr.key();
390 QVariant var = itr.value();
391 QVariant defaultVar = defaultMap[key];
393 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
401 variantListToItems(const QVector<QVariant> &lst,
402 const QVector<QVariant> &defaultLst,
403 QList<QTreeWidgetItem *> &items)
405 for (int i = 0; i < lst.count(); ++i) {
406 QString key = QString::number(i);
407 QVariant var = lst[i];
410 if (i < defaultLst.count()) {
411 defaultVar = defaultLst[i];
414 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
422 isVariantDeep(const QVariant &var)
424 if (var.type() == QVariant::List) {
425 QVector<QVariant> lst = var.toList().toVector();
426 for (int i = 0; i < lst.count(); ++i) {
427 if (isVariantDeep(lst[i])) {
432 } else if (var.type() == QVariant::Map) {
434 } else if (var.type() == QVariant::Hash) {
441 static QTreeWidgetItem *
442 variantToItem(const QString &key, const QVariant &var,
443 const QVariant &defaultVar)
445 if (var == defaultVar) {
451 bool deep = isVariantDeep(var);
453 variantToString(var, val);
456 //qDebug()<<"key = "<<key;
457 //qDebug()<<"val = "<<val;
462 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
465 QList<QTreeWidgetItem *> children;
466 if (var.type() == QVariant::Map) {
467 QVariantMap map = var.toMap();
468 QVariantMap defaultMap = defaultVar.toMap();
469 variantMapToItems(map, defaultMap, children);
471 if (var.type() == QVariant::List) {
472 QVector<QVariant> lst = var.toList().toVector();
473 QVector<QVariant> defaultLst = defaultVar.toList().toVector();
474 variantListToItems(lst, defaultLst, children);
476 item->addChildren(children);
482 static void addSurfaceItem(const ApiSurface &surface,
483 const QString &label,
484 QTreeWidgetItem *parent,
487 QIcon icon(QPixmap::fromImage(surface.thumb()));
488 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
489 item->setIcon(0, icon);
491 int width = surface.size().width();
492 int height = surface.size().height();
494 QString::fromLatin1("%1, %2, %3 x %4")
496 .arg(surface.formatName())
500 //item->setText(1, descr);
501 QLabel *l = new QLabel(descr, tree);
502 l->setWordWrap(true);
503 tree->setItemWidget(item, 1, l);
505 item->setData(0, Qt::UserRole, surface.image());
508 void MainWindow::fillStateForFrame()
510 if (!m_selectedEvent || !m_selectedEvent->hasState()) {
514 if (m_nonDefaultsLookupEvent) {
515 m_ui.nonDefaultsCB->blockSignals(true);
516 m_ui.nonDefaultsCB->setChecked(true);
517 m_ui.nonDefaultsCB->blockSignals(false);
520 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
521 QVariantMap defaultParams;
523 ApiTraceState defaultState = m_trace->defaultState();
524 defaultParams = defaultState.parameters();
527 const ApiTraceState &state = *m_selectedEvent->state();
528 m_ui.stateTreeWidget->clear();
529 QList<QTreeWidgetItem *> items;
530 variantMapToItems(state.parameters(), defaultParams, items);
531 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
533 QMap<QString, QString> shaderSources = state.shaderSources();
534 if (shaderSources.isEmpty()) {
535 m_sourcesWidget->setShaders(shaderSources);
537 m_sourcesWidget->setShaders(shaderSources);
540 m_ui.uniformsTreeWidget->clear();
541 QList<QTreeWidgetItem *> uniformsItems;
542 variantMapToItems(state.uniforms(), QVariantMap(), uniformsItems);
543 m_ui.uniformsTreeWidget->insertTopLevelItems(0, uniformsItems);
545 const QList<ApiTexture> &textures =
547 const QList<ApiFramebuffer> &fbos =
548 state.framebuffers();
550 m_ui.surfacesTreeWidget->clear();
551 if (textures.isEmpty() && fbos.isEmpty()) {
552 m_ui.surfacesTab->setDisabled(false);
554 m_ui.surfacesTreeWidget->setIconSize(QSize(THUMBNAIL_SIZE, THUMBNAIL_SIZE));
555 if (!textures.isEmpty()) {
556 QTreeWidgetItem *textureItem =
557 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
558 textureItem->setText(0, tr("Textures"));
559 if (textures.count() <= 6) {
560 textureItem->setExpanded(true);
563 for (int i = 0; i < textures.count(); ++i) {
564 const ApiTexture &texture =
566 addSurfaceItem(texture, texture.label(),
568 m_ui.surfacesTreeWidget);
571 if (!fbos.isEmpty()) {
572 QTreeWidgetItem *fboItem =
573 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
574 fboItem->setText(0, tr("Framebuffers"));
575 if (fbos.count() <= 6) {
576 fboItem->setExpanded(true);
579 for (int i = 0; i < fbos.count(); ++i) {
580 const ApiFramebuffer &fbo =
582 addSurfaceItem(fbo, fbo.type(),
584 m_ui.surfacesTreeWidget);
587 m_ui.surfacesTab->setEnabled(true);
589 m_ui.stateDock->show();
592 void MainWindow::showSettings()
594 SettingsDialog dialog;
595 dialog.setAPI(m_api);
596 dialog.setFilterModel(m_proxyModel);
600 m_api = dialog.getAPI();
603 void MainWindow::openHelp(const QUrl &url)
605 QDesktopServices::openUrl(url);
608 void MainWindow::showSurfacesMenu(const QPoint &pos)
610 QTreeWidget *tree = m_ui.surfacesTreeWidget;
611 QTreeWidgetItem *item = tree->itemAt(pos);
616 QMenu menu(tr("Surfaces"), this);
618 QAction *act = menu.addAction(tr("View Image"));
619 act->setStatusTip(tr("View the currently selected surface"));
620 connect(act, SIGNAL(triggered()),
621 SLOT(showSelectedSurface()));
623 act = menu.addAction(tr("Save Image"));
624 act->setStatusTip(tr("Save the currently selected surface"));
625 connect(act, SIGNAL(triggered()),
626 SLOT(saveSelectedSurface()));
628 menu.exec(tree->viewport()->mapToGlobal(pos));
631 void MainWindow::showSelectedSurface()
633 QTreeWidgetItem *item =
634 m_ui.surfacesTreeWidget->currentItem();
640 ImageViewer *viewer = new ImageViewer(this);
643 if (selectedCall()) {
644 title = tr("QApiTrace - Surface at %1 (%2)")
645 .arg(selectedCall()->name())
646 .arg(selectedCall()->index());
648 title = tr("QApiTrace - Surface Viewer");
650 viewer->setWindowTitle(title);
652 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
654 QVariant var = item->data(0, Qt::UserRole);
655 QImage img = var.value<QImage>();
656 viewer->setImage(img);
660 viewer->activateWindow();
663 void MainWindow::initObjects()
665 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
666 m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder);
668 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
669 QVBoxLayout *layout = new QVBoxLayout;
670 layout->addWidget(m_sourcesWidget);
671 m_ui.shadersTab->setLayout(layout);
673 m_trace = new ApiTrace();
674 m_retracer = new Retracer(this);
676 m_vdataInterpreter = new VertexDataInterpreter(this);
677 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
678 m_vdataInterpreter->setStride(
679 m_ui.vertexStrideSB->value());
680 m_vdataInterpreter->setComponents(
681 m_ui.vertexComponentsSB->value());
682 m_vdataInterpreter->setStartingOffset(
683 m_ui.startingOffsetSB->value());
684 m_vdataInterpreter->setTypeFromString(
685 m_ui.vertexTypeCB->currentText());
687 m_model = new ApiTraceModel();
688 m_model->setApiTrace(m_trace);
689 m_proxyModel = new ApiTraceFilter();
690 m_proxyModel->setSourceModel(m_model);
691 m_ui.callView->setModel(m_proxyModel);
692 m_ui.callView->setItemDelegate(
693 new ApiCallDelegate(m_ui.callView));
694 m_ui.callView->resizeColumnToContents(0);
695 m_ui.callView->header()->swapSections(0, 1);
696 m_ui.callView->setColumnWidth(1, 42);
697 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
699 m_progressBar = new QProgressBar();
700 m_progressBar->setRange(0, 100);
701 statusBar()->addPermanentWidget(m_progressBar);
702 m_progressBar->hide();
704 m_argsEditor = new ArgumentsEditor(this);
706 m_ui.detailsDock->hide();
707 m_ui.errorsDock->hide();
708 m_ui.vertexDataDock->hide();
709 m_ui.stateDock->hide();
710 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
712 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
713 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
715 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
717 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
718 QWebPage::DelegateExternalLinks);
720 m_jumpWidget = new JumpWidget(this);
721 m_ui.centralLayout->addWidget(m_jumpWidget);
722 m_jumpWidget->hide();
724 m_searchWidget = new SearchWidget(this);
725 m_ui.centralLayout->addWidget(m_searchWidget);
726 m_searchWidget->hide();
728 m_traceProcess = new TraceProcess(this);
731 void MainWindow::initConnections()
733 connect(m_trace, SIGNAL(startedLoadingTrace()),
734 this, SLOT(startedLoadingTrace()));
735 connect(m_trace, SIGNAL(loaded(int)),
736 this, SLOT(loadProgess(int)));
737 connect(m_trace, SIGNAL(finishedLoadingTrace()),
738 this, SLOT(finishedLoadingTrace()));
739 connect(m_trace, SIGNAL(startedSaving()),
740 this, SLOT(slotStartedSaving()));
741 connect(m_trace, SIGNAL(saved()),
742 this, SLOT(slotSaved()));
743 connect(m_trace, SIGNAL(changed(ApiTraceEvent*)),
744 this, SLOT(slotTraceChanged(ApiTraceEvent*)));
745 connect(m_trace, SIGNAL(findResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)),
746 this, SLOT(slotSearchResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)));
747 connect(m_trace, SIGNAL(foundFrameStart(ApiTraceFrame*)),
748 this, SLOT(slotFoundFrameStart(ApiTraceFrame*)));
749 connect(m_trace, SIGNAL(foundFrameEnd(ApiTraceFrame*)),
750 this, SLOT(slotFoundFrameEnd(ApiTraceFrame*)));
751 connect(m_trace, SIGNAL(foundCallIndex(ApiTraceCall*)),
752 this, SLOT(slotJumpToResult(ApiTraceCall*)));
754 connect(m_retracer, SIGNAL(finished(const QString&)),
755 this, SLOT(replayFinished(const QString&)));
756 connect(m_retracer, SIGNAL(error(const QString&)),
757 this, SLOT(replayError(const QString&)));
758 connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
759 this, SLOT(replayStateFound(ApiTraceState*)));
760 connect(m_retracer, SIGNAL(foundThumbnails(const QList<QImage>&)),
761 this, SLOT(replayThumbnailsFound(const QList<QImage>&)));
762 connect(m_retracer, SIGNAL(retraceErrors(const QList<ApiTraceError>&)),
763 this, SLOT(slotRetraceErrors(const QList<ApiTraceError>&)));
765 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
766 m_vdataInterpreter, SLOT(interpretData()));
767 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
768 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
769 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
770 m_vdataInterpreter, SLOT(setStride(int)));
771 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
772 m_vdataInterpreter, SLOT(setComponents(int)));
773 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
774 m_vdataInterpreter, SLOT(setStartingOffset(int)));
777 connect(m_ui.actionNew, SIGNAL(triggered()),
778 this, SLOT(createTrace()));
779 connect(m_ui.actionOpen, SIGNAL(triggered()),
780 this, SLOT(openTrace()));
781 connect(m_ui.actionQuit, SIGNAL(triggered()),
782 this, SLOT(close()));
784 connect(m_ui.actionFind, SIGNAL(triggered()),
785 this, SLOT(slotSearch()));
786 connect(m_ui.actionGo, SIGNAL(triggered()),
787 this, SLOT(slotGoTo()));
788 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
789 this, SLOT(slotGoFrameStart()));
790 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
791 this, SLOT(slotGoFrameEnd()));
793 connect(m_ui.actionReplay, SIGNAL(triggered()),
794 this, SLOT(replayStart()));
795 connect(m_ui.actionStop, SIGNAL(triggered()),
796 this, SLOT(replayStop()));
797 connect(m_ui.actionLookupState, SIGNAL(triggered()),
798 this, SLOT(lookupState()));
799 connect(m_ui.actionShowThumbnails, SIGNAL(triggered()),
800 this, SLOT(showThumbnails()));
801 connect(m_ui.actionOptions, SIGNAL(triggered()),
802 this, SLOT(showSettings()));
804 connect(m_ui.callView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
805 this, SLOT(callItemSelected(const QModelIndex &)));
806 connect(m_ui.callView, SIGNAL(doubleClicked(const QModelIndex &)),
807 this, SLOT(callItemActivated(const QModelIndex &)));
808 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
809 this, SLOT(customContextMenuRequested(QPoint)));
811 connect(m_ui.surfacesTreeWidget,
812 SIGNAL(customContextMenuRequested(const QPoint &)),
813 SLOT(showSurfacesMenu(const QPoint &)));
814 connect(m_ui.surfacesTreeWidget,
815 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
816 SLOT(showSelectedSurface()));
818 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
819 this, SLOT(openHelp(const QUrl&)));
821 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
822 this, SLOT(fillState(bool)));
824 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
825 SLOT(slotJumpTo(int)));
827 connect(m_searchWidget,
828 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
829 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
830 connect(m_searchWidget,
831 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
832 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
834 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
835 SLOT(createdTrace(const QString&)));
836 connect(m_traceProcess, SIGNAL(error(const QString&)),
837 SLOT(traceError(const QString&)));
839 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
840 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
841 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
842 m_ui.errorsDock, SLOT(setVisible(bool)));
843 connect(m_ui.errorsTreeWidget,
844 SIGNAL(itemActivated(QTreeWidgetItem*, int)),
845 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
848 void MainWindow::replayStateFound(ApiTraceState *state)
850 m_stateEvent->setState(state);
851 m_model->stateSetOnEvent(m_stateEvent);
852 if (m_selectedEvent == m_stateEvent ||
853 m_nonDefaultsLookupEvent == m_selectedEvent) {
856 m_ui.stateDock->hide();
858 m_nonDefaultsLookupEvent = 0;
861 void MainWindow::replayThumbnailsFound(const QList<QImage> &thumbnails)
863 m_ui.callView->setUniformRowHeights(false);
864 m_trace->bindThumbnailsToFrames(thumbnails);
867 void MainWindow::slotGoTo()
869 m_searchWidget->hide();
870 m_jumpWidget->show();
873 void MainWindow::slotJumpTo(int callNum)
875 m_trace->findCallIndex(callNum);
878 void MainWindow::createdTrace(const QString &path)
880 qDebug()<<"Done tracing "<<path;
884 void MainWindow::traceError(const QString &msg)
886 QMessageBox::warning(
892 void MainWindow::slotSearch()
894 m_jumpWidget->hide();
895 m_searchWidget->show();
898 void MainWindow::slotSearchNext(const QString &str,
899 Qt::CaseSensitivity sensitivity)
901 ApiTraceCall *call = currentCall();
902 ApiTraceFrame *frame = currentFrame();
904 Q_ASSERT(call || frame);
906 frame = call->parentFrame();
910 m_trace->findNext(frame, call, str, sensitivity);
913 void MainWindow::slotSearchPrev(const QString &str,
914 Qt::CaseSensitivity sensitivity)
916 ApiTraceCall *call = currentCall();
917 ApiTraceFrame *frame = currentFrame();
919 Q_ASSERT(call || frame);
921 frame = call->parentFrame();
925 m_trace->findPrev(frame, call, str, sensitivity);
928 void MainWindow::fillState(bool nonDefaults)
931 ApiTraceState defaultState = m_trace->defaultState();
932 if (defaultState.isEmpty()) {
933 m_ui.nonDefaultsCB->blockSignals(true);
934 m_ui.nonDefaultsCB->setChecked(false);
935 m_ui.nonDefaultsCB->blockSignals(false);
936 ApiTraceFrame *firstFrame =
941 if (!firstFrame->isLoaded()) {
942 m_trace->loadFrame(firstFrame);
945 ApiTraceCall *firstCall = firstFrame->calls().first();
946 ApiTraceEvent *oldSelected = m_selectedEvent;
947 m_nonDefaultsLookupEvent = m_selectedEvent;
948 m_selectedEvent = firstCall;
950 m_selectedEvent = oldSelected;
956 void MainWindow::customContextMenuRequested(QPoint pos)
958 QModelIndex index = m_ui.callView->indexAt(pos);
960 callItemSelected(index);
961 if (!index.isValid()) {
965 ApiTraceEvent *event =
966 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
972 menu.addAction(QIcon(":/resources/media-record.png"),
973 tr("Lookup state"), this, SLOT(lookupState()));
974 if (event->type() == ApiTraceEvent::Call) {
975 menu.addAction(tr("Edit"), this, SLOT(editCall()));
978 menu.exec(QCursor::pos());
981 void MainWindow::editCall()
983 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
984 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
985 m_argsEditor->setCall(call);
986 m_argsEditor->show();
990 void MainWindow::slotStartedSaving()
992 m_progressBar->show();
993 statusBar()->showMessage(
994 tr("Saving to %1").arg(m_trace->fileName()));
997 void MainWindow::slotSaved()
999 statusBar()->showMessage(
1000 tr("Saved to %1").arg(m_trace->fileName()), 2000);
1001 m_progressBar->hide();
1004 void MainWindow::slotGoFrameStart()
1006 ApiTraceFrame *frame = currentFrame();
1007 ApiTraceCall *call = currentCall();
1009 if (!frame && call) {
1010 frame = call->parentFrame();
1013 m_trace->findFrameStart(frame);
1016 void MainWindow::slotGoFrameEnd()
1018 ApiTraceFrame *frame = currentFrame();
1019 ApiTraceCall *call = currentCall();
1021 if (!frame && call) {
1022 frame = call->parentFrame();
1025 m_trace->findFrameEnd(frame);
1028 ApiTraceFrame * MainWindow::selectedFrame() const
1030 if (m_selectedEvent) {
1031 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
1032 return static_cast<ApiTraceFrame*>(m_selectedEvent);
1034 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1035 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1036 return call->parentFrame();
1042 void MainWindow::slotTraceChanged(ApiTraceEvent *event)
1045 if (event == m_selectedEvent) {
1046 if (event->type() == ApiTraceEvent::Call) {
1047 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
1048 m_ui.detailsWebView->setHtml(call->toHtml());
1053 void MainWindow::slotRetraceErrors(const QList<ApiTraceError> &errors)
1055 m_ui.errorsTreeWidget->clear();
1057 foreach(ApiTraceError error, errors) {
1058 m_trace->setCallError(error);
1060 QTreeWidgetItem *item =
1061 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1062 item->setData(0, Qt::DisplayRole, error.callIndex);
1063 item->setData(0, Qt::UserRole, error.callIndex);
1064 QString type = error.type;
1065 type[0] = type[0].toUpper();
1066 item->setData(1, Qt::DisplayRole, type);
1067 item->setData(2, Qt::DisplayRole, error.message);
1071 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1075 current->data(0, Qt::UserRole).toInt();
1076 m_trace->findCallIndex(callIndex);
1080 ApiTraceCall * MainWindow::selectedCall() const
1082 if (m_selectedEvent &&
1083 m_selectedEvent->type() == ApiTraceEvent::Call) {
1084 return static_cast<ApiTraceCall*>(m_selectedEvent);
1089 void MainWindow::saveSelectedSurface()
1091 QTreeWidgetItem *item =
1092 m_ui.surfacesTreeWidget->currentItem();
1094 if (!item || !m_trace) {
1098 QVariant var = item->data(0, Qt::UserRole);
1099 QImage img = var.value<QImage>();
1102 if (selectedCall()) {
1103 imageIndex = tr("_call_%1")
1104 .arg(selectedCall()->index());
1105 } else if (selectedFrame()) {
1106 ApiTraceCall *firstCall = selectedFrame()->call(0);
1108 imageIndex = tr("_frame_%1")
1109 .arg(firstCall->index());
1111 qDebug()<<"unknown frame number";
1112 imageIndex = tr("_frame_%1")
1113 .arg(firstCall->index());
1117 //which of the surfaces are we saving
1118 QTreeWidgetItem *parent = item->parent();
1120 m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent);
1121 if (parentIndex < 0) {
1126 childIndex = parent->indexOfChild(item);
1128 childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item);
1133 tr("%1%2-%3_%4.png")
1134 .arg(m_trace->fileName())
1138 //qDebug()<<"save "<<fileName;
1139 img.save(fileName, "PNG");
1140 statusBar()->showMessage( tr("Saved '%1'").arg(fileName), 5000);
1143 void MainWindow::loadProgess(int percent)
1145 m_progressBar->setValue(percent);
1148 void MainWindow::slotSearchResult(const ApiTrace::SearchRequest &request,
1149 ApiTrace::SearchResult result,
1153 case ApiTrace::SearchResult_NotFound:
1154 m_searchWidget->setFound(false);
1156 case ApiTrace::SearchResult_Found: {
1157 QModelIndex index = m_proxyModel->indexForCall(call);
1159 if (index.isValid()) {
1160 m_ui.callView->setCurrentIndex(index);
1161 m_searchWidget->setFound(true);
1163 //call is filtered out, so continue searching but from the
1166 qDebug()<<"Error: search success with no call";
1169 // qDebug()<<"filtered! search from "<<call->searchText()
1170 // <<", call idx = "<<call->index();
1172 if (request.direction == ApiTrace::SearchRequest::Next) {
1173 m_trace->findNext(call->parentFrame(), call,
1174 request.text, request.cs);
1176 m_trace->findNext(call->parentFrame(), call,
1177 request.text, request.cs);
1182 case ApiTrace::SearchResult_Wrapped:
1183 m_searchWidget->setFound(false);
1188 ApiTraceFrame * MainWindow::currentFrame() const
1190 QModelIndex index = m_ui.callView->currentIndex();
1191 ApiTraceEvent *event = 0;
1193 if (!index.isValid()) {
1194 index = m_proxyModel->index(0, 0, QModelIndex());
1195 if (!index.isValid()) {
1196 qDebug()<<"no currently valid index";
1201 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1207 ApiTraceFrame *frame = 0;
1208 if (event->type() == ApiTraceCall::Frame) {
1209 frame = static_cast<ApiTraceFrame*>(event);
1214 ApiTraceCall * MainWindow::currentCall() const
1216 QModelIndex index = m_ui.callView->currentIndex();
1217 ApiTraceEvent *event = 0;
1219 if (!index.isValid()) {
1220 index = m_proxyModel->index(0, 0, QModelIndex());
1221 if (!index.isValid()) {
1222 qDebug()<<"no currently valid index";
1227 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1233 ApiTraceCall *call = 0;
1234 if (event->type() == ApiTraceCall::Call) {
1235 call = static_cast<ApiTraceCall*>(event);
1242 void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame)
1244 Q_ASSERT(frame->isLoaded());
1245 if (!frame || frame->isEmpty()) {
1249 QVector<ApiTraceCall*>::const_iterator itr;
1250 QVector<ApiTraceCall*> calls = frame->calls();
1252 itr = calls.constBegin();
1253 while (itr != calls.constEnd()) {
1254 ApiTraceCall *call = *itr;
1255 QModelIndex idx = m_proxyModel->indexForCall(call);
1256 if (idx.isValid()) {
1257 m_ui.callView->setCurrentIndex(idx);
1264 void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame)
1266 Q_ASSERT(frame->isLoaded());
1267 if (!frame || frame->isEmpty()) {
1270 QVector<ApiTraceCall*>::const_iterator itr;
1271 QVector<ApiTraceCall*> calls = frame->calls();
1273 itr = calls.constEnd();
1276 ApiTraceCall *call = *itr;
1277 QModelIndex idx = m_proxyModel->indexForCall(call);
1278 if (idx.isValid()) {
1279 m_ui.callView->setCurrentIndex(idx);
1282 } while (itr != calls.constBegin());
1285 void MainWindow::slotJumpToResult(ApiTraceCall *call)
1287 QModelIndex index = m_proxyModel->indexForCall(call);
1288 if (index.isValid()) {
1289 m_ui.callView->setCurrentIndex(index);
1291 statusBar()->showMessage(tr("Call has been filtered out."));
1295 #include "mainwindow.moc"