Skip to content

Commit

Permalink
Fix AbstractStringSerialiserPrivate stream version
Browse files Browse the repository at this point in the history
AbstractStringSerialiserPrivate was ignoring the
streamVersion property when serialising variants

(cherry picked from commit 28308f5)
  • Loading branch information
VSRonin committed May 5, 2021
1 parent 834f3ce commit 5f6a00d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
16 changes: 6 additions & 10 deletions src/abstractstringserialiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,28 @@ QString AbstractStringSerialiserPrivate::guessDecimalsString(double val, QLocale
return QString::number(val, 'f', guessDecimals(val));
}

QString AbstractStringSerialiserPrivate::variantToString(const QVariant &val)
QString AbstractStringSerialiserPrivate::variantToString(const QVariant &val) const
{
QByteArray data;
QDataStream outStream(&data, QIODevice::WriteOnly);
#ifdef MS_DATASTREAM_VERSION
outStream.setVersion(MS_DATASTREAM_VERSION);
#endif // MS_DATASTREAM_VERSION
outStream.setVersion(m_streamVersion);
outStream << val;
data = qCompress(data);
return QString::fromLatin1(data.toBase64());
}

QVariant AbstractStringSerialiserPrivate::stringToVariant(const QString &val)
QVariant AbstractStringSerialiserPrivate::stringToVariant(const QString &val) const
{
QByteArray data = QByteArray::fromBase64(val.toLatin1());
data = qUncompress(data);
QDataStream inStream(data);
#ifdef MS_DATASTREAM_VERSION
inStream.setVersion(MS_DATASTREAM_VERSION);
#endif // MS_DATASTREAM_VERSION
inStream.setVersion(m_streamVersion);
QVariant result;
inStream >> result;
return result;
}

QVariant AbstractStringSerialiserPrivate::loadVariant(int type, const QString &val)
QVariant AbstractStringSerialiserPrivate::loadVariant(int type, const QString &val) const
{
if (val.isEmpty())
return QVariant();
Expand Down Expand Up @@ -150,7 +146,7 @@ QImage AbstractStringSerialiserPrivate::loadImageVariant(int type, const QString
}
#endif

QString AbstractStringSerialiserPrivate::saveVariant(const QVariant &val)
QString AbstractStringSerialiserPrivate::saveVariant(const QVariant &val) const
{
if (val.isNull())
return QString();
Expand Down
4 changes: 2 additions & 2 deletions src/htmlmodelserialiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ bool HtmlModelSerialiserPrivate::readHtml(QXmlStreamReader &reader)
return true;
}

void HtmlModelSerialiserPrivate::writeHtmlVariant(QXmlStreamWriter &writer, const QVariant &val)
void HtmlModelSerialiserPrivate::writeHtmlVariant(QXmlStreamWriter &writer, const QVariant &val) const
{
if (isImageType(val.userType())) {
writer.writeEmptyElement(QStringLiteral("img"));
Expand All @@ -277,7 +277,7 @@ void HtmlModelSerialiserPrivate::writeHtmlVariant(QXmlStreamWriter &writer, cons
writer.writeCharacters(saveVariant(val));
}

QVariant HtmlModelSerialiserPrivate::readHtmlVariant(QXmlStreamReader &reader, int valType)
QVariant HtmlModelSerialiserPrivate::readHtmlVariant(QXmlStreamReader &reader, int valType) const
{
if (isImageType(valType)) {
if (!reader.readNextStartElement())
Expand Down
10 changes: 5 additions & 5 deletions src/private/abstractstringserialiser_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ class QTextCodec;
#endif
class AbstractStringSerialiserPrivate : public AbstractModelSerialiserPrivate
{
Q_DISABLE_COPY(AbstractStringSerialiserPrivate);
Q_DISABLE_COPY(AbstractStringSerialiserPrivate)
Q_DECLARE_PUBLIC(AbstractStringSerialiser)
protected:
AbstractStringSerialiserPrivate(AbstractStringSerialiser *q);
static QString variantToString(const QVariant &val);
static QVariant stringToVariant(const QString &val);
QString variantToString(const QVariant &val) const;
QVariant stringToVariant(const QString &val) const;
#ifdef QT_GUI_LIB
static QImage loadImageVariant(int type, const QString &val);
static QString saveImageVariant(const QImage &val);
#endif
static QVariant loadVariant(int type, const QString &val);
static QString saveVariant(const QVariant &val);
QVariant loadVariant(int type, const QString &val) const;
QString saveVariant(const QVariant &val) const;
static int guessDecimals(double val);
static QString guessDecimalsString(double val, QLocale *loca = Q_NULLPTR);
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
Expand Down
4 changes: 2 additions & 2 deletions src/private/htmlmodelserialiser_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class HtmlModelSerialiserPrivate : public AbstractStringSerialiserPrivate
{
return val == QMetaType::QImage || val == QMetaType::QPixmap || val == QMetaType::QBitmap;
}
static void writeHtmlVariant(QXmlStreamWriter &writer, const QVariant &val);
static QVariant readHtmlVariant(QXmlStreamReader &reader, int valType);
void writeHtmlVariant(QXmlStreamWriter &writer, const QVariant &val) const;
QVariant readHtmlVariant(QXmlStreamReader &reader, int valType) const;
bool m_printStartDocument;
};
#endif // htmlmodelserialiser_p_h__

0 comments on commit 5f6a00d

Please sign in to comment.