mirror of https://github.com/qt/qtgraphs.git
Give a warning if a file is missing
setHeighMapFile and setMeshFile did not check whether the filename given pointed to an existing file. Pick-to: 6.8 Fixes: QTBUG-129824 Change-Id: I2326d839e27a612733b4edcda08c97c87bbd7ec4 Reviewed-by: Sakaria Pouke <sakaria.pouke@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io> Reviewed-by: Sami Varanka <sami.varanka@qt.io>
This commit is contained in:
parent
0a2ff2356f
commit
6ac03f52f9
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||
|
||||
#include <QtCore/qfileinfo.h>
|
||||
#include "qcustom3ditem_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
|
@ -236,6 +237,11 @@ QCustom3DItem::~QCustom3DItem() {}
|
|||
void QCustom3DItem::setMeshFile(const QString &meshFile)
|
||||
{
|
||||
Q_D(QCustom3DItem);
|
||||
QFileInfo validfile(meshFile);
|
||||
if (!validfile.exists() || !validfile.isFile()) {
|
||||
qWarning("Mesh file %ls does not exist.", qUtf16Printable(meshFile));
|
||||
return;
|
||||
}
|
||||
if (d->m_meshFile != meshFile) {
|
||||
d->m_meshFile = meshFile;
|
||||
d->m_dirtyBits.meshDirty = true;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <QtCore/qfileinfo.h>
|
||||
#include "qheightmapsurfacedataproxy_p.h"
|
||||
#include "qsurface3dseries_p.h"
|
||||
|
||||
|
|
@ -296,9 +297,18 @@ QImage QHeightMapSurfaceDataProxy::heightMap() const
|
|||
void QHeightMapSurfaceDataProxy::setHeightMapFile(const QString &filename)
|
||||
{
|
||||
Q_D(QHeightMapSurfaceDataProxy);
|
||||
d->m_heightMapFile = filename;
|
||||
setHeightMap(QImage(filename));
|
||||
emit heightMapFileChanged(filename);
|
||||
QFileInfo validfile(filename);
|
||||
// Check if the filename is empty, in which case we should clear the height map,
|
||||
// or if not, it's an actual file that can be found
|
||||
if (!filename.isEmpty() && (!validfile.exists() || !validfile.isFile())) {
|
||||
qWarning("Height map file %ls does not exist.", qUtf16Printable(filename));
|
||||
return;
|
||||
}
|
||||
if (d->m_heightMapFile != filename) {
|
||||
d->m_heightMapFile = filename;
|
||||
setHeightMap(QImage(filename));
|
||||
emit heightMapFileChanged(filename);
|
||||
}
|
||||
}
|
||||
|
||||
QString QHeightMapSurfaceDataProxy::heightMapFile() const
|
||||
|
|
|
|||
|
|
@ -8,3 +8,10 @@ qt_internal_add_test(tst_qgcustom
|
|||
Qt::Gui
|
||||
Qt::Graphs
|
||||
)
|
||||
|
||||
qt_internal_add_resource(tst_qgcustom "qgcustom"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
"customitem.mesh"
|
||||
)
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -19,6 +19,7 @@ private slots:
|
|||
|
||||
void initialProperties();
|
||||
void initializeProperties();
|
||||
void invalidProperties();
|
||||
|
||||
private:
|
||||
QCustom3DItem *m_custom;
|
||||
|
|
@ -129,5 +130,16 @@ void tst_custom::initializeProperties()
|
|||
QCOMPARE(updateSpy.size(), 10);
|
||||
}
|
||||
|
||||
void tst_custom::invalidProperties()
|
||||
{
|
||||
QVERIFY(m_custom);
|
||||
|
||||
// Verify we're getting this warning
|
||||
QTest::ignoreMessage(QtWarningMsg, "Mesh file :/nonexistentitem.mesh does not exist.");
|
||||
m_custom->setMeshFile(":/nonexistentitem.mesh");
|
||||
QEXPECT_FAIL("", "Nonexistent file given", Continue);
|
||||
QCOMPARE(m_custom->meshFile(), QString(":/nonexistentitem.mesh"));
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_custom)
|
||||
#include "tst_custom.moc"
|
||||
|
|
|
|||
|
|
@ -160,6 +160,12 @@ void tst_proxy::initializeProperties()
|
|||
|
||||
void tst_proxy::invalidProperties()
|
||||
{
|
||||
// Verify we're getting this warning
|
||||
QTest::ignoreMessage(QtWarningMsg, "Height map file :/nonexistenttexture.jpg does not exist.");
|
||||
m_proxy->setHeightMapFile(":/nonexistenttexture.jpg");
|
||||
QEXPECT_FAIL("", "Nonexistent file given", Continue);
|
||||
QCOMPARE(m_proxy->heightMapFile(), QString(":/nonexistenttexture.jpg"));
|
||||
|
||||
m_proxy->setMaxXValue(-10.0f);
|
||||
m_proxy->setMaxZValue(-10.0f);
|
||||
QCOMPARE(m_proxy->maxXValue(), -10.0f);
|
||||
|
|
|
|||
Loading…
Reference in New Issue