+ QImage img = var.value<QImage>();
+ viewer->setImage(img);
+
+ viewer->show();
+ viewer->raise();
+ viewer->activateWindow();
+}
+
+void MainWindow::initObjects()
+{
+ m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
+ m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder);
+
+ m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(m_sourcesWidget);
+ m_ui.shadersTab->setLayout(layout);
+
+ m_trace = new ApiTrace();
+ m_retracer = new Retracer(this);
+
+ m_vdataInterpreter = new VertexDataInterpreter(this);
+ m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
+ m_vdataInterpreter->setStride(
+ m_ui.vertexStrideSB->value());
+ m_vdataInterpreter->setComponents(
+ m_ui.vertexComponentsSB->value());
+ m_vdataInterpreter->setStartingOffset(
+ m_ui.startingOffsetSB->value());
+ m_vdataInterpreter->setTypeFromString(
+ m_ui.vertexTypeCB->currentText());
+
+ m_model = new ApiTraceModel();
+ m_model->setApiTrace(m_trace);
+ m_proxyModel = new ApiTraceFilter();
+ m_proxyModel->setSourceModel(m_model);
+ m_ui.callView->setModel(m_proxyModel);
+ m_ui.callView->setItemDelegate(
+ new ApiCallDelegate(m_ui.callView));
+ m_ui.callView->resizeColumnToContents(0);
+ m_ui.callView->header()->swapSections(0, 1);
+ m_ui.callView->setColumnWidth(1, 42);
+ m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
+
+ m_progressBar = new QProgressBar();
+ m_progressBar->setRange(0, 100);
+ statusBar()->addPermanentWidget(m_progressBar);
+ m_progressBar->hide();
+
+ m_argsEditor = new ArgumentsEditor(this);
+
+ m_ui.detailsDock->hide();
+ m_ui.errorsDock->hide();
+ m_ui.vertexDataDock->hide();
+ m_ui.stateDock->hide();
+ setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
+
+ tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
+ tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
+
+ m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
+
+ m_ui.detailsWebView->page()->setLinkDelegationPolicy(
+ QWebPage::DelegateExternalLinks);
+
+ m_jumpWidget = new JumpWidget(this);
+ m_ui.centralLayout->addWidget(m_jumpWidget);
+ m_jumpWidget->hide();
+
+ m_searchWidget = new SearchWidget(this);
+ m_ui.centralLayout->addWidget(m_searchWidget);
+ m_searchWidget->hide();
+
+ m_traceProcess = new TraceProcess(this);
+ m_trimProcess = new TrimProcess(this);
+
+ m_profileDialog = new ProfileDialog();
+}
+
+void MainWindow::initConnections()
+{
+ connect(m_trace, SIGNAL(startedLoadingTrace()),
+ this, SLOT(startedLoadingTrace()));
+ connect(m_trace, SIGNAL(loaded(int)),
+ this, SLOT(loadProgess(int)));
+ connect(m_trace, SIGNAL(finishedLoadingTrace()),
+ this, SLOT(finishedLoadingTrace()));
+ connect(m_trace, SIGNAL(startedSaving()),
+ this, SLOT(slotStartedSaving()));
+ connect(m_trace, SIGNAL(saved()),
+ this, SLOT(slotSaved()));
+ connect(m_trace, SIGNAL(changed(ApiTraceEvent*)),
+ this, SLOT(slotTraceChanged(ApiTraceEvent*)));
+ connect(m_trace, SIGNAL(findResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)),
+ this, SLOT(slotSearchResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)));
+ connect(m_trace, SIGNAL(foundFrameStart(ApiTraceFrame*)),
+ this, SLOT(slotFoundFrameStart(ApiTraceFrame*)));
+ connect(m_trace, SIGNAL(foundFrameEnd(ApiTraceFrame*)),
+ this, SLOT(slotFoundFrameEnd(ApiTraceFrame*)));
+ connect(m_trace, SIGNAL(foundCallIndex(ApiTraceCall*)),
+ this, SLOT(slotJumpToResult(ApiTraceCall*)));
+
+ connect(m_retracer, SIGNAL(finished(const QString&)),
+ this, SLOT(replayFinished(const QString&)));
+ connect(m_retracer, SIGNAL(error(const QString&)),
+ this, SLOT(replayError(const QString&)));
+ connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
+ this, SLOT(replayStateFound(ApiTraceState*)));
+ connect(m_retracer, SIGNAL(foundProfile(trace::Profile*)),
+ this, SLOT(replayProfileFound(trace::Profile*)));
+ connect(m_retracer, SIGNAL(foundThumbnails(const QList<QImage>&)),
+ this, SLOT(replayThumbnailsFound(const QList<QImage>&)));
+ connect(m_retracer, SIGNAL(retraceErrors(const QList<ApiTraceError>&)),
+ this, SLOT(slotRetraceErrors(const QList<ApiTraceError>&)));
+
+ connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
+ m_vdataInterpreter, SLOT(interpretData()));
+ connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
+ m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
+ connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
+ m_vdataInterpreter, SLOT(setStride(int)));
+ connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
+ m_vdataInterpreter, SLOT(setComponents(int)));
+ connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
+ m_vdataInterpreter, SLOT(setStartingOffset(int)));
+
+
+ connect(m_ui.actionNew, SIGNAL(triggered()),
+ this, SLOT(createTrace()));
+ connect(m_ui.actionOpen, SIGNAL(triggered()),
+ this, SLOT(openTrace()));
+ connect(m_ui.actionQuit, SIGNAL(triggered()),
+ this, SLOT(close()));
+
+ connect(m_ui.actionFind, SIGNAL(triggered()),
+ this, SLOT(slotSearch()));
+ connect(m_ui.actionGo, SIGNAL(triggered()),
+ this, SLOT(slotGoTo()));
+ connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
+ this, SLOT(slotGoFrameStart()));
+ connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
+ this, SLOT(slotGoFrameEnd()));
+
+ connect(m_ui.actionReplay, SIGNAL(triggered()),
+ this, SLOT(replayStart()));
+ connect(m_ui.actionProfile, SIGNAL(triggered()),
+ this, SLOT(replayProfile()));
+ connect(m_ui.actionStop, SIGNAL(triggered()),
+ this, SLOT(replayStop()));
+ connect(m_ui.actionLookupState, SIGNAL(triggered()),
+ this, SLOT(lookupState()));
+ connect(m_ui.actionTrim, SIGNAL(triggered()),
+ this, SLOT(trim()));
+ connect(m_ui.actionShowThumbnails, SIGNAL(triggered()),
+ this, SLOT(showThumbnails()));
+ connect(m_ui.actionOptions, SIGNAL(triggered()),
+ this, SLOT(showSettings()));
+
+ connect(m_ui.callView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
+ this, SLOT(callItemSelected(const QModelIndex &)));
+ connect(m_ui.callView, SIGNAL(doubleClicked(const QModelIndex &)),
+ this, SLOT(callItemActivated(const QModelIndex &)));
+ connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
+ this, SLOT(customContextMenuRequested(QPoint)));
+
+ connect(m_ui.surfacesTreeWidget,
+ SIGNAL(customContextMenuRequested(const QPoint &)),
+ SLOT(showSurfacesMenu(const QPoint &)));
+ connect(m_ui.surfacesTreeWidget,
+ SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
+ SLOT(showSelectedSurface()));
+
+ connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
+ this, SLOT(openHelp(const QUrl&)));
+
+ connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
+ this, SLOT(fillState(bool)));
+
+ connect(m_jumpWidget, SIGNAL(jumpTo(int)),
+ SLOT(slotJumpTo(int)));
+
+ connect(m_searchWidget,
+ SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
+ SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
+ connect(m_searchWidget,
+ SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
+ SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
+
+ connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
+ SLOT(createdTrace(const QString&)));
+ connect(m_traceProcess, SIGNAL(error(const QString&)),
+ SLOT(traceError(const QString&)));
+
+ connect(m_trimProcess, SIGNAL(trimmedFile(const QString&)),
+ SLOT(createdTrim(const QString&)));
+ connect(m_trimProcess, SIGNAL(error(const QString&)),
+ SLOT(trimError(const QString&)));
+
+ connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
+ m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
+ connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
+ m_ui.errorsDock, SLOT(setVisible(bool)));
+ connect(m_ui.errorsTreeWidget,
+ SIGNAL(itemActivated(QTreeWidgetItem*, int)),
+ this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
+
+ connect(m_ui.actionShowProfileDialog, SIGNAL(triggered(bool)),
+ m_profileDialog, SLOT(show()));
+ connect(m_profileDialog, SIGNAL(jumpToCall(int)),
+ this, SLOT(slotJumpTo(int)));
+}
+
+void MainWindow::updateActionsState(bool traceLoaded, bool stopped)
+{
+ if (traceLoaded) {
+ /* Edit */
+ m_ui.actionFind ->setEnabled(true);
+ m_ui.actionGo ->setEnabled(true);
+ m_ui.actionGoFrameStart ->setEnabled(true);
+ m_ui.actionGoFrameEnd ->setEnabled(true);
+
+ /* Trace */
+ if (stopped) {
+ m_ui.actionStop->setEnabled(false);
+ m_ui.actionReplay->setEnabled(true);
+ }
+ else {
+ m_ui.actionStop->setEnabled(true);
+ m_ui.actionReplay->setEnabled(false);
+ }
+
+ m_ui.actionProfile ->setEnabled(true);
+ m_ui.actionLookupState ->setEnabled(true);
+ m_ui.actionShowThumbnails->setEnabled(true);
+ m_ui.actionTrim ->setEnabled(true);
+ }
+ else {
+ /* Edit */
+ m_ui.actionFind ->setEnabled(false);
+ m_ui.actionGo ->setEnabled(false);
+ m_ui.actionGoFrameStart ->setEnabled(false);
+ m_ui.actionGoFrameEnd ->setEnabled(false);
+
+ /* Trace */
+ m_ui.actionReplay ->setEnabled(false);
+ m_ui.actionProfile ->setEnabled(false);
+ m_ui.actionStop ->setEnabled(false);
+ m_ui.actionLookupState ->setEnabled(false);
+ m_ui.actionShowThumbnails->setEnabled(false);
+ m_ui.actionTrim ->setEnabled(false);
+ }
+}
+
+void MainWindow::closeEvent(QCloseEvent * event)
+{
+ m_profileDialog->close();
+ QMainWindow::closeEvent(event);
+}
+
+void MainWindow::replayProfileFound(trace::Profile *profile)
+{
+ m_ui.actionShowProfileDialog->setEnabled(true);
+ m_profileDialog->setProfile(profile);
+ m_profileDialog->show();
+ m_profileDialog->activateWindow();
+ m_profileDialog->setFocus();
+}
+
+void MainWindow::replayStateFound(ApiTraceState *state)
+{
+ m_stateEvent->setState(state);
+ m_model->stateSetOnEvent(m_stateEvent);
+ if (m_selectedEvent == m_stateEvent ||
+ m_nonDefaultsLookupEvent == m_selectedEvent) {
+ fillStateForFrame();
+ } else {
+ m_ui.stateDock->hide();
+ }
+ m_nonDefaultsLookupEvent = 0;
+}
+
+void MainWindow::replayThumbnailsFound(const QList<QImage> &thumbnails)
+{
+ m_ui.callView->setUniformRowHeights(false);
+ m_trace->bindThumbnailsToFrames(thumbnails);
+}
+
+void MainWindow::slotGoTo()
+{
+ m_searchWidget->hide();
+ m_jumpWidget->show();
+}
+
+void MainWindow::slotJumpTo(int callNum)
+{
+ m_trace->findCallIndex(callNum);
+}
+
+void MainWindow::createdTrace(const QString &path)
+{
+ qDebug()<<"Done tracing "<<path;
+ newTraceFile(path);
+}
+
+void MainWindow::traceError(const QString &msg)
+{
+ QMessageBox::warning(
+ this,
+ tr("Tracing Error"),
+ msg);
+}
+
+void MainWindow::createdTrim(const QString &path)
+{
+ qDebug()<<"Done trimming "<<path;
+
+ newTraceFile(path);
+}
+
+void MainWindow::trimError(const QString &msg)
+{
+ QMessageBox::warning(
+ this,
+ tr("Trim Error"),
+ msg);
+}
+
+void MainWindow::slotSearch()
+{
+ m_jumpWidget->hide();
+ m_searchWidget->show();
+}
+
+void MainWindow::slotSearchNext(const QString &str,
+ Qt::CaseSensitivity sensitivity)
+{
+ ApiTraceCall *call = currentCall();
+ ApiTraceFrame *frame = currentFrame();
+
+ Q_ASSERT(call || frame);
+ if (!frame) {
+ frame = call->parentFrame();
+ }
+ Q_ASSERT(frame);
+
+ m_trace->findNext(frame, call, str, sensitivity);
+}
+
+void MainWindow::slotSearchPrev(const QString &str,
+ Qt::CaseSensitivity sensitivity)
+{
+ ApiTraceCall *call = currentCall();
+ ApiTraceFrame *frame = currentFrame();
+
+ Q_ASSERT(call || frame);
+ if (!frame) {
+ frame = call->parentFrame();
+ }
+ Q_ASSERT(frame);
+
+ m_trace->findPrev(frame, call, str, sensitivity);
+}
+
+void MainWindow::fillState(bool nonDefaults)
+{
+ if (nonDefaults) {
+ ApiTraceState defaultState = m_trace->defaultState();
+ if (defaultState.isEmpty()) {
+ m_ui.nonDefaultsCB->blockSignals(true);
+ m_ui.nonDefaultsCB->setChecked(false);
+ m_ui.nonDefaultsCB->blockSignals(false);
+ ApiTraceFrame *firstFrame =
+ m_trace->frameAt(0);
+ if (!firstFrame) {
+ return;
+ }
+ if (!firstFrame->isLoaded()) {
+ m_trace->loadFrame(firstFrame);
+ return;
+ }
+ ApiTraceCall *firstCall = firstFrame->calls().first();
+ ApiTraceEvent *oldSelected = m_selectedEvent;
+ m_nonDefaultsLookupEvent = m_selectedEvent;
+ m_selectedEvent = firstCall;
+ lookupState();
+ m_selectedEvent = oldSelected;
+ }
+ }
+ fillStateForFrame();
+}
+
+void MainWindow::customContextMenuRequested(QPoint pos)
+{
+ QModelIndex index = m_ui.callView->indexAt(pos);
+
+ callItemSelected(index);
+ if (!index.isValid()) {
+ return;
+ }
+
+ ApiTraceEvent *event =
+ index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
+ if (!event) {
+ return;
+ }
+
+ QMenu menu;
+ menu.addAction(QIcon(":/resources/media-record.png"),
+ tr("Lookup state"), this, SLOT(lookupState()));
+ if (event->type() == ApiTraceEvent::Call) {
+ menu.addAction(tr("Edit"), this, SLOT(editCall()));
+ }
+
+ menu.exec(QCursor::pos());
+}
+
+void MainWindow::editCall()
+{
+ if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
+ ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
+ m_argsEditor->setCall(call);
+ m_argsEditor->show();
+ }
+}
+
+void MainWindow::slotStartedSaving()
+{
+ m_progressBar->show();
+ statusBar()->showMessage(
+ tr("Saving to %1").arg(m_trace->fileName()));
+}
+
+void MainWindow::slotSaved()
+{
+ statusBar()->showMessage(
+ tr("Saved to %1").arg(m_trace->fileName()), 2000);
+ m_progressBar->hide();
+}
+
+void MainWindow::slotGoFrameStart()
+{
+ ApiTraceFrame *frame = currentFrame();
+ ApiTraceCall *call = currentCall();
+
+ if (!frame && call) {
+ frame = call->parentFrame();
+ }
+
+ m_trace->findFrameStart(frame);
+}
+
+void MainWindow::slotGoFrameEnd()
+{
+ ApiTraceFrame *frame = currentFrame();
+ ApiTraceCall *call = currentCall();
+
+ if (!frame && call) {
+ frame = call->parentFrame();
+ }
+
+ m_trace->findFrameEnd(frame);
+}
+
+ApiTraceFrame * MainWindow::selectedFrame() const
+{
+ if (m_selectedEvent) {
+ if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
+ return static_cast<ApiTraceFrame*>(m_selectedEvent);
+ } else {
+ Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
+ ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
+ return call->parentFrame();
+ }
+ }
+ return NULL;
+}
+
+void MainWindow::slotTraceChanged(ApiTraceEvent *event)
+{
+ Q_ASSERT(event);
+ if (event == m_selectedEvent) {
+ if (event->type() == ApiTraceEvent::Call) {
+ ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
+ m_ui.detailsWebView->setHtml(call->toHtml());
+ }
+ }
+}
+
+void MainWindow::slotRetraceErrors(const QList<ApiTraceError> &errors)
+{
+ m_ui.errorsTreeWidget->clear();
+
+ foreach(ApiTraceError error, errors) {
+ m_trace->setCallError(error);
+
+ QTreeWidgetItem *item =
+ new QTreeWidgetItem(m_ui.errorsTreeWidget);
+ item->setData(0, Qt::DisplayRole, error.callIndex);
+ item->setData(0, Qt::UserRole, error.callIndex);
+ QString type = error.type;
+ type[0] = type[0].toUpper();
+ item->setData(1, Qt::DisplayRole, type);
+ item->setData(2, Qt::DisplayRole, error.message);
+ }
+}
+
+void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
+{
+ if (current) {
+ int callIndex =
+ current->data(0, Qt::UserRole).toInt();
+ m_trace->findCallIndex(callIndex);
+ }
+}
+
+ApiTraceCall * MainWindow::selectedCall() const
+{
+ if (m_selectedEvent &&
+ m_selectedEvent->type() == ApiTraceEvent::Call) {
+ return static_cast<ApiTraceCall*>(m_selectedEvent);
+ }
+ return NULL;
+}
+
+void MainWindow::saveSelectedSurface()
+{
+ QTreeWidgetItem *item =
+ m_ui.surfacesTreeWidget->currentItem();
+
+ if (!item || !m_trace) {
+ return;
+ }
+
+ QVariant var = item->data(0, Qt::UserRole);
+ QImage img = var.value<QImage>();
+
+ QString imageIndex;
+ if (selectedCall()) {
+ imageIndex = tr("_call_%1")
+ .arg(selectedCall()->index());
+ } else if (selectedFrame()) {
+ ApiTraceCall *firstCall = selectedFrame()->call(0);
+ if (firstCall) {
+ imageIndex = tr("_frame_%1")
+ .arg(firstCall->index());
+ } else {
+ qDebug()<<"unknown frame number";
+ imageIndex = tr("_frame_%1")
+ .arg(firstCall->index());
+ }
+ }
+
+ //which of the surfaces are we saving
+ QTreeWidgetItem *parent = item->parent();
+ int parentIndex =
+ m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent);
+ if (parentIndex < 0) {
+ parentIndex = 0;
+ }
+ int childIndex = 0;
+ if (parent) {
+ childIndex = parent->indexOfChild(item);
+ } else {
+ childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item);
+ }
+
+
+ QString fileName =
+ tr("%1%2-%3_%4.png")
+ .arg(m_trace->fileName())
+ .arg(imageIndex)
+ .arg(parentIndex)
+ .arg(childIndex);
+ //qDebug()<<"save "<<fileName;
+ img.save(fileName, "PNG");
+ statusBar()->showMessage( tr("Saved '%1'").arg(fileName), 5000);
+}
+
+void MainWindow::loadProgess(int percent)
+{
+ m_progressBar->setValue(percent);
+}
+
+void MainWindow::slotSearchResult(const ApiTrace::SearchRequest &request,
+ ApiTrace::SearchResult result,
+ ApiTraceCall *call)
+{
+ switch (result) {
+ case ApiTrace::SearchResult_NotFound:
+ m_searchWidget->setFound(false);
+ break;
+ case ApiTrace::SearchResult_Found: {
+ QModelIndex index = m_proxyModel->indexForCall(call);
+
+ if (index.isValid()) {
+ m_ui.callView->setCurrentIndex(index);
+ m_searchWidget->setFound(true);
+ } else {
+ //call is filtered out, so continue searching but from the
+ // filtered call
+ if (!call) {
+ qDebug()<<"Error: search success with no call";
+ return;
+ }
+// qDebug()<<"filtered! search from "<<call->searchText()
+// <<", call idx = "<<call->index();
+
+ if (request.direction == ApiTrace::SearchRequest::Next) {
+ m_trace->findNext(call->parentFrame(), call,
+ request.text, request.cs);
+ } else {
+ m_trace->findNext(call->parentFrame(), call,
+ request.text, request.cs);
+ }
+ }
+ }
+ break;
+ case ApiTrace::SearchResult_Wrapped:
+ m_searchWidget->setFound(false);
+ break;
+ }
+}
+
+ApiTraceFrame * MainWindow::currentFrame() const
+{
+ QModelIndex index = m_ui.callView->currentIndex();
+ ApiTraceEvent *event = 0;
+
+ if (!index.isValid()) {
+ index = m_proxyModel->index(0, 0, QModelIndex());
+ if (!index.isValid()) {
+ qDebug()<<"no currently valid index";
+ return 0;
+ }
+ }
+
+ event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
+ Q_ASSERT(event);
+ if (!event) {
+ return 0;
+ }
+
+ ApiTraceFrame *frame = 0;
+ if (event->type() == ApiTraceCall::Frame) {
+ frame = static_cast<ApiTraceFrame*>(event);
+ }
+ return frame;
+}
+
+ApiTraceCall * MainWindow::currentCall() const
+{
+ QModelIndex index = m_ui.callView->currentIndex();
+ ApiTraceEvent *event = 0;
+
+ if (!index.isValid()) {
+ index = m_proxyModel->index(0, 0, QModelIndex());
+ if (!index.isValid()) {
+ qDebug()<<"no currently valid index";
+ return 0;
+ }
+ }
+
+ event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
+ Q_ASSERT(event);
+ if (!event) {
+ return 0;
+ }
+
+ ApiTraceCall *call = 0;
+ if (event->type() == ApiTraceCall::Call) {
+ call = static_cast<ApiTraceCall*>(event);
+ }
+
+ return call;
+
+}
+
+void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame)
+{
+ Q_ASSERT(frame->isLoaded());
+ if (!frame || frame->isEmpty()) {
+ return;
+ }
+
+ QVector<ApiTraceCall*>::const_iterator itr;
+ QVector<ApiTraceCall*> calls = frame->calls();
+
+ itr = calls.constBegin();
+ while (itr != calls.constEnd()) {
+ ApiTraceCall *call = *itr;
+ QModelIndex idx = m_proxyModel->indexForCall(call);
+ if (idx.isValid()) {
+ m_ui.callView->setCurrentIndex(idx);
+ m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtTop);
+ break;
+ }
+ ++itr;
+ }
+}
+
+void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame)
+{
+ Q_ASSERT(frame->isLoaded());
+ if (!frame || frame->isEmpty()) {
+ return;
+ }
+ QVector<ApiTraceCall*>::const_iterator itr;
+ QVector<ApiTraceCall*> calls = frame->calls();
+
+ itr = calls.constEnd();
+ do {
+ --itr;
+ ApiTraceCall *call = *itr;
+ QModelIndex idx = m_proxyModel->indexForCall(call);
+ if (idx.isValid()) {
+ m_ui.callView->setCurrentIndex(idx);
+ m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtBottom);
+ break;
+ }
+ } while (itr != calls.constBegin());
+}
+
+void MainWindow::slotJumpToResult(ApiTraceCall *call)
+{
+ QModelIndex idx = m_proxyModel->indexForCall(call);
+ if (idx.isValid()) {
+ activateWindow();
+ m_ui.callView->setFocus();
+ m_ui.callView->setCurrentIndex(idx);
+ m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
+ } else {
+ statusBar()->showMessage(tr("Call has been filtered out."));
+ }