Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
Refactor some functionality into a utils header
Browse files Browse the repository at this point in the history
Change-Id: I2dcb5d1044380cc7bb615bcddf3b2afeab1e79c9
Reviewed-on: https://kuesa-codereview.kdab.com/c/kuesa/kuesa/+/341
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
  • Loading branch information
Juan Jose Casafranca authored and lemirep committed Dec 4, 2019
1 parent 92c5086 commit 2614302
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 45 deletions.
6 changes: 4 additions & 2 deletions tools/gltfEditor/gltfEditor.pro
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ SOURCES += \
settingsdialog.cpp \
orbitcameracontroller.cpp \
exportdialog.cpp \
memoryusagewidget.cpp
memoryusagewidget.cpp \
utils.cpp

HEADERS += \
mainwindow.h \
Expand All @@ -80,7 +81,8 @@ HEADERS += \
settingsdialog.h \
orbitcameracontroller.h \
exportdialog.h \
memoryusagewidget.h
memoryusagewidget.h \
utils.h

FORMS += \
animationwidget.ui \
Expand Down
22 changes: 6 additions & 16 deletions tools/gltfEditor/memoryusagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,10 @@

#include <Kuesa/private/textureparser_p.h>
#include "textureinspector.h"
#include "utils.h"

namespace {
const QLatin1String LASTPATHSETTING("mainwindow/lastPath");

QString totalSizeString(int sizeInBytes)
{
auto size = sizeInBytes / 1024.0;
QString suffix(QStringLiteral(" KB"));
if (size > 1024.) {
size = size / 1024.;
suffix = QStringLiteral(" MB");
}
return QString::number(size, 'f', 2) + suffix;
}
const QLatin1String LASTPATHSETTING("mainwindow/lastPath");
}

MemoryUsageWidget::MemoryUsageWidget(QWidget *parent)
Expand Down Expand Up @@ -108,8 +98,8 @@ void MemoryUsageWidget::updateGeometryMemoryUsage() const
QVector<Qt3DRender::QBuffer *> visitedBuffer;
for (const auto &name: names) {
Qt3DRender::QGeometryRenderer *mesh = meshesCollection->find(name);

const auto &attributes = mesh->geometry()->attributes();

for (Qt3DRender::QAttribute *attribute : attributes) {
if (!visitedBuffer.contains(attribute->buffer())) {
geometrySize += attribute->buffer()->data().size();
Expand All @@ -118,7 +108,7 @@ void MemoryUsageWidget::updateGeometryMemoryUsage() const
}
}

m_ui->geometryUsage->setText(totalSizeString(geometrySize));
m_ui->geometryUsage->setText(glTFEditor::Utils::totalSizeString(geometrySize));
}

void MemoryUsageWidget::updateTextureMemoryUsage() const
Expand All @@ -127,7 +117,7 @@ void MemoryUsageWidget::updateTextureMemoryUsage() const
const auto &names = texturesCollection->names();

int texturesSize = 0;
QVector<Qt3DRender::QAbstractTextureImage*> visitedImages;
QVector<Qt3DRender::QAbstractTextureImage *> visitedImages;
for (const auto &name : qAsConst(names)) {
Qt3DRender::QAbstractTexture *texture = texturesCollection->find(name);
Qt3DRender::QAbstractTextureImage *image = texture->textureImages()[0];
Expand All @@ -137,5 +127,5 @@ void MemoryUsageWidget::updateTextureMemoryUsage() const
}
}

m_ui->textureUsage->setText(totalSizeString(texturesSize));
m_ui->textureUsage->setText(glTFEditor::Utils::totalSizeString(texturesSize));
}
11 changes: 0 additions & 11 deletions tools/gltfEditor/meshinspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,6 @@ QString MeshInspector::nameForPrimitiveType(int primitiveType)
}
}

QString MeshInspector::totalSizeString() const
{
double size = m_totalSize / 1024.0;
QString suffix(QStringLiteral(" KB"));
if (size > 1024.) {
size = size / 1024.;
suffix = QStringLiteral(" MB");
}
return QString::number(size, 'f', 2) + suffix;
}

