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()
41 m_nonDefaultsLookupEvent(0)
48 void MainWindow::createTrace()
50 if (!m_traceProcess->canTrace()) {
54 tr("Current configuration doesn't support tracing."));
59 if (dialog.exec() == QDialog::Accepted) {
60 qDebug()<< "App : " <<dialog.applicationPath();
61 qDebug()<< " Arguments: "<<dialog.arguments();
62 m_traceProcess->setExecutablePath(dialog.applicationPath());
63 m_traceProcess->setArguments(dialog.arguments());
64 m_traceProcess->start();
68 void MainWindow::openTrace()
71 QFileDialog::getOpenFileName(
75 tr("Trace Files (*.trace)"));
77 if (!fileName.isEmpty() && QFile::exists(fileName)) {
78 newTraceFile(fileName);
82 void MainWindow::loadTrace(const QString &fileName)
84 if (!QFile::exists(fileName)) {
85 QMessageBox::warning(this, tr("File Missing"),
86 tr("File '%1' doesn't exist.").arg(fileName));
90 newTraceFile(fileName);
93 void MainWindow::callItemSelected(const QModelIndex &index)
95 ApiTraceEvent *event =
96 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
98 if (event && event->type() == ApiTraceEvent::Call) {
99 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
100 m_ui.detailsDock->setWindowTitle(
101 tr("Details View. Frame %1, Call %2")
102 .arg(call->parentFrame() ? call->parentFrame()->number : 0)
103 .arg(call->index()));
104 m_ui.detailsWebView->setHtml(call->toHtml());
105 m_ui.detailsDock->show();
106 if (call->hasBinaryData()) {
108 call->arguments()[call->binaryDataIndex()].toByteArray();
109 m_vdataInterpreter->setData(data);
111 QVector<QVariant> args = call->arguments();
112 for (int i = 0; i < call->argNames().count(); ++i) {
113 QString name = call->argNames()[i];
114 if (name == QLatin1String("stride")) {
115 int stride = args[i].toInt();
116 m_ui.vertexStrideSB->setValue(stride);
117 } else if (name == QLatin1String("size")) {
118 int components = args[i].toInt();
119 m_ui.vertexComponentsSB->setValue(components);
120 } else if (name == QLatin1String("type")) {
121 QString val = args[i].toString();
122 int textIndex = m_ui.vertexTypeCB->findText(val);
123 if (textIndex >= 0) {
124 m_ui.vertexTypeCB->setCurrentIndex(textIndex);
129 m_ui.vertexDataDock->setVisible(call->hasBinaryData());
130 m_selectedEvent = call;
132 if (event && event->type() == ApiTraceEvent::Frame) {
133 m_selectedEvent = static_cast<ApiTraceFrame*>(event);
137 m_ui.detailsDock->hide();
138 m_ui.vertexDataDock->hide();
140 if (m_selectedEvent && m_selectedEvent->hasState()) {
143 m_ui.stateDock->hide();
147 void MainWindow::replayStart()
149 if (m_trace->isSaving()) {
150 QMessageBox::warning(
153 tr("QApiTrace is currently saving the edited trace file. "
154 "Please wait until it finishes and try again."));
158 Ui_RetracerDialog dlgUi;
161 dlgUi.doubleBufferingCB->setChecked(
162 m_retracer->isDoubleBuffered());
163 dlgUi.errorCheckCB->setChecked(
164 !m_retracer->isBenchmarking());
166 if (dlg.exec() == QDialog::Accepted) {
167 m_retracer->setDoubleBuffered(
168 dlgUi.doubleBufferingCB->isChecked());
169 m_retracer->setBenchmarking(
170 !dlgUi.errorCheckCB->isChecked());
175 void MainWindow::replayStop()
178 m_ui.actionStop->setEnabled(false);
179 m_ui.actionReplay->setEnabled(true);
180 m_ui.actionLookupState->setEnabled(true);
183 void MainWindow::newTraceFile(const QString &fileName)
185 qDebug()<< "Loading : " <<fileName;
187 m_progressBar->setValue(0);
188 m_trace->setFileName(fileName);
190 if (fileName.isEmpty()) {
191 m_ui.actionReplay->setEnabled(false);
192 m_ui.actionLookupState->setEnabled(false);
193 setWindowTitle(tr("QApiTrace"));
195 QFileInfo info(fileName);
196 m_ui.actionReplay->setEnabled(true);
197 m_ui.actionLookupState->setEnabled(true);
199 tr("QApiTrace - %1").arg(info.fileName()));
203 void MainWindow::replayFinished(const QString &output)
205 m_ui.actionStop->setEnabled(false);
206 m_ui.actionReplay->setEnabled(true);
207 m_ui.actionLookupState->setEnabled(true);
209 m_progressBar->hide();
210 if (output.length() < 80) {
211 statusBar()->showMessage(output);
214 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
215 m_ui.errorsDock->setVisible(m_trace->hasErrors());
216 if (!m_trace->hasErrors()) {
217 m_ui.errorsTreeWidget->clear();
220 statusBar()->showMessage(
221 tr("Replaying finished!"), 2000);
224 void MainWindow::replayError(const QString &message)
226 m_ui.actionStop->setEnabled(false);
227 m_ui.actionReplay->setEnabled(true);
228 m_ui.actionLookupState->setEnabled(true);
230 m_nonDefaultsLookupEvent = 0;
232 m_progressBar->hide();
233 statusBar()->showMessage(
234 tr("Replaying unsuccessful."), 2000);
235 QMessageBox::warning(
236 this, tr("Replay Failed"), message);
239 void MainWindow::startedLoadingTrace()
242 m_progressBar->show();
243 QFileInfo info(m_trace->fileName());
244 statusBar()->showMessage(
245 tr("Loading %1...").arg(info.fileName()));
248 void MainWindow::finishedLoadingTrace()
250 m_progressBar->hide();
254 QFileInfo info(m_trace->fileName());
255 statusBar()->showMessage(
256 tr("Loaded %1").arg(info.fileName()), 3000);
259 void MainWindow::replayTrace(bool dumpState)
261 if (m_trace->fileName().isEmpty()) {
265 m_retracer->setFileName(m_trace->fileName());
266 m_retracer->setCaptureState(dumpState);
267 if (m_retracer->captureState() && m_selectedEvent) {
269 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
270 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
271 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
272 ApiTraceFrame *frame =
273 static_cast<ApiTraceFrame*>(m_selectedEvent);
274 if (frame->isEmpty()) {
275 //XXX i guess we could still get the current state
276 qDebug()<<"tried to get a state for an empty frame";
279 index = frame->lastCallIndex();
281 qDebug()<<"Unknown event type";
284 m_retracer->setCaptureAtCallNumber(index);
288 m_ui.actionStop->setEnabled(true);
289 m_progressBar->show();
291 statusBar()->showMessage(
292 tr("Looking up the state..."));
294 statusBar()->showMessage(
295 tr("Replaying the trace file..."));
299 void MainWindow::lookupState()
301 if (!m_selectedEvent) {
302 QMessageBox::warning(
303 this, tr("Unknown Event"),
304 tr("To inspect the state select an event in the event list."));
307 if (m_trace->isSaving()) {
308 QMessageBox::warning(
311 tr("QApiTrace is currently saving the edited trace file. "
312 "Please wait until it finishes and try again."));
315 m_stateEvent = m_selectedEvent;
319 MainWindow::~MainWindow()
329 variantToString(const QVariant &var, QString &str)
331 if (var.type() == QVariant::List) {
332 QVector<QVariant> lst = var.toList().toVector();
333 str += QLatin1String("[");
334 for (int i = 0; i < lst.count(); ++i) {
335 QVariant val = lst[i];
336 variantToString(val, str);
337 if (i < lst.count() - 1)
338 str += QLatin1String(", ");
340 str += QLatin1String("]");
341 } else if (var.type() == QVariant::Map) {
342 Q_ASSERT(!"unsupported state type");
343 } else if (var.type() == QVariant::Hash) {
344 Q_ASSERT(!"unsupported state type");
346 str += var.toString();
350 static QTreeWidgetItem *
351 variantToItem(const QString &key, const QVariant &var,
352 const QVariant &defaultVar);
355 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap,
356 QList<QTreeWidgetItem *> &items)
358 QVariantMap::const_iterator itr;
359 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
360 QString key = itr.key();
361 QVariant var = itr.value();
362 QVariant defaultVar = defaultMap[key];
364 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
372 variantListToItems(const QVector<QVariant> &lst,
373 const QVector<QVariant> &defaultLst,
374 QList<QTreeWidgetItem *> &items)
376 for (int i = 0; i < lst.count(); ++i) {
377 QString key = QString::number(i);
378 QVariant var = lst[i];
381 if (i < defaultLst.count()) {
382 defaultVar = defaultLst[i];
385 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
393 isVariantDeep(const QVariant &var)
395 if (var.type() == QVariant::List) {
396 QVector<QVariant> lst = var.toList().toVector();
397 for (int i = 0; i < lst.count(); ++i) {
398 if (isVariantDeep(lst[i])) {
403 } else if (var.type() == QVariant::Map) {
405 } else if (var.type() == QVariant::Hash) {
412 static QTreeWidgetItem *
413 variantToItem(const QString &key, const QVariant &var,
414 const QVariant &defaultVar)
416 if (var == defaultVar) {
422 bool deep = isVariantDeep(var);
424 variantToString(var, val);
427 //qDebug()<<"key = "<<key;
428 //qDebug()<<"val = "<<val;
433 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
436 QList<QTreeWidgetItem *> children;
437 if (var.type() == QVariant::Map) {
438 QVariantMap map = var.toMap();
439 QVariantMap defaultMap = defaultVar.toMap();
440 variantMapToItems(map, defaultMap, children);
442 if (var.type() == QVariant::List) {
443 QVector<QVariant> lst = var.toList().toVector();
444 QVector<QVariant> defaultLst = defaultVar.toList().toVector();
445 variantListToItems(lst, defaultLst, children);
447 item->addChildren(children);
453 static void addSurfaceItem(const ApiSurface &surface,
454 const QString &label,
455 QTreeWidgetItem *parent,
458 QIcon icon(QPixmap::fromImage(surface.thumb()));
459 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
460 item->setIcon(0, icon);
462 int width = surface.size().width();
463 int height = surface.size().height();
465 QString::fromLatin1("%1, %2, %3 x %4")
467 .arg(surface.formatName())
471 //item->setText(1, descr);
472 QLabel *l = new QLabel(descr, tree);
473 l->setWordWrap(true);
474 tree->setItemWidget(item, 1, l);
476 item->setData(0, Qt::UserRole, surface.image());
479 void MainWindow::fillStateForFrame()
481 if (!m_selectedEvent || !m_selectedEvent->hasState()) {
485 if (m_nonDefaultsLookupEvent) {
486 m_ui.nonDefaultsCB->blockSignals(true);
487 m_ui.nonDefaultsCB->setChecked(true);
488 m_ui.nonDefaultsCB->blockSignals(false);
491 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
492 QVariantMap defaultParams;
494 ApiTraceState defaultState = m_trace->defaultState();
495 defaultParams = defaultState.parameters();
498 const ApiTraceState &state = *m_selectedEvent->state();
499 m_ui.stateTreeWidget->clear();
500 QList<QTreeWidgetItem *> items;
501 variantMapToItems(state.parameters(), defaultParams, items);
502 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
504 QMap<QString, QString> shaderSources = state.shaderSources();
505 if (shaderSources.isEmpty()) {
506 m_sourcesWidget->setShaders(shaderSources);
508 m_sourcesWidget->setShaders(shaderSources);
511 m_ui.uniformsTreeWidget->clear();
512 QList<QTreeWidgetItem *> uniformsItems;
513 variantMapToItems(state.uniforms(), QVariantMap(), uniformsItems);
514 m_ui.uniformsTreeWidget->insertTopLevelItems(0, uniformsItems);
516 const QList<ApiTexture> &textures =
518 const QList<ApiFramebuffer> &fbos =
519 state.framebuffers();
521 m_ui.surfacesTreeWidget->clear();
522 if (textures.isEmpty() && fbos.isEmpty()) {
523 m_ui.surfacesTab->setDisabled(false);
525 m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
526 if (!textures.isEmpty()) {
527 QTreeWidgetItem *textureItem =
528 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
529 textureItem->setText(0, tr("Textures"));
530 if (textures.count() <= 6) {
531 textureItem->setExpanded(true);
534 for (int i = 0; i < textures.count(); ++i) {
535 const ApiTexture &texture =
537 addSurfaceItem(texture, texture.label(),
539 m_ui.surfacesTreeWidget);
542 if (!fbos.isEmpty()) {
543 QTreeWidgetItem *fboItem =
544 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
545 fboItem->setText(0, tr("Framebuffers"));
546 if (fbos.count() <= 6) {
547 fboItem->setExpanded(true);
550 for (int i = 0; i < fbos.count(); ++i) {
551 const ApiFramebuffer &fbo =
553 addSurfaceItem(fbo, fbo.type(),
555 m_ui.surfacesTreeWidget);
558 m_ui.surfacesTab->setEnabled(true);
560 m_ui.stateDock->show();
563 void MainWindow::showSettings()
565 SettingsDialog dialog;
566 dialog.setFilterModel(m_proxyModel);
571 void MainWindow::openHelp(const QUrl &url)
573 QDesktopServices::openUrl(url);
576 void MainWindow::showSurfacesMenu(const QPoint &pos)
578 QTreeWidget *tree = m_ui.surfacesTreeWidget;
579 QTreeWidgetItem *item = tree->itemAt(pos);
584 QMenu menu(tr("Surfaces"), this);
586 QAction *act = menu.addAction(tr("View Image"));
587 act->setStatusTip(tr("View the currently selected surface"));
588 connect(act, SIGNAL(triggered()),
589 SLOT(showSelectedSurface()));
591 act = menu.addAction(tr("Save Image"));
592 act->setStatusTip(tr("Save the currently selected surface"));
593 connect(act, SIGNAL(triggered()),
594 SLOT(saveSelectedSurface()));
596 menu.exec(tree->viewport()->mapToGlobal(pos));
599 void MainWindow::showSelectedSurface()
601 QTreeWidgetItem *item =
602 m_ui.surfacesTreeWidget->currentItem();
608 ImageViewer *viewer = new ImageViewer(this);
611 if (selectedCall()) {
612 title = tr("QApiTrace - Surface at %1 (%2)")
613 .arg(selectedCall()->name())
614 .arg(selectedCall()->index());
616 title = tr("QApiTrace - Surface Viewer");
618 viewer->setWindowTitle(title);
620 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
622 QVariant var = item->data(0, Qt::UserRole);
623 QImage img = var.value<QImage>();
624 viewer->setImage(img);
628 viewer->activateWindow();
631 void MainWindow::initObjects()
633 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
634 m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder);
636 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
637 QVBoxLayout *layout = new QVBoxLayout;
638 layout->addWidget(m_sourcesWidget);
639 m_ui.shadersTab->setLayout(layout);
641 m_trace = new ApiTrace();
642 m_retracer = new Retracer(this);
644 m_vdataInterpreter = new VertexDataInterpreter(this);
645 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
646 m_vdataInterpreter->setStride(
647 m_ui.vertexStrideSB->value());
648 m_vdataInterpreter->setComponents(
649 m_ui.vertexComponentsSB->value());
650 m_vdataInterpreter->setStartingOffset(
651 m_ui.startingOffsetSB->value());
652 m_vdataInterpreter->setTypeFromString(
653 m_ui.vertexTypeCB->currentText());
655 m_model = new ApiTraceModel();
656 m_model->setApiTrace(m_trace);
657 m_proxyModel = new ApiTraceFilter();
658 m_proxyModel->setSourceModel(m_model);
659 m_ui.callView->setModel(m_proxyModel);
660 m_ui.callView->setItemDelegate(
661 new ApiCallDelegate(m_ui.callView));
662 m_ui.callView->resizeColumnToContents(0);
663 m_ui.callView->header()->swapSections(0, 1);
664 m_ui.callView->setColumnWidth(1, 42);
665 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
667 m_progressBar = new QProgressBar();
668 m_progressBar->setRange(0, 100);
669 statusBar()->addPermanentWidget(m_progressBar);
670 m_progressBar->hide();
672 m_argsEditor = new ArgumentsEditor(this);
674 m_ui.detailsDock->hide();
675 m_ui.errorsDock->hide();
676 m_ui.vertexDataDock->hide();
677 m_ui.stateDock->hide();
678 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
680 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
681 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
683 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
685 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
686 QWebPage::DelegateExternalLinks);
688 m_jumpWidget = new JumpWidget(this);
689 m_ui.centralLayout->addWidget(m_jumpWidget);
690 m_jumpWidget->hide();
692 m_searchWidget = new SearchWidget(this);
693 m_ui.centralLayout->addWidget(m_searchWidget);
694 m_searchWidget->hide();
696 m_traceProcess = new TraceProcess(this);
699 void MainWindow::initConnections()
701 connect(m_trace, SIGNAL(startedLoadingTrace()),
702 this, SLOT(startedLoadingTrace()));
703 connect(m_trace, SIGNAL(loaded(int)),
704 this, SLOT(loadProgess(int)));
705 connect(m_trace, SIGNAL(finishedLoadingTrace()),
706 this, SLOT(finishedLoadingTrace()));
707 connect(m_trace, SIGNAL(startedSaving()),
708 this, SLOT(slotStartedSaving()));
709 connect(m_trace, SIGNAL(saved()),
710 this, SLOT(slotSaved()));
711 connect(m_trace, SIGNAL(changed(ApiTraceCall*)),
712 this, SLOT(slotTraceChanged(ApiTraceCall*)));
713 connect(m_trace, SIGNAL(findResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)),
714 this, SLOT(slotSearchResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)));
715 connect(m_trace, SIGNAL(foundFrameStart(ApiTraceFrame*)),
716 this, SLOT(slotFoundFrameStart(ApiTraceFrame*)));
717 connect(m_trace, SIGNAL(foundFrameEnd(ApiTraceFrame*)),
718 this, SLOT(slotFoundFrameEnd(ApiTraceFrame*)));
719 connect(m_trace, SIGNAL(foundCallIndex(ApiTraceCall*)),
720 this, SLOT(slotJumpToResult(ApiTraceCall*)));
722 connect(m_retracer, SIGNAL(finished(const QString&)),
723 this, SLOT(replayFinished(const QString&)));
724 connect(m_retracer, SIGNAL(error(const QString&)),
725 this, SLOT(replayError(const QString&)));
726 connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
727 this, SLOT(replayStateFound(ApiTraceState*)));
728 connect(m_retracer, SIGNAL(retraceErrors(const QList<ApiTraceError>&)),
729 this, SLOT(slotRetraceErrors(const QList<ApiTraceError>&)));
731 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
732 m_vdataInterpreter, SLOT(interpretData()));
733 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
734 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
735 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
736 m_vdataInterpreter, SLOT(setStride(int)));
737 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
738 m_vdataInterpreter, SLOT(setComponents(int)));
739 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
740 m_vdataInterpreter, SLOT(setStartingOffset(int)));
743 connect(m_ui.actionNew, SIGNAL(triggered()),
744 this, SLOT(createTrace()));
745 connect(m_ui.actionOpen, SIGNAL(triggered()),
746 this, SLOT(openTrace()));
747 connect(m_ui.actionQuit, SIGNAL(triggered()),
748 this, SLOT(close()));
750 connect(m_ui.actionFind, SIGNAL(triggered()),
751 this, SLOT(slotSearch()));
752 connect(m_ui.actionGo, SIGNAL(triggered()),
753 this, SLOT(slotGoTo()));
754 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
755 this, SLOT(slotGoFrameStart()));
756 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
757 this, SLOT(slotGoFrameEnd()));
759 connect(m_ui.actionReplay, SIGNAL(triggered()),
760 this, SLOT(replayStart()));
761 connect(m_ui.actionStop, SIGNAL(triggered()),
762 this, SLOT(replayStop()));
763 connect(m_ui.actionLookupState, SIGNAL(triggered()),
764 this, SLOT(lookupState()));
765 connect(m_ui.actionOptions, SIGNAL(triggered()),
766 this, SLOT(showSettings()));
768 connect(m_ui.callView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
769 this, SLOT(callItemSelected(const QModelIndex &)));
770 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
771 this, SLOT(customContextMenuRequested(QPoint)));
773 connect(m_ui.surfacesTreeWidget,
774 SIGNAL(customContextMenuRequested(const QPoint &)),
775 SLOT(showSurfacesMenu(const QPoint &)));
776 connect(m_ui.surfacesTreeWidget,
777 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
778 SLOT(showSelectedSurface()));
780 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
781 this, SLOT(openHelp(const QUrl&)));
783 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
784 this, SLOT(fillState(bool)));
786 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
787 SLOT(slotJumpTo(int)));
789 connect(m_searchWidget,
790 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
791 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
792 connect(m_searchWidget,
793 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
794 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
796 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
797 SLOT(createdTrace(const QString&)));
798 connect(m_traceProcess, SIGNAL(error(const QString&)),
799 SLOT(traceError(const QString&)));
801 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
802 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
803 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
804 m_ui.errorsDock, SLOT(setVisible(bool)));
805 connect(m_ui.errorsTreeWidget,
806 SIGNAL(itemActivated(QTreeWidgetItem*, int)),
807 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
810 void MainWindow::replayStateFound(ApiTraceState *state)
812 m_stateEvent->setState(state);
813 m_model->stateSetOnEvent(m_stateEvent);
814 if (m_selectedEvent == m_stateEvent ||
815 m_nonDefaultsLookupEvent == m_selectedEvent) {
818 m_ui.stateDock->hide();
820 m_nonDefaultsLookupEvent = 0;
823 void MainWindow::slotGoTo()
825 m_searchWidget->hide();
826 m_jumpWidget->show();
829 void MainWindow::slotJumpTo(int callNum)
831 m_trace->findCallIndex(callNum);
834 void MainWindow::createdTrace(const QString &path)
836 qDebug()<<"Done tracing "<<path;
840 void MainWindow::traceError(const QString &msg)
842 QMessageBox::warning(
848 void MainWindow::slotSearch()
850 m_jumpWidget->hide();
851 m_searchWidget->show();
854 void MainWindow::slotSearchNext(const QString &str,
855 Qt::CaseSensitivity sensitivity)
857 ApiTraceCall *call = currentCall();
858 ApiTraceFrame *frame = currentFrame();
860 Q_ASSERT(call || frame);
862 frame = call->parentFrame();
866 m_trace->findNext(frame, call, str, sensitivity);
869 void MainWindow::slotSearchPrev(const QString &str,
870 Qt::CaseSensitivity sensitivity)
872 ApiTraceCall *call = currentCall();
873 ApiTraceFrame *frame = currentFrame();
875 Q_ASSERT(call || frame);
877 frame = call->parentFrame();
881 m_trace->findPrev(frame, call, str, sensitivity);
884 void MainWindow::fillState(bool nonDefaults)
887 ApiTraceState defaultState = m_trace->defaultState();
888 if (defaultState.isEmpty()) {
889 m_ui.nonDefaultsCB->blockSignals(true);
890 m_ui.nonDefaultsCB->setChecked(false);
891 m_ui.nonDefaultsCB->blockSignals(false);
892 ApiTraceFrame *firstFrame =
897 if (!firstFrame->isLoaded()) {
898 m_trace->loadFrame(firstFrame);
901 ApiTraceCall *firstCall = firstFrame->calls().first();
902 ApiTraceEvent *oldSelected = m_selectedEvent;
903 m_nonDefaultsLookupEvent = m_selectedEvent;
904 m_selectedEvent = firstCall;
906 m_selectedEvent = oldSelected;
912 void MainWindow::customContextMenuRequested(QPoint pos)
914 QModelIndex index = m_ui.callView->indexAt(pos);
916 callItemSelected(index);
917 if (!index.isValid()) {
921 ApiTraceEvent *event =
922 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
928 menu.addAction(QIcon(":/resources/media-record.png"),
929 tr("Lookup state"), this, SLOT(lookupState()));
930 if (event->type() == ApiTraceEvent::Call) {
931 menu.addAction(tr("Edit"), this, SLOT(editCall()));
934 menu.exec(QCursor::pos());
937 void MainWindow::editCall()
939 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
940 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
941 m_argsEditor->setCall(call);
942 m_argsEditor->show();
946 void MainWindow::slotStartedSaving()
948 m_progressBar->show();
949 statusBar()->showMessage(
950 tr("Saving to %1").arg(m_trace->fileName()));
953 void MainWindow::slotSaved()
955 statusBar()->showMessage(
956 tr("Saved to %1").arg(m_trace->fileName()), 2000);
957 m_progressBar->hide();
960 void MainWindow::slotGoFrameStart()
962 ApiTraceFrame *frame = currentFrame();
963 ApiTraceCall *call = currentCall();
965 if (!frame && call) {
966 frame = call->parentFrame();
969 m_trace->findFrameStart(frame);
972 void MainWindow::slotGoFrameEnd()
974 ApiTraceFrame *frame = currentFrame();
975 ApiTraceCall *call = currentCall();
977 if (!frame && call) {
978 frame = call->parentFrame();
981 m_trace->findFrameEnd(frame);
984 ApiTraceFrame * MainWindow::selectedFrame() const
986 if (m_selectedEvent) {
987 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
988 return static_cast<ApiTraceFrame*>(m_selectedEvent);
990 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
991 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
992 return call->parentFrame();
998 void MainWindow::slotTraceChanged(ApiTraceCall *call)
1001 if (call == m_selectedEvent) {
1002 m_ui.detailsWebView->setHtml(call->toHtml());
1006 void MainWindow::slotRetraceErrors(const QList<ApiTraceError> &errors)
1008 m_ui.errorsTreeWidget->clear();
1010 foreach(ApiTraceError error, errors) {
1011 m_trace->setCallError(error);
1013 QTreeWidgetItem *item =
1014 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1015 item->setData(0, Qt::DisplayRole, error.callIndex);
1016 item->setData(0, Qt::UserRole, error.callIndex);
1017 QString type = error.type;
1018 type[0] = type[0].toUpper();
1019 item->setData(1, Qt::DisplayRole, type);
1020 item->setData(2, Qt::DisplayRole, error.message);
1024 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1028 current->data(0, Qt::UserRole).toInt();
1029 m_trace->findCallIndex(callIndex);
1033 ApiTraceCall * MainWindow::selectedCall() const
1035 if (m_selectedEvent &&
1036 m_selectedEvent->type() == ApiTraceEvent::Call) {
1037 return static_cast<ApiTraceCall*>(m_selectedEvent);
1042 void MainWindow::saveSelectedSurface()
1044 QTreeWidgetItem *item =
1045 m_ui.surfacesTreeWidget->currentItem();
1047 if (!item || !m_trace) {
1051 QVariant var = item->data(0, Qt::UserRole);
1052 QImage img = var.value<QImage>();
1055 if (selectedCall()) {
1056 imageIndex = tr("_call_%1")
1057 .arg(selectedCall()->index());
1058 } else if (selectedFrame()) {
1059 ApiTraceCall *firstCall = selectedFrame()->call(0);
1061 imageIndex = tr("_frame_%1")
1062 .arg(firstCall->index());
1064 qDebug()<<"unknown frame number";
1065 imageIndex = tr("_frame_%1")
1066 .arg(firstCall->index());
1070 //which of the surfaces are we saving
1071 QTreeWidgetItem *parent = item->parent();
1073 m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent);
1074 if (parentIndex < 0) {
1079 childIndex = parent->indexOfChild(item);
1081 childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item);
1086 tr("%1%2-%3_%4.png")
1087 .arg(m_trace->fileName())
1091 //qDebug()<<"save "<<fileName;
1092 img.save(fileName, "PNG");
1093 statusBar()->showMessage( tr("Saved '%1'").arg(fileName), 5000);
1096 void MainWindow::loadProgess(int percent)
1098 m_progressBar->setValue(percent);
1101 void MainWindow::slotSearchResult(const ApiTrace::SearchRequest &request,
1102 ApiTrace::SearchResult result,
1106 case ApiTrace::SearchResult_NotFound:
1107 m_searchWidget->setFound(false);
1109 case ApiTrace::SearchResult_Found: {
1110 QModelIndex index = m_proxyModel->indexForCall(call);
1112 if (index.isValid()) {
1113 m_ui.callView->setCurrentIndex(index);
1114 m_searchWidget->setFound(true);
1116 //call is filtered out, so continue searching but from the
1119 qDebug()<<"Error: search success with no call";
1122 // qDebug()<<"filtered! search from "<<call->searchText()
1123 // <<", call idx = "<<call->index();
1125 if (request.direction == ApiTrace::SearchRequest::Next) {
1126 m_trace->findNext(call->parentFrame(), call,
1127 request.text, request.cs);
1129 m_trace->findNext(call->parentFrame(), call,
1130 request.text, request.cs);
1135 case ApiTrace::SearchResult_Wrapped:
1136 m_searchWidget->setFound(false);
1141 ApiTraceFrame * MainWindow::currentFrame() const
1143 QModelIndex index = m_ui.callView->currentIndex();
1144 ApiTraceEvent *event = 0;
1146 if (!index.isValid()) {
1147 index = m_proxyModel->index(0, 0, QModelIndex());
1148 if (!index.isValid()) {
1149 qDebug()<<"no currently valid index";
1154 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1160 ApiTraceFrame *frame = 0;
1161 if (event->type() == ApiTraceCall::Frame) {
1162 frame = static_cast<ApiTraceFrame*>(event);
1167 ApiTraceCall * MainWindow::currentCall() const
1169 QModelIndex index = m_ui.callView->currentIndex();
1170 ApiTraceEvent *event = 0;
1172 if (!index.isValid()) {
1173 index = m_proxyModel->index(0, 0, QModelIndex());
1174 if (!index.isValid()) {
1175 qDebug()<<"no currently valid index";
1180 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1186 ApiTraceCall *call = 0;
1187 if (event->type() == ApiTraceCall::Call) {
1188 call = static_cast<ApiTraceCall*>(event);
1195 void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame)
1197 Q_ASSERT(frame->isLoaded());
1198 if (!frame || frame->isEmpty()) {
1202 QVector<ApiTraceCall*>::const_iterator itr;
1203 QVector<ApiTraceCall*> calls = frame->calls();
1205 itr = calls.constBegin();
1206 while (itr != calls.constEnd()) {
1207 ApiTraceCall *call = *itr;
1208 QModelIndex idx = m_proxyModel->indexForCall(call);
1209 if (idx.isValid()) {
1210 m_ui.callView->setCurrentIndex(idx);
1217 void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame)
1219 Q_ASSERT(frame->isLoaded());
1220 if (!frame || frame->isEmpty()) {
1223 QVector<ApiTraceCall*>::const_iterator itr;
1224 QVector<ApiTraceCall*> calls = frame->calls();
1226 itr = calls.constEnd();
1229 ApiTraceCall *call = *itr;
1230 QModelIndex idx = m_proxyModel->indexForCall(call);
1231 if (idx.isValid()) {
1232 m_ui.callView->setCurrentIndex(idx);
1235 } while (itr != calls.constBegin());
1238 void MainWindow::slotJumpToResult(ApiTraceCall *call)
1240 QModelIndex index = m_proxyModel->indexForCall(call);
1241 if (index.isValid()) {
1242 m_ui.callView->setCurrentIndex(index);
1244 statusBar()->showMessage(tr("Call has been filtered out."));
1248 #include "mainwindow.moc"