QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
39  QgsErrorMessage() : mLine( 0 ), mFormat( Text ) {}
40 
48  QgsErrorMessage( const QString & theMessage, const QString & theTag = QString::null, const QString & theFile = QString::null, const QString & theFunction = QString::null, int theLine = 0 );
49 
50  QString message() const { return mMessage; }
51  QString tag() const { return mTag; }
52  QString file() const { return mFile; }
53  QString function() const { return mFunction; }
54  int line() const { return mLine; }
55 
56  private:
58  QString mMessage;
59 
61  QString mTag;
62 
64  QString mFile;
65  QString mFunction;
66  int mLine;
67 
68  /* Message format */
69  Format mFormat;
70 };
71 
77 class CORE_EXPORT QgsError
78 {
79  public:
80 
81  QgsError() {}
82 
87  QgsError( const QString & theMessage, const QString & theTag );
88 
93  void append( const QString & theMessage, const QString & theTag );
94 
98  void append( const QgsErrorMessage & theMessage );
99 
103  bool isEmpty() const { return mMessageList.isEmpty(); }
104 
109  QString message( QgsErrorMessage::Format theFormat = QgsErrorMessage::Html ) const;
110 
114  QString summary() const;
115 
117  void clear() { mMessageList.clear(); }
118 
119  private:
121  QList<QgsErrorMessage> mMessageList;
122 };
123 
124 #endif