Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
errorsview.cpp
Go to the documentation of this file.
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 "globals.h"
7#include "messagemodel.h"
8
9#include <QtCore/QList>
10#include <QtCore/QString>
11#include <QtCore/QUrl>
12
13#include <QtGui/QStandardItem>
14#include <QtGui/QStandardItemModel>
15#include <QtWidgets/QListView>
16#include <QtWidgets/QTextEdit>
17#include <QtWidgets/QVBoxLayout>
18
20
21using namespace Qt::Literals::StringLiterals;
22
23ErrorsView::ErrorsView(MultiDataModel *dataModel, QWidget *parent) :
24 QListView(parent),
25 m_dataModel(dataModel)
26{
27 m_list = new QStandardItemModel(this);
28 setModel(m_list);
29}
30
32{
33 m_list->clear();
34}
35
36void ErrorsView::addError(int model, const Validator::ErrorType type, const QString &arg)
37{
38 switch (type) {
39 case Validator::SuperfluousAccelerator:
40 addError(model, tr("Accelerator possibly superfluous in translation: %1").arg(arg));
41 break;
42 case Validator::MissingAccelerator:
43 addError(model, tr("Accelerator possibly missing in translation: %1").arg(arg));
44 break;
45 case Validator::SurroundingWhitespaceDiffers:
46 addError(model,
47 tr("Translation does not have same leading and trailing whitespace as the source "
48 "text: %1")
49 .arg(arg));
50 break;
51 case Validator::PunctuationDiffers:
52 addError(model,
53 tr("Translation does not end with the same punctuation as the source text: %1")
54 .arg(arg));
55 break;
56 case Validator::IgnoredPhrasebook:
57 addError(model, tr("A phrase book suggestion for '%1' was ignored.").arg(arg));
58 break;
59 case Validator::PlaceMarkersDiffer:
60 addError(
61 model,
62 tr("Translation does not refer to the same place markers as in the source text: %1")
63 .arg(arg));
64 break;
65 case Validator::NumerusMarkerMissing:
66 addError(model,
67 tr("Translation does not contain the necessary %n/%Ln place marker: %1").arg(arg));
68 break;
69 default:
70 addError(model, tr("Unknown error"));
71 break;
72 }
73}
74
76{
77 return (m_list->rowCount() == 0) ? QString() : m_list->item(0)->text();
78}
79
80void ErrorsView::addError(int model, const QString &error)
81{
82 static QIcon pxDanger = createMarkIcon(TranslationMarks::DangerMark);
83 QString lang;
84 if (m_dataModel->modelCount() > 1)
85 lang = m_dataModel->model(model)->localizedLanguage() + ": "_L1;
86 QStandardItem *item = new QStandardItem(pxDanger, lang + error);
87 item->setEditable(false);
88 m_list->appendRow(QList<QStandardItem*>() << item);
89}
90
91QT_END_NAMESPACE
void addError(int model, const Validator::ErrorType type, const QString &arg=QString())
QString firstError()
void clear()