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()
52 if (!m_traceProcess->canTrace()) {
56 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)
85 if (!QFile::exists(fileName)) {
86 QMessageBox::warning(this, tr("File Missing"),
87 tr("File '%1' doesn't exist.").arg(fileName));
91 newTraceFile(fileName);
94 void MainWindow::callItemSelected(const QModelIndex &index)
96 ApiTraceEvent *event =
97 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
99 if (event && event->type() == ApiTraceEvent::Call) {
100 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
101 m_ui.detailsWebView->setHtml(call->toHtml());
102 m_ui.detailsDock->show();
103 if (call->hasBinaryData()) {
105 call->arguments()[call->binaryDataIndex()].toByteArray();
106 m_vdataInterpreter->setData(data);
107 QVector<QVariant> args = call->arguments();
109 for (int i = 0; i < call->argNames().count(); ++i) {
110 QString name = call->argNames()[i];
111 if (name == QLatin1String("stride")) {
112 int stride = args[i].toInt();
113 m_ui.vertexStrideSB->setValue(stride);
114 } else if (name == QLatin1String("size")) {
115 int components = args[i].toInt();
116 m_ui.vertexComponentsSB->setValue(components);
117 } else if (name == QLatin1String("type")) {
118 QString val = args[i].toString();
119 int textIndex = m_ui.vertexTypeCB->findText(val);
121 m_ui.vertexTypeCB->setCurrentIndex(textIndex);
125 m_ui.vertexDataDock->setVisible(call->hasBinaryData());
126 m_selectedEvent = call;
128 if (event && event->type() == ApiTraceEvent::Frame) {
129 m_selectedEvent = static_cast<ApiTraceFrame*>(event);
132 m_ui.detailsDock->hide();
133 m_ui.vertexDataDock->hide();
135 if (m_selectedEvent && m_selectedEvent->hasState()) {
138 m_ui.stateDock->hide();
141 void MainWindow::replayStart()
143 if (m_trace->isSaving()) {
144 QMessageBox::warning(
147 tr("QApiTrace is currently saving the edited trace file. "
148 "Please wait until it finishes and try again."));
152 Ui_RetracerDialog dlgUi;
155 dlgUi.doubleBufferingCB->setChecked(
156 m_retracer->isDoubleBuffered());
157 dlgUi.errorCheckCB->setChecked(
158 !m_retracer->isBenchmarking());
160 if (dlg.exec() == QDialog::Accepted) {
161 m_retracer->setDoubleBuffered(
162 dlgUi.doubleBufferingCB->isChecked());
163 m_retracer->setBenchmarking(
164 !dlgUi.errorCheckCB->isChecked());
169 void MainWindow::replayStop()
172 m_ui.actionStop->setEnabled(false);
173 m_ui.actionReplay->setEnabled(true);
174 m_ui.actionLookupState->setEnabled(true);
177 void MainWindow::newTraceFile(const QString &fileName)
179 qDebug()<< "Loading : " <<fileName;
181 m_progressBar->setValue(0);
182 m_trace->setFileName(fileName);
184 if (fileName.isEmpty()) {
185 m_ui.actionReplay->setEnabled(false);
186 m_ui.actionLookupState->setEnabled(false);
187 setWindowTitle(tr("QApiTrace"));
189 QFileInfo info(fileName);
190 m_ui.actionReplay->setEnabled(true);
191 m_ui.actionLookupState->setEnabled(true);
193 tr("QApiTrace - %1").arg(info.fileName()));
197 void MainWindow::replayFinished(const QString &output)
199 m_ui.actionStop->setEnabled(false);
200 m_ui.actionReplay->setEnabled(true);
201 m_ui.actionLookupState->setEnabled(true);
203 m_progressBar->hide();
204 if (output.length() < 80) {
205 statusBar()->showMessage(output);
208 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
209 m_ui.errorsDock->setVisible(m_trace->hasErrors());
210 if (!m_trace->hasErrors())
211 m_ui.errorsTreeWidget->clear();
213 statusBar()->showMessage(
214 tr("Replaying finished!"), 2000);
217 void MainWindow::replayError(const QString &message)
219 m_ui.actionStop->setEnabled(false);
220 m_ui.actionReplay->setEnabled(true);
221 m_ui.actionLookupState->setEnabled(true);
223 m_nonDefaultsLookupEvent = 0;
225 m_progressBar->hide();
226 statusBar()->showMessage(
227 tr("Replaying unsuccessful."), 2000);
228 QMessageBox::warning(
229 this, tr("Replay Failed"), message);
232 void MainWindow::startedLoadingTrace()
235 m_progressBar->show();
236 QFileInfo info(m_trace->fileName());
237 statusBar()->showMessage(
238 tr("Loading %1...").arg(info.fileName()));
241 void MainWindow::finishedLoadingTrace()
243 m_progressBar->hide();
247 QFileInfo info(m_trace->fileName());
248 statusBar()->showMessage(
249 tr("Loaded %1").arg(info.fileName()), 3000);
252 void MainWindow::replayTrace(bool dumpState)
254 if (m_trace->fileName().isEmpty())
257 m_retracer->setFileName(m_trace->fileName());
258 m_retracer->setCaptureState(dumpState);
259 if (m_retracer->captureState() && m_selectedEvent) {
261 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
262 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
263 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
264 ApiTraceFrame *frame =
265 static_cast<ApiTraceFrame*>(m_selectedEvent);
266 if (frame->isEmpty()) {
267 //XXX i guess we could still get the current state
268 qDebug()<<"tried to get a state for an empty frame";
271 index = frame->calls().first()->index();
273 qDebug()<<"Unknown event type";
276 m_retracer->setCaptureAtCallNumber(index);
280 m_ui.actionStop->setEnabled(true);
281 m_progressBar->show();
283 statusBar()->showMessage(
284 tr("Looking up the state..."));
286 statusBar()->showMessage(
287 tr("Replaying the trace file..."));
290 void MainWindow::lookupState()
292 if (!m_selectedEvent) {
293 QMessageBox::warning(
294 this, tr("Unknown Event"),
295 tr("To inspect the state select an event in the event list."));
298 if (m_trace->isSaving()) {
299 QMessageBox::warning(
302 tr("QApiTrace is currently saving the edited trace file. "
303 "Please wait until it finishes and try again."));
306 m_stateEvent = m_selectedEvent;
310 MainWindow::~MainWindow()
320 variantToString(const QVariant &var, QString &str)
322 if (var.type() == QVariant::List) {
323 QVector<QVariant> lst = var.toList().toVector();
324 str += QLatin1String("[");
325 for (int i = 0; i < lst.count(); ++i) {
326 QVariant val = lst[i];
327 variantToString(val, str);
328 if (i < lst.count() - 1)
329 str += QLatin1String(", ");
331 str += QLatin1String("]");
332 } else if (var.type() == QVariant::Map) {
333 Q_ASSERT(!"unsupported state type");
334 } else if (var.type() == QVariant::Hash) {
335 Q_ASSERT(!"unsupported state type");
337 str += var.toString();
341 static QTreeWidgetItem *
342 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar);
345 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap, QList<QTreeWidgetItem *> &items)
347 QVariantMap::const_iterator itr;
348 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
349 QString key = itr.key();
350 QVariant var = itr.value();
351 QVariant defaultVar = defaultMap[key];
353 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
361 variantListToItems(const QVector<QVariant> &lst, const QVector<QVariant> &defaultLst,
362 QList<QTreeWidgetItem *> &items)
364 for (int i = 0; i < lst.count(); ++i) {
365 QString key = QString::number(i);
366 QVariant var = lst[i];
369 if (i < defaultLst.count()) {
370 defaultVar = defaultLst[i];
373 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
381 isVariantDeep(const QVariant &var)
383 if (var.type() == QVariant::List) {
384 QVector<QVariant> lst = var.toList().toVector();
385 for (int i = 0; i < lst.count(); ++i) {
386 if (isVariantDeep(lst[i])) {
391 } else if (var.type() == QVariant::Map) {
393 } else if (var.type() == QVariant::Hash) {
400 static QTreeWidgetItem *
401 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar)
403 if (var == defaultVar) {
409 bool deep = isVariantDeep(var);
411 variantToString(var, val);
414 //qDebug()<<"key = "<<key;
415 //qDebug()<<"val = "<<val;
420 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
423 QList<QTreeWidgetItem *> children;
424 if (var.type() == QVariant::Map) {
425 QVariantMap map = var.toMap();
426 QVariantMap defaultMap = defaultVar.toMap();
427 variantMapToItems(map, defaultMap, children);
429 if (var.type() == QVariant::List) {
430 QVector<QVariant> lst = var.toList().toVector();
431 QVector<QVariant> defaultLst = defaultVar.toList().toVector();
432 variantListToItems(lst, defaultLst, children);
434 item->addChildren(children);
440 static void addSurfaceItem(const ApiSurface &surface,
441 const QString &label,
442 QTreeWidgetItem *parent,
445 int width = surface.size().width();
446 int height = surface.size().height();
447 QIcon icon(QPixmap::fromImage(surface.thumb()));
448 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
450 item->setIcon(0, icon);
453 QString::fromLatin1("%1, %2 x %3")
458 //item->setText(1, descr);
459 QLabel *l = new QLabel(descr, tree);
460 l->setWordWrap(true);
461 tree->setItemWidget(item, 1, l);
463 item->setData(0, Qt::UserRole, surface.image());
466 void MainWindow::fillStateForFrame()
468 if (!m_selectedEvent || !m_selectedEvent->hasState())
471 if (m_nonDefaultsLookupEvent) {
472 m_ui.nonDefaultsCB->blockSignals(true);
473 m_ui.nonDefaultsCB->setChecked(true);
474 m_ui.nonDefaultsCB->blockSignals(false);
477 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
478 QVariantMap defaultParams;
480 ApiTraceState defaultState = m_trace->defaultState();
481 defaultParams = defaultState.parameters();
484 const ApiTraceState &state = *m_selectedEvent->state();
485 m_ui.stateTreeWidget->clear();
486 QList<QTreeWidgetItem *> items;
487 variantMapToItems(state.parameters(), defaultParams, items);
488 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
490 QMap<QString, QString> shaderSources = state.shaderSources();
491 if (shaderSources.isEmpty()) {
492 m_sourcesWidget->setShaders(shaderSources);
494 m_sourcesWidget->setShaders(shaderSources);
497 m_ui.uniformsTreeWidget->clear();
498 QList<QTreeWidgetItem *> uniformsItems;
499 variantMapToItems(state.uniforms(), QVariantMap(), uniformsItems);
500 m_ui.uniformsTreeWidget->insertTopLevelItems(0, uniformsItems);
502 const QList<ApiTexture> &textures =
504 const QList<ApiFramebuffer> &fbos =
505 state.framebuffers();
507 m_ui.surfacesTreeWidget->clear();
508 if (textures.isEmpty() && fbos.isEmpty()) {
509 m_ui.surfacesTab->setDisabled(false);
511 m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
512 if (!textures.isEmpty()) {
513 QTreeWidgetItem *textureItem =
514 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
515 textureItem->setText(0, tr("Textures"));
516 if (textures.count() <= 6)
517 textureItem->setExpanded(true);
519 for (int i = 0; i < textures.count(); ++i) {
520 const ApiTexture &texture =
522 addSurfaceItem(texture, texture.label(),
524 m_ui.surfacesTreeWidget);
527 if (!fbos.isEmpty()) {
528 QTreeWidgetItem *fboItem =
529 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
530 fboItem->setText(0, tr("Framebuffers"));
531 if (fbos.count() <= 6)
532 fboItem->setExpanded(true);
534 for (int i = 0; i < fbos.count(); ++i) {
535 const ApiFramebuffer &fbo =
537 addSurfaceItem(fbo, fbo.type(),
539 m_ui.surfacesTreeWidget);
542 m_ui.surfacesTab->setEnabled(true);
544 m_ui.stateDock->show();
547 void MainWindow::showSettings()
549 SettingsDialog dialog;
550 dialog.setFilterModel(m_proxyModel);
555 void MainWindow::openHelp(const QUrl &url)
557 QDesktopServices::openUrl(url);
560 void MainWindow::showSurfacesMenu(const QPoint &pos)
562 QTreeWidget *tree = m_ui.surfacesTreeWidget;
563 QTreeWidgetItem *item = tree->itemAt(pos);
567 QMenu menu(tr("Surfaces"), this);
569 QAction *act = menu.addAction(tr("View Image"));
570 act->setStatusTip(tr("View the currently selected surface"));
571 connect(act, SIGNAL(triggered()),
572 SLOT(showSelectedSurface()));
574 act = menu.addAction(tr("Save Image"));
575 act->setStatusTip(tr("Save the currently selected surface"));
576 connect(act, SIGNAL(triggered()),
577 SLOT(saveSelectedSurface()));
579 menu.exec(tree->viewport()->mapToGlobal(pos));
582 void MainWindow::showSelectedSurface()
584 QTreeWidgetItem *item =
585 m_ui.surfacesTreeWidget->currentItem();
590 QVariant var = item->data(0, Qt::UserRole);
591 QImage img = var.value<QImage>();
592 ImageViewer *viewer = new ImageViewer(this);
595 if (selectedCall()) {
596 title = tr("QApiTrace - Surface at %1 (%2)")
597 .arg(selectedCall()->name())
598 .arg(selectedCall()->index());
600 title = tr("QApiTrace - Surface Viewer");
602 viewer->setWindowTitle(title);
603 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
604 viewer->setImage(img);
605 QRect screenRect = QApplication::desktop()->availableGeometry();
606 viewer->resize(qMin(int(0.75 * screenRect.width()), img.width()) + 40,
607 qMin(int(0.75 * screenRect.height()), img.height()) + 40);
610 viewer->activateWindow();
613 void MainWindow::initObjects()
615 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
616 m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder);
618 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
619 QVBoxLayout *layout = new QVBoxLayout;
620 layout->addWidget(m_sourcesWidget);
621 m_ui.shadersTab->setLayout(layout);
623 m_trace = new ApiTrace();
624 m_retracer = new Retracer(this);
626 m_vdataInterpreter = new VertexDataInterpreter(this);
627 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
628 m_vdataInterpreter->setStride(
629 m_ui.vertexStrideSB->value());
630 m_vdataInterpreter->setComponents(
631 m_ui.vertexComponentsSB->value());
632 m_vdataInterpreter->setStartingOffset(
633 m_ui.startingOffsetSB->value());
634 m_vdataInterpreter->setTypeFromString(
635 m_ui.vertexTypeCB->currentText());
637 m_model = new ApiTraceModel();
638 m_model->setApiTrace(m_trace);
639 m_proxyModel = new ApiTraceFilter();
640 m_proxyModel->setSourceModel(m_model);
641 m_ui.callView->setModel(m_proxyModel);
642 m_ui.callView->setItemDelegate(
643 new ApiCallDelegate(m_ui.callView));
644 m_ui.callView->resizeColumnToContents(0);
645 m_ui.callView->header()->swapSections(0, 1);
646 m_ui.callView->setColumnWidth(1, 42);
647 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
649 m_progressBar = new QProgressBar();
650 m_progressBar->setRange(0, 100);
651 statusBar()->addPermanentWidget(m_progressBar);
652 m_progressBar->hide();
654 m_argsEditor = new ArgumentsEditor(this);
656 m_ui.detailsDock->hide();
657 m_ui.errorsDock->hide();
658 m_ui.vertexDataDock->hide();
659 m_ui.stateDock->hide();
660 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
662 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
663 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
665 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
667 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
668 QWebPage::DelegateExternalLinks);
670 m_jumpWidget = new JumpWidget(this);
671 m_ui.centralLayout->addWidget(m_jumpWidget);
672 m_jumpWidget->hide();
674 m_searchWidget = new SearchWidget(this);
675 m_ui.centralLayout->addWidget(m_searchWidget);
676 m_searchWidget->hide();
678 m_traceProcess = new TraceProcess(this);
681 void MainWindow::initConnections()
683 connect(m_trace, SIGNAL(startedLoadingTrace()),
684 this, SLOT(startedLoadingTrace()));
685 connect(m_trace, SIGNAL(loaded(int)),
686 this, SLOT(loadProgess(int)));
687 connect(m_trace, SIGNAL(finishedLoadingTrace()),
688 this, SLOT(finishedLoadingTrace()));
689 connect(m_trace, SIGNAL(startedSaving()),
690 this, SLOT(slotStartedSaving()));
691 connect(m_trace, SIGNAL(saved()),
692 this, SLOT(slotSaved()));
693 connect(m_trace, SIGNAL(changed(ApiTraceCall*)),
694 this, SLOT(slotTraceChanged(ApiTraceCall*)));
695 connect(m_trace, SIGNAL(findResult(ApiTrace::SearchResult,ApiTraceCall*)),
696 this, SLOT(slotSearchResult(ApiTrace::SearchResult,ApiTraceCall*)));
697 connect(m_trace, SIGNAL(foundFrameStart(ApiTraceFrame*)),
698 this, SLOT(slotFoundFrameStart(ApiTraceFrame*)));
699 connect(m_trace, SIGNAL(foundFrameEnd(ApiTraceFrame*)),
700 this, SLOT(slotFoundFrameEnd(ApiTraceFrame*)));
702 connect(m_retracer, SIGNAL(finished(const QString&)),
703 this, SLOT(replayFinished(const QString&)));
704 connect(m_retracer, SIGNAL(error(const QString&)),
705 this, SLOT(replayError(const QString&)));
706 connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
707 this, SLOT(replayStateFound(ApiTraceState*)));
708 connect(m_retracer, SIGNAL(retraceErrors(const QList<RetraceError>&)),
709 this, SLOT(slotRetraceErrors(const QList<RetraceError>&)));
711 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
712 m_vdataInterpreter, SLOT(interpretData()));
713 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
714 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
715 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
716 m_vdataInterpreter, SLOT(setStride(int)));
717 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
718 m_vdataInterpreter, SLOT(setComponents(int)));
719 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
720 m_vdataInterpreter, SLOT(setStartingOffset(int)));
723 connect(m_ui.actionNew, SIGNAL(triggered()),
724 this, SLOT(createTrace()));
725 connect(m_ui.actionOpen, SIGNAL(triggered()),
726 this, SLOT(openTrace()));
727 connect(m_ui.actionQuit, SIGNAL(triggered()),
728 this, SLOT(close()));
730 connect(m_ui.actionFind, SIGNAL(triggered()),
731 this, SLOT(slotSearch()));
732 connect(m_ui.actionGo, SIGNAL(triggered()),
733 this, SLOT(slotGoTo()));
734 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
735 this, SLOT(slotGoFrameStart()));
736 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
737 this, SLOT(slotGoFrameEnd()));
739 connect(m_ui.actionReplay, SIGNAL(triggered()),
740 this, SLOT(replayStart()));
741 connect(m_ui.actionStop, SIGNAL(triggered()),
742 this, SLOT(replayStop()));
743 connect(m_ui.actionLookupState, SIGNAL(triggered()),
744 this, SLOT(lookupState()));
745 connect(m_ui.actionOptions, SIGNAL(triggered()),
746 this, SLOT(showSettings()));
748 connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
749 this, SLOT(callItemSelected(const QModelIndex &)));
750 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
751 this, SLOT(customContextMenuRequested(QPoint)));
753 connect(m_ui.surfacesTreeWidget,
754 SIGNAL(customContextMenuRequested(const QPoint &)),
755 SLOT(showSurfacesMenu(const QPoint &)));
756 connect(m_ui.surfacesTreeWidget,
757 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
758 SLOT(showSelectedSurface()));
760 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
761 this, SLOT(openHelp(const QUrl&)));
763 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
764 this, SLOT(fillState(bool)));
766 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
767 SLOT(slotJumpTo(int)));
769 connect(m_searchWidget,
770 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
771 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
772 connect(m_searchWidget,
773 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
774 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
776 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
777 SLOT(createdTrace(const QString&)));
778 connect(m_traceProcess, SIGNAL(error(const QString&)),
779 SLOT(traceError(const QString&)));
781 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
782 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
783 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
784 m_ui.errorsDock, SLOT(setVisible(bool)));
785 connect(m_ui.errorsTreeWidget,
786 SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
787 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
790 void MainWindow::replayStateFound(ApiTraceState *state)
792 m_stateEvent->setState(state);
793 m_model->stateSetOnEvent(m_stateEvent);
794 if (m_selectedEvent == m_stateEvent ||
795 m_nonDefaultsLookupEvent == m_selectedEvent) {
798 m_ui.stateDock->hide();
800 m_nonDefaultsLookupEvent = 0;
803 void MainWindow::slotGoTo()
805 m_searchWidget->hide();
806 m_jumpWidget->show();
809 void MainWindow::slotJumpTo(int callNum)
811 QModelIndex index = m_proxyModel->callIndex(callNum);
812 if (index.isValid()) {
813 m_ui.callView->setCurrentIndex(index);
817 void MainWindow::createdTrace(const QString &path)
819 qDebug()<<"Done tracing "<<path;
823 void MainWindow::traceError(const QString &msg)
825 QMessageBox::warning(
831 void MainWindow::slotSearch()
833 m_jumpWidget->hide();
834 m_searchWidget->show();
837 void MainWindow::slotSearchNext(const QString &str,
838 Qt::CaseSensitivity sensitivity)
840 ApiTraceCall *call = currentCall();
841 ApiTraceFrame *frame = currentFrame();
843 Q_ASSERT(call || frame);
845 frame = call->parentFrame();
849 m_trace->findNext(frame, call, str, sensitivity);
852 void MainWindow::slotSearchPrev(const QString &str,
853 Qt::CaseSensitivity sensitivity)
855 ApiTraceCall *call = currentCall();
856 ApiTraceFrame *frame = currentFrame();
858 Q_ASSERT(call || frame);
860 frame = call->parentFrame();
864 m_trace->findPrev(frame, call, str, sensitivity);
867 void MainWindow::fillState(bool nonDefaults)
870 ApiTraceState defaultState = m_trace->defaultState();
871 if (defaultState.isEmpty()) {
872 m_ui.nonDefaultsCB->blockSignals(true);
873 m_ui.nonDefaultsCB->setChecked(false);
874 m_ui.nonDefaultsCB->blockSignals(false);
875 ApiTraceFrame *firstFrame =
877 ApiTraceEvent *oldSelected = m_selectedEvent;
880 m_nonDefaultsLookupEvent = m_selectedEvent;
881 m_selectedEvent = firstFrame;
883 m_selectedEvent = oldSelected;
889 void MainWindow::customContextMenuRequested(QPoint pos)
892 QModelIndex index = m_ui.callView->indexAt(pos);
894 callItemSelected(index);
895 if (!index.isValid())
898 ApiTraceEvent *event =
899 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
903 menu.addAction(QIcon(":/resources/media-record.png"),
904 tr("Lookup state"), this, SLOT(lookupState()));
905 if (event->type() == ApiTraceEvent::Call) {
906 menu.addAction(tr("Edit"), this, SLOT(editCall()));
909 menu.exec(QCursor::pos());
912 void MainWindow::editCall()
914 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
915 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
916 m_argsEditor->setCall(call);
917 m_argsEditor->show();
921 void MainWindow::slotStartedSaving()
923 m_progressBar->show();
924 statusBar()->showMessage(
925 tr("Saving to %1").arg(m_trace->fileName()));
928 void MainWindow::slotSaved()
930 statusBar()->showMessage(
931 tr("Saved to %1").arg(m_trace->fileName()), 2000);
932 m_progressBar->hide();
935 void MainWindow::slotGoFrameStart()
937 ApiTraceFrame *frame = currentFrame();
938 ApiTraceCall *call = currentCall();
940 if (!frame && call) {
941 frame = call->parentFrame();
944 m_trace->findFrameStart(frame);
947 void MainWindow::slotGoFrameEnd()
949 ApiTraceFrame *frame = currentFrame();
950 ApiTraceCall *call = currentCall();
952 if (!frame && call) {
953 frame = call->parentFrame();
956 m_trace->findFrameEnd(frame);
959 ApiTraceFrame * MainWindow::selectedFrame() const
961 if (m_selectedEvent) {
962 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
963 return static_cast<ApiTraceFrame*>(m_selectedEvent);
965 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
966 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
967 return call->parentFrame();
973 void MainWindow::slotTraceChanged(ApiTraceCall *call)
976 if (call == m_selectedEvent) {
977 m_ui.detailsWebView->setHtml(call->toHtml());
981 void MainWindow::slotRetraceErrors(const QList<RetraceError> &errors)
983 m_ui.errorsTreeWidget->clear();
985 foreach(RetraceError error, errors) {
986 ApiTraceCall *call = m_trace->callWithIndex(error.callIndex);
989 call->setError(error.message);
991 QTreeWidgetItem *item =
992 new QTreeWidgetItem(m_ui.errorsTreeWidget);
993 item->setData(0, Qt::DisplayRole, error.callIndex);
994 item->setData(0, Qt::UserRole, QVariant::fromValue(call));
995 QString type = error.type;
996 type[0] = type[0].toUpper();
997 item->setData(1, Qt::DisplayRole, type);
998 item->setData(2, Qt::DisplayRole, error.message);
1002 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1005 ApiTraceCall *call =
1006 current->data(0, Qt::UserRole).value<ApiTraceCall*>();
1008 QModelIndex index = m_proxyModel->indexForCall(call);
1009 if (index.isValid()) {
1010 m_ui.callView->setCurrentIndex(index);
1012 statusBar()->showMessage(tr("Call has been filtered out."));
1017 ApiTraceCall * MainWindow::selectedCall() const
1019 if (m_selectedEvent &&
1020 m_selectedEvent->type() == ApiTraceEvent::Call) {
1021 return static_cast<ApiTraceCall*>(m_selectedEvent);
1026 void MainWindow::saveSelectedSurface()
1028 QTreeWidgetItem *item =
1029 m_ui.surfacesTreeWidget->currentItem();
1031 if (!item || !m_trace)
1034 QVariant var = item->data(0, Qt::UserRole);
1035 QImage img = var.value<QImage>();
1038 if (selectedCall()) {
1039 imageIndex = tr("_call_%1")
1040 .arg(selectedCall()->index());
1041 } else if (selectedFrame()) {
1042 ApiTraceCall *firstCall = selectedFrame()->call(0);
1044 imageIndex = tr("_frame_%1")
1045 .arg(firstCall->index());
1047 qDebug()<<"unknown frame number";
1048 imageIndex = tr("_frame_%1")
1049 .arg(firstCall->index());
1053 //which of the surfaces are we saving
1054 QTreeWidgetItem *parent = item->parent();
1056 m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent);
1057 if (parentIndex < 0) {
1062 childIndex = parent->indexOfChild(item);
1064 childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item);
1069 tr("%1%2-%3_%4.png")
1070 .arg(m_trace->fileName())
1074 //qDebug()<<"save "<<fileName;
1075 img.save(fileName, "PNG");
1076 statusBar()->showMessage( tr("Saved '%1'").arg(fileName), 5000);
1079 void MainWindow::loadProgess(int percent)
1081 m_progressBar->setValue(percent);
1084 void MainWindow::slotSearchResult(ApiTrace::SearchResult result,
1088 case ApiTrace::SearchNotFound:
1089 m_searchWidget->setFound(false);
1091 case ApiTrace::SearchFound: {
1092 QModelIndex index = m_proxyModel->indexForCall(call);
1093 m_ui.callView->setCurrentIndex(index);
1094 m_searchWidget->setFound(true);
1097 case ApiTrace::SearchWrapped:
1098 m_searchWidget->setFound(false);
1103 ApiTraceFrame * MainWindow::currentFrame() const
1105 QModelIndex index = m_ui.callView->currentIndex();
1106 ApiTraceEvent *event = 0;
1108 if (!index.isValid()) {
1109 index = m_proxyModel->index(0, 0, QModelIndex());
1110 if (!index.isValid()) {
1111 qDebug()<<"no currently valid index";
1116 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1122 ApiTraceFrame *frame = 0;
1123 if (event->type() == ApiTraceCall::Frame) {
1124 frame = static_cast<ApiTraceFrame*>(event);
1129 ApiTraceCall * MainWindow::currentCall() const
1131 QModelIndex index = m_ui.callView->currentIndex();
1132 ApiTraceEvent *event = 0;
1134 if (!index.isValid()) {
1135 index = m_proxyModel->index(0, 0, QModelIndex());
1136 if (!index.isValid()) {
1137 qDebug()<<"no currently valid index";
1142 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1148 ApiTraceCall *call = 0;
1149 if (event->type() == ApiTraceCall::Call) {
1150 call = static_cast<ApiTraceCall*>(event);
1157 void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame)
1159 Q_ASSERT(frame->loaded());
1160 if (!frame || frame->isEmpty()) {
1164 QVector<ApiTraceCall*>::const_iterator itr;
1165 QVector<ApiTraceCall*> calls = frame->calls();
1167 itr = calls.constBegin();
1168 while (itr != calls.constEnd()) {
1169 ApiTraceCall *call = *itr;
1170 QModelIndex idx = m_proxyModel->indexForCall(call);
1171 if (idx.isValid()) {
1172 m_ui.callView->setCurrentIndex(idx);
1179 void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame)
1181 Q_ASSERT(frame->loaded());
1182 if (!frame || frame->isEmpty()) {
1185 QVector<ApiTraceCall*>::const_iterator itr;
1186 QVector<ApiTraceCall*> calls = frame->calls();
1188 itr = calls.constEnd();
1191 ApiTraceCall *call = *itr;
1192 QModelIndex idx = m_proxyModel->indexForCall(call);
1193 if (idx.isValid()) {
1194 m_ui.callView->setCurrentIndex(idx);
1197 } while (itr != calls.constBegin());
1200 #include "mainwindow.moc"