]> git.notmuchmail.org Git - apitrace/blobdiff - gui/mainwindow.cpp
Implement showing only of events specified by a regexp.
[apitrace] / gui / mainwindow.cpp
index b19a559fe681b882f5a16b2e0576e31cfa7fa4d5..f57ccc810076c810394c4541c0db80da300b0b59 100644 (file)
@@ -6,14 +6,16 @@
 #include "apitracemodel.h"
 #include "apitracefilter.h"
 #include "imageviewer.h"
+#include "jumpwidget.h"
 #include "retracer.h"
+#include "searchwidget.h"
 #include "settingsdialog.h"
 #include "shaderssourcewidget.h"
+#include "tracedialog.h"
+#include "traceprocess.h"
 #include "ui_retracerdialog.h"
 #include "vertexdatainterpreter.h"
 
-#include <qjson/parser.h>
-
 #include <QAction>
 #include <QDebug>
 #include <QDesktopServices>
@@ -22,6 +24,7 @@
 #include <QLineEdit>
 #include <QMessageBox>
 #include <QProgressBar>
+#include <QShortcut>
 #include <QToolBar>
 #include <QUrl>
 #include <QVBoxLayout>
 MainWindow::MainWindow()
     : QMainWindow(),
       m_selectedEvent(0),
-      m_stateEvent(0),
-      m_jsonParser(new QJson::Parser())
+      m_stateEvent(0)
 {
     m_ui.setupUi(this);
     initObjects();
     initConnections();
 }
 
+void MainWindow::createTrace()
+{
+    TraceDialog dialog;
+
+    if (!m_traceProcess->canTrace()) {
+        QMessageBox::warning(
+            this,
+            tr("Unsupported"),
+            tr("Current configuration doesn't support tracing."));
+        return;
+    }
+
+    if (dialog.exec() == QDialog::Accepted) {
+        qDebug()<< "App : " <<dialog.applicationPath();
+        qDebug()<< "  Arguments: "<<dialog.arguments();
+        m_traceProcess->setExecutablePath(dialog.applicationPath());
+        m_traceProcess->setArguments(dialog.arguments());
+        m_traceProcess->start();
+    }
+}
+
 void MainWindow::openTrace()
 {
     QString fileName =
@@ -113,11 +136,6 @@ void MainWindow::callItemSelected(const QModelIndex &index)
         m_ui.stateDock->hide();
 }
 
-void MainWindow::filterTrace()
-{
-    m_proxyModel->setFilterString(m_filterEdit->text());
-}
-
 void MainWindow::replayStart()
 {
     QDialog dlg;
@@ -140,7 +158,7 @@ void MainWindow::replayStart()
 
 void MainWindow::replayStop()
 {
-    m_retracer->terminate();
+    m_retracer->quit();
     m_ui.actionStop->setEnabled(false);
     m_ui.actionReplay->setEnabled(true);
     m_ui.actionLookupState->setEnabled(true);
@@ -164,20 +182,19 @@ void MainWindow::newTraceFile(const QString &fileName)
     }
 }
 
-void MainWindow::replayFinished(const QByteArray &output)
+void MainWindow::replayFinished(const QString &output)
 {
     m_ui.actionStop->setEnabled(false);
     m_ui.actionReplay->setEnabled(true);
     m_ui.actionLookupState->setEnabled(true);
 
-    if (m_retracer->captureState()) {
-        bool ok = false;
-        QVariantMap parsedJson = m_jsonParser->parse(output, &ok).toMap();
-        parseState(parsedJson);
-    } else if (output.length() < 80) {
+    m_progressBar->hide();
+    if (output.length() < 80) {
         statusBar()->showMessage(output);
     }
     m_stateEvent = 0;
+    statusBar()->showMessage(
+        tr("Replaying finished!"), 2000);
 }
 
 void MainWindow::replayError(const QString &message)
@@ -187,6 +204,9 @@ void MainWindow::replayError(const QString &message)
     m_ui.actionLookupState->setEnabled(true);
     m_stateEvent = 0;
 
+    m_progressBar->hide();
+    statusBar()->showMessage(
+        tr("Replaying unsuccessful."), 2000);
     QMessageBox::warning(
         this, tr("Replay Failed"), message);
 }
@@ -223,7 +243,8 @@ void MainWindow::replayTrace(bool dumpState)
         if (m_selectedEvent->type() == ApiTraceEvent::Call) {
             index = static_cast<ApiTraceCall*>(m_selectedEvent)->index;
         } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
-            ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(m_selectedEvent);
+            ApiTraceFrame *frame =
+                static_cast<ApiTraceFrame*>(m_selectedEvent);
             if (frame->calls.isEmpty()) {
                 //XXX i guess we could still get the current state
                 qDebug()<<"tried to get a state for an empty frame";
@@ -239,6 +260,13 @@ void MainWindow::replayTrace(bool dumpState)
     m_retracer->start();
 
     m_ui.actionStop->setEnabled(true);
+    m_progressBar->show();
+    if (dumpState)
+        statusBar()->showMessage(
+            tr("Looking up the state..."));
+    else
+        statusBar()->showMessage(
+            tr("Replaying the trace file..."));
 }
 
 void MainWindow::lookupState()
