QGIS API Documentation 3.39.0-Master (3aed037ce22)
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 <QString>
21#include <QList>
22
23#include "qgis_core.h"
24
25// Macro to create Error message including info about where it was created.
26#define QGS_ERROR_MESSAGE(message, tag) QgsErrorMessage(QString(message),QString(tag), QString(__FILE__), QString(__FUNCTION__), __LINE__)
27
32class CORE_EXPORT QgsErrorMessage
33{
34 public:
36 enum Format
37 {
38 Text, // Plain text
39 Html
40 };
41
42 QgsErrorMessage() = default;
43
52 QgsErrorMessage( const QString &message, const QString &tag = QString(), const QString &file = QString(), const QString &function = QString(), int line = 0 );
53
54 QString message() const { return mMessage; }
55 QString tag() const { return mTag; }
56 QString file() const { return mFile; }
57 QString function() const { return mFunction; }
58 int line() const { return mLine; }
59
60 private:
62 QString mMessage;
63
65 QString mTag;
66
68 QString mFile;
69 QString mFunction;
70 int mLine = 0;
71};
72
79class CORE_EXPORT QgsError
80{
81 public:
82
83 QgsError() = default;
84
90 QgsError( const QString &message, const QString &tag );
91
97 void append( const QString &message, const QString &tag );
98
103 void append( const QgsErrorMessage &message );
104
109 bool isEmpty() const { return mMessageList.isEmpty(); }
110
116 QString message( QgsErrorMessage::Format format = QgsErrorMessage::Html ) const;
117
122 QString summary() const;
123
125 void clear() { mMessageList.clear(); }
126
131 QList<QgsErrorMessage> messageList() const { return mMessageList; }
132
133
134#ifdef SIP_RUN
135 SIP_PYOBJECT __repr__();
136 % MethodCode
137 QString str = QStringLiteral( "<QgsError: %1>" ).arg( sipCpp->message( QgsErrorMessage::Text ) );
138 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
139 % End
140#endif
141
142 private:
144 QList<QgsErrorMessage> mMessageList;
145};
146
147#endif
QgsErrorMessage represents single error message.
Definition qgserror.h:33
QString tag() const
Definition qgserror.h:55
QString file() const
Definition qgserror.h:56
QString function() const
Definition qgserror.h:57
int line() const
Definition qgserror.h:58
QgsErrorMessage()=default
Format
Format.
Definition qgserror.h:37
QString message() const
Definition qgserror.h:54
QgsError is container for error messages (report).
Definition qgserror.h:80
void clear()
Clear error messages.
Definition qgserror.h:125
bool isEmpty() const
Test if any error is set.
Definition qgserror.h:109
QgsError()=default
QList< QgsErrorMessage > messageList() const
messageList return the list of current error messages
Definition qgserror.h:131
#define str(x)
Definition qgis.cpp:38