| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qerrormessage.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | class 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; | - | ||||||||||||
| 10 | public: | - | ||||||||||||
| 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 | - | |||||||||||||
| 26 | namespace { | - | ||||||||||||
| 27 | class QErrorMessageTextView : public QTextEdit | - | ||||||||||||
| 28 | { | - | ||||||||||||
| 29 | public: | - | ||||||||||||
| 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 | - | |||||||||||||
| 38 | QSize QErrorMessageTextView::minimumSizeHint() const | - | ||||||||||||
| 39 | { | - | ||||||||||||
| 40 | return never executed: QSize(50, 50);return QSize(50, 50);never executed: return QSize(50, 50); | 0 | ||||||||||||
| 41 | - | |||||||||||||
| 42 | } | - | ||||||||||||
| 43 | - | |||||||||||||
| 44 | QSize QErrorMessageTextView::sizeHint() const | - | ||||||||||||
| 45 | { | - | ||||||||||||
| 46 | return never executed: QSize(250, 75);return QSize(250, 75);never executed: return QSize(250, 75); | 0 | ||||||||||||
| 47 | - | |||||||||||||
| 48 | } | - | ||||||||||||
| 49 | static QErrorMessage * qtMessageHandler = 0; | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | static void deleteStaticcQErrorMessage() | - | ||||||||||||
| 52 | { | - | ||||||||||||
| 53 | if (qtMessageHandler
| 0 | ||||||||||||
| 54 | delete qtMessageHandler; | - | ||||||||||||
| 55 | qtMessageHandler = 0; | - | ||||||||||||
| 56 | } never executed: end of block | 0 | ||||||||||||
| 57 | } never executed: end of block | 0 | ||||||||||||
| 58 | - | |||||||||||||
| 59 | static bool metFatal = false; | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | static void jump(QtMsgType t, const QMessageLogContext & , const QString &m) | - | ||||||||||||
| 62 | { | - | ||||||||||||
| 63 | if (!qtMessageHandler
| 0 | ||||||||||||
| 64 | return; never executed: return; | 0 | ||||||||||||
| 65 | - | |||||||||||||
| 66 | QString rich; | - | ||||||||||||
| 67 | - | |||||||||||||
| 68 | switch (t) { | - | ||||||||||||
| 69 | case never executed: QtDebugMsg:case 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: QtWarningMsg:case QtWarningMsg:never executed: case QtWarningMsg: | 0 | ||||||||||||
| 74 | rich = QErrorMessage::tr("Warning:"); | - | ||||||||||||
| 75 | break; never executed: break; | 0 | ||||||||||||
| 76 | case never executed: QtFatalMsg:case 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>"))
| 0 | ||||||||||||
| 84 | rich.chop(4); never executed: rich.chop(4); | 0 | ||||||||||||
| 85 | - | |||||||||||||
| 86 | if (!metFatal
| 0 | ||||||||||||
| 87 | if (QThread::currentThread() == (static_cast<QApplication *>(QCoreApplication::instance()))->thread()
| 0 | ||||||||||||
| 88 | qtMessageHandler->showMessage(rich); | - | ||||||||||||
| 89 | } never executed: else {end of block | 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 | - | |||||||||||||
| 105 | QErrorMessage::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 | - | |||||||||||||
| 143 | QErrorMessage::~QErrorMessage() | - | ||||||||||||
| 144 | { | - | ||||||||||||
| 145 | if (this == qtMessageHandler
| 0 | ||||||||||||
| 146 | qtMessageHandler = 0; | - | ||||||||||||
| 147 | QtMessageHandler tmp = qInstallMessageHandler(0); | - | ||||||||||||
| 148 | - | |||||||||||||
| 149 | if (tmp != jump
| 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 | - | |||||||||||||
| 157 | void QErrorMessage::done(int a) | - | ||||||||||||
| 158 | { | - | ||||||||||||
| 159 | QErrorMessagePrivate * const d = d_func(); | - | ||||||||||||
| 160 | if (!d->again->isChecked()
| 0 | ||||||||||||
| 161 | if (d->currentType.isEmpty()
| 0 | ||||||||||||
| 162 | if (!d->currentMessage.isEmpty()
| 0 | ||||||||||||
| 163 | d->doNotShow.insert(d->currentMessage); never executed: d->doNotShow.insert(d->currentMessage); | 0 | ||||||||||||
| 164 | } never executed: else {end of block | 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()
| 0 | ||||||||||||
| 171 | QDialog::done(a); | - | ||||||||||||
| 172 | if (this == qtMessageHandler
| 0 | ||||||||||||
| 173 | exit(1); never executed: exit(1); | 0 | ||||||||||||
| 174 | } never executed: end of block | 0 | ||||||||||||
| 175 | } never executed: end of block | 0 | ||||||||||||
| 176 | QErrorMessage * QErrorMessage::qtHandler() | - | ||||||||||||
| 177 | { | - | ||||||||||||
| 178 | if (!qtMessageHandler
| 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: qtMessageHandler;return qtMessageHandler;never executed: return qtMessageHandler; | 0 | ||||||||||||
| 185 | } | - | ||||||||||||
| 186 | - | |||||||||||||
| 187 | - | |||||||||||||
| 188 | - | |||||||||||||
| 189 | - | |||||||||||||
| 190 | bool QErrorMessagePrivate::isMessageToBeShown(const QString &message, const QString &type) const | - | ||||||||||||
| 191 | { | - | ||||||||||||
| 192 | return never executed: !message.isEmpty()return !message.isEmpty() && (type.isEmpty() ? !doNotShow.contains(message) : !doNotShowType.contains(type));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 | - | |||||||||||||
| 196 | bool QErrorMessagePrivate::nextPending() | - | ||||||||||||
| 197 | { | - | ||||||||||||
| 198 | while (!pending.empty()
| 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)
| 0 | ||||||||||||
| 204 | - | |||||||||||||
| 205 | errors->setHtml(message); | - | ||||||||||||
| 206 | - | |||||||||||||
| 207 | - | |||||||||||||
| 208 | - | |||||||||||||
| 209 | currentMessage = std::move(message); | - | ||||||||||||
| 210 | currentType = std::move(type); | - | ||||||||||||
| 211 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 212 | } | - | ||||||||||||
| 213 | } never executed: end of block | 0 | ||||||||||||
| 214 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 215 | } | - | ||||||||||||
| 216 | void QErrorMessage::showMessage(const QString &message) | - | ||||||||||||
| 217 | { | - | ||||||||||||
| 218 | showMessage(message, QString()); | - | ||||||||||||
| 219 | } never executed: end of block | 0 | ||||||||||||
| 220 | void QErrorMessage::showMessage(const QString &message, const QString &type) | - | ||||||||||||
| 221 | { | - | ||||||||||||
| 222 | QErrorMessagePrivate * const d = d_func(); | - | ||||||||||||
| 223 | if (!d->isMessageToBeShown(message, type)
| 0 | ||||||||||||
| 224 | return; never executed: return; | 0 | ||||||||||||
| 225 | d->pending.push(qMakePair(message, type)); | - | ||||||||||||
| 226 | if (!isVisible()
| 0 | ||||||||||||
| 227 | show(); never executed: show(); | 0 | ||||||||||||
| 228 | } never executed: end of block | 0 | ||||||||||||
| 229 | - | |||||||||||||
| 230 | - | |||||||||||||
| 231 | - | |||||||||||||
| 232 | - | |||||||||||||
| 233 | void QErrorMessage::changeEvent(QEvent *e) | - | ||||||||||||
| 234 | { | - | ||||||||||||
| 235 | QErrorMessagePrivate * const d = d_func(); | - | ||||||||||||
| 236 | if (e->type() == QEvent::LanguageChange
| 0 | ||||||||||||
| 237 | d->retranslateStrings(); | - | ||||||||||||
| 238 | } never executed: end of block | 0 | ||||||||||||
| 239 | QDialog::changeEvent(e); | - | ||||||||||||
| 240 | } never executed: end of block | 0 | ||||||||||||
| 241 | - | |||||||||||||
| 242 | void 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 code | Preprocessed file |