11// xlsxcolor.cpp
22
3- #include < QtGlobal>
43#include < QDataStream>
54#include < QXmlStreamReader>
65#include < QXmlStreamWriter>
@@ -32,9 +31,7 @@ XlsxColor::XlsxColor(int index)
3231
3332bool XlsxColor::isRgbColor () const
3433{
35- if (val.userType () == qMetaTypeId<QColor>() && val.value <QColor>().isValid ())
36- return true ;
37- return false ;
34+ return val.userType () == qMetaTypeId<QColor>() && val.value <QColor>().isValid ();
3835}
3936
4037bool XlsxColor::isIndexedColor () const
@@ -54,23 +51,17 @@ bool XlsxColor::isInvalid() const
5451
5552QColor XlsxColor::rgbColor () const
5653{
57- if (isRgbColor ())
58- return val.value <QColor>();
59- return QColor ();
54+ return isRgbColor () ? val.value <QColor>() : QColor ();
6055}
6156
6257int XlsxColor::indexedColor () const
6358{
64- if (isIndexedColor ())
65- return val.toInt ();
66- return -1 ;
59+ return isIndexedColor () ? val.toInt () : -1 ;
6760}
6861
6962QStringList XlsxColor::themeColor () const
7063{
71- if (isThemeColor ())
72- return val.toStringList ();
73- return QStringList ();
64+ return isThemeColor () ? val.toStringList () : QStringList ();
7465}
7566
7667bool XlsxColor::saveToXml (QXmlStreamWriter &writer, const QString &node) const
@@ -98,29 +89,31 @@ bool XlsxColor::saveToXml(QXmlStreamWriter &writer, const QString &node) const
9889
9990bool XlsxColor::loadFromXml (QXmlStreamReader &reader)
10091{
101- QXmlStreamAttributes attributes = reader.attributes ();
92+ const auto & attributes = reader.attributes ();
10293
10394 if (attributes.hasAttribute (QLatin1String (" rgb" ))) {
104- QString colorString = attributes.value (QLatin1String (" rgb" )).toString ();
95+ const auto & colorString = attributes.value (QLatin1String (" rgb" )).toString ();
10596 val.setValue (fromARGBString (colorString));
10697 } else if (attributes.hasAttribute (QLatin1String (" indexed" ))) {
10798 int index = attributes.value (QLatin1String (" indexed" )).toString ().toInt ();
10899 val.setValue (index);
109100 } else if (attributes.hasAttribute (QLatin1String (" theme" ))) {
110- QString theme = attributes.value (QLatin1String (" theme" )).toString ();
111- QString tint = attributes.value (QLatin1String (" tint" )).toString ();
101+ const auto & theme = attributes.value (QLatin1String (" theme" )).toString ();
102+ const auto & tint = attributes.value (QLatin1String (" tint" )).toString ();
112103 val.setValue (QStringList ()<<theme<<tint);
113104 }
114105 return true ;
115106}
116107
117108XlsxColor::operator QVariant () const
118109{
110+ const auto & cref
119111#if QT_VERSION >= 0x060000 // Qt 6.0 or over
120- return QVariant ((QMetaType) qMetaTypeId <XlsxColor>(), this );
112+ = QMetaType::fromType <XlsxColor>();
121113#else
122- return QVariant ( qMetaTypeId<XlsxColor>(), this ) ;
114+ = qMetaTypeId<XlsxColor>() ;
123115#endif
116+ return QVariant (cref, this );
124117}
125118
126119
@@ -146,15 +139,13 @@ QColor XlsxColor::fromARGBString(const QString &c)
146139
147140QString XlsxColor::toARGBString (const QColor &c)
148141{
149- QString color;
150-
151142#if QT_VERSION >= 0x050600 // Qt 5.6 or over
152- color = QString::asprintf (" %02X%02X%02X%02X" , c.alpha (), c.red (), c.green (), c.blue ());
143+ return QString::asprintf (" %02X%02X%02X%02X" , c.alpha (), c.red (), c.green (), c.blue ());
153144#else
145+ QString color;
154146 color.sprintf (" %02X%02X%02X%02X" , c.alpha (), c.red (), c.green (), c.blue ());
155- #endif
156-
157147 return color;
148+ #endif
158149}
159150
160151#if !defined(QT_NO_DATASTREAM)
0 commit comments