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 <QColor>
30#include <QPair>
31#include <QVariant>
32
33#include "TestGroup.h"
34
35using namespace QPatternistSDK;
36
37TestGroup::TestGroup(TreeItem *p) : m_parent(p)
38{
39}
40
41QVariant TestGroup::data(const Qt::ItemDataRole role, int column) const
42{
43 if(role != Qt::DisplayRole && role != Qt::BackgroundRole && role != Qt::ToolTipRole)
44 return QVariant();
45
46 /* In ResultSummary, the first is the amount of passes and the second is the total. */
47 const ResultSummary sum(resultSummary());
48 const int failures = sum.second - sum.first;
49
50 switch(role)
51 {
52 case Qt::DisplayRole:
53 {
54
55 switch(column)
56 {
57 case 0:
58 return title();
59 case 1:
60 /* Passes. */
61 return QString::number(sum.first);
62 case 2:
63 /* Failures. */
64 return QString::number(failures);
65 case 3:
66 /* Total. */
67 return QString::number(sum.second);
68 default:
69 {
70 Q_ASSERT(false);
71 return QString();
72 }
73 }
74 }
75 case Qt::BackgroundRole:
76 {
77 switch(column)
78 {
79 case 1:
80 {
81 if(sum.first)
82 {
83 /* Pass. */
84 return QColor(Qt::green);
85 }
86 else
87 return QVariant();
88 }
89 case 2:
90 {
91 if(failures)
92 {
93 /* Failure. */
94 return QColor(Qt::red);
95 }
96 else
97 return QVariant();
98 }
99 default:
100 return QVariant();
101 }
102 }
103 case Qt::ToolTipRole:
104 {
105 return description();
106 }
107 default:
108 {
109 Q_ASSERT_X(false, Q_FUNC_INFO, "This shouldn't be reached");
110 return QVariant();
111 }
112 }
113}
114
115void TestGroup::setNote(const QString &n)
116{
117 m_note = n;
118}
119
120QString TestGroup::note() const
121{
122 return m_note;
123}
124
125TreeItem *TestGroup::parent() const
126{
127 return m_parent;
128}
129
130// vim: et:ts=4:sw=4:sts=4
131

source code of qtxmlpatterns/tests/auto/xmlpatternssdk/TestGroup.cpp