@@ -255,18 +283,6 @@ void MainWindow::lookupState()
 
 MainWindow::~MainWindow()
 {
-    delete m_jsonParser;
-}
-
-void MainWindow::parseState(const QVariantMap &parsedJson)
-{
-    m_stateEvent->setState(ApiTraceState(parsedJson));
-    m_model->stateSetOnEvent(m_stateEvent);
-    if (m_selectedEvent == m_stateEvent) {
-        fillStateForFrame();
-    } else {
-        m_ui.stateDock->hide();
-    }
 }
 
 static void
@@ -326,32 +342,65 @@ void MainWindow::fillStateForFrame()
 
     const QList<ApiTexture> &textures =
         state.textures();
+    const QList<ApiFramebuffer> &fbos =
+        state.framebuffers();
 
     m_ui.surfacesTreeWidget->clear();
-    if (textures.isEmpty()) {
+    if (textures.isEmpty() && fbos.isEmpty()) {
         m_ui.surfacesTab->setDisabled(false);
     } else {
-        QTreeWidgetItem *textureItem =
-            new QTreeWidgetItem(m_ui.surfacesTreeWidget);
         m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64));
-        textureItem->setText(0, tr("Textures"));
-        for (int i = 0; i < textures.count(); ++i) {
-            const ApiTexture &texture =
-                textures[i];
-            QIcon icon(QPixmap::fromImage(texture.thumb()));
-            QTreeWidgetItem *item = new QTreeWidgetItem(textureItem);
-            item->setIcon(0, icon);
-            int width = texture.size().width();
-            int height = texture.size().height();
-            QString descr =
-                QString::fromLatin1("%1, %2 x %3")
-                .arg(texture.target())
-                .arg(width)
-                .arg(height);
-            item->setText(1, descr);
-
-            item->setData(0, Qt::UserRole,
-                          texture.image());
+        if (!textures.isEmpty()) {
+            QTreeWidgetItem *textureItem =
+                new QTreeWidgetItem(m_ui.surfacesTreeWidget);
+            textureItem->setText(0, tr("Textures"));
+            if (textures.count() <= 6)
+                textureItem->setExpanded(true);
+
+            for (int i = 0; i < textures.count(); ++i) {
+                const ApiTexture &texture =
+                    textures[i];
+                QIcon icon(QPixmap::fromImage(texture.thumb()));
+                QTreeWidgetItem *item = new QTreeWidgetItem(textureItem);
+                item->setIcon(0, icon);
+                int width = texture.size().width();
+                int height = texture.size().height();
+                QString descr =
+                    QString::fromLatin1("%1, %2 x %3")
+                    .arg(texture.target())
+                    .arg(width)
+                    .arg(height);
+                item->setText(1, descr);
+
+                item->setData(0, Qt::UserRole,
+                              texture.image());
+            }
+        }
+        if (!fbos.isEmpty()) {
+            QTreeWidgetItem *fboItem =
+                new QTreeWidgetItem(m_ui.surfacesTreeWidget);
+            fboItem->setText(0, tr("Framebuffers"));
+            if (fbos.count() <= 6)
+                fboItem->setExpanded(true);
+
+            for (int i = 0; i < fbos.count(); ++i) {
+                const ApiFramebuffer &fbo =
+                    fbos[i];
+                QIcon icon(QPixmap::fromImage(fbo.thumb()));
+                QTreeWidgetItem *item = new QTreeWidgetItem(fboItem);
+                item->setIcon(0, icon);
+                int width = fbo.size().width();
+                int height = fbo.size().height();
+                QString descr =
+                    QString::fromLatin1("%1, %2 x %3")
+                    .arg(fbo.type())
+                    .arg(width)
+                    .arg(height);
+                item->setText(1, descr);
+
+                item->setData(0, Qt::UserRole,
+                              fbo.image());
+            }
         }
         m_ui.surfacesTab->setEnabled(true);
     }
@@ -361,11 +410,9 @@ void MainWindow::fillStateForFrame()
 void MainWindow::showSettings()
 {
     SettingsDialog dialog;
-    dialog.setFilterOptions(m_proxyModel->filterOptions());
+    dialog.setFilterModel(m_proxyModel);
 
-    if (dialog.exec() == QDialog::Accepted) {
-        m_proxyModel->setFilterOptions(dialog.filterOptions());
-    }
+    dialog.exec();
 }
 
 void MainWindow::openHelp(const QUrl &url)
@@ -440,10 +487,6 @@ void MainWindow::initObjects()
     m_ui.callView->header()->swapSections(0, 1);
     m_ui.callView->setColumnWidth(1, 42);
 
-    QToolBar *toolBar = addToolBar(tr("Navigation"));
-    m_filterEdit = new QLineEdit(toolBar);
-    toolBar->addWidget(m_filterEdit);
-
     m_progressBar = new QProgressBar();
     m_progressBar->setRange(0, 0);
     statusBar()->addPermanentWidget(m_progressBar);
