]> git.cworth.org Git - apitrace/blobdiff - gui/mainwindow.cpp
Switch more places from qlist to qvector.
[apitrace] / gui / mainwindow.cpp
index 23fa40e4edfaaec84d11047369b552ad98467303..591c557e55567eda81a93c1341eadf7cc727aa7a 100644 (file)
@@ -104,7 +104,7 @@ void MainWindow::callItemSelected(const QModelIndex &index)
             QByteArray data =
                 call->arguments()[call->binaryDataIndex()].toByteArray();
             m_vdataInterpreter->setData(data);
-            QVariantList args = call->arguments();
+            QVector<QVariant> args = call->arguments();
 
             for (int i = 0; i < call->argNames().count(); ++i) {
                 QString name = call->argNames()[i];
@@ -132,7 +132,7 @@ void MainWindow::callItemSelected(const QModelIndex &index)
         m_ui.detailsDock->hide();
         m_ui.vertexDataDock->hide();
     }
-    if (m_selectedEvent && !m_selectedEvent->state().isEmpty()) {
+    if (m_selectedEvent && m_selectedEvent->hasState()) {
         fillStateForFrame();
     } else
         m_ui.stateDock->hide();
@@ -320,7 +320,7 @@ static void
 variantToString(const QVariant &var, QString &str)
 {
     if (var.type() == QVariant::List) {
-        QVariantList lst = var.toList();
+        QVector<QVariant> lst = var.toList().toVector();
         str += QLatin1String("[");
         for (int i = 0; i < lst.count(); ++i) {
             QVariant val = lst[i];
@@ -358,7 +358,8 @@ variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap, QList<Q
 }
 
 static void
-variantListToItems(const QVariantList &lst, const QVariantList &defaultLst, QList<QTreeWidgetItem *> &items)
+variantListToItems(const QVector<QVariant> &lst, const QVector<QVariant> &defaultLst,
+                   QList<QTreeWidgetItem *> &items)
 {
     for (int i = 0; i < lst.count(); ++i) {
         QString key = QString::number(i);
@@ -380,7 +381,7 @@ static bool
 isVariantDeep(const QVariant &var)
 {
     if (var.type() == QVariant::List) {
-        QVariantList lst = var.toList();
+        QVector<QVariant> lst = var.toList().toVector();
         for (int i = 0; i < lst.count(); ++i) {
             if (isVariantDeep(lst[i])) {
                 return true;
@@ -426,8 +427,8 @@ variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVa
             variantMapToItems(map, defaultMap, children);
         }
         if (var.type() == QVariant::List) {
-            QVariantList lst = var.toList();
-            QVariantList defaultLst = defaultVar.toList();
+            QVector<QVariant> lst = var.toList().toVector();
+            QVector<QVariant> defaultLst = defaultVar.toList().toVector();
             variantListToItems(lst, defaultLst, children);
         }
         item->addChildren(children);
@@ -436,11 +437,35 @@ variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVa
     return item;
 }
 
-void MainWindow::fillStateForFrame()
+static void addSurfaceItem(const ApiSurface &surface,
+                           const QString &label,
+                           QTreeWidgetItem *parent,
+                           QTreeWidget *tree)
 {
-    QVariantMap params;
+    int width = surface.size().width();
+    int height = surface.size().height();
+    QIcon icon(QPixmap::fromImage(surface.thumb()));
+    QTreeWidgetItem *item = new QTreeWidgetItem(parent);
+
+    item->setIcon(0, icon);
+
+    QString descr =
+        QString::fromLatin1("%1, %2 x %3")
+        .arg(label)
+        .arg(width)
+        .arg(height);
 
-    if (!m_selectedEvent || m_selectedEvent->state().isEmpty())
+    //item->setText(1, descr);
+    QLabel *l = new QLabel(descr, tree);
+    l->setWordWrap(true);
+    tree->setItemWidget(item, 1, l);
+
+    item->setData(0, Qt::UserRole, surface.image());
+}
+
+void MainWindow::fillStateForFrame()
+{
+    if (!m_selectedEvent || !m_selectedEvent->hasState())
         return;
 
     if (m_nonDefaultsLookupEvent) {
@@ -456,11 +481,10 @@ void MainWindow::fillStateForFrame()
         defaultParams = defaultState.parameters();
     }
 
-    const ApiTraceState &state = m_selectedEvent->state();
+    const ApiTraceState &state = *m_selectedEvent->state();
     m_ui.stateTreeWidget->clear();
-    params = state.parameters();
     QList<QTreeWidgetItem *> items;
-    variantMapToItems(params, defaultParams, items);
+    variantMapToItems(state.parameters(), defaultParams, items);
     m_ui.stateTreeWidget->insertTopLevelItems(0, items);
 
     QMap<QString, QString> shaderSources = state.shaderSources();
@@ -470,6 +494,11 @@ void MainWindow::fillStateForFrame()
         m_sourcesWidget->setShaders(shaderSources);
     }
 
+    m_ui.uniformsTreeWidget->clear();
+    QList<QTreeWidgetItem *> uniformsItems;
+    variantMapToItems(state.uniforms(), QVariantMap(), uniformsItems);
+    m_ui.uniformsTreeWidget->insertTopLevelItems(0, uniformsItems);
+
     const QList<ApiTexture> &textures =
         state.textures();
     const QList<ApiFramebuffer> &fbos =
@@ -490,20 +519,9 @@ void MainWindow::fillStateForFrame()
             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.label())
-                    .arg(width)
-                    .arg(height);
-                item->setText(1, descr);
-
-                item->setData(0, Qt::UserRole,
-                              texture.image());
+                addSurfaceItem(texture, texture.label(),
+                               textureItem,
+                               m_ui.surfacesTreeWidget);
             }
         }
         if (!fbos.isEmpty()) {
@@ -516,20 +534,9 @@ void MainWindow::fillStateForFrame()
             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());
+                addSurfaceItem(fbo, fbo.type(),
+                               fboItem,
+                               m_ui.surfacesTreeWidget);
             }
         }
         m_ui.surfacesTab->setEnabled(true);
@@ -558,12 +565,17 @@ void MainWindow::showSurfacesMenu(const QPoint &pos)
         return;
 
     QMenu menu(tr("Surfaces"), this);
-    //add needed actions
+
     QAction *act = menu.addAction(tr("View Image"));
     act->setStatusTip(tr("View the currently selected surface"));
     connect(act, SIGNAL(triggered()),
             SLOT(showSelectedSurface()));
 
+    act = menu.addAction(tr("Save Image"));
+    act->setStatusTip(tr("Save the currently selected surface"));
+    connect(act, SIGNAL(triggered()),
+            SLOT(saveSelectedSurface()));
+
     menu.exec(tree->viewport()->mapToGlobal(pos));
 }
 
@@ -601,6 +613,7 @@ void MainWindow::showSelectedSurface()
 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;
@@ -682,8 +695,8 @@ void MainWindow::initConnections()
             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_retracer, SIGNAL(foundState(ApiTraceState*)),
+            this, SLOT(replayStateFound(ApiTraceState*)));
     connect(m_retracer, SIGNAL(retraceErrors(const QList<RetraceError>&)),
             this, SLOT(slotRetraceErrors(const QList<RetraceError>&)));
 
