diff options
author | Martin Schulze <schulmar@hrz.tu-chemnitz.de> | 2015-10-11 12:37:42 +0200 |
---|---|---|
committer | Jose Fonseca <jfonseca@vmware.com> | 2015-11-04 17:10:11 +0000 |
commit | 638ec448619fda80fcb439b1747af62169d05548 (patch) | |
tree | 1a1274bd8827013638b9aa8a98454c5a63589f38 /gui | |
parent | 34b56c7727184a9b4c746ecd289c86a85ca2d5b0 (diff) |
gui: Cleanup surface parsing.
Diffstat (limited to 'gui')
-rw-r--r-- | gui/apitracecall.cpp | 62 | ||||
-rw-r--r-- | gui/mainwindow.cpp | 56 | ||||
-rw-r--r-- | gui/mainwindow.h | 4 |
3 files changed, 61 insertions, 61 deletions
diff --git a/gui/apitracecall.cpp b/gui/apitracecall.cpp index 35235ac2..8ae03d0e 100644 --- a/gui/apitracecall.cpp +++ b/gui/apitracecall.cpp @@ -436,6 +436,34 @@ ApiTraceState::ApiTraceState() { } +static ApiTexture getTextureFrom(QVariantMap const &image, QString label) +{ + QSize size(image[QLatin1String("__width__")].toInt(), + image[QLatin1String("__height__")].toInt()); + QString cls = image[QLatin1String("__class__")].toString(); + int depth = + image[QLatin1String("__depth__")].toInt(); + QString formatName = + image[QLatin1String("__format__")].toString(); + + QByteArray dataArray = + image[QLatin1String("__data__")].toByteArray(); + + QString userLabel = + image[QLatin1String("__label__")].toString(); + if (!userLabel.isEmpty()) { + label += QString(", \"%1\"").arg(userLabel); + } + + ApiTexture tex; + tex.setSize(size); + tex.setDepth(depth); + tex.setFormatName(formatName); + tex.setLabel(label); + tex.setData(dataArray); + return tex; +} + ApiTraceState::ApiTraceState(const QVariantMap &parsedJson) { m_parameters = parsedJson[QLatin1String("parameters")].toMap(); @@ -455,36 +483,12 @@ ApiTraceState::ApiTraceState(const QVariantMap &parsedJson) m_buffers = parsedJson[QLatin1String("buffers")].toMap(); - QVariantMap textures = - parsedJson[QLatin1String("textures")].toMap(); - for (itr = textures.constBegin(); itr != textures.constEnd(); ++itr) { - QVariantMap image = itr.value().toMap(); - QSize size(image[QLatin1String("__width__")].toInt(), - image[QLatin1String("__height__")].toInt()); - QString cls = image[QLatin1String("__class__")].toString(); - int depth = - image[QLatin1String("__depth__")].toInt(); - QString formatName = - image[QLatin1String("__format__")].toString(); - - QByteArray dataArray = - image[QLatin1String("__data__")].toByteArray(); - - QString label = itr.key(); - QString userLabel = - image[QLatin1String("__label__")].toString(); - if (!userLabel.isEmpty()) { - label += QString(", \"%1\"").arg(userLabel); + { + QVariantMap textures = + parsedJson[QLatin1String("textures")].toMap(); + for (itr = textures.constBegin(); itr != textures.constEnd(); ++itr) { + m_textures.append(getTextureFrom(itr.value().toMap(), itr.key())); } - - ApiTexture tex; - tex.setSize(size); - tex.setDepth(depth); - tex.setFormatName(formatName); - tex.setLabel(label); - tex.setData(dataArray); - - m_textures.append(tex); } QVariantMap fbos = diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 17c2afaa..2264c3b6 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -766,6 +766,28 @@ static void addSurfaceItem(const ApiSurface &surface, item->setData(0, Qt::UserRole, surface.data()); } +void MainWindow::addSurface(const ApiTexture &image, QTreeWidgetItem *parent) { + addSurfaceItem(image, image.label(), parent, m_ui.surfacesTreeWidget); +} + +void MainWindow::addSurface(const ApiFramebuffer &fbo, QTreeWidgetItem *parent) { + addSurfaceItem(fbo, fbo.type(), parent, m_ui.surfacesTreeWidget); +} + +template <typename Surface> +void MainWindow::addSurfaces(const QList<Surface> &surfaces, const char *label) { + if (!surfaces.isEmpty()) { + QTreeWidgetItem *imageItem = new QTreeWidgetItem(m_ui.surfacesTreeWidget); + imageItem->setText(0, tr(label)); + if (surfaces.count() <= 6) { + imageItem->setExpanded(true); + } + for (int i = 0; i < surfaces.count(); ++i) { + addSurface(surfaces[i], imageItem); + } + } +} + void MainWindow::fillStateForFrame() { if (!m_selectedEvent || !m_selectedEvent->hasState()) { @@ -818,38 +840,8 @@ void MainWindow::fillStateForFrame() m_ui.surfacesTab->setDisabled(false); } else { m_ui.surfacesTreeWidget->setIconSize(QSize(THUMBNAIL_SIZE, THUMBNAIL_SIZE)); - 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]; - addSurfaceItem(texture, texture.label(), - textureItem, - m_ui.surfacesTreeWidget); - } - } - 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]; - addSurfaceItem(fbo, fbo.type(), - fboItem, - m_ui.surfacesTreeWidget); - } - } + addSurfaces(textures, "Textures"); + addSurfaces(fbos, "Framebuffers"); m_ui.surfacesTab->setEnabled(true); } m_ui.stateDock->show(); diff --git a/gui/mainwindow.h b/gui/mainwindow.h index d5107da7..1aabe2f2 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -126,6 +126,10 @@ private: void linkLocalAndroidTrace(const QString &localFile, const QString &deviceFile); QString linkedAndroidTrace(const QString &localFile); + void addSurface(const ApiTexture &image, QTreeWidgetItem *parent); + void addSurface(const ApiFramebuffer &image, QTreeWidgetItem *parent); + template <typename Surface> + void addSurfaces(const QList<Surface> &images, const char *label); protected: virtual void closeEvent(QCloseEvent * event); |