From 5de8f737237941df951c55bb504e2757d50bb475 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Thu, 5 Oct 2017 22:47:02 +0200 Subject: [PATCH] Use a more sophisticated method for detecting image data in Edit dialog In the Edit Data dialog we check if the data contained in a cell is an image. This check returned some false positives, so this commit adds another more sophisticated check to work around that. See issue #1138 and #1159. --- src/EditDialog.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/EditDialog.cpp b/src/EditDialog.cpp index 610a293c..5daa4ebe 100644 --- a/src/EditDialog.cpp +++ b/src/EditDialog.cpp @@ -419,13 +419,12 @@ int EditDialog::checkDataType(const QByteArray& data) return Null; } - // Check if it's an image + // Check if it's an image. First do a quick test by calling canRead() which only checks the first couple of bytes or so. Only if + // that returned true, do a more sophisticated test of the data. This way we get both, good performance and proper data checking. QBuffer imageBuffer(&cellData); QImageReader readerBuffer(&imageBuffer); - bool someCheck = readerBuffer.canRead(); - if (someCheck == true) { + if(readerBuffer.canRead() && !readerBuffer.read().isNull()) return Image; - } // Check if it's text only if (QString(cellData).toUtf8() == cellData) { // Is there a better way to check this?