void MeshInspector::setSelectionColor(const QColor &c)
{
if (c == m_selectionColor)
Expand Down
2 changes: 0 additions & 2 deletions tools/gltfEditor/meshinspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class MeshInspector : public QObject
Q_OBJECT
Q_PROPERTY(QString assetName READ assetName NOTIFY meshParamsChanged)
Q_PROPERTY(int totalSize READ totalSize NOTIFY meshParamsChanged)
Q_PROPERTY(QString totalSizeString READ totalSizeString NOTIFY meshParamsChanged)
Q_PROPERTY(int vertexCount READ vertexCount NOTIFY meshParamsChanged)
Q_PROPERTY(QString primitiveType READ primitiveType NOTIFY meshParamsChanged)
Q_PROPERTY(int primitiveCount READ primitiveCount NOTIFY meshParamsChanged)
Expand All @@ -82,7 +81,6 @@ class MeshInspector : public QObject
static unsigned int attributeSizeInBytes(Qt3DRender::QAttribute *attribute);
static int calculatePrimitiveCount(int indexCount, int primitiveType);
static QString nameForPrimitiveType(int primitiveType);
QString totalSizeString() const;

void setSelectionColor(const QColor &c);

Expand Down
3 changes: 2 additions & 1 deletion tools/gltfEditor/meshwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QDataWidgetMapper>
#include <QLabel>
#include <QAbstractItemModel>
#include "utils.h"

MeshWidget::MeshWidget(QWidget *parent)
: QWidget(parent)
Expand Down Expand Up @@ -62,7 +63,7 @@ void MeshWidget::setMeshInspector(MeshInspector *inspector)
void MeshWidget::updateData()
{
m_ui->nameLabel->setText(m_inspector->assetName());
m_ui->totalSizeLabel->setText(m_inspector->totalSizeString());
m_ui->totalSizeLabel->setText(glTFEditor::Utils::totalSizeString(m_inspector->totalSize()));
m_ui->vertexCountLabel->setText(QString::number(m_inspector->vertexCount()));
m_ui->primitiveTypeLabel->setText(m_inspector->primitiveType());
m_ui->primitiveCountLabel->setText(QString::number(m_inspector->primitiveCount()));
Expand Down
15 changes: 2 additions & 13 deletions tools/gltfEditor/texturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,7 @@
#include <QScrollBar>
#include <QQmlContext>

namespace {
QString totalSizeString(int sizeInBytes)
{
auto size = sizeInBytes / 1024.0;
QString suffix(QStringLiteral(" KB"));
if (size > 1024.) {
size = size / 1024.;
suffix = QStringLiteral(" MB");
}
return QString::number(size, 'f', 2) + suffix;
}
}
#include "utils.h"

TextureWidget::TextureWidget(QWidget *parent)
: QWidget(parent)
Expand Down Expand Up @@ -98,7 +87,7 @@ void TextureWidget::updateData()
{
ui->nameValue->setText(m_inspector->assetName());
ui->formatValue->setText(m_inspector->format());
ui->textureSize->setText(::totalSizeString(m_inspector->textureSize()));
ui->textureSize->setText(glTFEditor::Utils::totalSizeString(m_inspector->textureSize()));
ui->targetValue->setText(m_inspector->target());
ui->widthValue->setText(QString::number(m_inspector->width()));
ui->heightValue->setText(QString::number(m_inspector->height()));
Expand Down
46 changes: 46 additions & 0 deletions tools/gltfEditor/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
utils.cpp
This file is part of Kuesa.
Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
Author: Juan Casafranca <juan.casafranca@kdab.com>
Licensees holding valid proprietary KDAB Kuesa licenses may use this file in
accordance with the Kuesa Enterprise License Agreement provided with the Software in the
LICENSE.KUESA.ENTERPRISE file.
Contact info@kdab.com if any conditions of this licensing are not clear to you.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "utils.h"

namespace glTFEditor {
namespace Utils {

QString totalSizeString(int sizeInBytes)
{
auto size = sizeInBytes / 1024.0;
QString suffix(QStringLiteral(" KB"));
if (size > 1024.) {
size = size / 1024.;
suffix = QStringLiteral(" MB");
}
return QString::number(size, 'f', 2) + suffix;
}

} // namespace Utils
} // namespace glTFEditor
42 changes: 42 additions & 0 deletions tools/gltfEditor/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
utils.h
This file is part of Kuesa.
Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
Author: Juan Casafranca <juan.casafranca@kdab.com>
Licensees holding valid proprietary KDAB Kuesa licenses may use this file in
accordance with the Kuesa Enterprise License Agreement provided with the Software in the
LICENSE.KUESA.ENTERPRISE file.
Contact info@kdab.com if any conditions of this licensing are not clear to you.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef GLTFEDITOR_UTILS_H
#define GLTFEDITOR_UTILS_H

#include <QString>

namespace glTFEditor {
namespace Utils {

QString totalSizeString(int sizeInBytes);

} // namespace Utils
} // namespace glTFEditor

#endif //GLTFEDITOR_UTILS_H

0 comments on commit 2614302

Please sign in to comment.