From f05a948923da0d94ecfc235933981482fcfb7157 Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Fri, 29 Nov 2013 16:09:23 +0800 Subject: [PATCH] XlsxColor refactor --- src/xlsx/xlsxcolor.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/xlsx/xlsxcolor.cpp b/src/xlsx/xlsxcolor.cpp index 96d1a99..3a7534a 100644 --- a/src/xlsx/xlsxcolor.cpp +++ b/src/xlsx/xlsxcolor.cpp @@ -9,8 +9,9 @@ namespace QXlsx { XlsxColor::XlsxColor(const QColor &color) - :val(color) { + if (color.isValid()) + val.setValue(color); } XlsxColor::XlsxColor(const QString &theme, const QString &tint) @@ -44,9 +45,7 @@ bool XlsxColor::isThemeColor() const bool XlsxColor::isInvalid() const { - if (val.userType() == qMetaTypeId() && !val.value().isValid()) - return true; - return false; + return !val.isValid(); } QColor XlsxColor::rgbColor() const @@ -78,11 +77,7 @@ bool XlsxColor::saveToXml(QXmlStreamWriter &writer, const QString &node) const writer.writeEmptyElement(QStringLiteral("color")); if (val.userType() == qMetaTypeId()) { - QColor color = val.value(); - if (color.isValid()) - writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+color.name().mid(1));//remove # - else - writer.writeAttribute(QStringLiteral("auto"), QStringLiteral("1")); + writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+val.value().name().mid(1));//remove # } else if (val.userType() == QMetaType::QStringList) { QStringList themes = val.toStringList(); writer.writeAttribute(QStringLiteral("theme"), themes[0]); @@ -91,7 +86,7 @@ bool XlsxColor::saveToXml(QXmlStreamWriter &writer, const QString &node) const } else if (val.userType() == QMetaType::Int) { writer.writeAttribute(QStringLiteral("indexed"), val.toString()); } else { - return false; + writer.writeAttribute(QStringLiteral("auto"), QStringLiteral("1")); } return true;