Krita Source Code Documentation
Loading...
Searching...
No Matches
KisImportExportErrorCode.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 Agata Cacko <cacko.azh@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#ifndef KIS_IMPORT_EXPORT_ERROR_CODES_H
7#define KIS_IMPORT_EXPORT_ERROR_CODES_H
8
9
10#include <QFile>
11#include <QFileDevice>
12#include <QString>
13#include <kritaui_export.h>
14#include <QDebug>
15
16
18{
19
21 {
22 InternalError, // error that shouldn't happen; only inside ASSERTS
23
24 // Reading
25 FileNotExist, // there is no file with that name in that location,
26 NoAccessToRead, // Krita has no reading access to the file,
27 ErrorWhileReading, // there was an error that occurred during reading,
28 FileFormatIncorrect, // file format cannot be parsed,
29 FormatFeaturesUnsupported, // file format can be parsed, but some features are unsupported,
30 FormatColorSpaceUnsupported, // file format can be parsed, but color space of the image is unsupported
31
32 // Writing
33 CannotCreateFile, // file cannot be created
34 NoAccessToWrite, // Krita has no writing access to the file
35 ErrorWhileWriting, // there was an error that occurred during writing (can be insufficient memory, too, just we don't know)
36 InsufficientMemory, // there is not enough memory left
37 FileFormatNotSupported, // this file format is not supported by Krita
38
39 // Both
40 Cancelled, // cancelled by a user
41
42 // Other
43 Failure, // unspecified error
44
45 // Could not save because a save operation was already going on
47
48 // OK
49 OK, // everything went ok
50
51 };
52
53};
54
56
57struct KRITAUI_EXPORT KisImportExportComplexError
58{
59 virtual QString errorMessage() const = 0;
60 KisImportExportComplexError(QFileDevice::FileError error);
61
62 friend inline QDebug &operator<<(QDebug &d,
63 const KisImportExportErrorCode &errorCode);
64 virtual ~KisImportExportComplexError() = default;
65
66protected:
67 QString qtErrorMessage() const;
68 QFileDevice::FileError m_error;
69};
70
72{
73
74 KisImportExportErrorCannotWrite(QFileDevice::FileError error);
75 QString errorMessage() const override;
76
78
80
81private:
83
84 //friend KisImportExportErrorCode::KisImportExportErrorCode(KisImportExportErrorCannotWrite code);
86
87};
88
90{
91
92 KisImportExportErrorCannotRead(QFileDevice::FileError error);
93 QString errorMessage() const override;
94
95 ~KisImportExportErrorCannotRead() override = default;
96
98
99private:
101
102 //friend KisImportExportErrorCode::KisImportExportErrorCode(KisImportExportErrorCannotRead code);
104
105};
106
107
108
109class KRITAUI_EXPORT KisImportExportErrorCode
110{
111public:
112 // required by kis_async_action_feedback
114
118
119 QString errorMessage() const;
120 bool isOk() const;
121 bool isCancelled() const;
122 bool isInternalError() const;
123
124 friend inline QDebug &operator<<(QDebug &d,
125 const KisImportExportErrorCode &errorCode);
126
127 bool operator==(KisImportExportErrorCode errorCode);
128
129private:
131 {
135 CannotWrite
136 };
137
139
143};
144
145inline QDebug &operator<<(QDebug &d, const KisImportExportErrorCode &errorCode)
146{
147 switch (errorCode.errorFieldUsed) {
149 d << "None of the error fields is in use.";
150 break;
152 d << "Cannot read: " << errorCode.cannotRead.m_error;
153 break;
155 d << "Cannot write: " << errorCode.cannotRead.m_error;
156 break;
158 d << "Error code = " << errorCode.codeId;
159 }
160 d << " " << errorCode.errorMessage();
161 return d;
162}
163
164#endif // KIS_IMPORT_EXPORT_ERROR_CODES_H
QDebug KRITACOMMAND_EXPORT operator<<(QDebug dbg, const KisCumulativeUndoData &data)
QDebug & operator<<(QDebug &d, const KisImportExportErrorCode &errorCode)
bool operator==(const KisRegion &lhs, const KisRegion &rhs)
KisImportExportErrorCannotRead cannotRead
ImportExportCodes::ErrorCodeID codeId
KisImportExportErrorCannotWrite cannotWrite
virtual QString errorMessage() const =0
virtual ~KisImportExportComplexError()=default
~KisImportExportErrorCannotRead() override=default
~KisImportExportErrorCannotWrite() override=default