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
43 QT_BEGIN_NAMESPACE
44
ErrorsView(MultiDataModel * dataModel,QWidget * parent)45 ErrorsView::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
clear()53 void ErrorsView::clear()
54 {
55 m_list->clear();
56 }
57
addError(int model,const ErrorType type,const QString & arg)58 void ErrorsView::addError(int model, const ErrorType type, const QString &arg)
59 {
60 switch (type) {
61 case SuperfluousAccelerator:
62 addError(model, tr("Accelerator possibly superfluous in translation."));
63 break;
64 case MissingAccelerator:
65 addError(model, tr("Accelerator possibly missing in translation."));
66 break;
67 case SurroundingWhitespaceDiffers:
68 addError(model, tr("Translation does not have same leading and trailing whitespace as the source text."));
69 break;
70 case PunctuationDiffers:
71 addError(model, tr("Translation does not end with the same punctuation as the source text."));
72 break;
73 case IgnoredPhrasebook:
74 addError(model, tr("A phrase book suggestion for '%1' was ignored.").arg(arg));
75 break;
76 case PlaceMarkersDiffer:
77 addError(model, tr("Translation does not refer to the same place markers as in the source text."));
78 break;
79 case NumerusMarkerMissing:
80 addError(model, tr("Translation does not contain the necessary %n/%Ln place marker."));
81 break;
82 default:
83 addError(model, tr("Unknown error"));
84 break;
85 }
86 }
87
firstError()88 QString ErrorsView::firstError()
89 {
90 return (m_list->rowCount() == 0) ? QString() : m_list->item(0)->text();
91 }
92
addError(int model,const QString & error)93 void 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(model)->localizedLanguage() + QLatin1String(": ");
102 QStandardItem *item = new QStandardItem(pxDanger, lang + error);
103 item->setEditable(false);
104 m_list->appendRow(QList<QStandardItem*>() << item);
105 }
106
107 QT_END_NAMESPACE
108