| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/util/qvalidator.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | class QValidatorPrivate : public QObjectPrivate{ | - | ||||||||||||||||||
| 7 | inline QValidator* q_func() { return static_cast<QValidator *>(q_ptr); } inline const QValidator* q_func() const { return static_cast<const QValidator *>(q_ptr); } friend class QValidator; | - | ||||||||||||||||||
| 8 | public: | - | ||||||||||||||||||
| 9 | QValidatorPrivate() : QObjectPrivate() | - | ||||||||||||||||||
| 10 | { | - | ||||||||||||||||||
| 11 | } never executed: end of block | 0 | ||||||||||||||||||
| 12 | - | |||||||||||||||||||
| 13 | QLocale locale; | - | ||||||||||||||||||
| 14 | }; | - | ||||||||||||||||||
| 15 | - | |||||||||||||||||||
| 16 | - | |||||||||||||||||||
| 17 | - | |||||||||||||||||||
| 18 | - | |||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | - | |||||||||||||||||||
| 22 | QValidator::QValidator(QObject * parent) | - | ||||||||||||||||||
| 23 | : QObject(*new QValidatorPrivate, parent) | - | ||||||||||||||||||
| 24 | { | - | ||||||||||||||||||
| 25 | } never executed: end of block | 0 | ||||||||||||||||||
| 26 | - | |||||||||||||||||||
| 27 | - | |||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | - | |||||||||||||||||||
| 30 | - | |||||||||||||||||||
| 31 | - | |||||||||||||||||||
| 32 | QValidator::~QValidator() | - | ||||||||||||||||||
| 33 | { | - | ||||||||||||||||||
| 34 | } | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | - | |||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | - | |||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | - | |||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | QLocale QValidator::locale() const | - | ||||||||||||||||||
| 43 | { | - | ||||||||||||||||||
| 44 | const QValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 45 | return never executed: d->locale;return d->locale;never executed: return d->locale; | 0 | ||||||||||||||||||
| 46 | } | - | ||||||||||||||||||
| 47 | void QValidator::setLocale(const QLocale &locale) | - | ||||||||||||||||||
| 48 | { | - | ||||||||||||||||||
| 49 | QValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 50 | if (d->locale != locale
| 0 | ||||||||||||||||||
| 51 | d->locale = locale; | - | ||||||||||||||||||
| 52 | changed(); | - | ||||||||||||||||||
| 53 | } never executed: end of block | 0 | ||||||||||||||||||
| 54 | } never executed: end of block | 0 | ||||||||||||||||||
| 55 | void QValidator::fixup(QString &) const | - | ||||||||||||||||||
| 56 | { | - | ||||||||||||||||||
| 57 | } | - | ||||||||||||||||||
| 58 | QIntValidator::QIntValidator(QObject * parent) | - | ||||||||||||||||||
| 59 | : QValidator(parent) | - | ||||||||||||||||||
| 60 | { | - | ||||||||||||||||||
| 61 | b = (-2147483647 - 1); | - | ||||||||||||||||||
| 62 | t = 2147483647; | - | ||||||||||||||||||
| 63 | } never executed: end of block | 0 | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | - | |||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | QIntValidator::QIntValidator(int minimum, int maximum, | - | ||||||||||||||||||
| 72 | QObject * parent) | - | ||||||||||||||||||
| 73 | : QValidator(parent) | - | ||||||||||||||||||
| 74 | { | - | ||||||||||||||||||
| 75 | b = minimum; | - | ||||||||||||||||||
| 76 | t = maximum; | - | ||||||||||||||||||
| 77 | } never executed: end of block | 0 | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | - | |||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | QIntValidator::~QIntValidator() | - | ||||||||||||||||||
| 85 | { | - | ||||||||||||||||||
| 86 | - | |||||||||||||||||||
| 87 | } | - | ||||||||||||||||||
| 88 | static int numDigits(qlonglong n) | - | ||||||||||||||||||
| 89 | { | - | ||||||||||||||||||
| 90 | if (n == 0
| 0 | ||||||||||||||||||
| 91 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||||||||||||||
| 92 | return never executed: (int)std::log10(double(n)) + 1;return (int)std::log10(double(n)) + 1;never executed: return (int)std::log10(double(n)) + 1; | 0 | ||||||||||||||||||
| 93 | } | - | ||||||||||||||||||
| 94 | - | |||||||||||||||||||
| 95 | static qlonglong pow10(int exp) | - | ||||||||||||||||||
| 96 | { | - | ||||||||||||||||||
| 97 | qlonglong result = 1; | - | ||||||||||||||||||
| 98 | for (int i = 0; i < exp
| 0 | ||||||||||||||||||
| 99 | result *= 10; never executed: result *= 10; | 0 | ||||||||||||||||||
| 100 | return never executed: result;return result;never executed: return result; | 0 | ||||||||||||||||||
| 101 | } | - | ||||||||||||||||||
| 102 | - | |||||||||||||||||||
| 103 | QValidator::State QIntValidator::validate(QString & input, int&) const | - | ||||||||||||||||||
| 104 | { | - | ||||||||||||||||||
| 105 | QByteArray buff; | - | ||||||||||||||||||
| 106 | if (!locale().d->m_data->validateChars(input, QLocaleData::IntegerMode, &buff,
| 0 | ||||||||||||||||||
| 107 | -1, locale().numberOptions() & QLocale::RejectGroupSeparator)
| 0 | ||||||||||||||||||
| 108 | return never executed: Invalid;return Invalid;never executed: return Invalid; | 0 | ||||||||||||||||||
| 109 | } | - | ||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | if (buff.isEmpty()
| 0 | ||||||||||||||||||
| 112 | return never executed: Intermediate;return Intermediate;never executed: return Intermediate; | 0 | ||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | if (b >= 0
| 0 | ||||||||||||||||||
| 115 | return never executed: Invalid;return Invalid;never executed: return Invalid; | 0 | ||||||||||||||||||
| 116 | - | |||||||||||||||||||
| 117 | if (t < 0
| 0 | ||||||||||||||||||
| 118 | return never executed: Invalid;return Invalid;never executed: return Invalid; | 0 | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | if (buff.size() == 1
| 0 | ||||||||||||||||||
| 121 | return never executed: Intermediate;return Intermediate;never executed: return Intermediate; | 0 | ||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | bool ok, overflow; | - | ||||||||||||||||||
| 124 | qlonglong entered = QLocaleData::bytearrayToLongLong(buff.constData(), 10, &ok, &overflow); | - | ||||||||||||||||||
| 125 | if (overflow
| 0 | ||||||||||||||||||
| 126 | return never executed: Invalid;return Invalid;never executed: return Invalid; | 0 | ||||||||||||||||||
| 127 | - | |||||||||||||||||||
| 128 | if (entered >= b
| 0 | ||||||||||||||||||
| 129 | locale().toInt(input, &ok); | - | ||||||||||||||||||
| 130 | return never executed: okreturn ok ? Acceptable : Intermediate;
never executed: return ok ? Acceptable : Intermediate; | 0 | ||||||||||||||||||
| 131 | } | - | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | if (entered >= 0
| 0 | ||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | return never executed: (entered > treturn (entered > t && -entered < b) ? Invalid : Intermediate;
never executed: return (entered > t && -entered < b) ? Invalid : Intermediate; | 0 | ||||||||||||||||||
| 137 | } else { | - | ||||||||||||||||||
| 138 | return never executed: (return (entered < b) ? Invalid : Intermediate;
never executed: return (entered < b) ? Invalid : Intermediate; | 0 | ||||||||||||||||||
| 139 | } | - | ||||||||||||||||||
| 140 | } | - | ||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | - | |||||||||||||||||||
| 143 | void QIntValidator::fixup(QString &input) const | - | ||||||||||||||||||
| 144 | { | - | ||||||||||||||||||
| 145 | QByteArray buff; | - | ||||||||||||||||||
| 146 | if (!locale().d->m_data->validateChars(input, QLocaleData::IntegerMode, &buff,
| 0 | ||||||||||||||||||
| 147 | -1, locale().numberOptions() & QLocale::RejectGroupSeparator)
| 0 | ||||||||||||||||||
| 148 | return; never executed: return; | 0 | ||||||||||||||||||
| 149 | } | - | ||||||||||||||||||
| 150 | bool ok, overflow; | - | ||||||||||||||||||
| 151 | qlonglong entered = QLocaleData::bytearrayToLongLong(buff.constData(), 10, &ok, &overflow); | - | ||||||||||||||||||
| 152 | if (ok
| 0 | ||||||||||||||||||
| 153 | input = locale().toString(entered); never executed: input = locale().toString(entered); | 0 | ||||||||||||||||||
| 154 | } never executed: end of block | 0 | ||||||||||||||||||
| 155 | void QIntValidator::setRange(int bottom, int top) | - | ||||||||||||||||||
| 156 | { | - | ||||||||||||||||||
| 157 | bool rangeChanged = false; | - | ||||||||||||||||||
| 158 | if (b != bottom
| 0 | ||||||||||||||||||
| 159 | b = bottom; | - | ||||||||||||||||||
| 160 | rangeChanged = true; | - | ||||||||||||||||||
| 161 | bottomChanged(b); | - | ||||||||||||||||||
| 162 | } never executed: end of block | 0 | ||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | if (t != top
| 0 | ||||||||||||||||||
| 165 | t = top; | - | ||||||||||||||||||
| 166 | rangeChanged = true; | - | ||||||||||||||||||
| 167 | topChanged(t); | - | ||||||||||||||||||
| 168 | } never executed: end of block | 0 | ||||||||||||||||||
| 169 | - | |||||||||||||||||||
| 170 | if (rangeChanged
| 0 | ||||||||||||||||||
| 171 | changed(); never executed: changed(); | 0 | ||||||||||||||||||
| 172 | } never executed: end of block | 0 | ||||||||||||||||||
| 173 | void QIntValidator::setBottom(int bottom) | - | ||||||||||||||||||
| 174 | { | - | ||||||||||||||||||
| 175 | setRange(bottom, top()); | - | ||||||||||||||||||
| 176 | } never executed: end of block | 0 | ||||||||||||||||||
| 177 | void QIntValidator::setTop(int top) | - | ||||||||||||||||||
| 178 | { | - | ||||||||||||||||||
| 179 | setRange(bottom(), top); | - | ||||||||||||||||||
| 180 | } never executed: end of block | 0 | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | - | |||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | QValidator::QValidator(QObjectPrivate &d, QObject *parent) | - | ||||||||||||||||||
| 186 | : QObject(d, parent) | - | ||||||||||||||||||
| 187 | { | - | ||||||||||||||||||
| 188 | } never executed: end of block | 0 | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | QValidator::QValidator(QValidatorPrivate &d, QObject *parent) | - | ||||||||||||||||||
| 194 | : QObject(d, parent) | - | ||||||||||||||||||
| 195 | { | - | ||||||||||||||||||
| 196 | } never executed: end of block | 0 | ||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | - | |||||||||||||||||||
| 200 | class QDoubleValidatorPrivate : public QValidatorPrivate | - | ||||||||||||||||||
| 201 | { | - | ||||||||||||||||||
| 202 | inline QDoubleValidator* q_func() { return static_cast<QDoubleValidator *>(q_ptr); } inline const QDoubleValidator* q_func() const { return static_cast<const QDoubleValidator *>(q_ptr); } friend class QDoubleValidator; | - | ||||||||||||||||||
| 203 | public: | - | ||||||||||||||||||
| 204 | QDoubleValidatorPrivate() | - | ||||||||||||||||||
| 205 | : QValidatorPrivate() | - | ||||||||||||||||||
| 206 | , notation(QDoubleValidator::ScientificNotation) | - | ||||||||||||||||||
| 207 | { | - | ||||||||||||||||||
| 208 | } never executed: end of block | 0 | ||||||||||||||||||
| 209 | - | |||||||||||||||||||
| 210 | QDoubleValidator::Notation notation; | - | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | QValidator::State validateWithLocale(QString & input, QLocaleData::NumberMode numMode, const QLocale &locale) const; | - | ||||||||||||||||||
| 213 | }; | - | ||||||||||||||||||
| 214 | QDoubleValidator::QDoubleValidator(QObject * parent) | - | ||||||||||||||||||
| 215 | : QValidator(*new QDoubleValidatorPrivate , parent) | - | ||||||||||||||||||
| 216 | { | - | ||||||||||||||||||
| 217 | b = -(__builtin_huge_val()); | - | ||||||||||||||||||
| 218 | t = (__builtin_huge_val()); | - | ||||||||||||||||||
| 219 | dec = 1000; | - | ||||||||||||||||||
| 220 | } never executed: end of block | 0 | ||||||||||||||||||
| 221 | QDoubleValidator::QDoubleValidator(double bottom, double top, int decimals, | - | ||||||||||||||||||
| 222 | QObject * parent) | - | ||||||||||||||||||
| 223 | : QValidator(*new QDoubleValidatorPrivate , parent) | - | ||||||||||||||||||
| 224 | { | - | ||||||||||||||||||
| 225 | b = bottom; | - | ||||||||||||||||||
| 226 | t = top; | - | ||||||||||||||||||
| 227 | dec = decimals; | - | ||||||||||||||||||
| 228 | } never executed: end of block | 0 | ||||||||||||||||||
| 229 | - | |||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | QDoubleValidator::~QDoubleValidator() | - | ||||||||||||||||||
| 236 | { | - | ||||||||||||||||||
| 237 | } | - | ||||||||||||||||||
| 238 | QValidator::State QDoubleValidator::validate(QString & input, int &) const | - | ||||||||||||||||||
| 239 | { | - | ||||||||||||||||||
| 240 | const QDoubleValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 241 | - | |||||||||||||||||||
| 242 | QLocaleData::NumberMode numMode = QLocaleData::DoubleStandardMode; | - | ||||||||||||||||||
| 243 | switch (d->notation) { | - | ||||||||||||||||||
| 244 | case never executed: StandardNotation:case StandardNotation:never executed: case StandardNotation: | 0 | ||||||||||||||||||
| 245 | numMode = QLocaleData::DoubleStandardMode; | - | ||||||||||||||||||
| 246 | break; never executed: break; | 0 | ||||||||||||||||||
| 247 | case never executed: ScientificNotation:case ScientificNotation:never executed: case ScientificNotation: | 0 | ||||||||||||||||||
| 248 | numMode = QLocaleData::DoubleScientificMode; | - | ||||||||||||||||||
| 249 | break; never executed: break; | 0 | ||||||||||||||||||
| 250 | } | - | ||||||||||||||||||
| 251 | - | |||||||||||||||||||
| 252 | return never executed: d->validateWithLocale(input, numMode, locale());return d->validateWithLocale(input, numMode, locale());never executed: return d->validateWithLocale(input, numMode, locale()); | 0 | ||||||||||||||||||
| 253 | } | - | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | QValidator::State QDoubleValidatorPrivate::validateWithLocale(QString &input, QLocaleData::NumberMode numMode, const QLocale &locale) const | - | ||||||||||||||||||
| 256 | { | - | ||||||||||||||||||
| 257 | const QDoubleValidator * const q = q_func(); | - | ||||||||||||||||||
| 258 | QByteArray buff; | - | ||||||||||||||||||
| 259 | if (!locale.d->m_data->validateChars(input, numMode, &buff, q->dec,
| 0 | ||||||||||||||||||
| 260 | locale.numberOptions() & QLocale::RejectGroupSeparator)
| 0 | ||||||||||||||||||
| 261 | return never executed: QValidator::Invalid;return QValidator::Invalid;never executed: return QValidator::Invalid; | 0 | ||||||||||||||||||
| 262 | } | - | ||||||||||||||||||
| 263 | - | |||||||||||||||||||
| 264 | if (buff.isEmpty()
| 0 | ||||||||||||||||||
| 265 | return never executed: QValidator::Intermediate;return QValidator::Intermediate;never executed: return QValidator::Intermediate; | 0 | ||||||||||||||||||
| 266 | - | |||||||||||||||||||
| 267 | if (q->b >= 0
| 0 | ||||||||||||||||||
| 268 | return never executed: QValidator::Invalid;return QValidator::Invalid;never executed: return QValidator::Invalid; | 0 | ||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | if (q->t < 0
| 0 | ||||||||||||||||||
| 271 | return never executed: QValidator::Invalid;return QValidator::Invalid;never executed: return QValidator::Invalid; | 0 | ||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | bool ok, overflow; | - | ||||||||||||||||||
| 274 | double i = QLocaleData::bytearrayToDouble(buff.constData(), &ok, &overflow); | - | ||||||||||||||||||
| 275 | if (overflow
| 0 | ||||||||||||||||||
| 276 | return never executed: QValidator::Invalid;return QValidator::Invalid;never executed: return QValidator::Invalid; | 0 | ||||||||||||||||||
| 277 | if (!ok
| 0 | ||||||||||||||||||
| 278 | return never executed: QValidator::Intermediate;return QValidator::Intermediate;never executed: return QValidator::Intermediate; | 0 | ||||||||||||||||||
| 279 | - | |||||||||||||||||||
| 280 | if (i >= q->b
| 0 | ||||||||||||||||||
| 281 | return never executed: QValidator::Acceptable;return QValidator::Acceptable;never executed: return QValidator::Acceptable; | 0 | ||||||||||||||||||
| 282 | - | |||||||||||||||||||
| 283 | if (notation == QDoubleValidator::StandardNotation
| 0 | ||||||||||||||||||
| 284 | double max = qMax(qAbs(q->b), qAbs(q->t)); | - | ||||||||||||||||||
| 285 | if (max < 9223372036854775807LL
| 0 | ||||||||||||||||||
| 286 | qlonglong n = pow10(numDigits(qlonglong(max))) - 1; | - | ||||||||||||||||||
| 287 | if (qAbs(i) > n
| 0 | ||||||||||||||||||
| 288 | return never executed: QValidator::Invalid;return QValidator::Invalid;never executed: return QValidator::Invalid; | 0 | ||||||||||||||||||
| 289 | } never executed: end of block | 0 | ||||||||||||||||||
| 290 | } never executed: end of block | 0 | ||||||||||||||||||
| 291 | - | |||||||||||||||||||
| 292 | return never executed: QValidator::Intermediate;return QValidator::Intermediate;never executed: return QValidator::Intermediate; | 0 | ||||||||||||||||||
| 293 | } | - | ||||||||||||||||||
| 294 | void QDoubleValidator::setRange(double minimum, double maximum, int decimals) | - | ||||||||||||||||||
| 295 | { | - | ||||||||||||||||||
| 296 | bool rangeChanged = false; | - | ||||||||||||||||||
| 297 | if (b != minimum
| 0 | ||||||||||||||||||
| 298 | b = minimum; | - | ||||||||||||||||||
| 299 | rangeChanged = true; | - | ||||||||||||||||||
| 300 | bottomChanged(b); | - | ||||||||||||||||||
| 301 | } never executed: end of block | 0 | ||||||||||||||||||
| 302 | - | |||||||||||||||||||
| 303 | if (t != maximum
| 0 | ||||||||||||||||||
| 304 | t = maximum; | - | ||||||||||||||||||
| 305 | rangeChanged = true; | - | ||||||||||||||||||
| 306 | topChanged(t); | - | ||||||||||||||||||
| 307 | } never executed: end of block | 0 | ||||||||||||||||||
| 308 | - | |||||||||||||||||||
| 309 | if (dec != decimals
| 0 | ||||||||||||||||||
| 310 | dec = decimals; | - | ||||||||||||||||||
| 311 | rangeChanged = true; | - | ||||||||||||||||||
| 312 | decimalsChanged(dec); | - | ||||||||||||||||||
| 313 | } never executed: end of block | 0 | ||||||||||||||||||
| 314 | if (rangeChanged
| 0 | ||||||||||||||||||
| 315 | changed(); never executed: changed(); | 0 | ||||||||||||||||||
| 316 | } never executed: end of block | 0 | ||||||||||||||||||
| 317 | void QDoubleValidator::setBottom(double bottom) | - | ||||||||||||||||||
| 318 | { | - | ||||||||||||||||||
| 319 | setRange(bottom, top(), decimals()); | - | ||||||||||||||||||
| 320 | } never executed: end of block | 0 | ||||||||||||||||||
| 321 | void QDoubleValidator::setTop(double top) | - | ||||||||||||||||||
| 322 | { | - | ||||||||||||||||||
| 323 | setRange(bottom(), top, decimals()); | - | ||||||||||||||||||
| 324 | } never executed: end of block | 0 | ||||||||||||||||||
| 325 | void QDoubleValidator::setDecimals(int decimals) | - | ||||||||||||||||||
| 326 | { | - | ||||||||||||||||||
| 327 | setRange(bottom(), top(), decimals); | - | ||||||||||||||||||
| 328 | } never executed: end of block | 0 | ||||||||||||||||||
| 329 | void QDoubleValidator::setNotation(Notation newNotation) | - | ||||||||||||||||||
| 330 | { | - | ||||||||||||||||||
| 331 | QDoubleValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 332 | if (d->notation != newNotation
| 0 | ||||||||||||||||||
| 333 | d->notation = newNotation; | - | ||||||||||||||||||
| 334 | notationChanged(d->notation); | - | ||||||||||||||||||
| 335 | changed(); | - | ||||||||||||||||||
| 336 | } never executed: end of block | 0 | ||||||||||||||||||
| 337 | } never executed: end of block | 0 | ||||||||||||||||||
| 338 | - | |||||||||||||||||||
| 339 | QDoubleValidator::Notation QDoubleValidator::notation() const | - | ||||||||||||||||||
| 340 | { | - | ||||||||||||||||||
| 341 | const QDoubleValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 342 | return never executed: d->notation;return d->notation;never executed: return d->notation; | 0 | ||||||||||||||||||
| 343 | } | - | ||||||||||||||||||
| 344 | QRegExpValidator::QRegExpValidator(QObject *parent) | - | ||||||||||||||||||
| 345 | : QValidator(parent), r(QString::fromLatin1(".*")) | - | ||||||||||||||||||
| 346 | { | - | ||||||||||||||||||
| 347 | } never executed: end of block | 0 | ||||||||||||||||||
| 348 | QRegExpValidator::QRegExpValidator(const QRegExp& rx, QObject *parent) | - | ||||||||||||||||||
| 349 | : QValidator(parent), r(rx) | - | ||||||||||||||||||
| 350 | { | - | ||||||||||||||||||
| 351 | } never executed: end of block | 0 | ||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | - | |||||||||||||||||||
| 354 | - | |||||||||||||||||||
| 355 | - | |||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | - | |||||||||||||||||||
| 358 | QRegExpValidator::~QRegExpValidator() | - | ||||||||||||||||||
| 359 | { | - | ||||||||||||||||||
| 360 | } | - | ||||||||||||||||||
| 361 | QValidator::State QRegExpValidator::validate(QString &input, int& pos) const | - | ||||||||||||||||||
| 362 | { | - | ||||||||||||||||||
| 363 | QRegExp copy = r; | - | ||||||||||||||||||
| 364 | if (copy.exactMatch(input)
| 0 | ||||||||||||||||||
| 365 | return never executed: Acceptable;return Acceptable;never executed: return Acceptable; | 0 | ||||||||||||||||||
| 366 | } else { | - | ||||||||||||||||||
| 367 | if (copy.matchedLength() == input.size()
| 0 | ||||||||||||||||||
| 368 | return never executed: Intermediate;return Intermediate;never executed: return Intermediate; | 0 | ||||||||||||||||||
| 369 | } else { | - | ||||||||||||||||||
| 370 | pos = input.size(); | - | ||||||||||||||||||
| 371 | return never executed: Invalid;return Invalid;never executed: return Invalid; | 0 | ||||||||||||||||||
| 372 | } | - | ||||||||||||||||||
| 373 | } | - | ||||||||||||||||||
| 374 | } | - | ||||||||||||||||||
| 375 | void QRegExpValidator::setRegExp(const QRegExp& rx) | - | ||||||||||||||||||
| 376 | { | - | ||||||||||||||||||
| 377 | if (r != rx
| 0 | ||||||||||||||||||
| 378 | r = rx; | - | ||||||||||||||||||
| 379 | regExpChanged(r); | - | ||||||||||||||||||
| 380 | changed(); | - | ||||||||||||||||||
| 381 | } never executed: end of block | 0 | ||||||||||||||||||
| 382 | } never executed: end of block | 0 | ||||||||||||||||||
| 383 | class QRegularExpressionValidatorPrivate : public QValidatorPrivate | - | ||||||||||||||||||
| 384 | { | - | ||||||||||||||||||
| 385 | inline QRegularExpressionValidator* q_func() { return static_cast<QRegularExpressionValidator *>(q_ptr); } inline const QRegularExpressionValidator* q_func() const { return static_cast<const QRegularExpressionValidator *>(q_ptr); } friend class QRegularExpressionValidator; | - | ||||||||||||||||||
| 386 | - | |||||||||||||||||||
| 387 | public: | - | ||||||||||||||||||
| 388 | QRegularExpression origRe; | - | ||||||||||||||||||
| 389 | QRegularExpression usedRe; | - | ||||||||||||||||||
| 390 | void setRegularExpression(const QRegularExpression &re); | - | ||||||||||||||||||
| 391 | }; | - | ||||||||||||||||||
| 392 | - | |||||||||||||||||||
| 393 | - | |||||||||||||||||||
| 394 | - | |||||||||||||||||||
| 395 | - | |||||||||||||||||||
| 396 | - | |||||||||||||||||||
| 397 | - | |||||||||||||||||||
| 398 | QRegularExpressionValidator::QRegularExpressionValidator(QObject *parent) | - | ||||||||||||||||||
| 399 | : QValidator(*new QRegularExpressionValidatorPrivate, parent) | - | ||||||||||||||||||
| 400 | { | - | ||||||||||||||||||
| 401 | - | |||||||||||||||||||
| 402 | - | |||||||||||||||||||
| 403 | } never executed: end of block | 0 | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | - | |||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | - | |||||||||||||||||||
| 410 | QRegularExpressionValidator::QRegularExpressionValidator(const QRegularExpression &re, QObject *parent) | - | ||||||||||||||||||
| 411 | : QValidator(*new QRegularExpressionValidatorPrivate, parent) | - | ||||||||||||||||||
| 412 | { | - | ||||||||||||||||||
| 413 | QRegularExpressionValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 414 | d->setRegularExpression(re); | - | ||||||||||||||||||
| 415 | } never executed: end of block | 0 | ||||||||||||||||||
| 416 | - | |||||||||||||||||||
| 417 | - | |||||||||||||||||||
| 418 | - | |||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | - | |||||||||||||||||||
| 421 | - | |||||||||||||||||||
| 422 | QRegularExpressionValidator::~QRegularExpressionValidator() | - | ||||||||||||||||||
| 423 | { | - | ||||||||||||||||||
| 424 | } | - | ||||||||||||||||||
| 425 | QValidator::State QRegularExpressionValidator::validate(QString &input, int &pos) const | - | ||||||||||||||||||
| 426 | { | - | ||||||||||||||||||
| 427 | const QRegularExpressionValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 428 | - | |||||||||||||||||||
| 429 | - | |||||||||||||||||||
| 430 | - | |||||||||||||||||||
| 431 | - | |||||||||||||||||||
| 432 | if (d->origRe.pattern().isEmpty()
| 0 | ||||||||||||||||||
| 433 | return never executed: Acceptable;return Acceptable;never executed: return Acceptable; | 0 | ||||||||||||||||||
| 434 | - | |||||||||||||||||||
| 435 | const QRegularExpressionMatch m = d->usedRe.match(input, 0, QRegularExpression::PartialPreferCompleteMatch); | - | ||||||||||||||||||
| 436 | if (m.hasMatch()
| 0 | ||||||||||||||||||
| 437 | return never executed: Acceptable;return Acceptable;never executed: return Acceptable; | 0 | ||||||||||||||||||
| 438 | } else if (input.isEmpty()
| 0 | ||||||||||||||||||
| 439 | return never executed: Intermediate;return Intermediate;never executed: return Intermediate; | 0 | ||||||||||||||||||
| 440 | } else { | - | ||||||||||||||||||
| 441 | pos = input.size(); | - | ||||||||||||||||||
| 442 | return never executed: Invalid;return Invalid;never executed: return Invalid; | 0 | ||||||||||||||||||
| 443 | } | - | ||||||||||||||||||
| 444 | } | - | ||||||||||||||||||
| 445 | QRegularExpression QRegularExpressionValidator::regularExpression() const | - | ||||||||||||||||||
| 446 | { | - | ||||||||||||||||||
| 447 | const QRegularExpressionValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 448 | return never executed: d->origRe;return d->origRe;never executed: return d->origRe; | 0 | ||||||||||||||||||
| 449 | } | - | ||||||||||||||||||
| 450 | - | |||||||||||||||||||
| 451 | void QRegularExpressionValidator::setRegularExpression(const QRegularExpression &re) | - | ||||||||||||||||||
| 452 | { | - | ||||||||||||||||||
| 453 | QRegularExpressionValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 454 | d->setRegularExpression(re); | - | ||||||||||||||||||
| 455 | } never executed: end of block | 0 | ||||||||||||||||||
| 456 | - | |||||||||||||||||||
| 457 | - | |||||||||||||||||||
| 458 | - | |||||||||||||||||||
| 459 | - | |||||||||||||||||||
| 460 | - | |||||||||||||||||||
| 461 | - | |||||||||||||||||||
| 462 | - | |||||||||||||||||||
| 463 | void QRegularExpressionValidatorPrivate::setRegularExpression(const QRegularExpression &re) | - | ||||||||||||||||||
| 464 | { | - | ||||||||||||||||||
| 465 | QRegularExpressionValidator * const q = q_func(); | - | ||||||||||||||||||
| 466 | - | |||||||||||||||||||
| 467 | if (origRe != re
| 0 | ||||||||||||||||||
| 468 | usedRe = origRe = re; | - | ||||||||||||||||||
| 469 | usedRe.setPattern(([]() -> QString { enum { Size = sizeof(u"" "\\A(?:")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "\\A(?:" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return never executed: qstring_literal_temp;return qstring_literal_temp;never executed: }()) + re.pattern() + ([]() -> QString { enum { Size = sizeof(u"" ")\\z")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" ")\\z" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); returnreturn qstring_literal_temp;never executed: qstring_literal_temp;return qstring_literal_temp;never executed: }()));return qstring_literal_temp; | 0 | ||||||||||||||||||
| 470 | q->regularExpressionChanged(re); | - | ||||||||||||||||||
| 471 | q->changed(); | - | ||||||||||||||||||
| 472 | } never executed: end of block | 0 | ||||||||||||||||||
| 473 | } never executed: end of block | 0 | ||||||||||||||||||
| 474 | - | |||||||||||||||||||
| 475 | - | |||||||||||||||||||
| 476 | - | |||||||||||||||||||
| 477 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |