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"
22 #include <QDesktopServices>
24 #include <QFileDialog>
26 #include <QMessageBox>
27 #include <QProgressBar>
31 #include <QVBoxLayout>
36 MainWindow::MainWindow()
46 void MainWindow::createTrace()
50 if (!m_traceProcess->canTrace()) {
54 tr("Current configuration doesn't support tracing."));
58 if (dialog.exec() == QDialog::Accepted) {
59 qDebug()<< "App : " <<dialog.applicationPath();
60 qDebug()<< " Arguments: "<<dialog.arguments();
61 m_traceProcess->setExecutablePath(dialog.applicationPath());
62 m_traceProcess->setArguments(dialog.arguments());
63 m_traceProcess->start();
67 void MainWindow::openTrace()
70 QFileDialog::getOpenFileName(
74 tr("Trace Files (*.trace)"));
76 qDebug()<< "File name : " <<fileName;
78 newTraceFile(fileName);
81 void MainWindow::loadTrace(const QString &fileName)
83 if (!QFile::exists(fileName)) {
84 QMessageBox::warning(this, tr("File Missing"),
85 tr("File '%1' doesn't exist.").arg(fileName));
88 qDebug()<< "Loading : " <<fileName;
90 m_progressBar->setValue(0);
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.benchmarkCB->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.benchmarkCB->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 m_trace->setFileName(fileName);
181 if (fileName.isEmpty()) {
182 m_ui.actionReplay->setEnabled(false);
183 m_ui.actionLookupState->setEnabled(false);
184 setWindowTitle(tr("QApiTrace"));
186 QFileInfo info(fileName);
187 m_ui.actionReplay->setEnabled(true);
188 m_ui.actionLookupState->setEnabled(true);
190 tr("QApiTrace - %1").arg(info.fileName()));
194 void MainWindow::replayFinished(const QString &output)
196 m_ui.actionStop->setEnabled(false);
197 m_ui.actionReplay->setEnabled(true);
198 m_ui.actionLookupState->setEnabled(true);
200 m_progressBar->hide();
201 if (output.length() < 80) {
202 statusBar()->showMessage(output);
205 statusBar()->showMessage(
206 tr("Replaying finished!"), 2000);
209 void MainWindow::replayError(const QString &message)
211 m_ui.actionStop->setEnabled(false);
212 m_ui.actionReplay->setEnabled(true);
213 m_ui.actionLookupState->setEnabled(true);
216 m_progressBar->hide();
217 statusBar()->showMessage(
218 tr("Replaying unsuccessful."), 2000);
219 QMessageBox::warning(
220 this, tr("Replay Failed"), message);
223 void MainWindow::startedLoadingTrace()
226 m_progressBar->show();
227 QFileInfo info(m_trace->fileName());
228 statusBar()->showMessage(
229 tr("Loading %1...").arg(info.fileName()));
232 void MainWindow::finishedLoadingTrace()
234 m_progressBar->hide();
238 QFileInfo info(m_trace->fileName());
239 statusBar()->showMessage(
240 tr("Loaded %1").arg(info.fileName()), 3000);
243 void MainWindow::replayTrace(bool dumpState)
245 if (m_trace->fileName().isEmpty())
248 m_retracer->setFileName(m_trace->fileName());
249 m_retracer->setCaptureState(dumpState);
250 if (m_retracer->captureState() && m_selectedEvent) {
252 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
253 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
254 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
255 ApiTraceFrame *frame =
256 static_cast<ApiTraceFrame*>(m_selectedEvent);
257 if (frame->calls.isEmpty()) {
258 //XXX i guess we could still get the current state
259 qDebug()<<"tried to get a state for an empty frame";
262 index = frame->calls.first()->index();
264 qDebug()<<"Unknown event type";
267 m_retracer->setCaptureAtCallNumber(index);
271 m_ui.actionStop->setEnabled(true);
272 m_progressBar->show();
274 statusBar()->showMessage(
275 tr("Looking up the state..."));
277 statusBar()->showMessage(
278 tr("Replaying the trace file..."));
281 void MainWindow::lookupState()
283 if (!m_selectedEvent) {
284 QMessageBox::warning(
285 this, tr("Unknown Event"),
286 tr("To inspect the state select an event in the event list."));
289 if (m_trace->isSaving()) {
290 QMessageBox::warning(
293 tr("QApiTrace is currently saving the edited trace file. "
294 "Please wait until it finishes and try again."));
297 m_stateEvent = m_selectedEvent;
301 MainWindow::~MainWindow()
306 variantToString(const QVariant &var, QString &str)
308 if (var.type() == QVariant::List) {
309 QVariantList lst = var.toList();
310 str += QLatin1String("[");
311 for (int i = 0; i < lst.count(); ++i) {
312 QVariant val = lst[i];
313 variantToString(val, str);
314 if (i < lst.count() - 1)
315 str += QLatin1String(", ");
317 str += QLatin1String("]");
318 } else if (var.type() == QVariant::Map) {
319 Q_ASSERT(!"unsupported state type");
320 } else if (var.type() == QVariant::Hash) {
321 Q_ASSERT(!"unsupported state type");
323 str += var.toString();
327 static QTreeWidgetItem *
328 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar);
331 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap, QList<QTreeWidgetItem *> &items)
333 QVariantMap::const_iterator itr;
334 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
335 QString key = itr.key();
336 QVariant var = itr.value();
337 QVariant defaultVar = defaultMap[key];
339 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
347 variantListToItems(const QVariantList &lst, const QVariantList &defaultLst, QList<QTreeWidgetItem *> &items)
349 for (int i = 0; i < lst.count(); ++i) {
350 QString key = QString::number(i);
351 QVariant var = lst[i];
354 if (i < defaultLst.count()) {
355 defaultVar = defaultLst[i];
358 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
366 isVariantDeep(const QVariant &var)
368 if (var.type() == QVariant::List) {
369 QVariantList lst = var.toList();
370 for (int i = 0; i < lst.count(); ++i) {
371 if (isVariantDeep(lst[i])) {
376 } else if (var.type() == QVariant::Map) {
378 } else if (var.type() == QVariant::Hash) {
385 static QTreeWidgetItem *
386 variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVar)
388 if (var == defaultVar) {
394 bool deep = isVariantDeep(var);
396 variantToString(var, val);
399 //qDebug()<<"key = "<<key;
400 //qDebug()<<"val = "<<val;
405 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
408 QList<QTreeWidgetItem *> children;
409 if (var.type() == QVariant::Map) {
410 QVariantMap map = var.toMap();
411 QVariantMap defaultMap = defaultVar.toMap();
412 variantMapToItems(map, defaultMap, children);
414 if (var.type() == QVariant::List) {
415 QVariantList lst = var.toList();
416 QVariantList defaultLst = defaultVar.toList();
417 variantListToItems(lst, defaultLst, children);
419 item->addChildren(children);
425 void MainWindow::fillStateForFrame()
429 if (!m_selectedEvent || m_selectedEvent->state().isEmpty())
432 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
433 QVariantMap defaultParams;
435 ApiTraceState defaultState = m_trace->defaultState();
436 defaultParams = defaultState.parameters();
439 const ApiTraceState &state = m_selectedEvent->state();
440 m_ui.stateTreeWidget->clear();
441 params = state.parameters();
442 QList<QTreeWidgetItem *> items;
443 variantMapToItems(params, defaultParams, items);
444 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
446 QMap<QString, QString> shaderSources = state.shaderSources();
447 if (shaderSources.isEmpty()) {
448 m_sourcesWidget->setShaders(shaderSources);
450 m_sourcesWidget->setShaders(shaderSources);
453 const QList<ApiTexture> &textures =
455 const QList<ApiFramebuffer> &fbos =
456 state.framebuffers();
458 m_ui.surfacesTreeWidget->clear();
459 if (textures.isEmpty() && fbos.isEmpty()) {
460 m_ui.surfacesTab->setDisabled(false);
462 m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
463 if (!textures.isEmpty()) {
464 QTreeWidgetItem *textureItem =
465 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
466 textureItem->setText(0, tr("Textures"));
467 if (textures.count() <= 6)
468 textureItem->setExpanded(true);
470 for (int i = 0; i < textures.count(); ++i) {
471 const ApiTexture &texture =
473 QIcon icon(QPixmap::fromImage(texture.thumb()));
474 QTreeWidgetItem *item = new QTreeWidgetItem(textureItem);
475 item->setIcon(0, icon);
476 int width = texture.size().width();
477 int height = texture.size().height();
479 QString::fromLatin1("%1, %2 x %3")
480 .arg(texture.target())
483 item->setText(1, descr);
485 item->setData(0, Qt::UserRole,
489 if (!fbos.isEmpty()) {
490 QTreeWidgetItem *fboItem =
491 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
492 fboItem->setText(0, tr("Framebuffers"));
493 if (fbos.count() <= 6)
494 fboItem->setExpanded(true);
496 for (int i = 0; i < fbos.count(); ++i) {
497 const ApiFramebuffer &fbo =
499 QIcon icon(QPixmap::fromImage(fbo.thumb()));
500 QTreeWidgetItem *item = new QTreeWidgetItem(fboItem);
501 item->setIcon(0, icon);
502 int width = fbo.size().width();
503 int height = fbo.size().height();
505 QString::fromLatin1("%1, %2 x %3")
509 item->setText(1, descr);
511 item->setData(0, Qt::UserRole,
515 m_ui.surfacesTab->setEnabled(true);
517 m_ui.stateDock->show();
520 void MainWindow::showSettings()
522 SettingsDialog dialog;
523 dialog.setFilterModel(m_proxyModel);
528 void MainWindow::openHelp(const QUrl &url)
530 QDesktopServices::openUrl(url);
533 void MainWindow::showSurfacesMenu(const QPoint &pos)
535 QTreeWidget *tree = m_ui.surfacesTreeWidget;
536 QTreeWidgetItem *item = tree->itemAt(pos);
540 QMenu menu(tr("Surfaces"), this);
542 QAction *act = menu.addAction(tr("View Image"));
543 act->setStatusTip(tr("View the currently selected surface"));
544 connect(act, SIGNAL(triggered()),
545 SLOT(showSelectedSurface()));
547 menu.exec(tree->viewport()->mapToGlobal(pos));
550 void MainWindow::showSelectedSurface()
552 QTreeWidgetItem *item =
553 m_ui.surfacesTreeWidget->currentItem();
558 QVariant var = item->data(0, Qt::UserRole);
559 m_imageViewer->setImage(var.value<QImage>());
560 m_imageViewer->show();
561 m_imageViewer->raise();
562 m_imageViewer->activateWindow();
565 void MainWindow::initObjects()
567 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
569 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
570 QVBoxLayout *layout = new QVBoxLayout;
571 layout->addWidget(m_sourcesWidget);
572 m_ui.shadersTab->setLayout(layout);
574 m_trace = new ApiTrace();
575 m_retracer = new Retracer(this);
577 m_vdataInterpreter = new VertexDataInterpreter(this);
578 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
579 m_vdataInterpreter->setStride(
580 m_ui.vertexStrideSB->value());
581 m_vdataInterpreter->setComponents(
582 m_ui.vertexComponentsSB->value());
583 m_vdataInterpreter->setStartingOffset(
584 m_ui.startingOffsetSB->value());
585 m_vdataInterpreter->setTypeFromString(
586 m_ui.vertexTypeCB->currentText());
588 m_imageViewer = new ImageViewer(this);
590 m_model = new ApiTraceModel();
591 m_model->setApiTrace(m_trace);
592 m_proxyModel = new ApiTraceFilter();
593 m_proxyModel->setSourceModel(m_model);
594 m_ui.callView->setModel(m_proxyModel);
595 m_ui.callView->setItemDelegate(new ApiCallDelegate);
596 m_ui.callView->resizeColumnToContents(0);
597 m_ui.callView->header()->swapSections(0, 1);
598 m_ui.callView->setColumnWidth(1, 42);
599 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
601 m_progressBar = new QProgressBar();
602 m_progressBar->setRange(0, 0);
603 statusBar()->addPermanentWidget(m_progressBar);
604 m_progressBar->hide();
606 m_argsEditor = new ArgumentsEditor(this);
608 m_ui.detailsDock->hide();
609 m_ui.errorsDock->hide();
610 m_ui.vertexDataDock->hide();
611 m_ui.stateDock->hide();
612 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
614 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
615 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
617 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
619 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
620 QWebPage::DelegateExternalLinks);
622 m_jumpWidget = new JumpWidget(this);
623 m_ui.centralLayout->addWidget(m_jumpWidget);
624 m_jumpWidget->hide();
626 m_searchWidget = new SearchWidget(this);
627 m_ui.centralLayout->addWidget(m_searchWidget);
628 m_searchWidget->hide();
630 m_traceProcess = new TraceProcess(this);
632 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_G),
633 this, SLOT(slotGoTo()));
634 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F),
635 this, SLOT(slotSearch()));
638 void MainWindow::initConnections()
640 connect(m_trace, SIGNAL(startedLoadingTrace()),
641 this, SLOT(startedLoadingTrace()));
642 connect(m_trace, SIGNAL(finishedLoadingTrace()),
643 this, SLOT(finishedLoadingTrace()));
644 connect(m_trace, SIGNAL(startedSaving()),
645 this, SLOT(slotStartedSaving()));
646 connect(m_trace, SIGNAL(saved()),
647 this, SLOT(slotSaved()));
649 connect(m_retracer, SIGNAL(finished(const QString&)),
650 this, SLOT(replayFinished(const QString&)));
651 connect(m_retracer, SIGNAL(error(const QString&)),
652 this, SLOT(replayError(const QString&)));
653 connect(m_retracer, SIGNAL(foundState(const ApiTraceState&)),
654 this, SLOT(replayStateFound(const ApiTraceState&)));
656 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
657 m_vdataInterpreter, SLOT(interpretData()));
658 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
659 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
660 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
661 m_vdataInterpreter, SLOT(setStride(int)));
662 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
663 m_vdataInterpreter, SLOT(setComponents(int)));
664 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
665 m_vdataInterpreter, SLOT(setStartingOffset(int)));
668 connect(m_ui.actionNew, SIGNAL(triggered()),
669 this, SLOT(createTrace()));
670 connect(m_ui.actionOpen, SIGNAL(triggered()),
671 this, SLOT(openTrace()));
672 connect(m_ui.actionQuit, SIGNAL(triggered()),
673 this, SLOT(close()));
675 connect(m_ui.actionFind, SIGNAL(triggered()),
676 this, SLOT(slotSearch()));
677 connect(m_ui.actionGo, SIGNAL(triggered()),
678 this, SLOT(slotGoTo()));
679 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
680 this, SLOT(slotGoFrameStart()));
681 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
682 this, SLOT(slotGoFrameEnd()));
684 connect(m_ui.actionReplay, SIGNAL(triggered()),
685 this, SLOT(replayStart()));
686 connect(m_ui.actionStop, SIGNAL(triggered()),
687 this, SLOT(replayStop()));
688 connect(m_ui.actionLookupState, SIGNAL(triggered()),
689 this, SLOT(lookupState()));
690 connect(m_ui.actionOptions, SIGNAL(triggered()),
691 this, SLOT(showSettings()));
693 connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
694 this, SLOT(callItemSelected(const QModelIndex &)));
695 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
696 this, SLOT(customContextMenuRequested(QPoint)));
698 connect(m_ui.surfacesTreeWidget,
699 SIGNAL(customContextMenuRequested(const QPoint &)),
700 SLOT(showSurfacesMenu(const QPoint &)));
701 connect(m_ui.surfacesTreeWidget,
702 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
703 SLOT(showSelectedSurface()));
705 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
706 this, SLOT(openHelp(const QUrl&)));
708 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
709 this, SLOT(fillState(bool)));
711 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
712 SLOT(slotJumpTo(int)));
714 connect(m_searchWidget,
715 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
716 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
717 connect(m_searchWidget,
718 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
719 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
721 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
722 SLOT(createdTrace(const QString&)));
723 connect(m_traceProcess, SIGNAL(error(const QString&)),
724 SLOT(traceError(const QString&)));
727 void MainWindow::replayStateFound(const ApiTraceState &state)
729 m_stateEvent->setState(state);
730 if (m_stateEvent->type() == ApiTraceEvent::Call) {
731 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_stateEvent);
732 call->setError(tr("Some wonky error."));
734 m_model->stateSetOnEvent(m_stateEvent);
735 if (m_selectedEvent == m_stateEvent) {
738 m_ui.stateDock->hide();
742 void MainWindow::slotGoTo()
744 m_searchWidget->hide();
745 m_jumpWidget->show();
748 void MainWindow::slotJumpTo(int callNum)
750 QModelIndex index = m_proxyModel->callIndex(callNum);
751 if (index.isValid()) {
752 m_ui.callView->setCurrentIndex(index);
756 void MainWindow::createdTrace(const QString &path)
758 qDebug()<<"Done tracing "<<path;
762 void MainWindow::traceError(const QString &msg)
764 QMessageBox::warning(
770 void MainWindow::slotSearch()
772 m_jumpWidget->hide();
773 m_searchWidget->show();
776 void MainWindow::slotSearchNext(const QString &str, Qt::CaseSensitivity sensitivity)
778 QModelIndex index = m_ui.callView->currentIndex();
779 ApiTraceEvent *event = 0;
782 if (!index.isValid()) {
783 index = m_proxyModel->index(0, 0, QModelIndex());
784 if (!index.isValid()) {
785 qDebug()<<"no currently valid index";
786 m_searchWidget->setFound(false);
791 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
792 ApiTraceCall *call = 0;
794 if (event->type() == ApiTraceCall::Call)
795 call = static_cast<ApiTraceCall*>(event);
797 Q_ASSERT(event->type() == ApiTraceCall::Frame);
798 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
799 call = frame->calls.value(0);
803 m_searchWidget->setFound(false);
806 const QList<ApiTraceCall*> &calls = m_trace->calls();
807 int callNum = calls.indexOf(call);
809 for (int i = callNum + 1; i < calls.count(); ++i) {
810 ApiTraceCall *testCall = calls[i];
811 QString txt = testCall->filterText();
812 if (txt.contains(str, sensitivity)) {
813 QModelIndex index = m_proxyModel->indexForCall(testCall);
814 /* if it's not valid it means that the proxy model has already
816 if (index.isValid()) {
817 m_ui.callView->setCurrentIndex(index);
818 m_searchWidget->setFound(true);
823 m_searchWidget->setFound(false);
826 void MainWindow::slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitivity)
828 QModelIndex index = m_ui.callView->currentIndex();
829 ApiTraceEvent *event = 0;
832 if (!index.isValid()) {
833 index = m_proxyModel->index(0, 0, QModelIndex());
834 if (!index.isValid()) {
835 qDebug()<<"no currently valid index";
836 m_searchWidget->setFound(false);
841 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
842 ApiTraceCall *call = 0;
844 if (event->type() == ApiTraceCall::Call)
845 call = static_cast<ApiTraceCall*>(event);
847 Q_ASSERT(event->type() == ApiTraceCall::Frame);
848 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
849 call = frame->calls.value(0);
853 m_searchWidget->setFound(false);
856 const QList<ApiTraceCall*> &calls = m_trace->calls();
857 int callNum = calls.indexOf(call);
859 for (int i = callNum - 1; i >= 0; --i) {
860 ApiTraceCall *testCall = calls[i];
861 QString txt = testCall->filterText();
862 if (txt.contains(str, sensitivity)) {
863 QModelIndex index = m_proxyModel->indexForCall(testCall);
864 /* if it's not valid it means that the proxy model has already
866 if (index.isValid()) {
867 m_ui.callView->setCurrentIndex(index);
868 m_searchWidget->setFound(true);
873 m_searchWidget->setFound(false);
876 void MainWindow::fillState(bool nonDefaults)
879 ApiTraceState defaultState = m_trace->defaultState();
880 if (defaultState.isEmpty()) {
881 m_ui.nonDefaultsCB->blockSignals(true);
882 m_ui.nonDefaultsCB->setChecked(false);
883 m_ui.nonDefaultsCB->blockSignals(false);
884 int ret = QMessageBox::question(
885 this, tr("Empty Default State"),
886 tr("The applcation needs to figure out the "
887 "default state for the current trace. "
888 "This only has to be done once and "
889 "afterwards you will be able to enable "
890 "displaying of non default state for all calls."
891 "\nDo you want to lookup the default state now?"),
892 QMessageBox::Yes | QMessageBox::No);
893 if (ret != QMessageBox::Yes)
895 ApiTraceFrame *firstFrame =
897 ApiTraceEvent *oldSelected = m_selectedEvent;
900 m_selectedEvent = firstFrame;
902 m_selectedEvent = oldSelected;
908 void MainWindow::customContextMenuRequested(QPoint pos)
911 QModelIndex index = m_ui.callView->indexAt(pos);
913 callItemSelected(index);
914 if (!index.isValid())
917 ApiTraceEvent *event =
918 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
919 if (!event || event->type() != ApiTraceEvent::Call)
922 menu.addAction(QIcon(":/resources/media-record.png"),
923 tr("Lookup state"), this, SLOT(lookupState()));
924 menu.addAction(tr("Edit"), this, SLOT(editCall()));
926 menu.exec(QCursor::pos());
929 void MainWindow::editCall()
931 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
932 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
933 m_argsEditor->setCall(call);
934 m_argsEditor->show();
938 void MainWindow::slotStartedSaving()
940 m_progressBar->show();
941 statusBar()->showMessage(
942 tr("Saving to %1").arg(m_trace->fileName()));
945 void MainWindow::slotSaved()
947 statusBar()->showMessage(
948 tr("Saved to %1").arg(m_trace->fileName()), 2000);
949 m_progressBar->hide();
952 void MainWindow::slotGoFrameStart()
954 ApiTraceFrame *frame = currentFrame();
955 if (!frame || frame->calls.isEmpty()) {
959 QList<ApiTraceCall*>::const_iterator itr;
961 itr = frame->calls.constBegin();
962 while (itr != frame->calls.constEnd()) {
963 ApiTraceCall *call = *itr;
964 QModelIndex idx = m_proxyModel->indexForCall(call);
966 m_ui.callView->setCurrentIndex(idx);
973 void MainWindow::slotGoFrameEnd()
975 ApiTraceFrame *frame = currentFrame();
976 if (!frame || frame->calls.isEmpty()) {
979 QList<ApiTraceCall*>::const_iterator itr;
981 itr = frame->calls.constEnd();
984 ApiTraceCall *call = *itr;
985 QModelIndex idx = m_proxyModel->indexForCall(call);
987 m_ui.callView->setCurrentIndex(idx);
990 } while (itr != frame->calls.constBegin());
993 ApiTraceFrame * MainWindow::currentFrame() const
995 if (m_selectedEvent) {
996 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
997 return static_cast<ApiTraceFrame*>(m_selectedEvent);
999 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1000 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1001 return call->parentFrame();
1007 #include "mainwindow.moc"