qerrormessage.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qerrormessage.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7class QErrorMessagePrivate : public QDialogPrivate-
8{-
9 inline QErrorMessage* q_func() { return static_cast<QErrorMessage *>(q_ptr); } inline const QErrorMessage* q_func() const { return static_cast<const QErrorMessage *>(q_ptr); } friend class QErrorMessage;-
10public:-
11 QPushButton * ok;-
12 QCheckBox * again;-
13 QTextEdit * errors;-
14 QLabel * icon;-
15 std::queue<QPair<QString, QString> > pending;-
16 QSet<QString> doNotShow;-
17 QSet<QString> doNotShowType;-
18 QString currentMessage;-
19 QString currentType;-
20-
21 bool isMessageToBeShown(const QString &message, const QString &type) const;-
22 bool nextPending();-
23 void retranslateStrings();-
24};-
25-
26namespace {-
27class QErrorMessageTextView : public QTextEdit-
28{-
29public:-
30 QErrorMessageTextView(QWidget *parent)-
31 : QTextEdit(parent) { setReadOnly(true); }
never executed: end of block
0
32-
33 virtual QSize minimumSizeHint() const override;-
34 virtual QSize sizeHint() const override;-
35};-
36}-
37-
38QSize QErrorMessageTextView::minimumSizeHint() const-
39{-
40 return
never executed: return QSize(50, 50);
QSize(50, 50);
never executed: return QSize(50, 50);
0
41-
42}-
43-
44QSize QErrorMessageTextView::sizeHint() const-
45{-
46 return
never executed: return QSize(250, 75);
QSize(250, 75);
never executed: return QSize(250, 75);
0
47-
48}-
49static QErrorMessage * qtMessageHandler = 0;-
50-
51static void deleteStaticcQErrorMessage()-
52{-
53 if (qtMessageHandler
qtMessageHandlerDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
54 delete qtMessageHandler;-
55 qtMessageHandler = 0;-
56 }
never executed: end of block
0
57}
never executed: end of block
0
58-
59static bool metFatal = false;-
60-
61static void jump(QtMsgType t, const QMessageLogContext & , const QString &m)-
62{-
63 if (!qtMessageHandler
!qtMessageHandlerDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
64 return;
never executed: return;
0
65-
66 QString rich;-
67-
68 switch (t) {-
69 case
never executed: case QtDebugMsg:
QtDebugMsg:
never executed: case QtDebugMsg:
0
70 default
never executed: default:
:
never executed: default:
0
71 rich = QErrorMessage::tr("Debug Message:");-
72 break;
never executed: break;
0
73 case
never executed: case QtWarningMsg:
QtWarningMsg:
never executed: case QtWarningMsg:
0
74 rich = QErrorMessage::tr("Warning:");-
75 break;
never executed: break;
0
76 case
never executed: case QtFatalMsg:
QtFatalMsg:
never executed: case QtFatalMsg:
0
77 rich = QErrorMessage::tr("Fatal Error:");-
78 }
never executed: end of block
0
79 rich = QString::fromLatin1("<p><b>%1</b></p>").arg(rich);-
80 rich += Qt::convertFromPlainText(m, Qt::WhiteSpaceNormal);-
81-
82-
83 if (rich.endsWith(QLatin1String("</p>"))
rich.endsWith(...tring("</p>"))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
84 rich.chop(4);
never executed: rich.chop(4);
0
85-
86 if (!metFatal
!metFatalDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
87 if (QThread::currentThread() == (static_cast<QApplication *>(QCoreApplication::instance()))->thread()
QThread::curre...()))->thread()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
88 qtMessageHandler->showMessage(rich);-
89 }
never executed: end of block
else {
0
90 QMetaObject::invokeMethod(qtMessageHandler,-
91 "showMessage",-
92 Qt::QueuedConnection,-
93 QArgument<QString >("QString", rich));-
94 }
never executed: end of block
0
95 metFatal = (t == QtFatalMsg);-
96 }
never executed: end of block
0
97}
never executed: end of block
0
98-
99-
100-
101-
102-
103-
104-
105QErrorMessage::QErrorMessage(QWidget * parent)-
106 : QDialog(*new QErrorMessagePrivate, parent)-
107{-
108 QErrorMessagePrivate * const d = d_func();-
109-
110 d->icon = new QLabel(this);-
111 d->errors = new QErrorMessageTextView(this);-
112 d->again = new QCheckBox(this);-
113 d->ok = new QPushButton(this);-
114 QGridLayout * grid = new QGridLayout(this);-
115-
116 connect(d->ok, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "237"), this, qFlagLocation("1""accept()" "\0" __FILE__ ":" "237"));-
117-
118 grid->addWidget(d->icon, 0, 0, Qt::AlignTop);-
119 grid->addWidget(d->errors, 0, 1);-
120 grid->addWidget(d->again, 1, 1, Qt::AlignTop);-
121 grid->addWidget(d->ok, 2, 0, 1, 2, Qt::AlignCenter);-
122 grid->setColumnStretch(1, 42);-
123 grid->setRowStretch(0, 42);-
124-
125-
126 d->icon->setPixmap(QMessageBox::standardIcon(QMessageBox::Information));-
127 d->icon->setAlignment(Qt::AlignHCenter | Qt::AlignTop);-
128-
129 d->again->setChecked(true);-
130-
131-
132-
133 d->ok->setFocus();-
134-
135 d->retranslateStrings();-
136}
never executed: end of block
0
137-
138-
139-
140-
141-
142-
143QErrorMessage::~QErrorMessage()-
144{-
145 if (this == qtMessageHandler
this == qtMessageHandlerDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
146 qtMessageHandler = 0;-
147 QtMessageHandler tmp = qInstallMessageHandler(0);-
148-
149 if (tmp != jump
tmp != jumpDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
150 qInstallMessageHandler(tmp);
never executed: qInstallMessageHandler(tmp);
0
151 }
never executed: end of block
0
152}
never executed: end of block
0
153-
154-
155-
156-
157void QErrorMessage::done(int a)-
158{-
159 QErrorMessagePrivate * const d = d_func();-
160 if (!d->again->isChecked()
!d->again->isChecked()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
161 if (d->currentType.isEmpty()
d->currentType.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
162 if (!d->currentMessage.isEmpty()
!d->currentMessage.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
163 d->doNotShow.insert(d->currentMessage);
never executed: d->doNotShow.insert(d->currentMessage);
0
164 }
never executed: end of block
else {
0
165 d->doNotShowType.insert(d->currentType);-
166 }
never executed: end of block
0
167 }-
168 d->currentMessage.clear();-
169 d->currentType.clear();-
170 if (!d->nextPending()
!d->nextPending()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
171 QDialog::done(a);-
172 if (this == qtMessageHandler
this == qtMessageHandlerDescription
TRUEnever evaluated
FALSEnever evaluated
&& metFatal
metFatalDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
173 exit(1);
never executed: exit(1);
0
174 }
never executed: end of block
0
175}
never executed: end of block
0
176QErrorMessage * QErrorMessage::qtHandler()-
177{-
178 if (!qtMessageHandler
!qtMessageHandlerDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
179 qtMessageHandler = new QErrorMessage(0);-
180 qAddPostRoutine(deleteStaticcQErrorMessage);-
181 qtMessageHandler->setWindowTitle(QApplication::applicationName());-
182 qInstallMessageHandler(jump);-
183 }
never executed: end of block
0
184 return
never executed: return qtMessageHandler;
qtMessageHandler;
never executed: return qtMessageHandler;
0
185}-
186-
187-
188-
189-
190bool QErrorMessagePrivate::isMessageToBeShown(const QString &message, const QString &type) const-
191{-
192 return
never executed: return !message.isEmpty() && (type.isEmpty() ? !doNotShow.contains(message) : !doNotShowType.contains(type));
!message.isEmpty()
never executed: return !message.isEmpty() && (type.isEmpty() ? !doNotShow.contains(message) : !doNotShowType.contains(type));
0
193 && (type.isEmpty() ? !doNotShow.contains(message) : !doNotShowType.contains(type));
never executed: return !message.isEmpty() && (type.isEmpty() ? !doNotShow.contains(message) : !doNotShowType.contains(type));
0
194}-
195-
196bool QErrorMessagePrivate::nextPending()-
197{-
198 while (!pending.empty()
!pending.empty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
199 QPair<QString,QString> &pendingMessage = pending.front();-
200 QString message = std::move(pendingMessage.first);-
201 QString type = std::move(pendingMessage.second);-
202 pending.pop();-
203 if (isMessageToBeShown(message, type)
isMessageToBeS...message, type)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
204-
205 errors->setHtml(message);-
206-
207-
208-
209 currentMessage = std::move(message);-
210 currentType = std::move(type);-
211 return
never executed: return true;
true;
never executed: return true;
0
212 }-
213 }
never executed: end of block
0
214 return
never executed: return false;
false;
never executed: return false;
0
215}-
216void QErrorMessage::showMessage(const QString &message)-
217{-
218 showMessage(message, QString());-
219}
never executed: end of block
0
220void QErrorMessage::showMessage(const QString &message, const QString &type)-
221{-
222 QErrorMessagePrivate * const d = d_func();-
223 if (!d->isMessageToBeShown(message, type)
!d->isMessageT...message, type)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
224 return;
never executed: return;
0
225 d->pending.push(qMakePair(message, type));-
226 if (!isVisible()
!isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
&& d->nextPending()
d->nextPending()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
227 show();
never executed: show();
0
228}
never executed: end of block
0
229-
230-
231-
232-
233void QErrorMessage::changeEvent(QEvent *e)-
234{-
235 QErrorMessagePrivate * const d = d_func();-
236 if (e->type() == QEvent::LanguageChange
e->type() == Q...LanguageChangeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
237 d->retranslateStrings();-
238 }
never executed: end of block
0
239 QDialog::changeEvent(e);-
240}
never executed: end of block
0
241-
242void QErrorMessagePrivate::retranslateStrings()-
243{-
244 again->setText(QErrorMessage::tr("&Show this message again"));-
245 ok->setText(QErrorMessage::tr("&OK"));-
246}
never executed: end of block
0
247-
248-
249-
Switch to Source codePreprocessed file

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