OpenCoverage

qerrormessage.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qerrormessage.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
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 Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qerrormessage.h"-
41-
42#ifndef QT_NO_ERRORMESSAGE-
43-
44#include "qapplication.h"-
45#include "qcheckbox.h"-
46#include "qlabel.h"-
47#include "qlayout.h"-
48#include "qmessagebox.h"-
49#include "qpushbutton.h"-
50#include "qstringlist.h"-
51#include "qtextedit.h"-
52#include "qdialog_p.h"-
53#include "qpixmap.h"-
54#include "qmetaobject.h"-
55#include "qthread.h"-
56#include "qset.h"-
57-
58#include <queue>-
59-
60#include <stdio.h>-
61#include <stdlib.h>-
62-
63#ifdef Q_OS_WINCE-
64extern bool qt_wince_is_mobile(); //defined in qguifunctions_wince.cpp-
65extern bool qt_wince_is_high_dpi(); //defined in qguifunctions_wince.cpp-
66#endif-
67-
68QT_BEGIN_NAMESPACE-
69-
70class QErrorMessagePrivate : public QDialogPrivate-
71{-
72 Q_DECLARE_PUBLIC(QErrorMessage)-
73public:-
74 QPushButton * ok;-
75 QCheckBox * again;-
76 QTextEdit * errors;-
77 QLabel * icon;-
78 std::queue<QPair<QString, QString> > pending;-
79 QSet<QString> doNotShow;-
80 QSet<QString> doNotShowType;-
81 QString currentMessage;-
82 QString currentType;-
83-
84 bool isMessageToBeShown(const QString &message, const QString &type) const;-
85 bool nextPending();-
86 void retranslateStrings();-
87};-
88-
89namespace {-
90class QErrorMessageTextView : public QTextEdit-
91{-
92public:-
93 QErrorMessageTextView(QWidget *parent)-
94 : QTextEdit(parent) { setReadOnly(true); }
never executed: end of block
0
95-
96 virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE;-
97 virtual QSize sizeHint() const Q_DECL_OVERRIDE;-
98};-
99} // unnamed namespace-
100-
101QSize QErrorMessageTextView::minimumSizeHint() const-
102{-
103#ifdef Q_OS_WINCE-
104 if (qt_wince_is_mobile())-
105 if (qt_wince_is_high_dpi())-
106 return QSize(200, 200);-
107 else-
108 return QSize(100, 100);-
109 else-
110 return QSize(70, 70);-
111#else-
112 return QSize(50, 50);
never executed: return QSize(50, 50);
0
113#endif-
114}-
115-
116QSize QErrorMessageTextView::sizeHint() const-
117{-
118#ifdef Q_OS_WINCE-
119 if (qt_wince_is_mobile())-
120 if (qt_wince_is_high_dpi())-
121 return QSize(400, 200);-
122 else-
123 return QSize(320, 120);-
124 else-
125 return QSize(300, 100);-
126#else-
127 return QSize(250, 75);
never executed: return QSize(250, 75);
0
128#endif //Q_OS_WINCE-
129}-
130-
131/*!-
132 \class QErrorMessage-
133-
134 \brief The QErrorMessage class provides an error message display dialog.-
135-
136 \ingroup standard-dialog-
137 \inmodule QtWidgets-
138-
139 An error message widget consists of a text label and a checkbox. The-
140 checkbox lets the user control whether the same error message will be-
141 displayed again in the future, typically displaying the text,-
142 "Show this message again" translated into the appropriate local-
143 language.-
144-
145 For production applications, the class can be used to display messages which-
146 the user only needs to see once. To use QErrorMessage like this, you create-
147 the dialog in the usual way, and show it by calling the showMessage() slot or-
148 connecting signals to it.-
149-
150 The static qtHandler() function installs a message handler-
151 using qInstallMessageHandler() and creates a QErrorMessage that displays-
152 qDebug(), qWarning() and qFatal() messages. This is most useful in-
153 environments where no console is available to display warnings and-
154 error messages.-
155-
156 In both cases QErrorMessage will queue pending messages and display-
157 them in order, with each new message being shown as soon as the user-
158 has accepted the previous message. Once the user has specified that a-
159 message is not to be shown again it is automatically skipped, and the-
160 dialog will show the next appropriate message in the queue.-
161-
162 The \l{dialogs/standarddialogs}{Standard Dialogs} example shows-
163 how to use QErrorMessage as well as other built-in Qt dialogs.-
164-
165 \image qerrormessage.png-
166-
167 \sa QMessageBox, QStatusBar::showMessage(), {Standard Dialogs Example}-
168*/-
169-
170static QErrorMessage * qtMessageHandler = 0;-
171-
172static void deleteStaticcQErrorMessage() // post-routine-
173{-
174 if (qtMessageHandler) {
qtMessageHandlerDescription
TRUEnever evaluated
FALSEnever evaluated
0
175 delete qtMessageHandler;-
176 qtMessageHandler = 0;-
177 }
never executed: end of block
0
178}
never executed: end of block
0
179-
180static bool metFatal = false;-
181-
182static void jump(QtMsgType t, const QMessageLogContext & /*context*/, const QString &m)-
183{-
184 if (!qtMessageHandler)
!qtMessageHandlerDescription
TRUEnever evaluated
FALSEnever evaluated
0
185 return;
never executed: return;
0
186-
187 QString rich;-
188-
189 switch (t) {-
190 case QtDebugMsg:
never executed: case QtDebugMsg:
0
191 default:
never executed: default:
0
192 rich = QErrorMessage::tr("Debug Message:");-
193 break;
never executed: break;
0
194 case QtWarningMsg:
never executed: case QtWarningMsg:
0
195 rich = QErrorMessage::tr("Warning:");-
196 break;
never executed: break;
0
197 case QtFatalMsg:
never executed: case QtFatalMsg:
0
198 rich = QErrorMessage::tr("Fatal Error:");-
199 }
never executed: end of block
0
200 rich = QString::fromLatin1("<p><b>%1</b></p>").arg(rich);-
201 rich += Qt::convertFromPlainText(m, Qt::WhiteSpaceNormal);-
202-
203 // ### work around text engine quirk-
204 if (rich.endsWith(QLatin1String("</p>")))
rich.endsWith(...tring("</p>"))Description
TRUEnever evaluated
FALSEnever evaluated
0
205 rich.chop(4);
never executed: rich.chop(4);
0
206-
207 if (!metFatal) {
!metFatalDescription
TRUEnever evaluated
FALSEnever evaluated
0
208 if (QThread::currentThread() == qApp->thread()) {
QThread::curre...()))->thread()Description
TRUEnever evaluated
FALSEnever evaluated
0
209 qtMessageHandler->showMessage(rich);-
210 } else {
never executed: end of block
0
211 QMetaObject::invokeMethod(qtMessageHandler,-
212 "showMessage",-
213 Qt::QueuedConnection,-
214 Q_ARG(QString, rich));-
215 }
never executed: end of block
0
216 metFatal = (t == QtFatalMsg);-
217 }
never executed: end of block
0
218}
never executed: end of block
0
219-
220-
221/*!-
222 Constructs and installs an error handler window with the given \a-
223 parent.-
224*/-
225-
226QErrorMessage::QErrorMessage(QWidget * parent)-
227 : QDialog(*new QErrorMessagePrivate, parent)-
228{-
229 Q_D(QErrorMessage);-
230-
231 d->icon = new QLabel(this);-
232 d->errors = new QErrorMessageTextView(this);-
233 d->again = new QCheckBox(this);-
234 d->ok = new QPushButton(this);-
235 QGridLayout * grid = new QGridLayout(this);-
236-
237 connect(d->ok, SIGNAL(clicked()), this, SLOT(accept()));-
238-
239 grid->addWidget(d->icon, 0, 0, Qt::AlignTop);-
240 grid->addWidget(d->errors, 0, 1);-
241 grid->addWidget(d->again, 1, 1, Qt::AlignTop);-
242 grid->addWidget(d->ok, 2, 0, 1, 2, Qt::AlignCenter);-
243 grid->setColumnStretch(1, 42);-
244 grid->setRowStretch(0, 42);-
245-
246#ifndef QT_NO_MESSAGEBOX-
247 d->icon->setPixmap(QMessageBox::standardIcon(QMessageBox::Information));-
248 d->icon->setAlignment(Qt::AlignHCenter | Qt::AlignTop);-
249#endif-
250 d->again->setChecked(true);-
251#if defined(Q_OS_WINCE)-
252 d->ok->setFixedSize(0,0);-
253#endif-
254 d->ok->setFocus();-
255-
256 d->retranslateStrings();-
257}
never executed: end of block
0
258-
259-
260/*!-
261 Destroys the error message dialog.-
262*/-
263-
264QErrorMessage::~QErrorMessage()-
265{-
266 if (this == qtMessageHandler) {
this == qtMessageHandlerDescription
TRUEnever evaluated
FALSEnever evaluated
0
267 qtMessageHandler = 0;-
268 QtMessageHandler tmp = qInstallMessageHandler(0);-
269 // in case someone else has later stuck in another...-
270 if (tmp != jump)
tmp != jumpDescription
TRUEnever evaluated
FALSEnever evaluated
0
271 qInstallMessageHandler(tmp);
never executed: qInstallMessageHandler(tmp);
0
272 }
never executed: end of block
0
273}
never executed: end of block
0
274-
275-
276/*! \reimp */-
277-
278void QErrorMessage::done(int a)-
279{-
280 Q_D(QErrorMessage);-
281 if (!d->again->isChecked()) {
!d->again->isChecked()Description
TRUEnever evaluated
FALSEnever evaluated
0
282 if (d->currentType.isEmpty()) {
d->currentType.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
283 if (!d->currentMessage.isEmpty())
!d->currentMessage.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
284 d->doNotShow.insert(d->currentMessage);
never executed: d->doNotShow.insert(d->currentMessage);
0
285 } else {
never executed: end of block
0
286 d->doNotShowType.insert(d->currentType);-
287 }
never executed: end of block
0
288 }-
289 d->currentMessage.clear();-
290 d->currentType.clear();-
291 if (!d->nextPending()) {
!d->nextPending()Description
TRUEnever evaluated
FALSEnever evaluated
0
292 QDialog::done(a);-
293 if (this == qtMessageHandler && metFatal)
this == qtMessageHandlerDescription
TRUEnever evaluated
FALSEnever evaluated
metFatalDescription
TRUEnever evaluated
FALSEnever evaluated
0
294 exit(1);
never executed: exit(1);
0
295 }
never executed: end of block
0
296}
never executed: end of block
0
297-
298-
299/*!-
300 Returns a pointer to a QErrorMessage object that outputs the-
301 default Qt messages. This function creates such an object, if there-
302 isn't one already.-
303*/-
304-
305QErrorMessage * QErrorMessage::qtHandler()-
306{-
307 if (!qtMessageHandler) {
!qtMessageHandlerDescription
TRUEnever evaluated
FALSEnever evaluated
0
308 qtMessageHandler = new QErrorMessage(0);-
309 qAddPostRoutine(deleteStaticcQErrorMessage); // clean up-
310 qtMessageHandler->setWindowTitle(QApplication::applicationName());-
311 qInstallMessageHandler(jump);-
312 }
never executed: end of block
0
313 return qtMessageHandler;
never executed: return qtMessageHandler;
0
314}-
315-
316-
317/*! \internal */-
318-
319bool QErrorMessagePrivate::isMessageToBeShown(const QString &message, const QString &type) const-
320{-
321 return !message.isEmpty()
never executed: return !message.isEmpty() && (type.isEmpty() ? !doNotShow.contains(message) : !doNotShowType.contains(type));
0
322 && (type.isEmpty() ? !doNotShow.contains(message) : !doNotShowType.contains(type));
never executed: return !message.isEmpty() && (type.isEmpty() ? !doNotShow.contains(message) : !doNotShowType.contains(type));
0
323}-
324-
325bool QErrorMessagePrivate::nextPending()-
326{-
327 while (!pending.empty()) {
!pending.empty()Description
TRUEnever evaluated
FALSEnever evaluated
0
328 QPair<QString,QString> &pendingMessage = pending.front();-
329 QString message = qMove(pendingMessage.first);-
330 QString type = qMove(pendingMessage.second);-
331 pending.pop();-
332 if (isMessageToBeShown(message, type)) {
isMessageToBeS...message, type)Description
TRUEnever evaluated
FALSEnever evaluated
0
333#ifndef QT_NO_TEXTHTMLPARSER-
334 errors->setHtml(message);-
335#else-
336 errors->setPlainText(message);-
337#endif-
338 currentMessage = qMove(message);-
339 currentType = qMove(type);-
340 return true;
never executed: return true;
0
341 }-
342 }
never executed: end of block
0
343 return false;
never executed: return false;
0
344}-
345-
346-
347/*!-
348 Shows the given message, \a message, and returns immediately. If the user-
349 has requested for the message not to be shown again, this function does-
350 nothing.-
351-
352 Normally, the message is displayed immediately. However, if there are-
353 pending messages, it will be queued to be displayed later.-
354*/-
355-
356void QErrorMessage::showMessage(const QString &message)-
357{-
358 showMessage(message, QString());-
359}
never executed: end of block
0
360-
361/*!-
362 \since 4.5-
363 \overload-
364-
365 Shows the given message, \a message, and returns immediately. If the user-
366 has requested for messages of type, \a type, not to be shown again, this-
367 function does nothing.-
368-
369 Normally, the message is displayed immediately. However, if there are-
370 pending messages, it will be queued to be displayed later.-
371-
372 \sa showMessage()-
373*/-
374-
375void QErrorMessage::showMessage(const QString &message, const QString &type)-
376{-
377 Q_D(QErrorMessage);-
378 if (!d->isMessageToBeShown(message, type))
!d->isMessageT...message, type)Description
TRUEnever evaluated
FALSEnever evaluated
0
379 return;
never executed: return;
0
380 d->pending.push(qMakePair(message, type));-
381 if (!isVisible() && d->nextPending())
!isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
d->nextPending()Description
TRUEnever evaluated
FALSEnever evaluated
0
382 show();
never executed: show();
0
383}
never executed: end of block
0
384-
385/*!-
386 \reimp-
387*/-
388void QErrorMessage::changeEvent(QEvent *e)-
389{-
390 Q_D(QErrorMessage);-
391 if (e->type() == QEvent::LanguageChange) {
e->type() == Q...LanguageChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
392 d->retranslateStrings();-
393 }
never executed: end of block
0
394 QDialog::changeEvent(e);-
395}
never executed: end of block
0
396-
397void QErrorMessagePrivate::retranslateStrings()-
398{-
399 again->setText(QErrorMessage::tr("&Show this message again"));-
400 ok->setText(QErrorMessage::tr("&OK"));-
401}
never executed: end of block
0
402-
403QT_END_NAMESPACE-
404-
405#include "moc_qerrormessage.cpp"-
406-
407#endif // QT_NO_ERRORMESSAGE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9