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()
47 void MainWindow::createTrace()
51 if (!m_traceProcess->canTrace()) {
55 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.detailsWebView->setHtml(call->toHtml());
101 m_ui.detailsDock->show();
102 if (call->hasBinaryData()) {
104 call->arguments()[call->binaryDataIndex()].toByteArray();
105 m_vdataInterpreter->setData(data);
106 QVariantList args = call->arguments();
108 for (int i = 0; i < call->argNames().count(); ++i) {
109 QString name = call->argNames()[i];
110 if (name == QLatin1String("stride")) {
111 int stride = args[i].toInt();
112 m_ui.vertexStrideSB->setValue(stride);
113 } else if (name == QLatin1String("size")) {
114 int components = args[i].toInt();
115 m_ui.vertexComponentsSB->setValue(components);
116 } else if (name == QLatin1String("type")) {
117 QString val = args[i].toString();
118 int textIndex = m_ui.vertexTypeCB->findText(val);
120 m_ui.vertexTypeCB->setCurrentIndex(textIndex);
124 m_ui.vertexDataDock->setVisible(call->hasBinaryData());
125 m_selectedEvent = call;
127 if (event && event->type() == ApiTraceEvent::Frame) {
128 m_selectedEvent = static_cast<ApiTraceFrame*>(event);
131 m_ui.detailsDock->hide();
132 m_ui.vertexDataDock->hide();
134 if (m_selectedEvent && !m_selectedEvent->state().isEmpty()) {
137 m_ui.stateDock->hide();
140 void MainWindow::replayStart()
142 if (m_trace->isSaving()) {
143 QMessageBox::warning(
146 tr("QApiTrace is currently saving the edited trace file. "
147 "Please wait until it finishes and try again."));
151 Ui_RetracerDialog dlgUi;
154 dlgUi.doubleBufferingCB->setChecked(
155 m_retracer->isDoubleBuffered());
156 dlgUi.errorCheckCB->setChecked(
157 !m_retracer->isBenchmarking());
159 if (dlg.exec() == QDialog::Accepted) {
160 m_retracer->setDoubleBuffered(
161 dlgUi.doubleBufferingCB->isChecked());
162 m_retracer->setBenchmarking(
163 !dlgUi.errorCheckCB->isChecked());
168 void MainWindow::replayStop()
171 m_ui.actionStop->setEnabled(false);
172 m_ui.actionReplay->setEnabled(true);
173 m_ui.actionLookupState->setEnabled(true);
176 void MainWindow::newTraceFile(const QString &fileName)
178 qDebug()<< "Loading : " <<fileName;
180 m_progressBar->setValue(0);
181 m_trace->setFileName(fileName);
183 if (fileName.isEmpty()) {
184 m_ui.actionReplay->setEnabled(false);
185 m_ui.actionLookupState->setEnabled(false);
186 setWindowTitle(tr("QApiTrace"));
188 QFileInfo info(fileName);
189 m_ui.actionReplay->setEnabled(true);
190 m_ui.actionLookupState->setEnabled(true);
192 tr("QApiTrace - %1").arg(info.fileName()));
196 void MainWindow::replayFinished(const QString &output)
198 m_ui.actionStop->setEnabled(false);
199 m_ui.actionReplay->setEnabled(true);
200 m_ui.actionLookupState->setEnabled(true);
202 m_progressBar->hide();
203 if (output.length() < 80) {
204 statusBar()->showMessage(output);
207 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
208 m_ui.errorsDock->setVisible(m_trace->hasErrors());
209 if (!m_trace->hasErrors())
210 m_ui.errorsTreeWidget->clear();
212 statusBar()->showMessage(
213 tr("Replaying finished!"), 2000);
216 void MainWindow::replayError(const QString &message)
218 m_ui.actionStop->setEnabled(false);
219 m_ui.actionReplay->setEnabled(true);
220 m_ui.actionLookupState->setEnabled(true);
223 m_progressBar->hide();
224 statusBar()->showMessage(
225 tr("Replaying unsuccessful."), 2000);
226 QMessageBox::warning(
227 this, tr("Replay Failed"), message);
230 void MainWindow::startedLoadingTrace()
233 m_progressBar->show();
234 QFileInfo info(m_trace->fileName());
235 statusBar()->showMessage(
236 tr("Loading %1...").arg(info.fileName()));
239 void MainWindow::finishedLoadingTrace()
241 m_progressBar->hide();
245 QFileInfo info(m_trace->fileName());
246 statusBar()->showMessage(
247 tr("Loaded %1").arg(info.fileName()), 3000);
250 void MainWindow::replayTrace(bool dumpState)
252 if (m_trace->fileName().isEmpty())
255 m_retracer->setFileName(m_trace->fileName());
256 m_retracer->setCaptureState(dumpState);
257 if (m_retracer->captureState() && m_selectedEvent) {
259 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
260 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
261 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
262 ApiTraceFrame *frame =
263 static_cast<ApiTraceFrame*>(m_selectedEvent);
264 if (frame->isEmpty()) {
265 //XXX i guess we could still get the current state
266 qDebug()<<"tried to get a state for an empty frame";
269 index = frame->calls().first()->index();
271 qDebug()<<"Unknown event type";
274 m_retracer->setCaptureAtCallNumber(index);
278 m_ui.actionStop->setEnabled(true);
279 m_progressBar->show();
281 statusBar()->showMessage(
282 tr("Looking up the state..."));
284 statusBar()->showMessage(
285 tr("Replaying the trace file..."));
288 void MainWindow::lookupState()
290 if (!m_selectedEvent) {
291 QMessageBox::warning(
292 this, tr("Unknown Event"),
293 tr("To inspect the state select an event in the event list."));
296 if (m_trace->isSaving()) {
297 QMessageBox::warning(
300 tr("QApiTrace is currently saving the edited trace file. "
301 "Please wait until it finishes and try again."));
304 m_stateEvent = m_selectedEvent;
308 MainWindow::~MainWindow()
318 variantToString(const QVariant &var, QString &str)
320 if (var.type() == QVariant::List) {
321 QVariantList lst = var.toList();
322 str += QLatin1String("[");
323 for (int i = 0; i < lst.count(); ++i) {
324 QVariant val = lst[i];
325 variantToString(val, str);
326 if (i < lst.count() - 1)
327 str += QLatin1String(", ");
329 str += QLatin1String("]");
330 } else if (var.type() == QVariant::Map) {
331 Q_ASSERT(!"unsupported state type");
332 } else if (var.type() == QVariant::Hash) {
333 Q_ASSERT(!"unsupported state type");
335 str += var.toString();
339 static QTreeWidgetItem *
340 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar);
343 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap, QList<QTreeWidgetItem *> &items)
345 QVariantMap::const_iterator itr;
346 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
347 QString key = itr.key();
348 QVariant var = itr.value();
349 QVariant defaultVar = defaultMap[key];
351 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
359 variantListToItems(const QVariantList &lst, const QVariantList &defaultLst, QList<QTreeWidgetItem *> &items)
361 for (int i = 0; i < lst.count(); ++i) {
362 QString key = QString::number(i);
363 QVariant var = lst[i];
366 if (i < defaultLst.count()) {
367 defaultVar = defaultLst[i];
370 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
378 isVariantDeep(const QVariant &var)
380 if (var.type() == QVariant::List) {
381 QVariantList lst = var.toList();
382 for (int i = 0; i < lst.count(); ++i) {
383 if (isVariantDeep(lst[i])) {
388 } else if (var.type() == QVariant::Map) {
390 } else if (var.type() == QVariant::Hash) {
397 static QTreeWidgetItem *
398 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar)
400 if (var == defaultVar) {
406 bool deep = isVariantDeep(var);
408 variantToString(var, val);
411 //qDebug()<<"key = "<<key;
412 //qDebug()<<"val = "<<val;
417 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
420 QList<QTreeWidgetItem *> children;
421 if (var.type() == QVariant::Map) {
422 QVariantMap map = var.toMap();
423 QVariantMap defaultMap = defaultVar.toMap();
424 variantMapToItems(map, defaultMap, children);
426 if (var.type() == QVariant::List) {
427 QVariantList lst = var.toList();
428 QVariantList defaultLst = defaultVar.toList();
429 variantListToItems(lst, defaultLst, children);
431 item->addChildren(children);
437 void MainWindow::fillStateForFrame()
441 if (!m_selectedEvent || m_selectedEvent->state().isEmpty())
444 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
445 QVariantMap defaultParams;
447 ApiTraceState defaultState = m_trace->defaultState();
448 defaultParams = defaultState.parameters();
451 const ApiTraceState &state = m_selectedEvent->state();
452 m_ui.stateTreeWidget->clear();
453 params = state.parameters();
454 QList<QTreeWidgetItem *> items;
455 variantMapToItems(params, defaultParams, items);
456 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
458 QMap<QString, QString> shaderSources = state.shaderSources();
459 if (shaderSources.isEmpty()) {
460 m_sourcesWidget->setShaders(shaderSources);
462 m_sourcesWidget->setShaders(shaderSources);
465 const QList<ApiTexture> &textures =
467 const QList<ApiFramebuffer> &fbos =
468 state.framebuffers();
470 m_ui.surfacesTreeWidget->clear();
471 if (textures.isEmpty() && fbos.isEmpty()) {
472 m_ui.surfacesTab->setDisabled(false);
474 m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
475 if (!textures.isEmpty()) {
476 QTreeWidgetItem *textureItem =
477 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
478 textureItem->setText(0, tr("Textures"));
479 if (textures.count() <= 6)
480 textureItem->setExpanded(true);
482 for (int i = 0; i < textures.count(); ++i) {
483 const ApiTexture &texture =
485 QIcon icon(QPixmap::fromImage(texture.thumb()));
486 QTreeWidgetItem *item = new QTreeWidgetItem(textureItem);
487 item->setIcon(0, icon);
488 int width = texture.size().width();
489 int height = texture.size().height();
491 QString::fromLatin1("%1, %2 x %3")
492 .arg(texture.target())
495 item->setText(1, descr);
497 item->setData(0, Qt::UserRole,
501 if (!fbos.isEmpty()) {
502 QTreeWidgetItem *fboItem =
503 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
504 fboItem->setText(0, tr("Framebuffers"));
505 if (fbos.count() <= 6)
506 fboItem->setExpanded(true);
508 for (int i = 0; i < fbos.count(); ++i) {
509 const ApiFramebuffer &fbo =
511 QIcon icon(QPixmap::fromImage(fbo.thumb()));
512 QTreeWidgetItem *item = new QTreeWidgetItem(fboItem);
513 item->setIcon(0, icon);
514 int width = fbo.size().width();
515 int height = fbo.size().height();
517 QString::fromLatin1("%1, %2 x %3")
521 item->setText(1, descr);
523 item->setData(0, Qt::UserRole,
527 m_ui.surfacesTab->setEnabled(true);
529 m_ui.stateDock->show();
532 void MainWindow::showSettings()
534 SettingsDialog dialog;
535 dialog.setFilterModel(m_proxyModel);
540 void MainWindow::openHelp(const QUrl &url)
542 QDesktopServices::openUrl(url);
545 void MainWindow::showSurfacesMenu(const QPoint &pos)
547 QTreeWidget *tree = m_ui.surfacesTreeWidget;
548 QTreeWidgetItem *item = tree->itemAt(pos);
552 QMenu menu(tr("Surfaces"), this);
554 QAction *act = menu.addAction(tr("View Image"));
555 act->setStatusTip(tr("View the currently selected surface"));
556 connect(act, SIGNAL(triggered()),
557 SLOT(showSelectedSurface()));
559 menu.exec(tree->viewport()->mapToGlobal(pos));
562 void MainWindow::showSelectedSurface()
564 QTreeWidgetItem *item =
565 m_ui.surfacesTreeWidget->currentItem();
570 QVariant var = item->data(0, Qt::UserRole);
571 QImage img = var.value<QImage>();
572 ImageViewer *viewer = new ImageViewer(this);
576 title = tr("QApiTrace - Surface at %1 (%2)")
577 .arg(currentCall()->name())
578 .arg(currentCall()->index());
580 title = tr("QApiTrace - Surface Viewer");
582 viewer->setWindowTitle(title);
583 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
584 viewer->setImage(img);
585 QRect screenRect = QApplication::desktop()->availableGeometry();
586 viewer->resize(qMin(int(0.75 * screenRect.width()), img.width()) + 40,
587 qMin(int(0.75 * screenRect.height()), img.height()) + 40);
590 viewer->activateWindow();
593 void MainWindow::initObjects()
595 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
597 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
598 QVBoxLayout *layout = new QVBoxLayout;
599 layout->addWidget(m_sourcesWidget);
600 m_ui.shadersTab->setLayout(layout);
602 m_trace = new ApiTrace();
603 m_retracer = new Retracer(this);
605 m_vdataInterpreter = new VertexDataInterpreter(this);
606 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
607 m_vdataInterpreter->setStride(
608 m_ui.vertexStrideSB->value());
609 m_vdataInterpreter->setComponents(
610 m_ui.vertexComponentsSB->value());
611 m_vdataInterpreter->setStartingOffset(
612 m_ui.startingOffsetSB->value());
613 m_vdataInterpreter->setTypeFromString(
614 m_ui.vertexTypeCB->currentText());
616 m_model = new ApiTraceModel();
617 m_model->setApiTrace(m_trace);
618 m_proxyModel = new ApiTraceFilter();
619 m_proxyModel->setSourceModel(m_model);
620 m_ui.callView->setModel(m_proxyModel);
621 m_ui.callView->setItemDelegate(
622 new ApiCallDelegate(m_ui.callView));
623 m_ui.callView->resizeColumnToContents(0);
624 m_ui.callView->header()->swapSections(0, 1);
625 m_ui.callView->setColumnWidth(1, 42);
626 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
628 m_progressBar = new QProgressBar();
629 m_progressBar->setRange(0, 0);
630 statusBar()->addPermanentWidget(m_progressBar);
631 m_progressBar->hide();
633 m_argsEditor = new ArgumentsEditor(this);
635 m_ui.detailsDock->hide();
636 m_ui.errorsDock->hide();
637 m_ui.vertexDataDock->hide();
638 m_ui.stateDock->hide();
639 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
641 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
642 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
644 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
646 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
647 QWebPage::DelegateExternalLinks);
649 m_jumpWidget = new JumpWidget(this);
650 m_ui.centralLayout->addWidget(m_jumpWidget);
651 m_jumpWidget->hide();
653 m_searchWidget = new SearchWidget(this);
654 m_ui.centralLayout->addWidget(m_searchWidget);
655 m_searchWidget->hide();
657 m_traceProcess = new TraceProcess(this);
660 void MainWindow::initConnections()
662 connect(m_trace, SIGNAL(startedLoadingTrace()),
663 this, SLOT(startedLoadingTrace()));
664 connect(m_trace, SIGNAL(finishedLoadingTrace()),
665 this, SLOT(finishedLoadingTrace()));
666 connect(m_trace, SIGNAL(startedSaving()),
667 this, SLOT(slotStartedSaving()));
668 connect(m_trace, SIGNAL(saved()),
669 this, SLOT(slotSaved()));
670 connect(m_trace, SIGNAL(changed(ApiTraceCall*)),
671 this, SLOT(slotTraceChanged(ApiTraceCall*)));
673 connect(m_retracer, SIGNAL(finished(const QString&)),
674 this, SLOT(replayFinished(const QString&)));
675 connect(m_retracer, SIGNAL(error(const QString&)),
676 this, SLOT(replayError(const QString&)));
677 connect(m_retracer, SIGNAL(foundState(const ApiTraceState&)),
678 this, SLOT(replayStateFound(const ApiTraceState&)));
679 connect(m_retracer, SIGNAL(retraceErrors(const QList<RetraceError>&)),
680 this, SLOT(slotRetraceErrors(const QList<RetraceError>&)));
682 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
683 m_vdataInterpreter, SLOT(interpretData()));
684 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
685 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
686 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
687 m_vdataInterpreter, SLOT(setStride(int)));
688 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
689 m_vdataInterpreter, SLOT(setComponents(int)));
690 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
691 m_vdataInterpreter, SLOT(setStartingOffset(int)));
694 connect(m_ui.actionNew, SIGNAL(triggered()),
695 this, SLOT(createTrace()));
696 connect(m_ui.actionOpen, SIGNAL(triggered()),
697 this, SLOT(openTrace()));
698 connect(m_ui.actionQuit, SIGNAL(triggered()),
699 this, SLOT(close()));
701 connect(m_ui.actionFind, SIGNAL(triggered()),
702 this, SLOT(slotSearch()));
703 connect(m_ui.actionGo, SIGNAL(triggered()),
704 this, SLOT(slotGoTo()));
705 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
706 this, SLOT(slotGoFrameStart()));
707 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
708 this, SLOT(slotGoFrameEnd()));
710 connect(m_ui.actionReplay, SIGNAL(triggered()),
711 this, SLOT(replayStart()));
712 connect(m_ui.actionStop, SIGNAL(triggered()),
713 this, SLOT(replayStop()));
714 connect(m_ui.actionLookupState, SIGNAL(triggered()),
715 this, SLOT(lookupState()));
716 connect(m_ui.actionOptions, SIGNAL(triggered()),
717 this, SLOT(showSettings()));
719 connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
720 this, SLOT(callItemSelected(const QModelIndex &)));
721 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
722 this, SLOT(customContextMenuRequested(QPoint)));
724 connect(m_ui.surfacesTreeWidget,
725 SIGNAL(customContextMenuRequested(const QPoint &)),
726 SLOT(showSurfacesMenu(const QPoint &)));
727 connect(m_ui.surfacesTreeWidget,
728 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
729 SLOT(showSelectedSurface()));
731 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
732 this, SLOT(openHelp(const QUrl&)));
734 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
735 this, SLOT(fillState(bool)));
737 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
738 SLOT(slotJumpTo(int)));
740 connect(m_searchWidget,
741 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
742 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
743 connect(m_searchWidget,
744 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
745 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
747 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
748 SLOT(createdTrace(const QString&)));
749 connect(m_traceProcess, SIGNAL(error(const QString&)),
750 SLOT(traceError(const QString&)));
752 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
753 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
754 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
755 m_ui.errorsDock, SLOT(setVisible(bool)));
756 connect(m_ui.errorsTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
757 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
760 void MainWindow::replayStateFound(const ApiTraceState &state)
762 m_stateEvent->setState(state);
763 m_model->stateSetOnEvent(m_stateEvent);
764 if (m_selectedEvent == m_stateEvent) {
767 m_ui.stateDock->hide();
771 void MainWindow::slotGoTo()
773 m_searchWidget->hide();
774 m_jumpWidget->show();
777 void MainWindow::slotJumpTo(int callNum)
779 QModelIndex index = m_proxyModel->callIndex(callNum);
780 if (index.isValid()) {
781 m_ui.callView->setCurrentIndex(index);
785 void MainWindow::createdTrace(const QString &path)
787 qDebug()<<"Done tracing "<<path;
791 void MainWindow::traceError(const QString &msg)
793 QMessageBox::warning(
799 void MainWindow::slotSearch()
801 m_jumpWidget->hide();
802 m_searchWidget->show();
805 void MainWindow::slotSearchNext(const QString &str,
806 Qt::CaseSensitivity sensitivity)
808 QModelIndex index = m_ui.callView->currentIndex();
809 ApiTraceEvent *event = 0;
812 if (!index.isValid()) {
813 index = m_proxyModel->index(0, 0, QModelIndex());
814 if (!index.isValid()) {
815 qDebug()<<"no currently valid index";
816 m_searchWidget->setFound(false);
821 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
822 ApiTraceCall *call = 0;
824 if (event->type() == ApiTraceCall::Call)
825 call = static_cast<ApiTraceCall*>(event);
827 Q_ASSERT(event->type() == ApiTraceCall::Frame);
828 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
829 call = frame->call(0);
833 m_searchWidget->setFound(false);
836 const QList<ApiTraceCall*> &calls = m_trace->calls();
837 int callNum = calls.indexOf(call);
839 for (int i = callNum + 1; i < calls.count(); ++i) {
840 ApiTraceCall *testCall = calls[i];
841 QModelIndex index = m_proxyModel->indexForCall(testCall);
842 /* if it's not valid it means that the proxy model has already
844 if (index.isValid()) {
845 QString txt = testCall->filterText();
846 if (txt.contains(str, sensitivity)) {
847 m_ui.callView->setCurrentIndex(index);
848 m_searchWidget->setFound(true);
853 m_searchWidget->setFound(false);
856 void MainWindow::slotSearchPrev(const QString &str,
857 Qt::CaseSensitivity sensitivity)
859 QModelIndex index = m_ui.callView->currentIndex();
860 ApiTraceEvent *event = 0;
863 if (!index.isValid()) {
864 index = m_proxyModel->index(0, 0, QModelIndex());
865 if (!index.isValid()) {
866 qDebug()<<"no currently valid index";
867 m_searchWidget->setFound(false);
872 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
873 ApiTraceCall *call = 0;
875 if (event->type() == ApiTraceCall::Call)
876 call = static_cast<ApiTraceCall*>(event);
878 Q_ASSERT(event->type() == ApiTraceCall::Frame);
879 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
880 call = frame->call(0);
884 m_searchWidget->setFound(false);
887 const QList<ApiTraceCall*> &calls = m_trace->calls();
888 int callNum = calls.indexOf(call);
890 for (int i = callNum - 1; i >= 0; --i) {
891 ApiTraceCall *testCall = calls[i];
892 QModelIndex index = m_proxyModel->indexForCall(testCall);
893 /* if it's not valid it means that the proxy model has already
895 if (index.isValid()) {
896 QString txt = testCall->filterText();
897 if (txt.contains(str, sensitivity)) {
898 m_ui.callView->setCurrentIndex(index);
899 m_searchWidget->setFound(true);
904 m_searchWidget->setFound(false);
907 void MainWindow::fillState(bool nonDefaults)
910 ApiTraceState defaultState = m_trace->defaultState();
911 if (defaultState.isEmpty()) {
912 m_ui.nonDefaultsCB->blockSignals(true);
913 m_ui.nonDefaultsCB->setChecked(false);
914 m_ui.nonDefaultsCB->blockSignals(false);
915 int ret = QMessageBox::question(
916 this, tr("Empty Default State"),
917 tr("The applcation needs to figure out the "
918 "default state for the current trace. "
919 "This only has to be done once and "
920 "afterwards you will be able to enable "
921 "displaying of non default state for all calls."
922 "\nDo you want to lookup the default state now?"),
923 QMessageBox::Yes | QMessageBox::No);
924 if (ret != QMessageBox::Yes)
926 ApiTraceFrame *firstFrame =
928 ApiTraceEvent *oldSelected = m_selectedEvent;
931 m_selectedEvent = firstFrame;
933 m_selectedEvent = oldSelected;
939 void MainWindow::customContextMenuRequested(QPoint pos)
942 QModelIndex index = m_ui.callView->indexAt(pos);
944 callItemSelected(index);
945 if (!index.isValid())
948 ApiTraceEvent *event =
949 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
950 if (!event || event->type() != ApiTraceEvent::Call)
953 menu.addAction(QIcon(":/resources/media-record.png"),
954 tr("Lookup state"), this, SLOT(lookupState()));
955 menu.addAction(tr("Edit"), this, SLOT(editCall()));
957 menu.exec(QCursor::pos());
960 void MainWindow::editCall()
962 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
963 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
964 m_argsEditor->setCall(call);
965 m_argsEditor->show();
969 void MainWindow::slotStartedSaving()
971 m_progressBar->show();
972 statusBar()->showMessage(
973 tr("Saving to %1").arg(m_trace->fileName()));
976 void MainWindow::slotSaved()
978 statusBar()->showMessage(
979 tr("Saved to %1").arg(m_trace->fileName()), 2000);
980 m_progressBar->hide();
983 void MainWindow::slotGoFrameStart()
985 ApiTraceFrame *frame = currentFrame();
986 if (!frame || frame->isEmpty()) {
990 QList<ApiTraceCall*>::const_iterator itr;
991 QList<ApiTraceCall*> calls = frame->calls();
993 itr = calls.constBegin();
994 while (itr != calls.constEnd()) {
995 ApiTraceCall *call = *itr;
996 QModelIndex idx = m_proxyModel->indexForCall(call);
998 m_ui.callView->setCurrentIndex(idx);
1005 void MainWindow::slotGoFrameEnd()
1007 ApiTraceFrame *frame = currentFrame();
1008 if (!frame || frame->isEmpty()) {
1011 QList<ApiTraceCall*>::const_iterator itr;
1012 QList<ApiTraceCall*> calls = frame->calls();
1014 itr = calls.constEnd();
1017 ApiTraceCall *call = *itr;
1018 QModelIndex idx = m_proxyModel->indexForCall(call);
1019 if (idx.isValid()) {
1020 m_ui.callView->setCurrentIndex(idx);
1023 } while (itr != calls.constBegin());
1026 ApiTraceFrame * MainWindow::currentFrame() const
1028 if (m_selectedEvent) {
1029 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
1030 return static_cast<ApiTraceFrame*>(m_selectedEvent);
1032 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1033 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1034 return call->parentFrame();
1040 void MainWindow::slotTraceChanged(ApiTraceCall *call)
1043 if (call == m_selectedEvent) {
1044 m_ui.detailsWebView->setHtml(call->toHtml());
1048 void MainWindow::slotRetraceErrors(const QList<RetraceError> &errors)
1050 m_ui.errorsTreeWidget->clear();
1052 foreach(RetraceError error, errors) {
1053 ApiTraceCall *call = m_trace->callWithIndex(error.callIndex);
1056 call->setError(error.message);
1058 QTreeWidgetItem *item =
1059 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1060 item->setData(0, Qt::DisplayRole, error.callIndex);
1061 item->setData(0, Qt::UserRole, QVariant::fromValue(call));
1062 QString type = error.type;
1063 type[0] = type[0].toUpper();
1064 item->setData(1, Qt::DisplayRole, type);
1065 item->setData(2, Qt::DisplayRole, error.message);
1069 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1072 ApiTraceCall *call =
1073 current->data(0, Qt::UserRole).value<ApiTraceCall*>();
1075 QModelIndex index = m_proxyModel->indexForCall(call);
1076 if (index.isValid()) {
1077 m_ui.callView->setCurrentIndex(index);
1079 statusBar()->showMessage(tr("Call has been filtered out."));
1084 ApiTraceCall * MainWindow::currentCall() const
1086 if (m_selectedEvent &&
1087 m_selectedEvent->type() == ApiTraceEvent::Call) {
1088 return static_cast<ApiTraceCall*>(m_selectedEvent);
1093 #include "mainwindow.moc"