@@ -766,7 +779,7 @@ void MainWindow::initConnections()
             this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
 }
 
-void MainWindow::replayStateFound(const ApiTraceState &state)
+void MainWindow::replayStateFound(ApiTraceState *state)
 {
     m_stateEvent->setState(state);
     m_model->stateSetOnEvent(m_stateEvent);
@@ -844,7 +857,7 @@ void MainWindow::slotSearchNext(const QString &str,
         m_searchWidget->setFound(false);
         return;
     }
-    const QList<ApiTraceCall*> &calls = m_trace->calls();
+    const QVector<ApiTraceCall*> &calls = m_trace->calls();
     int callNum = calls.indexOf(call);
 
     for (int i = callNum + 1; i < calls.count(); ++i) {
@@ -853,7 +866,7 @@ void MainWindow::slotSearchNext(const QString &str,
         /* if it's not valid it means that the proxy model has already
          * filtered it out */
         if (index.isValid()) {
-            QString txt = testCall->filterText();
+            QString txt = testCall->searchText();
             if (txt.contains(str, sensitivity)) {
                 m_ui.callView->setCurrentIndex(index);
                 m_searchWidget->setFound(true);
@@ -895,7 +908,7 @@ void MainWindow::slotSearchPrev(const QString &str,
         m_searchWidget->setFound(false);
         return;
     }
-    const QList<ApiTraceCall*> &calls = m_trace->calls();
+    const QVector<ApiTraceCall*> &calls = m_trace->calls();
     int callNum = calls.indexOf(call);
 
     for (int i = callNum - 1; i >= 0; --i) {
@@ -904,7 +917,7 @@ void MainWindow::slotSearchPrev(const QString &str,
         /* if it's not valid it means that the proxy model has already
          * filtered it out */
         if (index.isValid()) {
-            QString txt = testCall->filterText();
+            QString txt = testCall->searchText();
             if (txt.contains(str, sensitivity)) {
                 m_ui.callView->setCurrentIndex(index);
                 m_searchWidget->setFound(true);
@@ -923,17 +936,6 @@ void MainWindow::fillState(bool nonDefaults)
             m_ui.nonDefaultsCB->blockSignals(true);
             m_ui.nonDefaultsCB->setChecked(false);
             m_ui.nonDefaultsCB->blockSignals(false);
-            int ret = QMessageBox::question(
-                this, tr("Empty Default State"),
-                tr("The applcation needs to figure out the "
-                   "default state for the current trace. "
-                   "This only has to be done once and "
-                   "afterwards you will be able to enable "
-                   "displaying of non default state for all calls."
-                   "\nDo you want to lookup the default state now?"),
-                QMessageBox::Yes | QMessageBox::No);
-            if (ret != QMessageBox::Yes)
-                return;
             ApiTraceFrame *firstFrame =
                 m_trace->frameAt(0);
             ApiTraceEvent *oldSelected = m_selectedEvent;
@@ -959,12 +961,14 @@ void MainWindow::customContextMenuRequested(QPoint pos)
 
     ApiTraceEvent *event =
         index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
-    if (!event || event->type() != ApiTraceEvent::Call)
+    if (!event)
         return;
 
     menu.addAction(QIcon(":/resources/media-record.png"),
                    tr("Lookup state"), this, SLOT(lookupState()));
-    menu.addAction(tr("Edit"), this, SLOT(editCall()));
+    if (event->type() == ApiTraceEvent::Call) {
+        menu.addAction(tr("Edit"), this, SLOT(editCall()));
+    }
 
     menu.exec(QCursor::pos());
 }
@@ -999,8 +1003,8 @@ void MainWindow::slotGoFrameStart()
         return;
     }
 
-    QList<ApiTraceCall*>::const_iterator itr;
-    QList<ApiTraceCall*> calls = frame->calls();
+    QVector<ApiTraceCall*>::const_iterator itr;
+    QVector<ApiTraceCall*> calls = frame->calls();
 
     itr = calls.constBegin();
     while (itr != calls.constEnd()) {
@@ -1020,8 +1024,8 @@ void MainWindow::slotGoFrameEnd()
     if (!frame || frame->isEmpty()) {
         return;
     }
-    QList<ApiTraceCall*>::const_iterator itr;
-    QList<ApiTraceCall*> calls = frame->calls();
+    QVector<ApiTraceCall*>::const_iterator itr;
+    QVector<ApiTraceCall*> calls = frame->calls();
 
     itr = calls.constEnd();
     do {
@@ -1102,4 +1106,57 @@ ApiTraceCall * MainWindow::currentCall() const
     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 (currentCall()) {
+        imageIndex = tr("_call_%1")
+                     .arg(currentCall()->index());
+    } else if (currentFrame()) {
+        ApiTraceCall *firstCall = currentFrame()->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);
+}
+
 #include "mainwindow.moc"