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 Qt Linguist 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 "errorsview.h"
30
31#include "messagemodel.h"
32
33#include <QtCore/QList>
34#include <QtCore/QString>
35#include <QtCore/QUrl>
36
37#include <QtGui/QStandardItem>
38#include <QtGui/QStandardItemModel>
39#include <QtWidgets/QListView>
40#include <QtWidgets/QTextEdit>
41#include <QtWidgets/QVBoxLayout>
42
43QT_BEGIN_NAMESPACE
44
45ErrorsView::ErrorsView(MultiDataModel *dataModel, QWidget *parent) :
46 QListView(parent),
47 m_dataModel(dataModel)
48{
49 m_list = new QStandardItemModel(this);
50 setModel(m_list);
51}
52
53void ErrorsView::clear()
54{
55 m_list->clear();
56}
57
58void ErrorsView::addError(int model, const ErrorType type, const QString &arg)
59{
60 switch (type) {
61 case SuperfluousAccelerator:
62 addError(model, error: tr(s: "Accelerator possibly superfluous in translation."));
63 break;
64 case MissingAccelerator:
65 addError(model, error: tr(s: "Accelerator possibly missing in translation."));
66 break;
67 case SurroundingWhitespaceDiffers:
68 addError(model, error: tr(s: "Translation does not have same leading and trailing whitespace as the source text."));
69 break;
70 case PunctuationDiffers:
71 addError(model, error: tr(s: "Translation does not end with the same punctuation as the source text."));
72 break;
73 case IgnoredPhrasebook:
74 addError(model, error: tr(s: "A phrase book suggestion for '%1' was ignored.").arg(a: arg));
75 break;
76 case PlaceMarkersDiffer:
77 addError(model, error: tr(s: "Translation does not refer to the same place markers as in the source text."));
78 break;
79 case NumerusMarkerMissing:
80 addError(model, error: tr(s: "Translation does not contain the necessary %n/%Ln place marker."));
81 break;
82 default:
83 addError(model, error: tr(s: "Unknown error"));
84 break;
85 }
86}
87
88QString ErrorsView::firstError()
89{
90 return (m_list->rowCount() == 0) ? QString() : m_list->item(row: 0)->text();
91}
92
93void ErrorsView::addError(int model, const QString &error)
94{
95 // NOTE: Three statics instead of one just for GCC 3.3.5
96 static QLatin1String imageLocation(":/images/s_check_danger.png");
97 static QPixmap image(imageLocation);
98 static QIcon pxDanger(image);
99 QString lang;
100 if (m_dataModel->modelCount() > 1)
101 lang = m_dataModel->model(i: model)->localizedLanguage() + QLatin1String(": ");
102 QStandardItem *item = new QStandardItem(pxDanger, lang + error);
103 item->setEditable(false);
104 m_list->appendRow(items: QList<QStandardItem*>() << item);
105}
106
107QT_END_NAMESPACE
108

source code of qttools/src/linguist/linguist/errorsview.cpp