Update obsolete contact address.
[profile/ivi/qtxmlpatterns.git] / tests / auto / xmlpatternsview / view / TestResultView.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <QHeaderView>
43
44 #include "ASTItem.h"
45 #include "ErrorItem.h"
46 #include "TestCase.h"
47 #include "TestResult.h"
48 #include "TreeModel.h"
49 #include "XDTItemItem.h"
50
51 #include "TestResultView.h"
52
53 using namespace QPatternistSDK;
54
55 TestResultView::TestResultView(QWidget *const p) : QDockWidget(QLatin1String("Test Result View"), p)
56 {
57     Q_ASSERT(p);
58     setObjectName(QLatin1String("TestResultView"));
59     setWidget(new QWidget());
60     setupUi(widget());
61
62     QStringList astColumns;
63     astColumns << QLatin1String("Node Name")
64                << QLatin1String("Details")
65                << QLatin1String("Static Type")
66                << QLatin1String("Required Type");
67     astView->setModel(new TreeModel(astColumns, this));
68
69     QStringList itemColumns;
70     itemColumns << QLatin1String("#")
71                 << QLatin1String("Value")
72                 << QLatin1String("Type");
73     itemListResult->setModel(new TreeModel(itemColumns, this));
74
75     QStringList errColumns;
76     errColumns << QLatin1String("Severity")
77                << QLatin1String("Error Code")
78                << QLatin1String("Message");
79     messageOutput->setModel(new TreeModel(errColumns, this));
80     messageOutput->horizontalHeader()->setStretchLastSection(true);
81 }
82
83 void TestResultView::displayTestResult(const TestResult *const result)
84 {
85     if(!result)
86     {
87         displayNone();
88         return;
89     }
90
91     /* ------- the Test Status Label --------- */
92     resultStatus->setText(result->status() ? TestResult::displayName(result->status())
93                                            : QLatin1String("Not Applicable"));
94     /* --------------------------------------- */
95
96     /* ------------ the AST View ------------- */
97     ASTItem *astTree = result->astTree();
98     static_cast<TreeModel *>(astView->model())->setRoot(astTree);
99     /* --------------------------------------- */
100
101     /* ------- the Error code/msg View ------- */
102     ErrorItem *msgRoot = new ErrorItem(ErrorHandler::Message(), 0);
103
104     const ErrorHandler::Message::List msgs(result->messages());
105     ErrorHandler::Message::List::const_iterator it(msgs.constBegin());
106     const ErrorHandler::Message::List::const_iterator end(msgs.constEnd());
107
108     for(; it != end; ++it)
109         msgRoot->appendChild(new ErrorItem(*it, msgRoot));
110
111     TreeModel *etm = static_cast<TreeModel *>(messageOutput->model());
112     etm->setRoot(msgRoot);
113     /* --------------------------------------- */
114
115     const QPatternist::Item::List items(result->items());
116     /* ----- the Serialized Output View ------ */
117     serializedResult->setPlainText(result->asSerialized());
118     /* --------------------------------------- */
119
120     /* ------ the Item List Output View ------ */
121     XDTItemItem *itemRoot = new XDTItemItem(QPatternist::Item(), 0);
122     QPatternist::Item item;
123
124     QPatternist::Item::List::const_iterator itemIt(items.constBegin());
125     const QPatternist::Item::List::const_iterator itemsEnd(items.constEnd());
126
127     for(; itemIt != itemsEnd; ++itemIt)
128         itemRoot->appendChild(new XDTItemItem(*itemIt, itemRoot));
129
130     TreeModel *itm = static_cast<TreeModel *>(itemListResult->model());
131     itm->setRoot(itemRoot);
132     /* --------------------------------------- */
133 }
134
135 void TestResultView::displayTestResult(TestCase *const tc)
136 {
137     if(tc)
138         displayTestResult(tc->testResult());
139     else
140         displayNone();
141 }
142
143 void TestResultView::displayNone()
144 {
145     TreeModel *tm;
146
147     tm = static_cast<TreeModel *>(astView->model());
148     Q_ASSERT(tm);
149     tm->setRoot(0);
150
151     tm = static_cast<TreeModel *>(messageOutput->model());
152     Q_ASSERT(tm);
153     tm->setRoot(0);
154
155     tm = static_cast<TreeModel *>(itemListResult->model());
156     Q_ASSERT(tm);
157     tm->setRoot(0);
158
159     serializedResult->clear();
160     resultStatus->clear();
161 }
162
163 // vim: et:ts=4:sw=4:sts=4