1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #include "errorsview.h" |
5 | |
6 | #include "messagemodel.h" |
7 | |
8 | #include <QtCore/QList> |
9 | #include <QtCore/QString> |
10 | #include <QtCore/QUrl> |
11 | |
12 | #include <QtGui/QStandardItem> |
13 | #include <QtGui/QStandardItemModel> |
14 | #include <QtWidgets/QListView> |
15 | #include <QtWidgets/QTextEdit> |
16 | #include <QtWidgets/QVBoxLayout> |
17 | |
18 | QT_BEGIN_NAMESPACE |
19 | |
20 | ErrorsView::ErrorsView(MultiDataModel *dataModel, QWidget *parent) : |
21 | QListView(parent), |
22 | m_dataModel(dataModel) |
23 | { |
24 | m_list = new QStandardItemModel(this); |
25 | setModel(m_list); |
26 | } |
27 | |
28 | void ErrorsView::clear() |
29 | { |
30 | m_list->clear(); |
31 | } |
32 | |
33 | void ErrorsView::addError(int model, const ErrorType type, const QString &arg) |
34 | { |
35 | switch (type) { |
36 | case SuperfluousAccelerator: |
37 | addError(model, error: tr(s: "Accelerator possibly superfluous in translation." )); |
38 | break; |
39 | case MissingAccelerator: |
40 | addError(model, error: tr(s: "Accelerator possibly missing in translation." )); |
41 | break; |
42 | case SurroundingWhitespaceDiffers: |
43 | addError(model, error: tr(s: "Translation does not have same leading and trailing whitespace as the source text." )); |
44 | break; |
45 | case PunctuationDiffers: |
46 | addError(model, error: tr(s: "Translation does not end with the same punctuation as the source text." )); |
47 | break; |
48 | case IgnoredPhrasebook: |
49 | addError(model, error: tr(s: "A phrase book suggestion for '%1' was ignored." ).arg(a: arg)); |
50 | break; |
51 | case PlaceMarkersDiffer: |
52 | addError(model, error: tr(s: "Translation does not refer to the same place markers as in the source text." )); |
53 | break; |
54 | case NumerusMarkerMissing: |
55 | addError(model, error: tr(s: "Translation does not contain the necessary %n/%Ln place marker." )); |
56 | break; |
57 | default: |
58 | addError(model, error: tr(s: "Unknown error" )); |
59 | break; |
60 | } |
61 | } |
62 | |
63 | QString ErrorsView::firstError() |
64 | { |
65 | return (m_list->rowCount() == 0) ? QString() : m_list->item(row: 0)->text(); |
66 | } |
67 | |
68 | void ErrorsView::addError(int model, const QString &error) |
69 | { |
70 | // NOTE: Three statics instead of one just for GCC 3.3.5 |
71 | static QLatin1String imageLocation(":/images/s_check_danger.png" ); |
72 | static QPixmap image(imageLocation); |
73 | static QIcon pxDanger(image); |
74 | QString lang; |
75 | if (m_dataModel->modelCount() > 1) |
76 | lang = m_dataModel->model(i: model)->localizedLanguage() + QLatin1String(": " ); |
77 | QStandardItem *item = new QStandardItem(pxDanger, lang + error); |
78 | item->setEditable(false); |
79 | m_list->appendRow(items: QList<QStandardItem*>() << item); |
80 | } |
81 | |
82 | QT_END_NAMESPACE |
83 | |