-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqgserror.cpp
130 lines (119 loc) · 3.94 KB
/
qgserror.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/***************************************************************************
qgserror.cpp - Error container
-------------------
begin : October 2012
copyright : (C) 2012 Radim Blazek
email : radim dot blazek at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgis.h"
#include "qgsversion.h"
#include "qgsconfig.h"
#include "qgserror.h"
#include "qgslogger.h"
#include <QRegExp>
QgsErrorMessage::QgsErrorMessage( const QString & theMessage, const QString & theTag, const QString & theFile, const QString & theFunction, int theLine )
: mMessage( theMessage )
, mTag( theTag )
, mFile( theFile )
, mFunction( theFunction )
, mLine( theLine )
, mFormat( Text )
{
}
QgsError::QgsError( const QString & theMessage, const QString & theTag )
{
append( theMessage, theTag );
}
void QgsError::append( const QString & theMessage, const QString & theTag )
{
mMessageList.append( QgsErrorMessage( theMessage, theTag ) );
}
void QgsError::append( const QgsErrorMessage & theMessage )
{
mMessageList.append( theMessage );
}
QString QgsError::message( QgsErrorMessage::Format theFormat ) const
{
QString str;
QString srcUrl;
#if defined(QGISDEBUG) && defined(QGS_GIT_REMOTE_URL)
// TODO: verify if we are not ahead to origin (remote hash does not exist)
// and there are no local not commited changes
QString hash = QString( QGis::QGIS_DEV_VERSION );
QString remote = QString( QGS_GIT_REMOTE_URL );
if ( !hash.isEmpty() && !remote.isEmpty() && remote.contains( "github.com" ) )
{
QString path = remote.remove( QRegExp( ".*github.com[:/]" ) ).remove( ".git" );
srcUrl = "https://github.com/" + path + "/blob/" + hash;
}
#endif
foreach ( QgsErrorMessage m, mMessageList )
{
#ifdef QGISDEBUG
QString file;
#ifndef _MSC_VER
int sPrefixLength = strlen( CMAKE_SOURCE_DIR ) + 1;
file = m.file().mid( sPrefixLength );
#else
file = m.file();
#endif
#endif
if ( theFormat == QgsErrorMessage::Text )
{
if ( !str.isEmpty() )
{
str += "\n"; // new message
}
if ( !m.tag().isEmpty() )
{
str += m.tag() + " ";
}
str += m.message();
#ifdef QGISDEBUG
QString where;
if ( !file.isEmpty() )
{
where += QString( "file: %1 row: %2" ).arg( file ).arg( m.line() );
}
if ( !m.function().isEmpty() )
{
where += QString( "function %1:" ).arg( m.function() );
}
if ( !where.isEmpty() )
{
str += QString( " (%1)" ).arg( where );
}
#endif
}
else // QgsErrorMessage::Html
{
str += "<p><b>" + m.tag() + ":</b> " + m.message();
#ifdef QGISDEBUG
QString location = QString( "%1 : %2 : %3" ).arg( file ).arg( m.line() ).arg( m.function() );
if ( !srcUrl.isEmpty() )
{
QString url = QString( "%1/%2#L%3" ).arg( srcUrl ).arg( file ).arg( m.line() );
str += QString( "<br>(<a href='%1'>%2</a>)" ).arg( url ).arg( location );
}
else
{
str += QString( "<br>(%1)" ).arg( location );
}
#endif
}
}
return str;
}
QString QgsError::summary() const
{
// The first message in chain is usually the real error given by backend/server
return mMessageList.first().message();
}