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 qDebug()<< "File name : " <<fileName;
79 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));
89 qDebug()<< "Loading : " <<fileName;
91 m_progressBar->setValue(0);
92 newTraceFile(fileName);
95 void MainWindow::callItemSelected(const QModelIndex &index)
97 ApiTraceEvent *event =
98 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
100 if (event && event->type() == ApiTraceEvent::Call) {
101 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
102 m_ui.detailsWebView->setHtml(call->toHtml());
103 m_ui.detailsDock->show();
104 if (call->hasBinaryData()) {
106 call->arguments()[call->binaryDataIndex()].toByteArray();
107 m_vdataInterpreter->setData(data);
108 QVariantList args = call->arguments();
110 for (int i = 0; i < call->argNames().count(); ++i) {
111 QString name = call->argNames()[i];
112 if (name == QLatin1String("stride")) {
113 int stride = args[i].toInt();
114 m_ui.vertexStrideSB->setValue(stride);
115 } else if (name == QLatin1String("size")) {
116 int components = args[i].toInt();
117 m_ui.vertexComponentsSB->setValue(components);
118 } else if (name == QLatin1String("type")) {
119 QString val = args[i].toString();
120 int textIndex = m_ui.vertexTypeCB->findText(val);
122 m_ui.vertexTypeCB->setCurrentIndex(textIndex);
126 m_ui.vertexDataDock->setVisible(call->hasBinaryData());
127 m_selectedEvent = call;
129 if (event && event->type() == ApiTraceEvent::Frame) {
130 m_selectedEvent = static_cast<ApiTraceFrame*>(event);
133 m_ui.detailsDock->hide();
134 m_ui.vertexDataDock->hide();
136 if (m_selectedEvent && !m_selectedEvent->state().isEmpty()) {
139 m_ui.stateDock->hide();
142 void MainWindow::replayStart()
144 if (m_trace->isSaving()) {
145 QMessageBox::warning(
148 tr("QApiTrace is currently saving the edited trace file. "
149 "Please wait until it finishes and try again."));
153 Ui_RetracerDialog dlgUi;
156 dlgUi.doubleBufferingCB->setChecked(
157 m_retracer->isDoubleBuffered());
158 dlgUi.errorCheckCB->setChecked(
159 !m_retracer->isBenchmarking());
161 if (dlg.exec() == QDialog::Accepted) {
162 m_retracer->setDoubleBuffered(
163 dlgUi.doubleBufferingCB->isChecked());
164 m_retracer->setBenchmarking(
165 !dlgUi.errorCheckCB->isChecked());
170 void MainWindow::replayStop()
173 m_ui.actionStop->setEnabled(false);
174 m_ui.actionReplay->setEnabled(true);
175 m_ui.actionLookupState->setEnabled(true);
178 void MainWindow::newTraceFile(const QString &fileName)
180 m_trace->setFileName(fileName);
182 if (fileName.isEmpty()) {
183 m_ui.actionReplay->setEnabled(false);
184 m_ui.actionLookupState->setEnabled(false);
185 setWindowTitle(tr("QApiTrace"));
187 QFileInfo info(fileName);
188 m_ui.actionReplay->setEnabled(true);
189 m_ui.actionLookupState->setEnabled(true);
191 tr("QApiTrace - %1").arg(info.fileName()));
195 void MainWindow::replayFinished(const QString &output)
197 m_ui.actionStop->setEnabled(false);
198 m_ui.actionReplay->setEnabled(true);
199 m_ui.actionLookupState->setEnabled(true);
201 m_progressBar->hide();
202 if (output.length() < 80) {
203 statusBar()->showMessage(output);
206 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
207 m_ui.errorsDock->setVisible(m_trace->hasErrors());
208 if (!m_trace->hasErrors())
209 m_ui.errorsTreeWidget->clear();
211 statusBar()->showMessage(
212 tr("Replaying finished!"), 2000);
215 void MainWindow::replayError(const QString &message)
217 m_ui.actionStop->setEnabled(false);
218 m_ui.actionReplay->setEnabled(true);
219 m_ui.actionLookupState->setEnabled(true);
222 m_progressBar->hide();
223 statusBar()->showMessage(
224 tr("Replaying unsuccessful."), 2000);
225 QMessageBox::warning(
226 this, tr("Replay Failed"), message);
229 void MainWindow::startedLoadingTrace()
232 m_progressBar->show();
233 QFileInfo info(m_trace->fileName());
234 statusBar()->showMessage(
235 tr("Loading %1...").arg(info.fileName()));
238 void MainWindow::finishedLoadingTrace()
240 m_progressBar->hide();
244 QFileInfo info(m_trace->fileName());
245 statusBar()->showMessage(
246 tr("Loaded %1").arg(info.fileName()), 3000);
249 void MainWindow::replayTrace(bool dumpState)
251 if (m_trace->fileName().isEmpty())
254 m_retracer->setFileName(m_trace->fileName());
255 m_retracer->setCaptureState(dumpState);
256 if (m_retracer->captureState() && m_selectedEvent) {
258 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
259 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
260 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
261 ApiTraceFrame *frame =
262 static_cast<ApiTraceFrame*>(m_selectedEvent);
263 if (frame->calls.isEmpty()) {
264 //XXX i guess we could still get the current state
265 qDebug()<<"tried to get a state for an empty frame";
268 index = frame->calls.first()->index();
270 qDebug()<<"Unknown event type";
273 m_retracer->setCaptureAtCallNumber(index);
277 m_ui.actionStop->setEnabled(true);
278 m_progressBar->show();
280 statusBar()->showMessage(
281 tr("Looking up the state..."));
283 statusBar()->showMessage(
284 tr("Replaying the trace file..."));
287 void MainWindow::lookupState()
289 if (!m_selectedEvent) {
290 QMessageBox::warning(
291 this, tr("Unknown Event"),
292 tr("To inspect the state select an event in the event list."));
295 if (m_trace->isSaving()) {
296 QMessageBox::warning(
299 tr("QApiTrace is currently saving the edited trace file. "
300 "Please wait until it finishes and try again."));
303 m_stateEvent = m_selectedEvent;
307 MainWindow::~MainWindow()
317 variantToString(const QVariant &var, QString &str)
319 if (var.type() == QVariant::List) {
320 QVariantList lst = var.toList();
321 str += QLatin1String("[");
322 for (int i = 0; i < lst.count(); ++i) {
323 QVariant val = lst[i];
324 variantToString(val, str);
325 if (i < lst.count() - 1)
326 str += QLatin1String(", ");
328 str += QLatin1String("]");
329 } else if (var.type() == QVariant::Map) {
330 Q_ASSERT(!"unsupported state type");
331 } else if (var.type() == QVariant::Hash) {
332 Q_ASSERT(!"unsupported state type");
334 str += var.toString();
338 static QTreeWidgetItem *
339 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar);
342 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap, QList<QTreeWidgetItem *> &items)
344 QVariantMap::const_iterator itr;
345 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
346 QString key = itr.key();
347 QVariant var = itr.value();
348 QVariant defaultVar = defaultMap[key];
350 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
358 variantListToItems(const QVariantList &lst, const QVariantList &defaultLst, QList<QTreeWidgetItem *> &items)
360 for (int i = 0; i < lst.count(); ++i) {
361 QString key = QString::number(i);
362 QVariant var = lst[i];
365 if (i < defaultLst.count()) {
366 defaultVar = defaultLst[i];
369 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
377 isVariantDeep(const QVariant &var)
379 if (var.type() == QVariant::List) {
380 QVariantList lst = var.toList();
381 for (int i = 0; i < lst.count(); ++i) {
382 if (isVariantDeep(lst[i])) {
387 } else if (var.type() == QVariant::Map) {
389 } else if (var.type() == QVariant::Hash) {
396 static QTreeWidgetItem *
397 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar)
399 if (var == defaultVar) {
405 bool deep = isVariantDeep(var);
407 variantToString(var, val);
410 //qDebug()<<"key = "<<key;
411 //qDebug()<<"val = "<<val;
416 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
419 QList<QTreeWidgetItem *> children;
420 if (var.type() == QVariant::Map) {
421 QVariantMap map = var.toMap();
422 QVariantMap defaultMap = defaultVar.toMap();
423 variantMapToItems(map, defaultMap, children);
425 if (var.type() == QVariant::List) {
426 QVariantList lst = var.toList();
427 QVariantList defaultLst = defaultVar.toList();
428 variantListToItems(lst, defaultLst, children);
430 item->addChildren(children);
436 void MainWindow::fillStateForFrame()
440 if (!m_selectedEvent || m_selectedEvent->state().isEmpty())
443 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
444 QVariantMap defaultParams;
446 ApiTraceState defaultState = m_trace->defaultState();
447 defaultParams = defaultState.parameters();
450 const ApiTraceState &state = m_selectedEvent->state();
451 m_ui.stateTreeWidget->clear();
452 params = state.parameters();
453 QList<QTreeWidgetItem *> items;
454 variantMapToItems(params, defaultParams, items);
455 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
457 QMap<QString, QString> shaderSources = state.shaderSources();
458 if (shaderSources.isEmpty()) {
459 m_sourcesWidget->setShaders(shaderSources);
461 m_sourcesWidget->setShaders(shaderSources);
464 const QList<ApiTexture> &textures =
466 const QList<ApiFramebuffer> &fbos =
467 state.framebuffers();
469 m_ui.surfacesTreeWidget->clear();
470 if (textures.isEmpty() && fbos.isEmpty()) {
471 m_ui.surfacesTab->setDisabled(false);
473 m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
474 if (!textures.isEmpty()) {
475 QTreeWidgetItem *textureItem =
476 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
477 textureItem->setText(0, tr("Textures"));
478 if (textures.count() <= 6)
479 textureItem->setExpanded(true);
481 for (int i = 0; i < textures.count(); ++i) {
482 const ApiTexture &texture =
484 QIcon icon(QPixmap::fromImage(texture.thumb()));
485 QTreeWidgetItem *item = new QTreeWidgetItem(textureItem);
486 item->setIcon(0, icon);
487 int width = texture.size().width();
488 int height = texture.size().height();
490 QString::fromLatin1("%1, %2 x %3")
491 .arg(texture.target())
494 item->setText(1, descr);
496 item->setData(0, Qt::UserRole,
500 if (!fbos.isEmpty()) {
501 QTreeWidgetItem *fboItem =
502 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
503 fboItem->setText(0, tr("Framebuffers"));
504 if (fbos.count() <= 6)
505 fboItem->setExpanded(true);
507 for (int i = 0; i < fbos.count(); ++i) {
508 const ApiFramebuffer &fbo =
510 QIcon icon(QPixmap::fromImage(fbo.thumb()));
511 QTreeWidgetItem *item = new QTreeWidgetItem(fboItem);
512 item->setIcon(0, icon);
513 int width = fbo.size().width();
514 int height = fbo.size().height();
516 QString::fromLatin1("%1, %2 x %3")
520 item->setText(1, descr);
522 item->setData(0, Qt::UserRole,
526 m_ui.surfacesTab->setEnabled(true);
528 m_ui.stateDock->show();
531 void MainWindow::showSettings()
533 SettingsDialog dialog;
534 dialog.setFilterModel(m_proxyModel);
539 void MainWindow::openHelp(const QUrl &url)
541 QDesktopServices::openUrl(url);
544 void MainWindow::showSurfacesMenu(const QPoint &pos)
546 QTreeWidget *tree = m_ui.surfacesTreeWidget;
547 QTreeWidgetItem *item = tree->itemAt(pos);
551 QMenu menu(tr("Surfaces"), this);
553 QAction *act = menu.addAction(tr("View Image"));
554 act->setStatusTip(tr("View the currently selected surface"));
555 connect(act, SIGNAL(triggered()),
556 SLOT(showSelectedSurface()));
558 menu.exec(tree->viewport()->mapToGlobal(pos));
561 void MainWindow::showSelectedSurface()
563 QTreeWidgetItem *item =
564 m_ui.surfacesTreeWidget->currentItem();
569 QVariant var = item->data(0, Qt::UserRole);
570 QImage img = var.value<QImage>();
571 ImageViewer *viewer = new ImageViewer(this);
575 title = tr("QApiTrace - Surface at %1 (%2)")
576 .arg(currentCall()->name())
577 .arg(currentCall()->index());
579 title = tr("QApiTrace - Surface Viewer");
581 viewer->setWindowTitle(title);
582 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
583 viewer->setImage(img);
584 QRect screenRect = QApplication::desktop()->availableGeometry();
585 viewer->resize(qMin(int(0.75 * screenRect.width()), img.width()) + 40,
586 qMin(int(0.75 * screenRect.height()), img.height()) + 40);
589 viewer->activateWindow();
592 void MainWindow::initObjects()
594 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
596 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
597 QVBoxLayout *layout = new QVBoxLayout;
598 layout->addWidget(m_sourcesWidget);
599 m_ui.shadersTab->setLayout(layout);
601 m_trace = new ApiTrace();
602 m_retracer = new Retracer(this);
604 m_vdataInterpreter = new VertexDataInterpreter(this);
605 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
606 m_vdataInterpreter->setStride(
607 m_ui.vertexStrideSB->value());
608 m_vdataInterpreter->setComponents(
609 m_ui.vertexComponentsSB->value());
610 m_vdataInterpreter->setStartingOffset(
611 m_ui.startingOffsetSB->value());
612 m_vdataInterpreter->setTypeFromString(
613 m_ui.vertexTypeCB->currentText());
615 m_model = new ApiTraceModel();
616 m_model->setApiTrace(m_trace);
617 m_proxyModel = new ApiTraceFilter();
618 m_proxyModel->setSourceModel(m_model);
619 m_ui.callView->setModel(m_proxyModel);
620 m_ui.callView->setItemDelegate(new ApiCallDelegate);
621 m_ui.callView->resizeColumnToContents(0);
622 m_ui.callView->header()->swapSections(0, 1);
623 m_ui.callView->setColumnWidth(1, 42);
624 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
626 m_progressBar = new QProgressBar();
627 m_progressBar->setRange(0, 0);
628 statusBar()->addPermanentWidget(m_progressBar);
629 m_progressBar->hide();
631 m_argsEditor = new ArgumentsEditor(this);
633 m_ui.detailsDock->hide();
634 m_ui.errorsDock->hide();
635 m_ui.vertexDataDock->hide();
636 m_ui.stateDock->hide();
637 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
639 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
640 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
642 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
644 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
645 QWebPage::DelegateExternalLinks);
647 m_jumpWidget = new JumpWidget(this);
648 m_ui.centralLayout->addWidget(m_jumpWidget);
649 m_jumpWidget->hide();
651 m_searchWidget = new SearchWidget(this);
652 m_ui.centralLayout->addWidget(m_searchWidget);
653 m_searchWidget->hide();
655 m_traceProcess = new TraceProcess(this);
658 void MainWindow::initConnections()
660 connect(m_trace, SIGNAL(startedLoadingTrace()),
661 this, SLOT(startedLoadingTrace()));
662 connect(m_trace, SIGNAL(finishedLoadingTrace()),
663 this, SLOT(finishedLoadingTrace()));
664 connect(m_trace, SIGNAL(startedSaving()),
665 this, SLOT(slotStartedSaving()));
666 connect(m_trace, SIGNAL(saved()),
667 this, SLOT(slotSaved()));
668 connect(m_trace, SIGNAL(changed(ApiTraceCall*)),
669 this, SLOT(slotTraceChanged(ApiTraceCall*)));
671 connect(m_retracer, SIGNAL(finished(const QString&)),
672 this, SLOT(replayFinished(const QString&)));
673 connect(m_retracer, SIGNAL(error(const QString&)),
674 this, SLOT(replayError(const QString&)));
675 connect(m_retracer, SIGNAL(foundState(const ApiTraceState&)),
676 this, SLOT(replayStateFound(const ApiTraceState&)));
677 connect(m_retracer, SIGNAL(retraceErrors(const QList<RetraceError>&)),
678 this, SLOT(slotRetraceErrors(const QList<RetraceError>&)));
680 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
681 m_vdataInterpreter, SLOT(interpretData()));
682 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
683 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
684 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
685 m_vdataInterpreter, SLOT(setStride(int)));
686 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
687 m_vdataInterpreter, SLOT(setComponents(int)));
688 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
689 m_vdataInterpreter, SLOT(setStartingOffset(int)));
692 connect(m_ui.actionNew, SIGNAL(triggered()),
693 this, SLOT(createTrace()));
694 connect(m_ui.actionOpen, SIGNAL(triggered()),
695 this, SLOT(openTrace()));
696 connect(m_ui.actionQuit, SIGNAL(triggered()),
697 this, SLOT(close()));
699 connect(m_ui.actionFind, SIGNAL(triggered()),
700 this, SLOT(slotSearch()));
701 connect(m_ui.actionGo, SIGNAL(triggered()),
702 this, SLOT(slotGoTo()));
703 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
704 this, SLOT(slotGoFrameStart()));
705 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
706 this, SLOT(slotGoFrameEnd()));
708 connect(m_ui.actionReplay, SIGNAL(triggered()),
709 this, SLOT(replayStart()));
710 connect(m_ui.actionStop, SIGNAL(triggered()),
711 this, SLOT(replayStop()));
712 connect(m_ui.actionLookupState, SIGNAL(triggered()),
713 this, SLOT(lookupState()));
714 connect(m_ui.actionOptions, SIGNAL(triggered()),
715 this, SLOT(showSettings()));
717 connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
718 this, SLOT(callItemSelected(const QModelIndex &)));
719 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
720 this, SLOT(customContextMenuRequested(QPoint)));
722 connect(m_ui.surfacesTreeWidget,
723 SIGNAL(customContextMenuRequested(const QPoint &)),
724 SLOT(showSurfacesMenu(const QPoint &)));
725 connect(m_ui.surfacesTreeWidget,
726 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
727 SLOT(showSelectedSurface()));
729 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
730 this, SLOT(openHelp(const QUrl&)));
732 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
733 this, SLOT(fillState(bool)));
735 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
736 SLOT(slotJumpTo(int)));
738 connect(m_searchWidget,
739 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
740 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
741 connect(m_searchWidget,
742 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
743 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
745 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
746 SLOT(createdTrace(const QString&)));
747 connect(m_traceProcess, SIGNAL(error(const QString&)),
748 SLOT(traceError(const QString&)));
750 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
751 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
752 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
753 m_ui.errorsDock, SLOT(setVisible(bool)));
754 connect(m_ui.errorsTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
755 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
758 void MainWindow::replayStateFound(const ApiTraceState &state)
760 m_stateEvent->setState(state);
761 m_model->stateSetOnEvent(m_stateEvent);
762 if (m_selectedEvent == m_stateEvent) {
765 m_ui.stateDock->hide();
769 void MainWindow::slotGoTo()
771 m_searchWidget->hide();
772 m_jumpWidget->show();
775 void MainWindow::slotJumpTo(int callNum)
777 QModelIndex index = m_proxyModel->callIndex(callNum);
778 if (index.isValid()) {
779 m_ui.callView->setCurrentIndex(index);
783 void MainWindow::createdTrace(const QString &path)
785 qDebug()<<"Done tracing "<<path;
789 void MainWindow::traceError(const QString &msg)
791 QMessageBox::warning(
797 void MainWindow::slotSearch()
799 m_jumpWidget->hide();
800 m_searchWidget->show();
803 void MainWindow::slotSearchNext(const QString &str,
804 Qt::CaseSensitivity sensitivity)
806 QModelIndex index = m_ui.callView->currentIndex();
807 ApiTraceEvent *event = 0;
810 if (!index.isValid()) {
811 index = m_proxyModel->index(0, 0, QModelIndex());
812 if (!index.isValid()) {
813 qDebug()<<"no currently valid index";
814 m_searchWidget->setFound(false);
819 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
820 ApiTraceCall *call = 0;
822 if (event->type() == ApiTraceCall::Call)
823 call = static_cast<ApiTraceCall*>(event);
825 Q_ASSERT(event->type() == ApiTraceCall::Frame);
826 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
827 call = frame->calls.value(0);
831 m_searchWidget->setFound(false);
834 const QList<ApiTraceCall*> &calls = m_trace->calls();
835 int callNum = calls.indexOf(call);
837 for (int i = callNum + 1; i < calls.count(); ++i) {
838 ApiTraceCall *testCall = calls[i];
839 QModelIndex index = m_proxyModel->indexForCall(testCall);
840 /* if it's not valid it means that the proxy model has already
842 if (index.isValid()) {
843 QString txt = testCall->filterText();
844 if (txt.contains(str, sensitivity)) {
845 m_ui.callView->setCurrentIndex(index);
846 m_searchWidget->setFound(true);
851 m_searchWidget->setFound(false);
854 void MainWindow::slotSearchPrev(const QString &str,
855 Qt::CaseSensitivity sensitivity)
857 QModelIndex index = m_ui.callView->currentIndex();
858 ApiTraceEvent *event = 0;
861 if (!index.isValid()) {
862 index = m_proxyModel->index(0, 0, QModelIndex());
863 if (!index.isValid()) {
864 qDebug()<<"no currently valid index";
865 m_searchWidget->setFound(false);
870 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
871 ApiTraceCall *call = 0;
873 if (event->type() == ApiTraceCall::Call)
874 call = static_cast<ApiTraceCall*>(event);
876 Q_ASSERT(event->type() == ApiTraceCall::Frame);
877 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
878 call = frame->calls.value(0);
882 m_searchWidget->setFound(false);
885 const QList<ApiTraceCall*> &calls = m_trace->calls();
886 int callNum = calls.indexOf(call);
888 for (int i = callNum - 1; i >= 0; --i) {
889 ApiTraceCall *testCall = calls[i];
890 QModelIndex index = m_proxyModel->indexForCall(testCall);
891 /* if it's not valid it means that the proxy model has already
893 if (index.isValid()) {
894 QString txt = testCall->filterText();
895 if (txt.contains(str, sensitivity)) {
896 m_ui.callView->setCurrentIndex(index);
897 m_searchWidget->setFound(true);
902 m_searchWidget->setFound(false);
905 void MainWindow::fillState(bool nonDefaults)
908 ApiTraceState defaultState = m_trace->defaultState();
909 if (defaultState.isEmpty()) {
910 m_ui.nonDefaultsCB->blockSignals(true);
911 m_ui.nonDefaultsCB->setChecked(false);
912 m_ui.nonDefaultsCB->blockSignals(false);
913 int ret = QMessageBox::question(
914 this, tr("Empty Default State"),
915 tr("The applcation needs to figure out the "
916 "default state for the current trace. "
917 "This only has to be done once and "
918 "afterwards you will be able to enable "
919 "displaying of non default state for all calls."
920 "\nDo you want to lookup the default state now?"),
921 QMessageBox::Yes | QMessageBox::No);
922 if (ret != QMessageBox::Yes)
924 ApiTraceFrame *firstFrame =
926 ApiTraceEvent *oldSelected = m_selectedEvent;
929 m_selectedEvent = firstFrame;
931 m_selectedEvent = oldSelected;
937 void MainWindow::customContextMenuRequested(QPoint pos)
940 QModelIndex index = m_ui.callView->indexAt(pos);
942 callItemSelected(index);
943 if (!index.isValid())
946 ApiTraceEvent *event =
947 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
948 if (!event || event->type() != ApiTraceEvent::Call)
951 menu.addAction(QIcon(":/resources/media-record.png"),
952 tr("Lookup state"), this, SLOT(lookupState()));
953 menu.addAction(tr("Edit"), this, SLOT(editCall()));
955 menu.exec(QCursor::pos());
958 void MainWindow::editCall()
960 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
961 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
962 m_argsEditor->setCall(call);
963 m_argsEditor->show();
967 void MainWindow::slotStartedSaving()
969 m_progressBar->show();
970 statusBar()->showMessage(
971 tr("Saving to %1").arg(m_trace->fileName()));
974 void MainWindow::slotSaved()
976 statusBar()->showMessage(
977 tr("Saved to %1").arg(m_trace->fileName()), 2000);
978 m_progressBar->hide();
981 void MainWindow::slotGoFrameStart()
983 ApiTraceFrame *frame = currentFrame();
984 if (!frame || frame->calls.isEmpty()) {
988 QList<ApiTraceCall*>::const_iterator itr;
990 itr = frame->calls.constBegin();
991 while (itr != frame->calls.constEnd()) {
992 ApiTraceCall *call = *itr;
993 QModelIndex idx = m_proxyModel->indexForCall(call);
995 m_ui.callView->setCurrentIndex(idx);
1002 void MainWindow::slotGoFrameEnd()
1004 ApiTraceFrame *frame = currentFrame();
1005 if (!frame || frame->calls.isEmpty()) {
1008 QList<ApiTraceCall*>::const_iterator itr;
1010 itr = frame->calls.constEnd();
1013 ApiTraceCall *call = *itr;
1014 QModelIndex idx = m_proxyModel->indexForCall(call);
1015 if (idx.isValid()) {
1016 m_ui.callView->setCurrentIndex(idx);
1019 } while (itr != frame->calls.constBegin());
1022 ApiTraceFrame * MainWindow::currentFrame() const
1024 if (m_selectedEvent) {
1025 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
1026 return static_cast<ApiTraceFrame*>(m_selectedEvent);
1028 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1029 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1030 return call->parentFrame();
1036 void MainWindow::slotTraceChanged(ApiTraceCall *call)
1039 if (call == m_selectedEvent) {
1040 m_ui.detailsWebView->setHtml(call->toHtml());
1044 void MainWindow::slotRetraceErrors(const QList<RetraceError> &errors)
1046 m_ui.errorsTreeWidget->clear();
1048 foreach(RetraceError error, errors) {
1049 ApiTraceCall *call = m_trace->callWithIndex(error.callIndex);
1052 call->setError(error.message);
1054 QTreeWidgetItem *item =
1055 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1056 item->setData(0, Qt::DisplayRole, error.callIndex);
1057 item->setData(0, Qt::UserRole, QVariant::fromValue(call));
1058 QString type = error.type;
1059 type[0] = type[0].toUpper();
1060 item->setData(1, Qt::DisplayRole, type);
1061 item->setData(2, Qt::DisplayRole, error.message);
1065 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1068 ApiTraceCall *call =
1069 current->data(0, Qt::UserRole).value<ApiTraceCall*>();
1071 QModelIndex index = m_proxyModel->indexForCall(call);
1072 if (index.isValid()) {
1073 m_ui.callView->setCurrentIndex(index);
1075 statusBar()->showMessage(tr("Call has been filtered out."));
1080 ApiTraceCall * MainWindow::currentCall() const
1082 if (m_selectedEvent &&
1083 m_selectedEvent->type() == ApiTraceEvent::Call) {
1084 return static_cast<ApiTraceCall*>(m_selectedEvent);
1089 #include "mainwindow.moc"