+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(ApiTraceCall *call)
+{
+ Q_ASSERT(call);
+ if (call == m_selectedEvent) {
+ 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);
+ 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);
+ break;
+ }
+ } while (itr != calls.constBegin());
+}
+
+void MainWindow::slotJumpToResult(ApiTraceCall *call)
+{
+ QModelIndex index = m_proxyModel->indexForCall(call);
+ if (index.isValid()) {
+ m_ui.callView->setCurrentIndex(index);
+ } else {
+ statusBar()->showMessage(tr("Call has been filtered out."));
+ }
+}
+