From f7b36ac4c7a12126f70cbc272d2ce76d87ab8d6a Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 24 Oct 2020 03:32:40 +0200 Subject: [PATCH] Replace use of QVariant::type() with Qt 6 --- src/collection/collectionmodel.cpp | 11 +++++++++-- src/collection/collectionquery.cpp | 13 ++++++++++++- src/context/contextalbumsmodel.cpp | 10 ++++++++-- src/core/multisortfilterproxy.cpp | 15 +++++++++++++++ src/engine/gstenginepipeline.cpp | 22 ++++++++++++++++++++++ src/engine/vlcengine.cpp | 9 ++++++++- src/playlist/playlistdelegates.cpp | 8 ++++++++ src/playlist/playlistitem.h | 2 +- src/playlist/playlistview.cpp | 5 +++++ src/settings/backendsettingspage.cpp | 28 ++++++++++++++++++++++++++-- 10 files changed, 114 insertions(+), 9 deletions(-) diff --git a/src/collection/collectionmodel.cpp b/src/collection/collectionmodel.cpp index 759913ada..bd1e1b078 100644 --- a/src/collection/collectionmodel.cpp +++ b/src/collection/collectionmodel.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1730,8 +1731,14 @@ bool CollectionModel::CompareItems(const CollectionItem *a, const CollectionItem QVariant left(data(a, CollectionModel::Role_SortText)); QVariant right(data(b, CollectionModel::Role_SortText)); - if (left.type() == QVariant::Int) return left.toInt() < right.toInt(); - return left.toString() < right.toString(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (left.metaType().id() == QMetaType::Int) +#else + if (left.type() == QVariant::Int) +#endif + return left.toInt() < right.toInt(); + else + return left.toString() < right.toString(); } diff --git a/src/collection/collectionquery.cpp b/src/collection/collectionquery.cpp index 19b4b0dac..97226104b 100644 --- a/src/collection/collectionquery.cpp +++ b/src/collection/collectionquery.cpp @@ -21,6 +21,7 @@ #include "config.h" #include +#include #include #include #include @@ -133,10 +134,20 @@ void CollectionQuery::AddWhere(const QString &column, const QVariant &value, con } else { // Do integers inline - sqlite seems to get confused when you pass integers to bound parameters +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (value.metaType().id() == QMetaType::Int) { +#else if (value.type() == QVariant::Int) { +#endif where_clauses_ << QString("%1 %2 %3").arg(column, op, value.toString()); } - else if (value.type() == QVariant::String && value.toString().isNull()) { + else if ( +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + value.metaType().id() == QMetaType::QString +#else + value.type() == QVariant::String +#endif + && value.toString().isNull()) { where_clauses_ << QString("%1 %2 ?").arg(column, op); bound_values_ << QString(""); } diff --git a/src/context/contextalbumsmodel.cpp b/src/context/contextalbumsmodel.cpp index b63b59887..623db3f40 100644 --- a/src/context/contextalbumsmodel.cpp +++ b/src/context/contextalbumsmodel.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -444,8 +445,13 @@ bool ContextAlbumsModel::CompareItems(const CollectionItem *a, const CollectionI QVariant left(data(a, ContextAlbumsModel::Role_SortText)); QVariant right(data(b, ContextAlbumsModel::Role_SortText)); - if (left.type() == QVariant::Int) return left.toInt() < right.toInt(); - return left.toString() < right.toString(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (left.metaType().id() == QMetaType::Int) +#else + if (left.type() == QVariant::Int) +#endif + return left.toInt() < right.toInt(); + else return left.toString() < right.toString(); } diff --git a/src/core/multisortfilterproxy.cpp b/src/core/multisortfilterproxy.cpp index c4a4cd0e9..b8eacc43c 100644 --- a/src/core/multisortfilterproxy.cpp +++ b/src/core/multisortfilterproxy.cpp @@ -69,6 +69,20 @@ int MultiSortFilterProxy::Compare(const QVariant &left, const QVariant &right) c // Copied from the QSortFilterProxyModel::lessThan implementation, but returns -1, 0 or 1 instead of true or false. switch (left.userType()) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + case QMetaType::UnknownType: return (right.metaType().id() != QMetaType::UnknownType) ? -1 : 0; + case QMetaType::Int: return DoCompare(left.toInt(), right.toInt()); + case QMetaType::UInt: return DoCompare(left.toUInt(), right.toUInt()); + case QMetaType::LongLong: return DoCompare(left.toLongLong(), right.toLongLong()); + case QMetaType::ULongLong: return DoCompare(left.toULongLong(), right.toULongLong()); + case QMetaType::Float: return DoCompare(left.toFloat(), right.toFloat()); + case QMetaType::Double: return DoCompare(left.toDouble(), right.toDouble()); + case QMetaType::Char: return DoCompare(left.toChar(), right.toChar()); + case QMetaType::QDate: return DoCompare(left.toDate(), right.toDate()); + case QMetaType::QTime: return DoCompare(left.toTime(), right.toTime()); + case QMetaType::QDateTime: return DoCompare(left.toDateTime(), right.toDateTime()); + case QMetaType::QString: +#else case QVariant::Invalid: return (right.type() != QVariant::Invalid) ? -1 : 0; case QVariant::Int: return DoCompare(left.toInt(), right.toInt()); case QVariant::UInt: return DoCompare(left.toUInt(), right.toUInt()); @@ -81,6 +95,7 @@ int MultiSortFilterProxy::Compare(const QVariant &left, const QVariant &right) c case QVariant::Time: return DoCompare(left.toTime(), right.toTime()); case QVariant::DateTime: return DoCompare(left.toDateTime(), right.toDateTime()); case QVariant::String: +#endif default: if (isSortLocaleAware()) return left.toString().localeAwareCompare(right.toString()); diff --git a/src/engine/gstenginepipeline.cpp b/src/engine/gstenginepipeline.cpp index 9f6ab1c61..cab2ff5b2 100644 --- a/src/engine/gstenginepipeline.cpp +++ b/src/engine/gstenginepipeline.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -242,21 +243,42 @@ bool GstEnginePipeline::InitAudioBin() { } if (device_.isValid() && g_object_class_find_property(G_OBJECT_GET_CLASS(audiosink), "device")) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + switch (device_.metaType().id()) { + case QMetaType::QString: +#else switch (device_.type()) { case QVariant::String: +#endif if (device_.toString().isEmpty()) break; g_object_set(G_OBJECT(audiosink), "device", device_.toString().toUtf8().constData(), nullptr); break; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + case QMetaType::QByteArray: +#else case QVariant::ByteArray: +#endif g_object_set(G_OBJECT(audiosink), "device", device_.toByteArray().constData(), nullptr); break; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + case QMetaType::LongLong: +#else case QVariant::LongLong: +#endif g_object_set(G_OBJECT(audiosink), "device", device_.toLongLong(), nullptr); break; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + case QMetaType::Int: +#else case QVariant::Int: +#endif g_object_set(G_OBJECT(audiosink), "device", device_.toInt(), nullptr); break; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + case QMetaType::QUuid: +#else case QVariant::Uuid: +#endif g_object_set(G_OBJECT(audiosink), "device", device_.toUuid(), nullptr); break; default: diff --git a/src/engine/vlcengine.cpp b/src/engine/vlcengine.cpp index 765eec2b8..a28fc58e8 100644 --- a/src/engine/vlcengine.cpp +++ b/src/engine/vlcengine.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -130,7 +131,13 @@ bool VLCEngine::Play(const quint64 offset_nanosec) { } // Set audio device - if (device_.isValid() && device_.type() == QVariant::String && !device_.toString().isEmpty()) { + if (device_.isValid() && +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + device_.metaType().id() == QMetaType::QString +#else + device_.type() == QVariant::String +#endif + && !device_.toString().isEmpty()) { libvlc_audio_output_device_set(player_, nullptr, device_.toString().toLocal8Bit().data()); } diff --git a/src/playlist/playlistdelegates.cpp b/src/playlist/playlistdelegates.cpp index 0c980209f..bf014247f 100644 --- a/src/playlist/playlistdelegates.cpp +++ b/src/playlist/playlistdelegates.cpp @@ -177,7 +177,11 @@ QString PlaylistDelegateBase::displayText(const QVariant &value, const QLocale&) QString text; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + switch(value.metaType().id()) { +#else switch (static_cast(value.type())) { +#endif case QMetaType::Int: { int v = value.toInt(); if (v > 0) text = QString::number(v); @@ -432,7 +436,11 @@ QString NativeSeparatorsDelegate::displayText(const QVariant &value, const QLoca const QString string_value = value.toString(); QUrl url; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (value.metaType().id() == QMetaType::QUrl) { +#else if (value.type() == QVariant::Url) { +#endif url = value.toUrl(); } else if (string_value.contains("://")) { diff --git a/src/playlist/playlistitem.h b/src/playlist/playlistitem.h index 24663b8e4..fe5fc2951 100644 --- a/src/playlist/playlistitem.h +++ b/src/playlist/playlistitem.h @@ -116,7 +116,7 @@ class PlaylistItem : public std::enable_shared_from_this { enum DatabaseColumn { Column_CollectionId }; virtual QVariant DatabaseValue(DatabaseColumn) const { - return QVariant(QVariant::String); + return QVariant(QString()); } virtual Song DatabaseSongMetadata() const { return Song(); } diff --git a/src/playlist/playlistview.cpp b/src/playlist/playlistview.cpp index 7ac2fe296..443cc5272 100644 --- a/src/playlist/playlistview.cpp +++ b/src/playlist/playlistview.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -1328,7 +1329,11 @@ void PlaylistView::CopyCurrentSongToClipboard() const { } const QVariant var_data = model()->data(currentIndex().sibling(currentIndex().row(), i)); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (var_data.metaType().id() == QMetaType::QString) { +#else if (var_data.type() == QVariant::String) { +#endif columns << var_data.toString(); } } diff --git a/src/settings/backendsettingspage.cpp b/src/settings/backendsettingspage.cpp index 94b0caa06..c676694a4 100644 --- a/src/settings/backendsettingspage.cpp +++ b/src/settings/backendsettingspage.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -365,7 +366,13 @@ void BackendSettingsPage::Load_Device(const QString &output, const QVariant &dev } // This allows a custom ALSA device string ie: "hw:0,0" even if it is not listed. - if (engine()->CustomDeviceSupport(output) && device.type() == QVariant::String && !device.toString().isEmpty()) { + if (engine()->CustomDeviceSupport(output) && +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + device.metaType().id() == QMetaType::QString +#else + device.type() == QVariant::String +#endif + && !device.toString().isEmpty()) { ui_->lineedit_device->setText(device.toString()); if (!found) { for (int i = 0; i < ui_->combobox_device->count(); ++i) { @@ -484,7 +491,12 @@ void BackendSettingsPage::DeviceSelectionChanged(int index) { if (engine()->CustomDeviceSupport(output.name)) { ui_->lineedit_device->setEnabled(true); if (ui_->combobox_device->currentText() != "Custom") { - if (device.type() == QVariant::String) ui_->lineedit_device->setText(device.toString()); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (device.metaType().id() == QMetaType::QString) +#else + if (device.type() == QVariant::String) +#endif + ui_->lineedit_device->setText(device.toString()); else ui_->lineedit_device->clear(); } } @@ -519,7 +531,11 @@ void BackendSettingsPage::DeviceStringChanged() { for (int i = 0; i < ui_->combobox_device->count(); ++i) { QVariant device = ui_->combobox_device->itemData(i).value(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (device.metaType().id() != QMetaType::QString) continue; +#else if (device.type() != QVariant::String) continue; +#endif if (device.toString().isEmpty()) continue; if (ui_->combobox_device->itemText(i) == "Custom") continue; if (device.toString() == ui_->lineedit_device->text()) { @@ -599,7 +615,11 @@ void BackendSettingsPage::radiobutton_alsa_hw_clicked(const bool checked) { bool found(false); for (int i = 0; i < ui_->combobox_device->count(); ++i) { QVariant device = ui_->combobox_device->itemData(i).value(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (device.metaType().id() != QMetaType::QString) continue; +#else if (device.type() != QVariant::String) continue; +#endif if (device.toString().isEmpty()) continue; if (device.toString() == device_new) { if (ui_->combobox_device->currentIndex() != i) ui_->combobox_device->setCurrentIndex(i); @@ -630,7 +650,11 @@ void BackendSettingsPage::radiobutton_alsa_plughw_clicked(const bool checked) { bool found(false); for (int i = 0; i < ui_->combobox_device->count(); ++i) { QVariant device = ui_->combobox_device->itemData(i).value(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (device.metaType().id() != QMetaType::QString) continue; +#else if (device.type() != QVariant::String) continue; +#endif if (device.toString().isEmpty()) continue; if (device.toString() == device_new) { if (ui_->combobox_device->currentIndex() != i) ui_->combobox_device->setCurrentIndex(i);