xlsx兼容qt6

This commit is contained in:
Gangphon 2023-10-20 18:43:30 +08:00
parent b3ebcb885d
commit 4c2a30cbe1
8 changed files with 31 additions and 15 deletions

View File

@ -265,7 +265,7 @@ bool ChartPrivate::loadXmlPlotArea(QXmlStreamReader &reader)
bool ChartPrivate::loadXmlXxxChart(QXmlStreamReader &reader)
{
QStringRef name = reader.name();
auto name = reader.name();
if (name == QLatin1String("pieChart"))
chartType = Chart::CT_Pie;
else if (name == QLatin1String("pie3DChart"))
@ -314,7 +314,7 @@ bool ChartPrivate::loadXmlSer(QXmlStreamReader &reader)
&& !(reader.tokenType() == QXmlStreamReader::EndElement
&& reader.name() == QLatin1String("ser"))) {
if (reader.readNextStartElement()) {
QStringRef name = reader.name();
auto name = reader.name();
if (name == QLatin1String("cat") || name == QLatin1String("xVal")) {
while (!reader.atEnd()
&& !(reader.tokenType() == QXmlStreamReader::EndElement
@ -613,7 +613,7 @@ bool ChartPrivate::loadXmlAxis(QXmlStreamReader &reader)
if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("axPos")) {
QXmlStreamAttributes attrs = reader.attributes();
QStringRef pos = attrs.value(QLatin1String("val"));
auto pos = attrs.value(QLatin1String("val"));
if (pos == QLatin1String("l"))
axis->axisPos = XlsxAxis::Left;
else if (pos == QLatin1String("r"))

View File

@ -111,7 +111,11 @@ bool XlsxColor::loadFromXml(QXmlStreamReader &reader)
XlsxColor::operator QVariant() const
{
#if(QT_VERSION_MAJOR > 5)
return QVariant::fromValue(this);
#else
return QVariant(qMetaTypeId<XlsxColor>(), this);
#endif
}
QColor XlsxColor::fromARGBString(const QString &c)
@ -127,9 +131,7 @@ QColor XlsxColor::fromARGBString(const QString &c)
QString XlsxColor::toARGBString(const QColor &c)
{
QString color;
color.sprintf("%02X%02X%02X%02X", c.alpha(), c.red(), c.green(), c.blue());
return color;
return QString::asprintf("%02X%02X%02X%02X", c.alpha(), c.red(), c.green(), c.blue());
}
#if !defined(QT_NO_DATASTREAM)

View File

@ -151,8 +151,8 @@ bool DocPropsCore::loadFromXmlFile(QIODevice *device)
while (!reader.atEnd()) {
QXmlStreamReader::TokenType token = reader.readNext();
if (token == QXmlStreamReader::StartElement) {
const QStringRef nsUri = reader.namespaceUri();
const QStringRef name = reader.name();
const auto nsUri = reader.namespaceUri();
const auto name = reader.name();
if (name == QStringLiteral("subject") && nsUri == dc) {
setProperty(QStringLiteral("subject"), reader.readElementText());
} else if (name == QStringLiteral("title") && nsUri == dc) {

View File

@ -29,6 +29,10 @@
#include <QDataStream>
#include <QDebug>
#if(QT_VERSION_MAJOR < 6)
#define QIODeviceBase QIODevice
#endif
QT_BEGIN_NAMESPACE_XLSX
FormatPrivate::FormatPrivate()
@ -544,7 +548,7 @@ QByteArray Format::fontKey() const
if (d->font_dirty) {
QByteArray key;
QDataStream stream(&key, QIODevice::WriteOnly);
QDataStream stream(&key, QIODeviceBase::WriteOnly);
for (int i = FormatPrivate::P_Font_STARTID; i < FormatPrivate::P_Font_ENDID; ++i) {
if (d->properties.contains(i))
stream << i << d->properties[i];
@ -955,7 +959,7 @@ QByteArray Format::borderKey() const
if (d->border_dirty) {
QByteArray key;
QDataStream stream(&key, QIODevice::WriteOnly);
QDataStream stream(&key, QIODeviceBase::WriteOnly);
for (int i = FormatPrivate::P_Border_STARTID; i < FormatPrivate::P_Border_ENDID; ++i) {
if (d->properties.contains(i))
stream << i << d->properties[i];
@ -1075,7 +1079,7 @@ QByteArray Format::fillKey() const
if (d->fill_dirty) {
QByteArray key;
QDataStream stream(&key, QIODevice::WriteOnly);
QDataStream stream(&key, QIODeviceBase::WriteOnly);
for (int i = FormatPrivate::P_Fill_STARTID; i < FormatPrivate::P_Fill_ENDID; ++i) {
if (d->properties.contains(i))
stream << i << d->properties[i];
@ -1201,7 +1205,7 @@ QByteArray Format::formatKey() const
if (d->dirty) {
QByteArray key;
QDataStream stream(&key, QIODevice::WriteOnly);
QDataStream stream(&key, QIODeviceBase::WriteOnly);
QMapIterator<int, QVariant> i(d->properties);
while (i.hasNext()) {

View File

@ -101,7 +101,11 @@ RichString &RichString::operator=(const RichString &other)
*/
RichString::operator QVariant() const
{
#if(QT_VERSION_MAJOR > 5)
return QVariant::fromValue(this);
#else
return QVariant(qMetaTypeId<RichString>(), this);
#endif
}
/*!

View File

@ -50,6 +50,9 @@ Styles::Styles(CreateFlag flag)
//! Fix me. Should the custom num fmt Id starts with 164 or 176 or others??
//! Fix me! Where should we put these register code?
#if(QT_VERSION_MAJOR > 5)
qRegisterMetaType<XlsxColor>("XlsxColor");
#else
if (QMetaType::type("XlsxColor") == QMetaType::UnknownType) {
qRegisterMetaType<XlsxColor>("XlsxColor");
qRegisterMetaTypeStreamOperators<XlsxColor>("XlsxColor");
@ -57,6 +60,7 @@ Styles::Styles(CreateFlag flag)
QMetaType::registerDebugStreamOperator<XlsxColor>();
#endif
}
#endif
if (flag == F_NewFromScratch) {
// Add default Format

View File

@ -39,7 +39,9 @@
#include "xlsxglobal.h"
class QPoint;
class QString;
#if(QT_VERSION_MAJOR < 6)
class QStringList;
#endif
class QColor;
class QDateTime;
class QTime;

View File

@ -578,9 +578,9 @@ bool Workbook::loadFromXmlFile(QIODevice *device)
QXmlStreamAttributes attributes = reader.attributes();
const QString name = attributes.value(QLatin1String("name")).toString();
int sheetId = attributes.value(QLatin1String("sheetId")).toString().toInt();
const QString rId = attributes.value(QLatin1String("r:id")).toString();
const QStringRef &stateString = attributes.value(QLatin1String("state"));
AbstractSheet::SheetState state = AbstractSheet::SS_Visible;
const auto rId = attributes.value(QLatin1String("r:id")).toString();
const auto &stateString = attributes.value(QLatin1String("state"));
auto state = AbstractSheet::SS_Visible;
if (stateString == QLatin1String("hidden"))
state = AbstractSheet::SS_Hidden;
else if (stateString == QLatin1String("veryHidden"))