1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include <QList> |
30 | #include <QPointer> |
31 | #include <QVariant> |
32 | |
33 | #include <private/qreportcontext_p.h> |
34 | #include <private/qcommonnamespaces_p.h> |
35 | |
36 | #include "ErrorItem.h" |
37 | |
38 | using namespace QPatternistSDK; |
39 | |
40 | QString ErrorItem::toString(const QtMsgType type) |
41 | { |
42 | switch(type) |
43 | { |
44 | case QtWarningMsg: |
45 | return QLatin1String("Warning"); |
46 | case QtFatalMsg: |
47 | return QLatin1String("Error"); |
48 | default: |
49 | { |
50 | Q_ASSERT(false); |
51 | return QString(); |
52 | } |
53 | } |
54 | } |
55 | |
56 | ErrorItem::ErrorItem(const ErrorHandler::Message &error, |
57 | ErrorItem *p) : m_message(error), |
58 | m_parent(p) |
59 | { |
60 | } |
61 | |
62 | ErrorItem::~ErrorItem() |
63 | { |
64 | qDeleteAll(c: m_children); |
65 | } |
66 | |
67 | int ErrorItem::columnCount() const |
68 | { |
69 | return 3; |
70 | } |
71 | |
72 | QVariant ErrorItem::data(const Qt::ItemDataRole role, int column) const |
73 | { |
74 | if(role != Qt::DisplayRole) |
75 | return QVariant(); |
76 | |
77 | switch(column) |
78 | { |
79 | case 0: |
80 | return toString(type: m_message.type()); |
81 | case 1: |
82 | { |
83 | if(!m_message.type()) /* It's a warning, likely. */ |
84 | return QString(); |
85 | |
86 | QString ns; |
87 | const QString code(QPatternist::ReportContext::codeFromURI(typeURI: m_message.identifier().toString(), uri&: ns)); |
88 | |
89 | if(ns == QPatternist::CommonNamespaces::XPERR) |
90 | return code; |
91 | else /* Do the full version. */ |
92 | return m_message.type(); |
93 | } |
94 | case 2: |
95 | return m_message.description(); |
96 | default: |
97 | { |
98 | Q_ASSERT(false); |
99 | return QVariant(); |
100 | } |
101 | } |
102 | } |
103 | |
104 | TreeItem::List ErrorItem::children() const |
105 | { |
106 | return m_children; |
107 | } |
108 | |
109 | void ErrorItem::appendChild(TreeItem *item) |
110 | { |
111 | m_children.append(t: item); |
112 | } |
113 | |
114 | TreeItem *ErrorItem::child(const unsigned int rowP) const |
115 | { |
116 | return m_children.value(i: rowP); |
117 | } |
118 | |
119 | unsigned int ErrorItem::childCount() const |
120 | { |
121 | return m_children.count(); |
122 | } |
123 | |
124 | TreeItem *ErrorItem::parent() const |
125 | { |
126 | return m_parent; |
127 | } |
128 | |
129 | // vim: et:ts=4:sw=4:sts=4 |
130 |