| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QERRORINFO_P_H |
| 5 | #define QERRORINFO_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtMultimedia/qtmultimediaglobal.h> |
| 19 | #include <QString> |
| 20 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | template <typename ErrorCode, ErrorCode NoError = ErrorCode::NoError> |
| 24 | class QErrorInfo |
| 25 | { |
| 26 | public: |
| 27 | QErrorInfo(ErrorCode error = NoError, QString description = {}) |
| 28 | : m_code(error), m_description(std::move(description)) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | template <typename Notifier> |
| 33 | void setAndNotify(ErrorCode code, QString description, Notifier ¬ifier) |
| 34 | { |
| 35 | const bool changed = code != m_code || description != m_description; |
| 36 | |
| 37 | m_code = code; |
| 38 | m_description = std::move(description); |
| 39 | |
| 40 | if (code != NoError) |
| 41 | emit notifier.errorOccurred(m_code, m_description); |
| 42 | |
| 43 | if (changed) |
| 44 | emit notifier.errorChanged(); |
| 45 | } |
| 46 | |
| 47 | ErrorCode code() const { return m_code; } |
| 48 | QString description() const { return m_description; }; |
| 49 | |
| 50 | private: |
| 51 | ErrorCode m_code; |
| 52 | QString m_description; |
| 53 | }; |
| 54 | |
| 55 | QT_END_NAMESPACE |
| 56 | |
| 57 | #endif // QERRORINFO_P_H |
| 58 | |