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 QVariantList 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->state().isEmpty()) {
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 QVariantList lst = var.toList();
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 QVariantList &lst, const QVariantList &defaultLst, QList<QTreeWidgetItem *> &items)
363 for (int i = 0; i < lst.count(); ++i) {
364 QString key = QString::number(i);
365 QVariant var = lst[i];
368 if (i < defaultLst.count()) {
369 defaultVar = defaultLst[i];
372 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
380 isVariantDeep(const QVariant &var)
382 if (var.type() == QVariant::List) {
383 QVariantList lst = var.toList();
384 for (int i = 0; i < lst.count(); ++i) {
385 if (isVariantDeep(lst[i])) {
390 } else if (var.type() == QVariant::Map) {
392 } else if (var.type() == QVariant::Hash) {
399 static QTreeWidgetItem *
400 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar)
402 if (var == defaultVar) {
408 bool deep = isVariantDeep(var);
410 variantToString(var, val);
413 //qDebug()<<"key = "<<key;
414 //qDebug()<<"val = "<<val;
419 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
422 QList<QTreeWidgetItem *> children;
423 if (var.type() == QVariant::Map) {
424 QVariantMap map = var.toMap();
425 QVariantMap defaultMap = defaultVar.toMap();
426 variantMapToItems(map, defaultMap, children);
428 if (var.type() == QVariant::List) {
429 QVariantList lst = var.toList();
430 QVariantList defaultLst = defaultVar.toList();
431 variantListToItems(lst, defaultLst, children);
433 item->addChildren(children);
439 static void addSurfaceItem(const ApiSurface &surface,
440 const QString &label,
441 QTreeWidgetItem *parent,
444 int width = surface.size().width();
445 int height = surface.size().height();
446 QIcon icon(QPixmap::fromImage(surface.thumb()));
447 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
449 item->setIcon(0, icon);
452 QString::fromLatin1("%1, %2 x %3")
457 //item->setText(1, descr);
458 QLabel *l = new QLabel(descr, tree);
459 l->setWordWrap(true);
460 tree->setItemWidget(item, 1, l);
462 item->setData(0, Qt::UserRole, surface.image());
465 void MainWindow::fillStateForFrame()
469 if (!m_selectedEvent || m_selectedEvent->state().isEmpty())
472 if (m_nonDefaultsLookupEvent) {
473 m_ui.nonDefaultsCB->blockSignals(true);
474 m_ui.nonDefaultsCB->setChecked(true);
475 m_ui.nonDefaultsCB->blockSignals(false);
478 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
479 QVariantMap defaultParams;
481 ApiTraceState defaultState = m_trace->defaultState();
482 defaultParams = defaultState.parameters();
485 const ApiTraceState &state = m_selectedEvent->state();
486 m_ui.stateTreeWidget->clear();
487 params = state.parameters();
488 QList<QTreeWidgetItem *> items;
489 variantMapToItems(params, defaultParams, items);
490 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
492 QMap<QString, QString> shaderSources = state.shaderSources();
493 if (shaderSources.isEmpty()) {
494 m_sourcesWidget->setShaders(shaderSources);
496 m_sourcesWidget->setShaders(shaderSources);
499 const QList<ApiTexture> &textures =
501 const QList<ApiFramebuffer> &fbos =
502 state.framebuffers();
504 m_ui.surfacesTreeWidget->clear();
505 if (textures.isEmpty() && fbos.isEmpty()) {
506 m_ui.surfacesTab->setDisabled(false);
508 m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
509 if (!textures.isEmpty()) {
510 QTreeWidgetItem *textureItem =
511 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
512 textureItem->setText(0, tr("Textures"));
513 if (textures.count() <= 6)
514 textureItem->setExpanded(true);
516 for (int i = 0; i < textures.count(); ++i) {
517 const ApiTexture &texture =
519 addSurfaceItem(texture, texture.label(),
521 m_ui.surfacesTreeWidget);
524 if (!fbos.isEmpty()) {
525 QTreeWidgetItem *fboItem =
526 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
527 fboItem->setText(0, tr("Framebuffers"));
528 if (fbos.count() <= 6)
529 fboItem->setExpanded(true);
531 for (int i = 0; i < fbos.count(); ++i) {
532 const ApiFramebuffer &fbo =
534 addSurfaceItem(fbo, fbo.type(),
536 m_ui.surfacesTreeWidget);
539 m_ui.surfacesTab->setEnabled(true);
541 m_ui.stateDock->show();
544 void MainWindow::showSettings()
546 SettingsDialog dialog;
547 dialog.setFilterModel(m_proxyModel);
552 void MainWindow::openHelp(const QUrl &url)
554 QDesktopServices::openUrl(url);
557 void MainWindow::showSurfacesMenu(const QPoint &pos)
559 QTreeWidget *tree = m_ui.surfacesTreeWidget;
560 QTreeWidgetItem *item = tree->itemAt(pos);
564 QMenu menu(tr("Surfaces"), this);
566 QAction *act = menu.addAction(tr("View Image"));
567 act->setStatusTip(tr("View the currently selected surface"));
568 connect(act, SIGNAL(triggered()),
569 SLOT(showSelectedSurface()));
571 menu.exec(tree->viewport()->mapToGlobal(pos));
574 void MainWindow::showSelectedSurface()
576 QTreeWidgetItem *item =
577 m_ui.surfacesTreeWidget->currentItem();
582 QVariant var = item->data(0, Qt::UserRole);
583 QImage img = var.value<QImage>();
584 ImageViewer *viewer = new ImageViewer(this);
588 title = tr("QApiTrace - Surface at %1 (%2)")
589 .arg(currentCall()->name())
590 .arg(currentCall()->index());
592 title = tr("QApiTrace - Surface Viewer");
594 viewer->setWindowTitle(title);
595 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
596 viewer->setImage(img);
597 QRect screenRect = QApplication::desktop()->availableGeometry();
598 viewer->resize(qMin(int(0.75 * screenRect.width()), img.width()) + 40,
599 qMin(int(0.75 * screenRect.height()), img.height()) + 40);
602 viewer->activateWindow();
605 void MainWindow::initObjects()
607 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
609 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
610 QVBoxLayout *layout = new QVBoxLayout;
611 layout->addWidget(m_sourcesWidget);
612 m_ui.shadersTab->setLayout(layout);
614 m_trace = new ApiTrace();
615 m_retracer = new Retracer(this);
617 m_vdataInterpreter = new VertexDataInterpreter(this);
618 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
619 m_vdataInterpreter->setStride(
620 m_ui.vertexStrideSB->value());
621 m_vdataInterpreter->setComponents(
622 m_ui.vertexComponentsSB->value());
623 m_vdataInterpreter->setStartingOffset(
624 m_ui.startingOffsetSB->value());
625 m_vdataInterpreter->setTypeFromString(
626 m_ui.vertexTypeCB->currentText());
628 m_model = new ApiTraceModel();
629 m_model->setApiTrace(m_trace);
630 m_proxyModel = new ApiTraceFilter();
631 m_proxyModel->setSourceModel(m_model);
632 m_ui.callView->setModel(m_proxyModel);
633 m_ui.callView->setItemDelegate(
634 new ApiCallDelegate(m_ui.callView));
635 m_ui.callView->resizeColumnToContents(0);
636 m_ui.callView->header()->swapSections(0, 1);
637 m_ui.callView->setColumnWidth(1, 42);
638 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
640 m_progressBar = new QProgressBar();
641 m_progressBar->setRange(0, 0);
642 statusBar()->addPermanentWidget(m_progressBar);
643 m_progressBar->hide();
645 m_argsEditor = new ArgumentsEditor(this);
647 m_ui.detailsDock->hide();
648 m_ui.errorsDock->hide();
649 m_ui.vertexDataDock->hide();
650 m_ui.stateDock->hide();
651 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
653 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
654 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
656 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
658 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
659 QWebPage::DelegateExternalLinks);
661 m_jumpWidget = new JumpWidget(this);
662 m_ui.centralLayout->addWidget(m_jumpWidget);
663 m_jumpWidget->hide();
665 m_searchWidget = new SearchWidget(this);
666 m_ui.centralLayout->addWidget(m_searchWidget);
667 m_searchWidget->hide();
669 m_traceProcess = new TraceProcess(this);
672 void MainWindow::initConnections()
674 connect(m_trace, SIGNAL(startedLoadingTrace()),
675 this, SLOT(startedLoadingTrace()));
676 connect(m_trace, SIGNAL(finishedLoadingTrace()),
677 this, SLOT(finishedLoadingTrace()));
678 connect(m_trace, SIGNAL(startedSaving()),
679 this, SLOT(slotStartedSaving()));
680 connect(m_trace, SIGNAL(saved()),
681 this, SLOT(slotSaved()));
682 connect(m_trace, SIGNAL(changed(ApiTraceCall*)),
683 this, SLOT(slotTraceChanged(ApiTraceCall*)));
685 connect(m_retracer, SIGNAL(finished(const QString&)),
686 this, SLOT(replayFinished(const QString&)));
687 connect(m_retracer, SIGNAL(error(const QString&)),
688 this, SLOT(replayError(const QString&)));
689 connect(m_retracer, SIGNAL(foundState(const ApiTraceState&)),
690 this, SLOT(replayStateFound(const ApiTraceState&)));
691 connect(m_retracer, SIGNAL(retraceErrors(const QList<RetraceError>&)),
692 this, SLOT(slotRetraceErrors(const QList<RetraceError>&)));
694 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
695 m_vdataInterpreter, SLOT(interpretData()));
696 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
697 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
698 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
699 m_vdataInterpreter, SLOT(setStride(int)));
700 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
701 m_vdataInterpreter, SLOT(setComponents(int)));
702 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
703 m_vdataInterpreter, SLOT(setStartingOffset(int)));
706 connect(m_ui.actionNew, SIGNAL(triggered()),
707 this, SLOT(createTrace()));
708 connect(m_ui.actionOpen, SIGNAL(triggered()),
709 this, SLOT(openTrace()));
710 connect(m_ui.actionQuit, SIGNAL(triggered()),
711 this, SLOT(close()));
713 connect(m_ui.actionFind, SIGNAL(triggered()),
714 this, SLOT(slotSearch()));
715 connect(m_ui.actionGo, SIGNAL(triggered()),
716 this, SLOT(slotGoTo()));
717 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
718 this, SLOT(slotGoFrameStart()));
719 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
720 this, SLOT(slotGoFrameEnd()));
722 connect(m_ui.actionReplay, SIGNAL(triggered()),
723 this, SLOT(replayStart()));
724 connect(m_ui.actionStop, SIGNAL(triggered()),
725 this, SLOT(replayStop()));
726 connect(m_ui.actionLookupState, SIGNAL(triggered()),
727 this, SLOT(lookupState()));
728 connect(m_ui.actionOptions, SIGNAL(triggered()),
729 this, SLOT(showSettings()));
731 connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
732 this, SLOT(callItemSelected(const QModelIndex &)));
733 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
734 this, SLOT(customContextMenuRequested(QPoint)));
736 connect(m_ui.surfacesTreeWidget,
737 SIGNAL(customContextMenuRequested(const QPoint &)),
738 SLOT(showSurfacesMenu(const QPoint &)));
739 connect(m_ui.surfacesTreeWidget,
740 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
741 SLOT(showSelectedSurface()));
743 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
744 this, SLOT(openHelp(const QUrl&)));
746 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
747 this, SLOT(fillState(bool)));
749 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
750 SLOT(slotJumpTo(int)));
752 connect(m_searchWidget,
753 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
754 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
755 connect(m_searchWidget,
756 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
757 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
759 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
760 SLOT(createdTrace(const QString&)));
761 connect(m_traceProcess, SIGNAL(error(const QString&)),
762 SLOT(traceError(const QString&)));
764 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
765 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
766 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
767 m_ui.errorsDock, SLOT(setVisible(bool)));
768 connect(m_ui.errorsTreeWidget,
769 SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
770 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
773 void MainWindow::replayStateFound(const ApiTraceState &state)
775 m_stateEvent->setState(state);
776 m_model->stateSetOnEvent(m_stateEvent);
777 if (m_selectedEvent == m_stateEvent ||
778 m_nonDefaultsLookupEvent == m_selectedEvent) {
781 m_ui.stateDock->hide();
783 m_nonDefaultsLookupEvent = 0;
786 void MainWindow::slotGoTo()
788 m_searchWidget->hide();
789 m_jumpWidget->show();
792 void MainWindow::slotJumpTo(int callNum)
794 QModelIndex index = m_proxyModel->callIndex(callNum);
795 if (index.isValid()) {
796 m_ui.callView->setCurrentIndex(index);
800 void MainWindow::createdTrace(const QString &path)
802 qDebug()<<"Done tracing "<<path;
806 void MainWindow::traceError(const QString &msg)
808 QMessageBox::warning(
814 void MainWindow::slotSearch()
816 m_jumpWidget->hide();
817 m_searchWidget->show();
820 void MainWindow::slotSearchNext(const QString &str,
821 Qt::CaseSensitivity sensitivity)
823 QModelIndex index = m_ui.callView->currentIndex();
824 ApiTraceEvent *event = 0;
827 if (!index.isValid()) {
828 index = m_proxyModel->index(0, 0, QModelIndex());
829 if (!index.isValid()) {
830 qDebug()<<"no currently valid index";
831 m_searchWidget->setFound(false);
836 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
837 ApiTraceCall *call = 0;
839 if (event->type() == ApiTraceCall::Call)
840 call = static_cast<ApiTraceCall*>(event);
842 Q_ASSERT(event->type() == ApiTraceCall::Frame);
843 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
844 call = frame->call(0);
848 m_searchWidget->setFound(false);
851 const QList<ApiTraceCall*> &calls = m_trace->calls();
852 int callNum = calls.indexOf(call);
854 for (int i = callNum + 1; i < calls.count(); ++i) {
855 ApiTraceCall *testCall = calls[i];
856 QModelIndex index = m_proxyModel->indexForCall(testCall);
857 /* if it's not valid it means that the proxy model has already
859 if (index.isValid()) {
860 QString txt = testCall->filterText();
861 if (txt.contains(str, sensitivity)) {
862 m_ui.callView->setCurrentIndex(index);
863 m_searchWidget->setFound(true);
868 m_searchWidget->setFound(false);
871 void MainWindow::slotSearchPrev(const QString &str,
872 Qt::CaseSensitivity sensitivity)
874 QModelIndex index = m_ui.callView->currentIndex();
875 ApiTraceEvent *event = 0;
878 if (!index.isValid()) {
879 index = m_proxyModel->index(0, 0, QModelIndex());
880 if (!index.isValid()) {
881 qDebug()<<"no currently valid index";
882 m_searchWidget->setFound(false);
887 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
888 ApiTraceCall *call = 0;
890 if (event->type() == ApiTraceCall::Call)
891 call = static_cast<ApiTraceCall*>(event);
893 Q_ASSERT(event->type() == ApiTraceCall::Frame);
894 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
895 call = frame->call(0);
899 m_searchWidget->setFound(false);
902 const QList<ApiTraceCall*> &calls = m_trace->calls();
903 int callNum = calls.indexOf(call);
905 for (int i = callNum - 1; i >= 0; --i) {
906 ApiTraceCall *testCall = calls[i];
907 QModelIndex index = m_proxyModel->indexForCall(testCall);
908 /* if it's not valid it means that the proxy model has already
910 if (index.isValid()) {
911 QString txt = testCall->filterText();
912 if (txt.contains(str, sensitivity)) {
913 m_ui.callView->setCurrentIndex(index);
914 m_searchWidget->setFound(true);
919 m_searchWidget->setFound(false);
922 void MainWindow::fillState(bool nonDefaults)
925 ApiTraceState defaultState = m_trace->defaultState();
926 if (defaultState.isEmpty()) {
927 m_ui.nonDefaultsCB->blockSignals(true);
928 m_ui.nonDefaultsCB->setChecked(false);
929 m_ui.nonDefaultsCB->blockSignals(false);
930 ApiTraceFrame *firstFrame =
932 ApiTraceEvent *oldSelected = m_selectedEvent;
935 m_nonDefaultsLookupEvent = m_selectedEvent;
936 m_selectedEvent = firstFrame;
938 m_selectedEvent = oldSelected;
944 void MainWindow::customContextMenuRequested(QPoint pos)
947 QModelIndex index = m_ui.callView->indexAt(pos);
949 callItemSelected(index);
950 if (!index.isValid())
953 ApiTraceEvent *event =
954 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
958 menu.addAction(QIcon(":/resources/media-record.png"),
959 tr("Lookup state"), this, SLOT(lookupState()));
960 if (event->type() == ApiTraceEvent::Call) {
961 menu.addAction(tr("Edit"), this, SLOT(editCall()));
964 menu.exec(QCursor::pos());
967 void MainWindow::editCall()
969 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
970 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
971 m_argsEditor->setCall(call);
972 m_argsEditor->show();
976 void MainWindow::slotStartedSaving()
978 m_progressBar->show();
979 statusBar()->showMessage(
980 tr("Saving to %1").arg(m_trace->fileName()));
983 void MainWindow::slotSaved()
985 statusBar()->showMessage(
986 tr("Saved to %1").arg(m_trace->fileName()), 2000);
987 m_progressBar->hide();
990 void MainWindow::slotGoFrameStart()
992 ApiTraceFrame *frame = currentFrame();
993 if (!frame || frame->isEmpty()) {
997 QList<ApiTraceCall*>::const_iterator itr;
998 QList<ApiTraceCall*> calls = frame->calls();
1000 itr = calls.constBegin();
1001 while (itr != calls.constEnd()) {
1002 ApiTraceCall *call = *itr;
1003 QModelIndex idx = m_proxyModel->indexForCall(call);
1004 if (idx.isValid()) {
1005 m_ui.callView->setCurrentIndex(idx);
1012 void MainWindow::slotGoFrameEnd()
1014 ApiTraceFrame *frame = currentFrame();
1015 if (!frame || frame->isEmpty()) {
1018 QList<ApiTraceCall*>::const_iterator itr;
1019 QList<ApiTraceCall*> calls = frame->calls();
1021 itr = calls.constEnd();
1024 ApiTraceCall *call = *itr;
1025 QModelIndex idx = m_proxyModel->indexForCall(call);
1026 if (idx.isValid()) {
1027 m_ui.callView->setCurrentIndex(idx);
1030 } while (itr != calls.constBegin());
1033 ApiTraceFrame * MainWindow::currentFrame() const
1035 if (m_selectedEvent) {
1036 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
1037 return static_cast<ApiTraceFrame*>(m_selectedEvent);
1039 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1040 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1041 return call->parentFrame();
1047 void MainWindow::slotTraceChanged(ApiTraceCall *call)
1050 if (call == m_selectedEvent) {
1051 m_ui.detailsWebView->setHtml(call->toHtml());
1055 void MainWindow::slotRetraceErrors(const QList<RetraceError> &errors)
1057 m_ui.errorsTreeWidget->clear();
1059 foreach(RetraceError error, errors) {
1060 ApiTraceCall *call = m_trace->callWithIndex(error.callIndex);
1063 call->setError(error.message);
1065 QTreeWidgetItem *item =
1066 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1067 item->setData(0, Qt::DisplayRole, error.callIndex);
1068 item->setData(0, Qt::UserRole, QVariant::fromValue(call));
1069 QString type = error.type;
1070 type[0] = type[0].toUpper();
1071 item->setData(1, Qt::DisplayRole, type);
1072 item->setData(2, Qt::DisplayRole, error.message);
1076 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1079 ApiTraceCall *call =
1080 current->data(0, Qt::UserRole).value<ApiTraceCall*>();
1082 QModelIndex index = m_proxyModel->indexForCall(call);
1083 if (index.isValid()) {
1084 m_ui.callView->setCurrentIndex(index);
1086 statusBar()->showMessage(tr("Call has been filtered out."));
1091 ApiTraceCall * MainWindow::currentCall() const
1093 if (m_selectedEvent &&
1094 m_selectedEvent->type() == ApiTraceEvent::Call) {
1095 return static_cast<ApiTraceCall*>(m_selectedEvent);
1100 #include "mainwindow.moc"