Make write string slightly fast
This commit is contained in:
@@ -70,9 +70,6 @@ RichString::RichString()
|
|||||||
RichString::RichString(const QString text)
|
RichString::RichString(const QString text)
|
||||||
:d(new RichStringPrivate)
|
:d(new RichStringPrivate)
|
||||||
{
|
{
|
||||||
if (Qt::mightBeRichText(text))
|
|
||||||
setHtml(text);
|
|
||||||
else
|
|
||||||
addFragment(text, Format());
|
addFragment(text, Format());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ WorkbookPrivate::WorkbookPrivate(Workbook *q, Workbook::CreateFlag flag) :
|
|||||||
window_height = 9660;
|
window_height = 9660;
|
||||||
|
|
||||||
strings_to_numbers_enabled = false;
|
strings_to_numbers_enabled = false;
|
||||||
|
strings_to_hyperlinks_enabled = true;
|
||||||
html_to_richstring_enabled = false;
|
html_to_richstring_enabled = false;
|
||||||
date1904 = false;
|
date1904 = false;
|
||||||
defaultDateFormat = QStringLiteral("yyyy-mm-dd");
|
defaultDateFormat = QStringLiteral("yyyy-mm-dd");
|
||||||
@@ -118,6 +119,18 @@ bool Workbook::isStringsToNumbersEnabled() const
|
|||||||
return d->strings_to_numbers_enabled;
|
return d->strings_to_numbers_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Workbook::setStringsToHyperlinksEnabled(bool enable)
|
||||||
|
{
|
||||||
|
Q_D(Workbook);
|
||||||
|
d->strings_to_hyperlinks_enabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Workbook::isStringsToHyperlinksEnabled() const
|
||||||
|
{
|
||||||
|
Q_D(const Workbook);
|
||||||
|
return d->strings_to_hyperlinks_enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void Workbook::setHtmlToRichStringEnabled(bool enable)
|
void Workbook::setHtmlToRichStringEnabled(bool enable)
|
||||||
{
|
{
|
||||||
Q_D(Workbook);
|
Q_D(Workbook);
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ public:
|
|||||||
void setDate1904(bool date1904);
|
void setDate1904(bool date1904);
|
||||||
bool isStringsToNumbersEnabled() const;
|
bool isStringsToNumbersEnabled() const;
|
||||||
void setStringsToNumbersEnabled(bool enable=true);
|
void setStringsToNumbersEnabled(bool enable=true);
|
||||||
|
bool isStringsToHyperlinksEnabled() const;
|
||||||
|
void setStringsToHyperlinksEnabled(bool enable=true);
|
||||||
bool isHtmlToRichStringEnabled() const;
|
bool isHtmlToRichStringEnabled() const;
|
||||||
void setHtmlToRichStringEnabled(bool enable=true);
|
void setHtmlToRichStringEnabled(bool enable=true);
|
||||||
QString defaultDateFormat() const;
|
QString defaultDateFormat() const;
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ public:
|
|||||||
QList<XlsxDefineNameData> definedNamesList;
|
QList<XlsxDefineNameData> definedNamesList;
|
||||||
|
|
||||||
bool strings_to_numbers_enabled;
|
bool strings_to_numbers_enabled;
|
||||||
|
bool strings_to_hyperlinks_enabled;
|
||||||
bool html_to_richstring_enabled;
|
bool html_to_richstring_enabled;
|
||||||
bool date1904;
|
bool date1904;
|
||||||
QString defaultDateFormat;
|
QString defaultDateFormat;
|
||||||
|
|||||||
+29
-30
@@ -60,7 +60,7 @@ WorksheetPrivate::WorksheetPrivate(Worksheet *p, Worksheet::CreateFlag flag)
|
|||||||
: AbstractSheetPrivate(p, flag)
|
: AbstractSheetPrivate(p, flag)
|
||||||
, windowProtection(false), showFormulas(false), showGridLines(true), showRowColHeaders(true)
|
, windowProtection(false), showFormulas(false), showGridLines(true), showRowColHeaders(true)
|
||||||
, showZeros(true), rightToLeft(false), tabSelected(false), showRuler(false)
|
, showZeros(true), rightToLeft(false), tabSelected(false), showRuler(false)
|
||||||
, showOutlineSymbols(true), showWhiteSpace(true)
|
, showOutlineSymbols(true), showWhiteSpace(true), urlPattern(QStringLiteral("^([fh]tt?ps?://)|(mailto:)|(file://)"))
|
||||||
{
|
{
|
||||||
previous_row = 0;
|
previous_row = 0;
|
||||||
|
|
||||||
@@ -429,8 +429,35 @@ bool Worksheet::write(int row, int column, const QVariant &value, const Format &
|
|||||||
if (value.isNull()) {
|
if (value.isNull()) {
|
||||||
//Blank
|
//Blank
|
||||||
ret = writeBlank(row, column, format);
|
ret = writeBlank(row, column, format);
|
||||||
|
} else if (value.userType() == QMetaType::QString) {
|
||||||
|
//String
|
||||||
|
QString token = value.toString();
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
if (token.startsWith(QLatin1String("="))) {
|
||||||
|
//convert to formula
|
||||||
|
ret = writeFormula(row, column, token, format);
|
||||||
|
} else if (token.startsWith(QLatin1String("{=")) && token.endsWith(QLatin1Char('}'))) {
|
||||||
|
//convert to array formula
|
||||||
|
ret = writeArrayFormula(CellRange(row, column, row, column), token, format);
|
||||||
|
} else if (d->workbook->isStringsToHyperlinksEnabled() && token.contains(d->urlPattern)) {
|
||||||
|
//convert to url
|
||||||
|
ret = writeHyperlink(row, column, QUrl(token));
|
||||||
|
} else if (d->workbook->isStringsToNumbersEnabled() && (value.toDouble(&ok), ok)) {
|
||||||
|
//Try convert string to number if the flag enabled.
|
||||||
|
ret = writeString(row, column, value.toString(), format);
|
||||||
|
} else {
|
||||||
|
//normal string now
|
||||||
|
ret = writeString(row, column, token, format);
|
||||||
|
}
|
||||||
} else if (value.userType() == qMetaTypeId<RichString>()) {
|
} else if (value.userType() == qMetaTypeId<RichString>()) {
|
||||||
ret = writeString(row, column, value.value<RichString>(), format);
|
ret = writeString(row, column, value.value<RichString>(), format);
|
||||||
|
} else if (value.userType() == QMetaType::Int || value.userType() == QMetaType::UInt
|
||||||
|
|| value.userType() == QMetaType::LongLong || value.userType() == QMetaType::ULongLong
|
||||||
|
|| value.userType() == QMetaType::Double || value.userType() == QMetaType::Float) {
|
||||||
|
//Number
|
||||||
|
|
||||||
|
ret = writeNumeric(row, column, value.toDouble(), format);
|
||||||
} else if (value.userType() == QMetaType::Bool) {
|
} else if (value.userType() == QMetaType::Bool) {
|
||||||
//Bool
|
//Bool
|
||||||
ret = writeBool(row,column, value.toBool(), format);
|
ret = writeBool(row,column, value.toBool(), format);
|
||||||
@@ -441,37 +468,9 @@ bool Worksheet::write(int row, int column, const QVariant &value, const Format &
|
|||||||
} else if (value.userType() == QMetaType::QTime) {
|
} else if (value.userType() == QMetaType::QTime) {
|
||||||
//Time
|
//Time
|
||||||
ret = writeTime(row, column, value.toTime(), format);
|
ret = writeTime(row, column, value.toTime(), format);
|
||||||
} else if (value.userType() == QMetaType::Int || value.userType() == QMetaType::UInt
|
|
||||||
|| value.userType() == QMetaType::LongLong || value.userType() == QMetaType::ULongLong
|
|
||||||
|| value.userType() == QMetaType::Double || value.userType() == QMetaType::Float) {
|
|
||||||
//Number
|
|
||||||
|
|
||||||
ret = writeNumeric(row, column, value.toDouble(), format);
|
|
||||||
} else if (value.userType() == QMetaType::QUrl) {
|
} else if (value.userType() == QMetaType::QUrl) {
|
||||||
//Url
|
//Url
|
||||||
ret = writeHyperlink(row, column, value.toUrl(), format);
|
ret = writeHyperlink(row, column, value.toUrl(), format);
|
||||||
} else if (value.userType() == QMetaType::QString) {
|
|
||||||
//String
|
|
||||||
QString token = value.toString();
|
|
||||||
bool ok;
|
|
||||||
QRegularExpression urlPattern(QStringLiteral("^([fh]tt?ps?://)|(mailto:)|(file://)"));
|
|
||||||
|
|
||||||
if (token.startsWith(QLatin1String("="))) {
|
|
||||||
//convert to formula
|
|
||||||
ret = writeFormula(row, column, token, format);
|
|
||||||
} else if (token.startsWith(QLatin1String("{=")) && token.endsWith(QLatin1Char('}'))) {
|
|
||||||
//convert to array formula
|
|
||||||
ret = writeArrayFormula(CellRange(row, column, row, column), token, format);
|
|
||||||
} else if (token.contains(urlPattern)) {
|
|
||||||
//convert to url
|
|
||||||
ret = writeHyperlink(row, column, QUrl(token));
|
|
||||||
} else if (d->workbook->isStringsToNumbersEnabled() && (value.toDouble(&ok), ok)) {
|
|
||||||
//Try convert string to number if the flag enabled.
|
|
||||||
ret = writeString(row, column, value.toString(), format);
|
|
||||||
} else {
|
|
||||||
//normal string now
|
|
||||||
ret = writeString(row, column, token, format);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//Wrong type
|
//Wrong type
|
||||||
return false;
|
return false;
|
||||||
@@ -635,7 +634,7 @@ bool Worksheet::writeString(int row, int column, const QString &value, const For
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
RichString rs;
|
RichString rs;
|
||||||
if (Qt::mightBeRichText(value) && d->workbook->isHtmlToRichStringEnabled())
|
if (d->workbook->isHtmlToRichStringEnabled() && Qt::mightBeRichText(value))
|
||||||
rs.setHtml(value);
|
rs.setHtml(value);
|
||||||
else
|
else
|
||||||
rs.addFragment(value, Format());
|
rs.addFragment(value, Format());
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
class QXmlStreamWriter;
|
class QXmlStreamWriter;
|
||||||
class QXmlStreamReader;
|
class QXmlStreamReader;
|
||||||
@@ -176,6 +177,8 @@ public:
|
|||||||
bool showRuler;
|
bool showRuler;
|
||||||
bool showOutlineSymbols;
|
bool showOutlineSymbols;
|
||||||
bool showWhiteSpace;
|
bool showWhiteSpace;
|
||||||
|
|
||||||
|
QRegularExpression urlPattern;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user