QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 // Macro to create Error message including info about where it was created.
24 #define QGS_ERROR_MESSAGE(message, tag) QgsErrorMessage(QString(message),QString(tag), QString(__FILE__), QString(__FUNCTION__), __LINE__)
25 
29 class CORE_EXPORT QgsErrorMessage
30 {
31  public:
33  enum Format
34  {
35  Text, // Plain text
36  Html
37  };
38 
40  : mLine( 0 )
41  , mFormat( Text )
42  {}
43 
51  QgsErrorMessage( const QString & theMessage, const QString & theTag = QString::null, const QString & theFile = QString::null, const QString & theFunction = QString::null, int theLine = 0 );
52 
53  QString message() const { return mMessage; }
54  QString tag() const { return mTag; }
55  QString file() const { return mFile; }
56  QString function() const { return mFunction; }
57  int line() const { return mLine; }
58 
59  private:
61  QString mMessage;
62 
64  QString mTag;
65 
67  QString mFile;
68  QString mFunction;
69  int mLine;
70 
72  Format mFormat;
73 };
74 
80 class CORE_EXPORT QgsError
81 {
82  public:
83 
84  QgsError() {}
85 
90  QgsError( const QString & theMessage, const QString & theTag );
91 
96  void append( const QString & theMessage, const QString & theTag );
97 
101  void append( const QgsErrorMessage & theMessage );
102 
106  bool isEmpty() const { return mMessageList.isEmpty(); }
107 
112  QString message( QgsErrorMessage::Format theFormat = QgsErrorMessage::Html ) const;
113 
117  QString summary() const;
118 
120  void clear() { mMessageList.clear(); }
121 
122  private:
124  QList<QgsErrorMessage> mMessageList;
125 };
126 
127 #endif
QString message() const
Definition: qgserror.h:53
bool isEmpty() const
Test if any error is set.
Definition: qgserror.h:106
Format
Format.
Definition: qgserror.h:33
QgsErrorMessage represents single error message.
Definition: qgserror.h:29
int line() const
Definition: qgserror.h:57
QgsError is container for error messages (report).
Definition: qgserror.h:80
QString tag() const
Definition: qgserror.h:54
QgsError()
Definition: qgserror.h:84
QString file() const
Definition: qgserror.h:55
void clear()
Clear error messages.
Definition: qgserror.h:120