QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgserror.h
Go to the documentation of this file.
1/***************************************************************************
2 qgserror.h - Error container
3 -------------------
4 begin : October 2012
5 copyright : (C) 2012 Radim Blazek
6 email : radim dot blazek at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#ifndef QGSERROR_H
18#define QGSERROR_H
19
20#include "qgis_core.h"
21
22#include <QList>
23#include <QString>
24
25using namespace Qt::StringLiterals;
26
27// Macro to create Error message including info about where it was created.
28#define QGS_ERROR_MESSAGE(message, tag) QgsErrorMessage(QString(message),QString(tag), QString(__FILE__), QString(__FUNCTION__), __LINE__)
29
34class CORE_EXPORT QgsErrorMessage
35{
36 public:
38 enum Format
39 {
40 Text, // Plain text
42 };
43
44 QgsErrorMessage() = default;
45
54 QgsErrorMessage( const QString &message, const QString &tag = QString(), const QString &file = QString(), const QString &function = QString(), int line = 0 );
55
56 QString message() const { return mMessage; }
57 QString tag() const { return mTag; }
58 QString file() const { return mFile; }
59 QString function() const { return mFunction; }
60 int line() const { return mLine; }
61
62 private:
64 QString mMessage;
65
67 QString mTag;
68
70 QString mFile;
71 QString mFunction;
72 int mLine = 0;
73};
74
82class CORE_EXPORT QgsError
83{
84 public:
85
86 QgsError() = default;
87
93 QgsError( const QString &message, const QString &tag );
94
100 void append( const QString &message, const QString &tag );
101
106 void append( const QgsErrorMessage &message );
107
112 bool isEmpty() const { return mMessageList.isEmpty(); }
113
119 QString message( QgsErrorMessage::Format format = QgsErrorMessage::Html ) const;
120
125 QString summary() const;
126
128 void clear() { mMessageList.clear(); }
129
134 QList<QgsErrorMessage> messageList() const { return mMessageList; }
135
136
137#ifdef SIP_RUN
138 SIP_PYOBJECT __repr__();
139 % MethodCode
140 QString str = u"<QgsError: %1>"_s.arg( sipCpp->message( QgsErrorMessage::Text ) );
141 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
142 % End
143#endif
144
145 private:
147 QList<QgsErrorMessage> mMessageList;
148};
149
150#endif
Represents a single error message.
Definition qgserror.h:35
QString tag() const
Definition qgserror.h:57
QString file() const
Definition qgserror.h:58
QString function() const
Definition qgserror.h:59
int line() const
Definition qgserror.h:60
QgsErrorMessage()=default
Format
Format.
Definition qgserror.h:39
QString message() const
Definition qgserror.h:56
void clear()
Clear error messages.
Definition qgserror.h:128
bool isEmpty() const
Test if no error is set.
Definition qgserror.h:112
QgsError()=default
QString message(QgsErrorMessage::Format format=QgsErrorMessage::Html) const
Full error messages description.
Definition qgserror.cpp:53
QList< QgsErrorMessage > messageList() const
messageList return the list of current error messages
Definition qgserror.h:134
void append(const QString &message, const QString &tag)
Append new error message.
Definition qgserror.cpp:43