@@ -460,6 +503,21 @@ void MainWindow::initObjects()
 
     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);
+
+    new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_G),
+                  this, SLOT(slotGoTo()));
+    new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F),
+                  this, SLOT(slotSearch()));
 }
 
 void MainWindow::initConnections()
@@ -469,10 +527,12 @@ void MainWindow::initConnections()
     connect(m_trace, SIGNAL(finishedLoadingTrace()),
             this, SLOT(finishedLoadingTrace()));
 
-    connect(m_retracer, SIGNAL(finished(const QByteArray&)),
-            this, SLOT(replayFinished(const QByteArray&)));
+    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(const ApiTraceState&)),
+            this, SLOT(replayStateFound(const ApiTraceState&)));
 
     connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
             m_vdataInterpreter, SLOT(interpretData()));
@@ -486,6 +546,8 @@ void MainWindow::initConnections()
             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()),
@@ -502,8 +564,6 @@ void MainWindow::initConnections()
 
     connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
             this, SLOT(callItemSelected(const QModelIndex &)));
-    connect(m_filterEdit, SIGNAL(returnPressed()),
-            this, SLOT(filterTrace()));
 
     connect(m_ui.surfacesTreeWidget,
             SIGNAL(customContextMenuRequested(const QPoint &)),
@@ -514,6 +574,164 @@ void MainWindow::initConnections()
 
     connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
             this, SLOT(openHelp(const QUrl&)));
+
+    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&)));
+}
+
+void MainWindow::replayStateFound(const ApiTraceState &state)
+{
+    m_stateEvent->setState(state);
+    m_model->stateSetOnEvent(m_stateEvent);
+    if (m_selectedEvent == m_stateEvent) {
+        fillStateForFrame();
+    } else {
+        m_ui.stateDock->hide();
+    }
+}
+
+void MainWindow::slotGoTo()
+{
+    m_searchWidget->hide();
+    m_jumpWidget->show();
+}
+
+void MainWindow::slotJumpTo(int callNum)
+{
+    QModelIndex index = m_proxyModel->callIndex(callNum);
+    if (index.isValid()) {
+        m_ui.callView->setCurrentIndex(index);
+    }
+}
+
+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::slotSearch()
+{
+    m_jumpWidget->hide();
+    m_searchWidget->show();
+}
+
+void MainWindow::slotSearchNext(const QString &str, Qt::CaseSensitivity sensitivity)
+{
+    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";
+            m_searchWidget->setFound(false);
+            return;
+        }
+    }
+
+    event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
+    ApiTraceCall *call = 0;
+
+    if (event->type() == ApiTraceCall::Call)
+        call = static_cast<ApiTraceCall*>(event);
+    else {
+        Q_ASSERT(event->type() == ApiTraceCall::Frame);
+        ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
+        call = frame->calls.value(0);
+    }
+
+    if (!call) {
+        m_searchWidget->setFound(false);
+        return;
+    }
+    const QList<ApiTraceCall*> &calls = m_trace->calls();
+    int callNum = calls.indexOf(call);
+
+    for (int i = callNum + 1; i < calls.count(); ++i) {
+        ApiTraceCall *testCall = calls[i];
+        QString txt = testCall->filterText();
+        if (txt.contains(str, sensitivity)) {
+            QModelIndex index = m_proxyModel->indexForCall(testCall);
+            /* if it's not valid it means that the proxy model has already
+             * filtered it out */
+            if (index.isValid()) {
+                m_ui.callView->setCurrentIndex(index);
+                m_searchWidget->setFound(true);
+                return;
+            }
+        }
+    }
+    m_searchWidget->setFound(false);
+}
+
+void MainWindow::slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitivity)
+{
+    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";
+            m_searchWidget->setFound(false);
+            return;
+        }
+    }
+
+    event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
+    ApiTraceCall *call = 0;
+
+    if (event->type() == ApiTraceCall::Call)
+        call = static_cast<ApiTraceCall*>(event);
+    else {
+        Q_ASSERT(event->type() == ApiTraceCall::Frame);
+        ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event);
+        call = frame->calls.value(0);
+    }
+
+    if (!call) {
+        m_searchWidget->setFound(false);
+        return;
+    }
+    const QList<ApiTraceCall*> &calls = m_trace->calls();
+    int callNum = calls.indexOf(call);
+
+    for (int i = callNum - 1; i >= 0; --i) {
+        ApiTraceCall *testCall = calls[i];
+        QString txt = testCall->filterText();
+        if (txt.contains(str, sensitivity)) {
+            QModelIndex index = m_proxyModel->indexForCall(testCall);
+            /* if it's not valid it means that the proxy model has already
+             * filtered it out */
+            if (index.isValid()) {
+                m_ui.callView->setCurrentIndex(index);
+                m_searchWidget->setFound(true);
+                return;
+            }
+        }
+    }
+    m_searchWidget->setFound(false);
 }
 
 #include "mainwindow.moc"