#pragma once #include #include #include #include #include #include #include #include "util/assert.h" inline qreal getDevicePixelRatioF(const QWidget* widget) { return widget->devicePixelRatioF(); } inline QScreen* getPrimaryScreen() { QGuiApplication* app = static_cast(QCoreApplication::instance()); VERIFY_OR_DEBUG_ASSERT(app) { qWarning() << "Unable to get applications QCoreApplication instance, cannot determine primary screen!"; // All attempts to find primary screen failed, return nullptr return nullptr; } return app->primaryScreen(); } inline QString uuidToStringWithoutBraces(const QUuid& uuid) { return uuid.toString(QUuid::WithoutBraces); } inline QString uuidToNullableStringWithoutBraces(const QUuid& uuid) { if (uuid.isNull()) { return QString(); } else { return uuidToStringWithoutBraces(uuid); } } template inline T atomicLoadAcquire(const QAtomicInteger& atomicInt) { // TODO: QBasicAtomicInteger::load() is deprecated and should be // replaced with QBasicAtomicInteger::loadRelaxed() However, the // proposed alternative has just been introduced in Qt 5.14. Until the // minimum required Qt version of Mixxx is increased, we need a version // check here #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) return atomicInt.loadAcquire(); #else return atomicInt.load(); #endif } template inline T* atomicLoadAcquire(const QAtomicPointer& atomicPtr) { // TODO: QBasicAtomicPointer::load() is deprecated and should be // replaced with QBasicAtomicPointer::loadRelaxed() However, the // proposed alternative has just been introduced in Qt 5.14. Until the // minimum required Qt version of Mixxx is increased, we need a version // check here #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) return atomicPtr.loadAcquire(); #else return atomicPtr.load(); #endif } template inline T atomicLoadRelaxed(const QAtomicInteger& atomicInt) { // TODO: QBasicAtomicInteger::load() is deprecated and should be // replaced with QBasicAtomicInteger::loadRelaxed() However, the // proposed alternative has just been introduced in Qt 5.14. Until the // minimum required Qt version of Mixxx is increased, we need a version // check here #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) return atomicInt.loadRelaxed(); #else return atomicInt.load(); #endif } template inline T* atomicLoadRelaxed(const QAtomicPointer& atomicPtr) { // TODO: QBasicAtomicPointer::load() is deprecated and should be // replaced with QBasicAtomicPointer::loadRelaxed() However, the // proposed alternative has just been introduced in Qt 5.14. Until the // minimum required Qt version of Mixxx is increased, we need a version // check here #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) return atomicPtr.loadRelaxed(); #else return atomicPtr.load(); #endif } template inline void atomicStoreRelaxed(QAtomicInteger& atomicInt, T newValue) { // TODO: QBasicAtomicInteger::store(T newValue) is deprecated and should // be replaced with QBasicAtomicInteger::storeRelaxed(T newValue) // However, the proposed alternative has just been introduced in Qt 5.14. // Until the minimum required Qt version of Mixxx is increased, we need a // version check here #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) atomicInt.storeRelaxed(newValue); #else atomicInt.store(newValue); #endif } template inline void atomicStoreRelaxed(QAtomicPointer& atomicPtr, T* newValue) { // TODO: QBasicAtomicPointer::store(T* newValue) is deprecated and // should be replaced with QBasicAtomicPointer::storeRelaxed(T* // newValue) However, the proposed alternative has just been introduced in // Qt 5.14. Until the minimum required Qt version of Mixxx is increased, we // need a version check here #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) atomicPtr.storeRelaxed(newValue); #else atomicPtr.store(newValue); #endif } /// Helper to insert values into a QList with specific indices. /// /// *For legacy code only - Do not use for new code!* template inline void listAppendOrReplaceAt(QList* pList, int index, const T& value) { VERIFY_OR_DEBUG_ASSERT(index <= pList->size()) { qWarning() << "listAppendOrReplaceAt: Padding list with" << (index - pList->size()) << "default elements"; while (index > pList->size()) { pList->append(T()); } } VERIFY_OR_DEBUG_ASSERT(index == pList->size()) { pList->replace(index, value); return; } pList->append(value); }