| 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, -1,
| 0 | ||||||||||||||||||
| 107 | locale().numberOptions())
| 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: ok ? Acceptable : Intermediate;return ok ? Acceptable : Intermediate;never executed: return ok ? Acceptable : Intermediate; | 0 | ||||||||||||||||||
| 131 | } | - | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | if (entered >= 0
| 0 | ||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | return never executed: (entered > t && -entered < b) ? Invalid : Intermediate;return (entered > t && -entered < b) ? Invalid : Intermediate;never executed: return (entered > t && -entered < b) ? Invalid : Intermediate; | 0 | ||||||||||||||||||
| 137 | } else { | - | ||||||||||||||||||
| 138 | return never executed: (entered < b) ? Invalid : Intermediate;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, -1,
| 0 | ||||||||||||||||||
| 147 | locale().numberOptions())
| 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, locale.numberOptions())
| 0 | ||||||||||||||||||
| 260 | return never executed: QValidator::Invalid;return QValidator::Invalid;never executed: return QValidator::Invalid; | 0 | ||||||||||||||||||
| 261 | } | - | ||||||||||||||||||
| 262 | - | |||||||||||||||||||
| 263 | if (buff.isEmpty()
| 0 | ||||||||||||||||||
| 264 | return never executed: QValidator::Intermediate;return QValidator::Intermediate;never executed: return QValidator::Intermediate; | 0 | ||||||||||||||||||
| 265 | - | |||||||||||||||||||
| 266 | if (q->b >= 0
| 0 | ||||||||||||||||||
| 267 | return never executed: QValidator::Invalid;return QValidator::Invalid;never executed: return QValidator::Invalid; | 0 | ||||||||||||||||||
| 268 | - | |||||||||||||||||||
| 269 | if (q->t < 0
| 0 | ||||||||||||||||||
| 270 | return never executed: QValidator::Invalid;return QValidator::Invalid;never executed: return QValidator::Invalid; | 0 | ||||||||||||||||||
| 271 | - | |||||||||||||||||||
| 272 | bool ok = false; | - | ||||||||||||||||||
| 273 | double i = buff.toDouble(&ok); | - | ||||||||||||||||||
| 274 | if (i == qt_qnan()
| 0 | ||||||||||||||||||
| 275 | return never executed: QValidator::Invalid;return QValidator::Invalid;never executed: return QValidator::Invalid; | 0 | ||||||||||||||||||
| 276 | if (!ok
| 0 | ||||||||||||||||||
| 277 | return never executed: QValidator::Intermediate;return QValidator::Intermediate;never executed: return QValidator::Intermediate; | 0 | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | if (i >= q->b
| 0 | ||||||||||||||||||
| 280 | return never executed: QValidator::Acceptable;return QValidator::Acceptable;never executed: return QValidator::Acceptable; | 0 | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | if (notation == QDoubleValidator::StandardNotation
| 0 | ||||||||||||||||||
| 283 | double max = qMax(qAbs(q->b), qAbs(q->t)); | - | ||||||||||||||||||
| 284 | if (max < 9223372036854775807LL
| 0 | ||||||||||||||||||
| 285 | qlonglong n = pow10(numDigits(qlonglong(max))) - 1; | - | ||||||||||||||||||
| 286 | if (qAbs(i) > n
| 0 | ||||||||||||||||||
| 287 | return never executed: QValidator::Invalid;return QValidator::Invalid;never executed: return QValidator::Invalid; | 0 | ||||||||||||||||||
| 288 | } never executed: end of block | 0 | ||||||||||||||||||
| 289 | } never executed: end of block | 0 | ||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | return never executed: QValidator::Intermediate;return QValidator::Intermediate;never executed: return QValidator::Intermediate; | 0 | ||||||||||||||||||
| 292 | } | - | ||||||||||||||||||
| 293 | void QDoubleValidator::setRange(double minimum, double maximum, int decimals) | - | ||||||||||||||||||
| 294 | { | - | ||||||||||||||||||
| 295 | bool rangeChanged = false; | - | ||||||||||||||||||
| 296 | if (b != minimum
| 0 | ||||||||||||||||||
| 297 | b = minimum; | - | ||||||||||||||||||
| 298 | rangeChanged = true; | - | ||||||||||||||||||
| 299 | bottomChanged(b); | - | ||||||||||||||||||
| 300 | } never executed: end of block | 0 | ||||||||||||||||||
| 301 | - | |||||||||||||||||||
| 302 | if (t != maximum
| 0 | ||||||||||||||||||
| 303 | t = maximum; | - | ||||||||||||||||||
| 304 | rangeChanged = true; | - | ||||||||||||||||||
| 305 | topChanged(t); | - | ||||||||||||||||||
| 306 | } never executed: end of block | 0 | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | if (dec != decimals
| 0 | ||||||||||||||||||
| 309 | dec = decimals; | - | ||||||||||||||||||
| 310 | rangeChanged = true; | - | ||||||||||||||||||
| 311 | decimalsChanged(dec); | - | ||||||||||||||||||
| 312 | } never executed: end of block | 0 | ||||||||||||||||||
| 313 | if (rangeChanged
| 0 | ||||||||||||||||||
| 314 | changed(); never executed: changed(); | 0 | ||||||||||||||||||
| 315 | } never executed: end of block | 0 | ||||||||||||||||||
| 316 | void QDoubleValidator::setBottom(double bottom) | - | ||||||||||||||||||
| 317 | { | - | ||||||||||||||||||
| 318 | setRange(bottom, top(), decimals()); | - | ||||||||||||||||||
| 319 | } never executed: end of block | 0 | ||||||||||||||||||
| 320 | void QDoubleValidator::setTop(double top) | - | ||||||||||||||||||
| 321 | { | - | ||||||||||||||||||
| 322 | setRange(bottom(), top, decimals()); | - | ||||||||||||||||||
| 323 | } never executed: end of block | 0 | ||||||||||||||||||
| 324 | void QDoubleValidator::setDecimals(int decimals) | - | ||||||||||||||||||
| 325 | { | - | ||||||||||||||||||
| 326 | setRange(bottom(), top(), decimals); | - | ||||||||||||||||||
| 327 | } never executed: end of block | 0 | ||||||||||||||||||
| 328 | void QDoubleValidator::setNotation(Notation newNotation) | - | ||||||||||||||||||
| 329 | { | - | ||||||||||||||||||
| 330 | QDoubleValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 331 | if (d->notation != newNotation
| 0 | ||||||||||||||||||
| 332 | d->notation = newNotation; | - | ||||||||||||||||||
| 333 | notationChanged(d->notation); | - | ||||||||||||||||||
| 334 | changed(); | - | ||||||||||||||||||
| 335 | } never executed: end of block | 0 | ||||||||||||||||||
| 336 | } never executed: end of block | 0 | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | QDoubleValidator::Notation QDoubleValidator::notation() const | - | ||||||||||||||||||
| 339 | { | - | ||||||||||||||||||
| 340 | const QDoubleValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 341 | return never executed: d->notation;return d->notation;never executed: return d->notation; | 0 | ||||||||||||||||||
| 342 | } | - | ||||||||||||||||||
| 343 | QRegExpValidator::QRegExpValidator(QObject *parent) | - | ||||||||||||||||||
| 344 | : QValidator(parent), r(QString::fromLatin1(".*")) | - | ||||||||||||||||||
| 345 | { | - | ||||||||||||||||||
| 346 | } never executed: end of block | 0 | ||||||||||||||||||
| 347 | QRegExpValidator::QRegExpValidator(const QRegExp& rx, QObject *parent) | - | ||||||||||||||||||
| 348 | : QValidator(parent), r(rx) | - | ||||||||||||||||||
| 349 | { | - | ||||||||||||||||||
| 350 | } never executed: end of block | 0 | ||||||||||||||||||
| 351 | - | |||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | - | |||||||||||||||||||
| 354 | - | |||||||||||||||||||
| 355 | - | |||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | QRegExpValidator::~QRegExpValidator() | - | ||||||||||||||||||
| 358 | { | - | ||||||||||||||||||
| 359 | } | - | ||||||||||||||||||
| 360 | QValidator::State QRegExpValidator::validate(QString &input, int& pos) const | - | ||||||||||||||||||
| 361 | { | - | ||||||||||||||||||
| 362 | QRegExp copy = r; | - | ||||||||||||||||||
| 363 | if (copy.exactMatch(input)
| 0 | ||||||||||||||||||
| 364 | return never executed: Acceptable;return Acceptable;never executed: return Acceptable; | 0 | ||||||||||||||||||
| 365 | } else { | - | ||||||||||||||||||
| 366 | if (copy.matchedLength() == input.size()
| 0 | ||||||||||||||||||
| 367 | return never executed: Intermediate;return Intermediate;never executed: return Intermediate; | 0 | ||||||||||||||||||
| 368 | } else { | - | ||||||||||||||||||
| 369 | pos = input.size(); | - | ||||||||||||||||||
| 370 | return never executed: Invalid;return Invalid;never executed: return Invalid; | 0 | ||||||||||||||||||
| 371 | } | - | ||||||||||||||||||
| 372 | } | - | ||||||||||||||||||
| 373 | } | - | ||||||||||||||||||
| 374 | void QRegExpValidator::setRegExp(const QRegExp& rx) | - | ||||||||||||||||||
| 375 | { | - | ||||||||||||||||||
| 376 | if (r != rx
| 0 | ||||||||||||||||||
| 377 | r = rx; | - | ||||||||||||||||||
| 378 | regExpChanged(r); | - | ||||||||||||||||||
| 379 | changed(); | - | ||||||||||||||||||
| 380 | } never executed: end of block | 0 | ||||||||||||||||||
| 381 | } never executed: end of block | 0 | ||||||||||||||||||
| 382 | class QRegularExpressionValidatorPrivate : public QValidatorPrivate | - | ||||||||||||||||||
| 383 | { | - | ||||||||||||||||||
| 384 | 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; | - | ||||||||||||||||||
| 385 | - | |||||||||||||||||||
| 386 | public: | - | ||||||||||||||||||
| 387 | QRegularExpression origRe; | - | ||||||||||||||||||
| 388 | QRegularExpression usedRe; | - | ||||||||||||||||||
| 389 | void setRegularExpression(const QRegularExpression &re); | - | ||||||||||||||||||
| 390 | }; | - | ||||||||||||||||||
| 391 | - | |||||||||||||||||||
| 392 | - | |||||||||||||||||||
| 393 | - | |||||||||||||||||||
| 394 | - | |||||||||||||||||||
| 395 | - | |||||||||||||||||||
| 396 | - | |||||||||||||||||||
| 397 | QRegularExpressionValidator::QRegularExpressionValidator(QObject *parent) | - | ||||||||||||||||||
| 398 | : QValidator(*new QRegularExpressionValidatorPrivate, parent) | - | ||||||||||||||||||
| 399 | { | - | ||||||||||||||||||
| 400 | - | |||||||||||||||||||
| 401 | - | |||||||||||||||||||
| 402 | } never executed: end of block | 0 | ||||||||||||||||||
| 403 | - | |||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | - | |||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | QRegularExpressionValidator::QRegularExpressionValidator(const QRegularExpression &re, QObject *parent) | - | ||||||||||||||||||
| 410 | : QValidator(*new QRegularExpressionValidatorPrivate, parent) | - | ||||||||||||||||||
| 411 | { | - | ||||||||||||||||||
| 412 | QRegularExpressionValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 413 | d->setRegularExpression(re); | - | ||||||||||||||||||
| 414 | } never executed: end of block | 0 | ||||||||||||||||||
| 415 | - | |||||||||||||||||||
| 416 | - | |||||||||||||||||||
| 417 | - | |||||||||||||||||||
| 418 | - | |||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | - | |||||||||||||||||||
| 421 | QRegularExpressionValidator::~QRegularExpressionValidator() | - | ||||||||||||||||||
| 422 | { | - | ||||||||||||||||||
| 423 | } | - | ||||||||||||||||||
| 424 | QValidator::State QRegularExpressionValidator::validate(QString &input, int &pos) const | - | ||||||||||||||||||
| 425 | { | - | ||||||||||||||||||
| 426 | const QRegularExpressionValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 427 | - | |||||||||||||||||||
| 428 | - | |||||||||||||||||||
| 429 | - | |||||||||||||||||||
| 430 | - | |||||||||||||||||||
| 431 | if (d->origRe.pattern().isEmpty()
| 0 | ||||||||||||||||||
| 432 | return never executed: Acceptable;return Acceptable;never executed: return Acceptable; | 0 | ||||||||||||||||||
| 433 | - | |||||||||||||||||||
| 434 | const QRegularExpressionMatch m = d->usedRe.match(input, 0, QRegularExpression::PartialPreferCompleteMatch); | - | ||||||||||||||||||
| 435 | if (m.hasMatch()
| 0 | ||||||||||||||||||
| 436 | return never executed: Acceptable;return Acceptable;never executed: return Acceptable; | 0 | ||||||||||||||||||
| 437 | } else if (input.isEmpty()
| 0 | ||||||||||||||||||
| 438 | return never executed: Intermediate;return Intermediate;never executed: return Intermediate; | 0 | ||||||||||||||||||
| 439 | } else { | - | ||||||||||||||||||
| 440 | pos = input.size(); | - | ||||||||||||||||||
| 441 | return never executed: Invalid;return Invalid;never executed: return Invalid; | 0 | ||||||||||||||||||
| 442 | } | - | ||||||||||||||||||
| 443 | } | - | ||||||||||||||||||
| 444 | QRegularExpression QRegularExpressionValidator::regularExpression() const | - | ||||||||||||||||||
| 445 | { | - | ||||||||||||||||||
| 446 | const QRegularExpressionValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 447 | return never executed: d->origRe;return d->origRe;never executed: return d->origRe; | 0 | ||||||||||||||||||
| 448 | } | - | ||||||||||||||||||
| 449 | - | |||||||||||||||||||
| 450 | void QRegularExpressionValidator::setRegularExpression(const QRegularExpression &re) | - | ||||||||||||||||||
| 451 | { | - | ||||||||||||||||||
| 452 | QRegularExpressionValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 453 | d->setRegularExpression(re); | - | ||||||||||||||||||
| 454 | } never executed: end of block | 0 | ||||||||||||||||||
| 455 | - | |||||||||||||||||||
| 456 | - | |||||||||||||||||||
| 457 | - | |||||||||||||||||||
| 458 | - | |||||||||||||||||||
| 459 | - | |||||||||||||||||||
| 460 | - | |||||||||||||||||||
| 461 | - | |||||||||||||||||||
| 462 | void QRegularExpressionValidatorPrivate::setRegularExpression(const QRegularExpression &re) | - | ||||||||||||||||||
| 463 | { | - | ||||||||||||||||||
| 464 | QRegularExpressionValidator * const q = q_func(); | - | ||||||||||||||||||
| 465 | - | |||||||||||||||||||
| 466 | if (origRe != re
| 0 | ||||||||||||||||||
| 467 | usedRe = origRe = re; | - | ||||||||||||||||||
| 468 | usedRe.setPattern(QLatin1String("\\A(?:") + re.pattern() + QLatin1String(")\\z")); | - | ||||||||||||||||||
| 469 | q->regularExpressionChanged(re); | - | ||||||||||||||||||
| 470 | q->changed(); | - | ||||||||||||||||||
| 471 | } never executed: end of block | 0 | ||||||||||||||||||
| 472 | } never executed: end of block | 0 | ||||||||||||||||||
| 473 | - | |||||||||||||||||||
| 474 | - | |||||||||||||||||||
| 475 | - | |||||||||||||||||||
| 476 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |