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