QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
32 class CORE_EXPORT QgsErrorMessage
33 {
34  public:
36  enum Format
37  {
38  Text, // Plain text
39  Html
40  };
41 
43  QgsErrorMessage() = default;
44 
53  QgsErrorMessage( const QString &message, const QString &tag = QString(), const QString &file = QString(), const QString &function = QString(), int line = 0 );
54 
55  QString message() const { return mMessage; }
56  QString tag() const { return mTag; }
57  QString file() const { return mFile; }
58  QString function() const { return mFunction; }
59  int line() const { return mLine; }
60 
61  private:
63  QString mMessage;
64 
66  QString mTag;
67 
69  QString mFile;
70  QString mFunction;
71  int mLine = 0;
72 };
73 
80 class CORE_EXPORT QgsError
81 {
82  public:
83 
85  QgsError() = default;
86 
92  QgsError( const QString &message, const QString &tag );
93 
99  void append( const QString &message, const QString &tag );
100 
105  void append( const QgsErrorMessage &message );
106 
111  bool isEmpty() const { return mMessageList.isEmpty(); }
112 
118  QString message( QgsErrorMessage::Format format = QgsErrorMessage::Html ) const;
119 
124  QString summary() const;
125 
127  void clear() { mMessageList.clear(); }
128 
133  QList<QgsErrorMessage> messageList() const { return mMessageList; }
134 
135 
136 #ifdef SIP_RUN
137  SIP_PYOBJECT __repr__();
138  % MethodCode
139  QString str = QStringLiteral( "<QgsError: %1>" ).arg( sipCpp->message( QgsErrorMessage::Text ) );
140  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
141  % End
142 #endif
143 
144  private:
146  QList<QgsErrorMessage> mMessageList;
147 };
148 
149 #endif
QgsError
QgsError is container for error messages (report).
Definition: qgserror.h:81
QgsError::QgsError
QgsError()=default
Constructor for QgsError.
QgsError::clear
void clear()
Clear error messages.
Definition: qgserror.h:127
QgsError::messageList
QList< QgsErrorMessage > messageList() const
messageList return the list of current error messages
Definition: qgserror.h:133
QgsErrorMessage::line
int line() const
Definition: qgserror.h:59
QgsErrorMessage::file
QString file() const
Definition: qgserror.h:57
QgsErrorMessage::tag
QString tag() const
Definition: qgserror.h:56
QgsErrorMessage::QgsErrorMessage
QgsErrorMessage()=default
Constructor for QgsErrorMessage.
QgsError::isEmpty
bool isEmpty() const
Test if any error is set.
Definition: qgserror.h:111
QgsErrorMessage
QgsErrorMessage represents single error message.
Definition: qgserror.h:33
QgsErrorMessage::Format
Format
Format.
Definition: qgserror.h:37
QgsErrorMessage::message
QString message() const
Definition: qgserror.h:55
QgsErrorMessage::Text
@ Text
Definition: qgserror.h:38
QgsErrorMessage::Html
@ Html
Definition: qgserror.h:39