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()
42 m_nonDefaultsLookupEvent(0)
49 void MainWindow::createTrace()
51 if (!m_traceProcess->canTrace()) {
55 tr("Current configuration doesn't support tracing."));
60 if (dialog.exec() == QDialog::Accepted) {
61 qDebug()<< "App : " <<dialog.applicationPath();
62 qDebug()<< " Arguments: "<<dialog.arguments();
63 m_traceProcess->setExecutablePath(dialog.applicationPath());
64 m_traceProcess->setArguments(dialog.arguments());
65 m_traceProcess->start();
69 void MainWindow::openTrace()
72 QFileDialog::getOpenFileName(
76 tr("Trace Files (*.trace)"));
78 if (!fileName.isEmpty() && QFile::exists(fileName)) {
79 newTraceFile(fileName);
83 void MainWindow::loadTrace(const QString &fileName, int callNum)
85 if (!QFile::exists(fileName)) {
86 QMessageBox::warning(this, tr("File Missing"),
87 tr("File '%1' doesn't exist.").arg(fileName));
91 m_initalCallNum = callNum;
92 newTraceFile(fileName);
95 void MainWindow::callItemSelected(const QModelIndex &index)
97 ApiTraceEvent *event =
98 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
100 if (event && event->type() == ApiTraceEvent::Call) {
101 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
102 m_ui.detailsDock->setWindowTitle(
103 tr("Details View. Frame %1, Call %2")
104 .arg(call->parentFrame() ? call->parentFrame()->number : 0)
105 .arg(call->index()));
106 m_ui.detailsWebView->setHtml(call->toHtml());
107 m_ui.detailsDock->show();
108 if (call->hasBinaryData()) {
110 call->arguments()[call->binaryDataIndex()].toByteArray();
111 m_vdataInterpreter->setData(data);
113 QVector<QVariant> args = call->arguments();
114 for (int i = 0; i < call->argNames().count(); ++i) {
115 QString name = call->argNames()[i];
116 if (name == QLatin1String("stride")) {
117 int stride = args[i].toInt();
118 m_ui.vertexStrideSB->setValue(stride);
119 } else if (name == QLatin1String("size")) {
120 int components = args[i].toInt();
121 m_ui.vertexComponentsSB->setValue(components);
122 } else if (name == QLatin1String("type")) {
123 QString val = args[i].toString();
124 int textIndex = m_ui.vertexTypeCB->findText(val);
125 if (textIndex >= 0) {
126 m_ui.vertexTypeCB->setCurrentIndex(textIndex);
131 m_ui.vertexDataDock->setVisible(call->hasBinaryData());
132 m_selectedEvent = call;
134 if (event && event->type() == ApiTraceEvent::Frame) {
135 m_selectedEvent = static_cast<ApiTraceFrame*>(event);
139 m_ui.detailsDock->hide();
140 m_ui.vertexDataDock->hide();
142 if (m_selectedEvent && m_selectedEvent->hasState()) {
145 m_ui.stateDock->hide();
149 void MainWindow::replayStart()
151 if (m_trace->isSaving()) {
152 QMessageBox::warning(
155 tr("QApiTrace is currently saving the edited trace file. "
156 "Please wait until it finishes and try again."));
160 Ui_RetracerDialog dlgUi;
163 dlgUi.doubleBufferingCB->setChecked(
164 m_retracer->isDoubleBuffered());
165 dlgUi.errorCheckCB->setChecked(
166 !m_retracer->isBenchmarking());
168 if (dlg.exec() == QDialog::Accepted) {
169 m_retracer->setDoubleBuffered(
170 dlgUi.doubleBufferingCB->isChecked());
171 m_retracer->setBenchmarking(
172 !dlgUi.errorCheckCB->isChecked());
177 void MainWindow::replayStop()
180 m_ui.actionStop->setEnabled(false);
181 m_ui.actionReplay->setEnabled(true);
182 m_ui.actionLookupState->setEnabled(true);
185 void MainWindow::newTraceFile(const QString &fileName)
187 qDebug()<< "Loading : " <<fileName;
189 m_progressBar->setValue(0);
190 m_trace->setFileName(fileName);
192 if (fileName.isEmpty()) {
193 m_ui.actionReplay->setEnabled(false);
194 m_ui.actionLookupState->setEnabled(false);
195 setWindowTitle(tr("QApiTrace"));
197 QFileInfo info(fileName);
198 m_ui.actionReplay->setEnabled(true);
199 m_ui.actionLookupState->setEnabled(true);
201 tr("QApiTrace - %1").arg(info.fileName()));
205 void MainWindow::replayFinished(const QString &output)
207 m_ui.actionStop->setEnabled(false);
208 m_ui.actionReplay->setEnabled(true);
209 m_ui.actionLookupState->setEnabled(true);
211 m_progressBar->hide();
212 if (output.length() < 80) {
213 statusBar()->showMessage(output);
216 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
217 m_ui.errorsDock->setVisible(m_trace->hasErrors());
218 if (!m_trace->hasErrors()) {
219 m_ui.errorsTreeWidget->clear();
222 statusBar()->showMessage(
223 tr("Replaying finished!"), 2000);
226 void MainWindow::replayError(const QString &message)
228 m_ui.actionStop->setEnabled(false);
229 m_ui.actionReplay->setEnabled(true);
230 m_ui.actionLookupState->setEnabled(true);
232 m_nonDefaultsLookupEvent = 0;
234 m_progressBar->hide();
235 statusBar()->showMessage(
236 tr("Replaying unsuccessful."), 2000);
237 QMessageBox::warning(
238 this, tr("Replay Failed"), message);
241 void MainWindow::startedLoadingTrace()
244 m_progressBar->show();
245 QFileInfo info(m_trace->fileName());
246 statusBar()->showMessage(
247 tr("Loading %1...").arg(info.fileName()));
250 void MainWindow::finishedLoadingTrace()
252 m_progressBar->hide();
256 QFileInfo info(m_trace->fileName());
257 statusBar()->showMessage(
258 tr("Loaded %1").arg(info.fileName()), 3000);
259 if (m_initalCallNum >= 0) {
260 m_trace->findCallIndex(m_initalCallNum);
261 m_initalCallNum = -1;
265 void MainWindow::replayTrace(bool dumpState)
267 if (m_trace->fileName().isEmpty()) {
271 m_retracer->setFileName(m_trace->fileName());
272 m_retracer->setCaptureState(dumpState);
273 if (m_retracer->captureState() && m_selectedEvent) {
275 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
276 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
277 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
278 ApiTraceFrame *frame =
279 static_cast<ApiTraceFrame*>(m_selectedEvent);
280 if (frame->isEmpty()) {
281 //XXX i guess we could still get the current state
282 qDebug()<<"tried to get a state for an empty frame";
285 index = frame->lastCallIndex();
287 qDebug()<<"Unknown event type";
290 m_retracer->setCaptureAtCallNumber(index);
294 m_ui.actionStop->setEnabled(true);
295 m_progressBar->show();
297 statusBar()->showMessage(
298 tr("Looking up the state..."));
300 statusBar()->showMessage(
301 tr("Replaying the trace file..."));
305 void MainWindow::lookupState()
307 if (!m_selectedEvent) {
308 QMessageBox::warning(
309 this, tr("Unknown Event"),
310 tr("To inspect the state select an event in the event list."));
313 if (m_trace->isSaving()) {
314 QMessageBox::warning(
317 tr("QApiTrace is currently saving the edited trace file. "
318 "Please wait until it finishes and try again."));
321 m_stateEvent = m_selectedEvent;
325 MainWindow::~MainWindow()
335 variantToString(const QVariant &var, QString &str)
337 if (var.type() == QVariant::List) {
338 QVector<QVariant> lst = var.toList().toVector();
339 str += QLatin1String("[");
340 for (int i = 0; i < lst.count(); ++i) {
341 QVariant val = lst[i];
342 variantToString(val, str);
343 if (i < lst.count() - 1)
344 str += QLatin1String(", ");
346 str += QLatin1String("]");
347 } else if (var.type() == QVariant::Map) {
348 Q_ASSERT(!"unsupported state type");
349 } else if (var.type() == QVariant::Hash) {
350 Q_ASSERT(!"unsupported state type");
352 str += var.toString();
356 static QTreeWidgetItem *
357 variantToItem(const QString &key, const QVariant &var,
358 const QVariant &defaultVar);
361 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap,
362 QList<QTreeWidgetItem *> &items)
364 QVariantMap::const_iterator itr;
365 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
366 QString key = itr.key();
367 QVariant var = itr.value();
368 QVariant defaultVar = defaultMap[key];
370 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
378 variantListToItems(const QVector<QVariant> &lst,
379 const QVector<QVariant> &defaultLst,
380 QList<QTreeWidgetItem *> &items)
382 for (int i = 0; i < lst.count(); ++i) {
383 QString key = QString::number(i);
384 QVariant var = lst[i];
387 if (i < defaultLst.count()) {
388 defaultVar = defaultLst[i];
391 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
399 isVariantDeep(const QVariant &var)
401 if (var.type() == QVariant::List) {
402 QVector<QVariant> lst = var.toList().toVector();
403 for (int i = 0; i < lst.count(); ++i) {
404 if (isVariantDeep(lst[i])) {
409 } else if (var.type() == QVariant::Map) {
411 } else if (var.type() == QVariant::Hash) {
418 static QTreeWidgetItem *
419 variantToItem(const QString &key, const QVariant &var,
420 const QVariant &defaultVar)
422 if (var == defaultVar) {
428 bool deep = isVariantDeep(var);
430 variantToString(var, val);
433 //qDebug()<<"key = "<<key;
434 //qDebug()<<"val = "<<val;
439 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
442 QList<QTreeWidgetItem *> children;
443 if (var.type() == QVariant::Map) {
444 QVariantMap map = var.toMap();
445 QVariantMap defaultMap = defaultVar.toMap();
446 variantMapToItems(map, defaultMap, children);
448 if (var.type() == QVariant::List) {
449 QVector<QVariant> lst = var.toList().toVector();
450 QVector<QVariant> defaultLst = defaultVar.toList().toVector();
451 variantListToItems(lst, defaultLst, children);
453 item->addChildren(children);
459 static void addSurfaceItem(const ApiSurface &surface,
460 const QString &label,
461 QTreeWidgetItem *parent,
464 QIcon icon(QPixmap::fromImage(surface.thumb()));
465 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
466 item->setIcon(0, icon);
468 int width = surface.size().width();
469 int height = surface.size().height();
471 QString::fromLatin1("%1, %2, %3 x %4")
473 .arg(surface.formatName())
477 //item->setText(1, descr);
478 QLabel *l = new QLabel(descr, tree);
479 l->setWordWrap(true);
480 tree->setItemWidget(item, 1, l);
482 item->setData(0, Qt::UserRole, surface.image());
485 void MainWindow::fillStateForFrame()
487 if (!m_selectedEvent || !m_selectedEvent->hasState()) {
491 if (m_nonDefaultsLookupEvent) {
492 m_ui.nonDefaultsCB->blockSignals(true);
493 m_ui.nonDefaultsCB->setChecked(true);
494 m_ui.nonDefaultsCB->blockSignals(false);
497 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
498 QVariantMap defaultParams;
500 ApiTraceState defaultState = m_trace->defaultState();
501 defaultParams = defaultState.parameters();
504 const ApiTraceState &state = *m_selectedEvent->state();
505 m_ui.stateTreeWidget->clear();
506 QList<QTreeWidgetItem *> items;
507 variantMapToItems(state.parameters(), defaultParams, items);
508 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
510 QMap<QString, QString> shaderSources = state.shaderSources();
511 if (shaderSources.isEmpty()) {
512 m_sourcesWidget->setShaders(shaderSources);
514 m_sourcesWidget->setShaders(shaderSources);
517 m_ui.uniformsTreeWidget->clear();
518 QList<QTreeWidgetItem *> uniformsItems;
519 variantMapToItems(state.uniforms(), QVariantMap(), uniformsItems);
520 m_ui.uniformsTreeWidget->insertTopLevelItems(0, uniformsItems);
522 const QList<ApiTexture> &textures =
524 const QList<ApiFramebuffer> &fbos =
525 state.framebuffers();
527 m_ui.surfacesTreeWidget->clear();
528 if (textures.isEmpty() && fbos.isEmpty()) {
529 m_ui.surfacesTab->setDisabled(false);
531 m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
532 if (!textures.isEmpty()) {
533 QTreeWidgetItem *textureItem =
534 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
535 textureItem->setText(0, tr("Textures"));
536 if (textures.count() <= 6) {
537 textureItem->setExpanded(true);
540 for (int i = 0; i < textures.count(); ++i) {
541 const ApiTexture &texture =
543 addSurfaceItem(texture, texture.label(),
545 m_ui.surfacesTreeWidget);
548 if (!fbos.isEmpty()) {
549 QTreeWidgetItem *fboItem =
550 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
551 fboItem->setText(0, tr("Framebuffers"));
552 if (fbos.count() <= 6) {
553 fboItem->setExpanded(true);
556 for (int i = 0; i < fbos.count(); ++i) {
557 const ApiFramebuffer &fbo =
559 addSurfaceItem(fbo, fbo.type(),
561 m_ui.surfacesTreeWidget);
564 m_ui.surfacesTab->setEnabled(true);
566 m_ui.stateDock->show();
569 void MainWindow::showSettings()
571 SettingsDialog dialog;
572 dialog.setFilterModel(m_proxyModel);
577 void MainWindow::openHelp(const QUrl &url)
579 QDesktopServices::openUrl(url);
582 void MainWindow::showSurfacesMenu(const QPoint &pos)
584 QTreeWidget *tree = m_ui.surfacesTreeWidget;
585 QTreeWidgetItem *item = tree->itemAt(pos);
590 QMenu menu(tr("Surfaces"), this);
592 QAction *act = menu.addAction(tr("View Image"));
593 act->setStatusTip(tr("View the currently selected surface"));
594 connect(act, SIGNAL(triggered()),
595 SLOT(showSelectedSurface()));
597 act = menu.addAction(tr("Save Image"));
598 act->setStatusTip(tr("Save the currently selected surface"));
599 connect(act, SIGNAL(triggered()),
600 SLOT(saveSelectedSurface()));
602 menu.exec(tree->viewport()->mapToGlobal(pos));
605 void MainWindow::showSelectedSurface()
607 QTreeWidgetItem *item =
608 m_ui.surfacesTreeWidget->currentItem();
614 ImageViewer *viewer = new ImageViewer(this);
617 if (selectedCall()) {
618 title = tr("QApiTrace - Surface at %1 (%2)")
619 .arg(selectedCall()->name())
620 .arg(selectedCall()->index());
622 title = tr("QApiTrace - Surface Viewer");
624 viewer->setWindowTitle(title);
626 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
628 QVariant var = item->data(0, Qt::UserRole);
629 QImage img = var.value<QImage>();
630 viewer->setImage(img);
634 viewer->activateWindow();
637 void MainWindow::initObjects()
639 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
640 m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder);
642 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
643 QVBoxLayout *layout = new QVBoxLayout;
644 layout->addWidget(m_sourcesWidget);
645 m_ui.shadersTab->setLayout(layout);
647 m_trace = new ApiTrace();
648 m_retracer = new Retracer(this);
650 m_vdataInterpreter = new VertexDataInterpreter(this);
651 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
652 m_vdataInterpreter->setStride(
653 m_ui.vertexStrideSB->value());
654 m_vdataInterpreter->setComponents(
655 m_ui.vertexComponentsSB->value());
656 m_vdataInterpreter->setStartingOffset(
657 m_ui.startingOffsetSB->value());
658 m_vdataInterpreter->setTypeFromString(
659 m_ui.vertexTypeCB->currentText());
661 m_model = new ApiTraceModel();
662 m_model->setApiTrace(m_trace);
663 m_proxyModel = new ApiTraceFilter();
664 m_proxyModel->setSourceModel(m_model);
665 m_ui.callView->setModel(m_proxyModel);
666 m_ui.callView->setItemDelegate(
667 new ApiCallDelegate(m_ui.callView));
668 m_ui.callView->resizeColumnToContents(0);
669 m_ui.callView->header()->swapSections(0, 1);
670 m_ui.callView->setColumnWidth(1, 42);
671 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
673 m_progressBar = new QProgressBar();
674 m_progressBar->setRange(0, 100);
675 statusBar()->addPermanentWidget(m_progressBar);
676 m_progressBar->hide();
678 m_argsEditor = new ArgumentsEditor(this);
680 m_ui.detailsDock->hide();
681 m_ui.errorsDock->hide();
682 m_ui.vertexDataDock->hide();
683 m_ui.stateDock->hide();
684 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
686 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
687 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
689 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
691 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
692 QWebPage::DelegateExternalLinks);
694 m_jumpWidget = new JumpWidget(this);
695 m_ui.centralLayout->addWidget(m_jumpWidget);
696 m_jumpWidget->hide();
698 m_searchWidget = new SearchWidget(this);
699 m_ui.centralLayout->addWidget(m_searchWidget);
700 m_searchWidget->hide();
702 m_traceProcess = new TraceProcess(this);
705 void MainWindow::initConnections()
707 connect(m_trace, SIGNAL(startedLoadingTrace()),
708 this, SLOT(startedLoadingTrace()));
709 connect(m_trace, SIGNAL(loaded(int)),
710 this, SLOT(loadProgess(int)));
711 connect(m_trace, SIGNAL(finishedLoadingTrace()),
712 this, SLOT(finishedLoadingTrace()));
713 connect(m_trace, SIGNAL(startedSaving()),
714 this, SLOT(slotStartedSaving()));
715 connect(m_trace, SIGNAL(saved()),
716 this, SLOT(slotSaved()));
717 connect(m_trace, SIGNAL(changed(ApiTraceCall*)),
718 this, SLOT(slotTraceChanged(ApiTraceCall*)));
719 connect(m_trace, SIGNAL(findResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)),
720 this, SLOT(slotSearchResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)));
721 connect(m_trace, SIGNAL(foundFrameStart(ApiTraceFrame*)),
722 this, SLOT(slotFoundFrameStart(ApiTraceFrame*)));
723 connect(m_trace, SIGNAL(foundFrameEnd(ApiTraceFrame*)),
724 this, SLOT(slotFoundFrameEnd(ApiTraceFrame*)));
725 connect(m_trace, SIGNAL(foundCallIndex(ApiTraceCall*)),
726 this, SLOT(slotJumpToResult(ApiTraceCall*)));
728 connect(m_retracer, SIGNAL(finished(const QString&)),
729 this, SLOT(replayFinished(const QString&)));
730 connect(m_retracer, SIGNAL(error(const QString&)),
731 this, SLOT(replayError(const QString&)));
732 connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
733 this, SLOT(replayStateFound(ApiTraceState*)));
734 connect(m_retracer, SIGNAL(retraceErrors(const QList<ApiTraceError>&)),
735 this, SLOT(slotRetraceErrors(const QList<ApiTraceError>&)));
737 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
738 m_vdataInterpreter, SLOT(interpretData()));
739 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
740 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
741 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
742 m_vdataInterpreter, SLOT(setStride(int)));
743 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
744 m_vdataInterpreter, SLOT(setComponents(int)));
745 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
746 m_vdataInterpreter, SLOT(setStartingOffset(int)));
749 connect(m_ui.actionNew, SIGNAL(triggered()),
750 this, SLOT(createTrace()));
751 connect(m_ui.actionOpen, SIGNAL(triggered()),
752 this, SLOT(openTrace()));
753 connect(m_ui.actionQuit, SIGNAL(triggered()),
754 this, SLOT(close()));
756 connect(m_ui.actionFind, SIGNAL(triggered()),
757 this, SLOT(slotSearch()));
758 connect(m_ui.actionGo, SIGNAL(triggered()),
759 this, SLOT(slotGoTo()));
760 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
761 this, SLOT(slotGoFrameStart()));
762 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
763 this, SLOT(slotGoFrameEnd()));
765 connect(m_ui.actionReplay, SIGNAL(triggered()),
766 this, SLOT(replayStart()));
767 connect(m_ui.actionStop, SIGNAL(triggered()),
768 this, SLOT(replayStop()));
769 connect(m_ui.actionLookupState, SIGNAL(triggered()),
770 this, SLOT(lookupState()));
771 connect(m_ui.actionOptions, SIGNAL(triggered()),
772 this, SLOT(showSettings()));
774 connect(m_ui.callView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
775 this, SLOT(callItemSelected(const QModelIndex &)));
776 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
777 this, SLOT(customContextMenuRequested(QPoint)));
779 connect(m_ui.surfacesTreeWidget,
780 SIGNAL(customContextMenuRequested(const QPoint &)),
781 SLOT(showSurfacesMenu(const QPoint &)));
782 connect(m_ui.surfacesTreeWidget,
783 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
784 SLOT(showSelectedSurface()));
786 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
787 this, SLOT(openHelp(const QUrl&)));
789 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
790 this, SLOT(fillState(bool)));
792 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
793 SLOT(slotJumpTo(int)));
795 connect(m_searchWidget,
796 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
797 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
798 connect(m_searchWidget,
799 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
800 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
802 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
803 SLOT(createdTrace(const QString&)));
804 connect(m_traceProcess, SIGNAL(error(const QString&)),
805 SLOT(traceError(const QString&)));
807 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
808 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
809 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
810 m_ui.errorsDock, SLOT(setVisible(bool)));
811 connect(m_ui.errorsTreeWidget,
812 SIGNAL(itemActivated(QTreeWidgetItem*, int)),
813 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
816 void MainWindow::replayStateFound(ApiTraceState *state)
818 m_stateEvent->setState(state);
819 m_model->stateSetOnEvent(m_stateEvent);
820 if (m_selectedEvent == m_stateEvent ||
821 m_nonDefaultsLookupEvent == m_selectedEvent) {
824 m_ui.stateDock->hide();
826 m_nonDefaultsLookupEvent = 0;
829 void MainWindow::slotGoTo()
831 m_searchWidget->hide();
832 m_jumpWidget->show();
835 void MainWindow::slotJumpTo(int callNum)
837 m_trace->findCallIndex(callNum);
840 void MainWindow::createdTrace(const QString &path)
842 qDebug()<<"Done tracing "<<path;
846 void MainWindow::traceError(const QString &msg)
848 QMessageBox::warning(
854 void MainWindow::slotSearch()
856 m_jumpWidget->hide();
857 m_searchWidget->show();
860 void MainWindow::slotSearchNext(const QString &str,
861 Qt::CaseSensitivity sensitivity)
863 ApiTraceCall *call = currentCall();
864 ApiTraceFrame *frame = currentFrame();
866 Q_ASSERT(call || frame);
868 frame = call->parentFrame();
872 m_trace->findNext(frame, call, str, sensitivity);
875 void MainWindow::slotSearchPrev(const QString &str,
876 Qt::CaseSensitivity sensitivity)
878 ApiTraceCall *call = currentCall();
879 ApiTraceFrame *frame = currentFrame();
881 Q_ASSERT(call || frame);
883 frame = call->parentFrame();
887 m_trace->findPrev(frame, call, str, sensitivity);
890 void MainWindow::fillState(bool nonDefaults)
893 ApiTraceState defaultState = m_trace->defaultState();
894 if (defaultState.isEmpty()) {
895 m_ui.nonDefaultsCB->blockSignals(true);
896 m_ui.nonDefaultsCB->setChecked(false);
897 m_ui.nonDefaultsCB->blockSignals(false);
898 ApiTraceFrame *firstFrame =
903 if (!firstFrame->isLoaded()) {
904 m_trace->loadFrame(firstFrame);
907 ApiTraceCall *firstCall = firstFrame->calls().first();
908 ApiTraceEvent *oldSelected = m_selectedEvent;
909 m_nonDefaultsLookupEvent = m_selectedEvent;
910 m_selectedEvent = firstCall;
912 m_selectedEvent = oldSelected;
918 void MainWindow::customContextMenuRequested(QPoint pos)
920 QModelIndex index = m_ui.callView->indexAt(pos);
922 callItemSelected(index);
923 if (!index.isValid()) {
927 ApiTraceEvent *event =
928 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
934 menu.addAction(QIcon(":/resources/media-record.png"),
935 tr("Lookup state"), this, SLOT(lookupState()));
936 if (event->type() == ApiTraceEvent::Call) {
937 menu.addAction(tr("Edit"), this, SLOT(editCall()));
940 menu.exec(QCursor::pos());
943 void MainWindow::editCall()
945 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
946 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
947 m_argsEditor->setCall(call);
948 m_argsEditor->show();
952 void MainWindow::slotStartedSaving()
954 m_progressBar->show();
955 statusBar()->showMessage(
956 tr("Saving to %1").arg(m_trace->fileName()));
959 void MainWindow::slotSaved()
961 statusBar()->showMessage(
962 tr("Saved to %1").arg(m_trace->fileName()), 2000);
963 m_progressBar->hide();
966 void MainWindow::slotGoFrameStart()
968 ApiTraceFrame *frame = currentFrame();
969 ApiTraceCall *call = currentCall();
971 if (!frame && call) {
972 frame = call->parentFrame();
975 m_trace->findFrameStart(frame);
978 void MainWindow::slotGoFrameEnd()
980 ApiTraceFrame *frame = currentFrame();
981 ApiTraceCall *call = currentCall();
983 if (!frame && call) {
984 frame = call->parentFrame();
987 m_trace->findFrameEnd(frame);
990 ApiTraceFrame * MainWindow::selectedFrame() const
992 if (m_selectedEvent) {
993 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
994 return static_cast<ApiTraceFrame*>(m_selectedEvent);
996 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
997 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
998 return call->parentFrame();
1004 void MainWindow::slotTraceChanged(ApiTraceCall *call)
1007 if (call == m_selectedEvent) {
1008 m_ui.detailsWebView->setHtml(call->toHtml());
1012 void MainWindow::slotRetraceErrors(const QList<ApiTraceError> &errors)
1014 m_ui.errorsTreeWidget->clear();
1016 foreach(ApiTraceError error, errors) {
1017 m_trace->setCallError(error);
1019 QTreeWidgetItem *item =
1020 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1021 item->setData(0, Qt::DisplayRole, error.callIndex);
1022 item->setData(0, Qt::UserRole, error.callIndex);
1023 QString type = error.type;
1024 type[0] = type[0].toUpper();
1025 item->setData(1, Qt::DisplayRole, type);
1026 item->setData(2, Qt::DisplayRole, error.message);
1030 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1034 current->data(0, Qt::UserRole).toInt();
1035 m_trace->findCallIndex(callIndex);
1039 ApiTraceCall * MainWindow::selectedCall() const
1041 if (m_selectedEvent &&
1042 m_selectedEvent->type() == ApiTraceEvent::Call) {
1043 return static_cast<ApiTraceCall*>(m_selectedEvent);
1048 void MainWindow::saveSelectedSurface()
1050 QTreeWidgetItem *item =
1051 m_ui.surfacesTreeWidget->currentItem();
1053 if (!item || !m_trace) {
1057 QVariant var = item->data(0, Qt::UserRole);
1058 QImage img = var.value<QImage>();
1061 if (selectedCall()) {
1062 imageIndex = tr("_call_%1")
1063 .arg(selectedCall()->index());
1064 } else if (selectedFrame()) {
1065 ApiTraceCall *firstCall = selectedFrame()->call(0);
1067 imageIndex = tr("_frame_%1")
1068 .arg(firstCall->index());
1070 qDebug()<<"unknown frame number";
1071 imageIndex = tr("_frame_%1")
1072 .arg(firstCall->index());
1076 //which of the surfaces are we saving
1077 QTreeWidgetItem *parent = item->parent();
1079 m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent);
1080 if (parentIndex < 0) {
1085 childIndex = parent->indexOfChild(item);
1087 childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item);
1092 tr("%1%2-%3_%4.png")
1093 .arg(m_trace->fileName())
1097 //qDebug()<<"save "<<fileName;
1098 img.save(fileName, "PNG");
1099 statusBar()->showMessage( tr("Saved '%1'").arg(fileName), 5000);
1102 void MainWindow::loadProgess(int percent)
1104 m_progressBar->setValue(percent);
1107 void MainWindow::slotSearchResult(const ApiTrace::SearchRequest &request,
1108 ApiTrace::SearchResult result,
1112 case ApiTrace::SearchResult_NotFound:
1113 m_searchWidget->setFound(false);
1115 case ApiTrace::SearchResult_Found: {
1116 QModelIndex index = m_proxyModel->indexForCall(call);
1118 if (index.isValid()) {
1119 m_ui.callView->setCurrentIndex(index);
1120 m_searchWidget->setFound(true);
1122 //call is filtered out, so continue searching but from the
1125 qDebug()<<"Error: search success with no call";
1128 // qDebug()<<"filtered! search from "<<call->searchText()
1129 // <<", call idx = "<<call->index();
1131 if (request.direction == ApiTrace::SearchRequest::Next) {
1132 m_trace->findNext(call->parentFrame(), call,
1133 request.text, request.cs);
1135 m_trace->findNext(call->parentFrame(), call,
1136 request.text, request.cs);
1141 case ApiTrace::SearchResult_Wrapped:
1142 m_searchWidget->setFound(false);
1147 ApiTraceFrame * MainWindow::currentFrame() const
1149 QModelIndex index = m_ui.callView->currentIndex();
1150 ApiTraceEvent *event = 0;
1152 if (!index.isValid()) {
1153 index = m_proxyModel->index(0, 0, QModelIndex());
1154 if (!index.isValid()) {
1155 qDebug()<<"no currently valid index";
1160 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1166 ApiTraceFrame *frame = 0;
1167 if (event->type() == ApiTraceCall::Frame) {
1168 frame = static_cast<ApiTraceFrame*>(event);
1173 ApiTraceCall * MainWindow::currentCall() const
1175 QModelIndex index = m_ui.callView->currentIndex();
1176 ApiTraceEvent *event = 0;
1178 if (!index.isValid()) {
1179 index = m_proxyModel->index(0, 0, QModelIndex());
1180 if (!index.isValid()) {
1181 qDebug()<<"no currently valid index";
1186 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1192 ApiTraceCall *call = 0;
1193 if (event->type() == ApiTraceCall::Call) {
1194 call = static_cast<ApiTraceCall*>(event);
1201 void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame)
1203 Q_ASSERT(frame->isLoaded());
1204 if (!frame || frame->isEmpty()) {
1208 QVector<ApiTraceCall*>::const_iterator itr;
1209 QVector<ApiTraceCall*> calls = frame->calls();
1211 itr = calls.constBegin();
1212 while (itr != calls.constEnd()) {
1213 ApiTraceCall *call = *itr;
1214 QModelIndex idx = m_proxyModel->indexForCall(call);
1215 if (idx.isValid()) {
1216 m_ui.callView->setCurrentIndex(idx);
1223 void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame)
1225 Q_ASSERT(frame->isLoaded());
1226 if (!frame || frame->isEmpty()) {
1229 QVector<ApiTraceCall*>::const_iterator itr;
1230 QVector<ApiTraceCall*> calls = frame->calls();
1232 itr = calls.constEnd();
1235 ApiTraceCall *call = *itr;
1236 QModelIndex idx = m_proxyModel->indexForCall(call);
1237 if (idx.isValid()) {
1238 m_ui.callView->setCurrentIndex(idx);
1241 } while (itr != calls.constBegin());
1244 void MainWindow::slotJumpToResult(ApiTraceCall *call)
1246 QModelIndex index = m_proxyModel->indexForCall(call);
1247 if (index.isValid()) {
1248 m_ui.callView->setCurrentIndex(index);
1250 statusBar()->showMessage(tr("Call has been filtered out."));
1254 #include "mainwindow.moc"