Skip to content

Commit

Permalink
Port away from deprecated API in Qt 6.6: QColor::setNamedColor
Browse files Browse the repository at this point in the history
The replacement, QColor::fromString() exists since Qt 6.4.
  • Loading branch information
dfaure-kdab committed Jul 3, 2024
1 parent 1f2ca71 commit 92595e3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion QXlsx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ target_compile_definitions(QXlsx PRIVATE
QT_USE_QSTRINGBUILDER
QT_NO_SIGNALS_SLOTS_KEYWORDS
QT_USE_FAST_OPERATOR_PLUS
QT_DISABLE_DEPRECATED_BEFORE=0x060200
QT_DISABLE_DEPRECATED_BEFORE=0x060600
)

if (NOT WIN32)
Expand Down
2 changes: 1 addition & 1 deletion QXlsx/QXlsx.pri
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060600 # disables all the APIs deprecated before Qt 6.6.0

isEmpty(QXLSX_PARENTPATH) {
message( 'QXLSX_PARENTPATH is empty. use default value.' )
Expand Down
2 changes: 1 addition & 1 deletion QXlsx/QXlsx.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060600 # disables all the APIs deprecated before Qt 6.6.0

QXLSX_PARENTPATH=$$PWD/
QXLSX_HEADERPATH=$$PWD/header/
Expand Down
8 changes: 8 additions & 0 deletions QXlsx/source/xlsxcolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,21 @@ XlsxColor::operator QVariant() const

QColor XlsxColor::fromARGBString(const QString &c)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
if (c.startsWith(u'#')) {
return QColor::fromString(c);
} else {
return QColor::fromString(QLatin1Char('#') + c);
}
#else
QColor color;
if (c.startsWith(u'#')) {
color.setNamedColor(c);
} else {
color.setNamedColor(QLatin1Char('#') + c);
}
return color;
#endif
}

QString XlsxColor::toARGBString(const QColor &c)
Expand Down

0 comments on commit 92595e3

Please sign in to comment.