| 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 | } | - | ||||||||||||||||||
| 12 | - | |||||||||||||||||||
| 13 | QLocale locale; | - | ||||||||||||||||||
| 14 | }; | - | ||||||||||||||||||
| 15 | - | |||||||||||||||||||
| 16 | - | |||||||||||||||||||
| 17 | - | |||||||||||||||||||
| 18 | - | |||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | - | |||||||||||||||||||
| 22 | QValidator::QValidator(QObject * parent) | - | ||||||||||||||||||
| 23 | : QObject(*new QValidatorPrivate, parent) | - | ||||||||||||||||||
| 24 | { | - | ||||||||||||||||||
| 25 | } | - | ||||||||||||||||||
| 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 d->locale; | - | ||||||||||||||||||
| 46 | } | - | ||||||||||||||||||
| 47 | void QValidator::setLocale(const QLocale &locale) | - | ||||||||||||||||||
| 48 | { | - | ||||||||||||||||||
| 49 | QValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 50 | if (d->locale != locale) { | - | ||||||||||||||||||
| 51 | d->locale = locale; | - | ||||||||||||||||||
| 52 | changed(); | - | ||||||||||||||||||
| 53 | } | - | ||||||||||||||||||
| 54 | } | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | - | |||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | QIntValidator::~QIntValidator() | - | ||||||||||||||||||
| 85 | { | - | ||||||||||||||||||
| 86 | - | |||||||||||||||||||
| 87 | } | - | ||||||||||||||||||
| 88 | static int numDigits(qlonglong n) | - | ||||||||||||||||||
| 89 | { | - | ||||||||||||||||||
| 90 | if (n == 0) | - | ||||||||||||||||||
| 91 | return 1; | - | ||||||||||||||||||
| 92 | return (int)std::log10(double(n)) + 1; | - | ||||||||||||||||||
| 93 | } | - | ||||||||||||||||||
| 94 | - | |||||||||||||||||||
| 95 | static qlonglong pow10(int exp) | - | ||||||||||||||||||
| 96 | { | - | ||||||||||||||||||
| 97 | qlonglong result = 1; | - | ||||||||||||||||||
| 98 | for (int i = 0; i < exp; ++i) | - | ||||||||||||||||||
| 99 | result *= 10; | - | ||||||||||||||||||
| 100 | return result; | - | ||||||||||||||||||
| 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() & 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:   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() & 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) { | - | ||||||||||||||||||
| 159 | b = bottom; | - | ||||||||||||||||||
| 160 | rangeChanged = true; | - | ||||||||||||||||||
| 161 | bottomChanged(b); | - | ||||||||||||||||||
| 162 | } | - | ||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | if (t != top) { | - | ||||||||||||||||||
| 165 | t = top; | - | ||||||||||||||||||
| 166 | rangeChanged = true; | - | ||||||||||||||||||
| 167 | topChanged(t); | - | ||||||||||||||||||
| 168 | } | - | ||||||||||||||||||
| 169 | - | |||||||||||||||||||
| 170 | if (rangeChanged) | - | ||||||||||||||||||
| 171 | changed(); | - | ||||||||||||||||||
| 172 | } | - | ||||||||||||||||||
| 173 | void QIntValidator::setBottom(int bottom) | - | ||||||||||||||||||
| 174 | { | - | ||||||||||||||||||
| 175 | setRange(bottom, top()); | - | ||||||||||||||||||
| 176 | } | - | ||||||||||||||||||
| 177 | void QIntValidator::setTop(int top) | - | ||||||||||||||||||
| 178 | { | - | ||||||||||||||||||
| 179 | setRange(bottom(), top); | - | ||||||||||||||||||
| 180 | } | - | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | - | |||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | QValidator::QValidator(QObjectPrivate &d, QObject *parent) | - | ||||||||||||||||||
| 186 | : QObject(d, parent) | - | ||||||||||||||||||
| 187 | { | - | ||||||||||||||||||
| 188 | } | - | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | QValidator::QValidator(QValidatorPrivate &d, QObject *parent) | - | ||||||||||||||||||
| 194 | : QObject(d, parent) | - | ||||||||||||||||||
| 195 | { | - | ||||||||||||||||||
| 196 | } | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 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 StandardNotation: | - | ||||||||||||||||||
| 245 | numMode = QLocaleData::DoubleStandardMode; | - | ||||||||||||||||||
| 246 | break; | - | ||||||||||||||||||
| 247 | case ScientificNotation: | - | ||||||||||||||||||
| 248 | numMode = QLocaleData::DoubleScientificMode; | - | ||||||||||||||||||
| 249 | break; | - | ||||||||||||||||||
| 250 | } | - | ||||||||||||||||||
| 251 | - | |||||||||||||||||||
| 252 | return d->validateWithLocale(input, numMode, locale()); | - | ||||||||||||||||||
| 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() & QLocale::RejectGroupSeparator))())
  | 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 , overflow= false; | - | ||||||||||||||||||
| 273 | double i = QLocaleData::bytearrayToDouble(buff.constData(),toDouble(&ok, &overflow); | - | ||||||||||||||||||
| 274 |     if (overflow)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) { | - | ||||||||||||||||||
| 297 | b = minimum; | - | ||||||||||||||||||
| 298 | rangeChanged = true; | - | ||||||||||||||||||
| 299 | bottomChanged(b); | - | ||||||||||||||||||
| 300 | } | - | ||||||||||||||||||
| 301 | - | |||||||||||||||||||
| 302 | if (t != maximum) { | - | ||||||||||||||||||
| 303 | t = maximum; | - | ||||||||||||||||||
| 304 | rangeChanged = true; | - | ||||||||||||||||||
| 305 | topChanged(t); | - | ||||||||||||||||||
| 306 | } | - | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | if (dec != decimals) { | - | ||||||||||||||||||
| 309 | dec = decimals; | - | ||||||||||||||||||
| 310 | rangeChanged = true; | - | ||||||||||||||||||
| 311 | decimalsChanged(dec); | - | ||||||||||||||||||
| 312 | } | - | ||||||||||||||||||
| 313 | if (rangeChanged) | - | ||||||||||||||||||
| 314 | changed(); | - | ||||||||||||||||||
| 315 | } | - | ||||||||||||||||||
| 316 | void QDoubleValidator::setBottom(double bottom) | - | ||||||||||||||||||
| 317 | { | - | ||||||||||||||||||
| 318 | setRange(bottom, top(), decimals()); | - | ||||||||||||||||||
| 319 | } | - | ||||||||||||||||||
| 320 | void QDoubleValidator::setTop(double top) | - | ||||||||||||||||||
| 321 | { | - | ||||||||||||||||||
| 322 | setRange(bottom(), top, decimals()); | - | ||||||||||||||||||
| 323 | } | - | ||||||||||||||||||
| 324 | void QDoubleValidator::setDecimals(int decimals) | - | ||||||||||||||||||
| 325 | { | - | ||||||||||||||||||
| 326 | setRange(bottom(), top(), decimals); | - | ||||||||||||||||||
| 327 | } | - | ||||||||||||||||||
| 328 | void QDoubleValidator::setNotation(Notation newNotation) | - | ||||||||||||||||||
| 329 | { | - | ||||||||||||||||||
| 330 | QDoubleValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 331 | if (d->notation != newNotation) { | - | ||||||||||||||||||
| 332 | d->notation = newNotation; | - | ||||||||||||||||||
| 333 | notationChanged(d->notation); | - | ||||||||||||||||||
| 334 | changed(); | - | ||||||||||||||||||
| 335 | } | - | ||||||||||||||||||
| 336 | } | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | QDoubleValidator::Notation QDoubleValidator::notation() const | - | ||||||||||||||||||
| 339 | { | - | ||||||||||||||||||
| 340 | const QDoubleValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 341 | return d->notation; | - | ||||||||||||||||||
| 342 | } | - | ||||||||||||||||||
| 343 | QRegExpValidator::QRegExpValidator(QObject *parent) | - | ||||||||||||||||||
| 344 | : QValidator(parent), r(QString::fromLatin1(".*")) | - | ||||||||||||||||||
| 345 | { | - | ||||||||||||||||||
| 346 | } | - | ||||||||||||||||||
| 347 | QRegExpValidator::QRegExpValidator(const QRegExp& rx, QObject *parent) | - | ||||||||||||||||||
| 348 | : QValidator(parent), r(rx) | - | ||||||||||||||||||
| 349 | { | - | ||||||||||||||||||
| 350 | } | - | ||||||||||||||||||
| 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)) { | - | ||||||||||||||||||
| 364 | return Acceptable; | - | ||||||||||||||||||
| 365 | } else { | - | ||||||||||||||||||
| 366 | if (copy.matchedLength() == input.size()) { | - | ||||||||||||||||||
| 367 | return Intermediate; | - | ||||||||||||||||||
| 368 | } else { | - | ||||||||||||||||||
| 369 | pos = input.size(); | - | ||||||||||||||||||
| 370 | return Invalid; | - | ||||||||||||||||||
| 371 | } | - | ||||||||||||||||||
| 372 | } | - | ||||||||||||||||||
| 373 | } | - | ||||||||||||||||||
| 374 | void QRegExpValidator::setRegExp(const QRegExp& rx) | - | ||||||||||||||||||
| 375 | { | - | ||||||||||||||||||
| 376 | if (r != rx) { | - | ||||||||||||||||||
| 377 | r = rx; | - | ||||||||||||||||||
| 378 | regExpChanged(r); | - | ||||||||||||||||||
| 379 | changed(); | - | ||||||||||||||||||
| 380 | } | - | ||||||||||||||||||
| 381 | } | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 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()) | - | ||||||||||||||||||
| 432 | return Acceptable; | - | ||||||||||||||||||
| 433 | - | |||||||||||||||||||
| 434 | const QRegularExpressionMatch m = d->usedRe.match(input, 0, QRegularExpression::PartialPreferCompleteMatch); | - | ||||||||||||||||||
| 435 | if (m.hasMatch()) { | - | ||||||||||||||||||
| 436 | return Acceptable; | - | ||||||||||||||||||
| 437 | } else if (input.isEmpty() || m.hasPartialMatch()) { | - | ||||||||||||||||||
| 438 | return Intermediate; | - | ||||||||||||||||||
| 439 | } else { | - | ||||||||||||||||||
| 440 | pos = input.size(); | - | ||||||||||||||||||
| 441 | return Invalid; | - | ||||||||||||||||||
| 442 | } | - | ||||||||||||||||||
| 443 | } | - | ||||||||||||||||||
| 444 | QRegularExpression QRegularExpressionValidator::regularExpression() const | - | ||||||||||||||||||
| 445 | { | - | ||||||||||||||||||
| 446 | const QRegularExpressionValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 447 | return d->origRe; | - | ||||||||||||||||||
| 448 | } | - | ||||||||||||||||||
| 449 | - | |||||||||||||||||||
| 450 | void QRegularExpressionValidator::setRegularExpression(const QRegularExpression &re) | - | ||||||||||||||||||
| 451 | { | - | ||||||||||||||||||
| 452 | QRegularExpressionValidatorPrivate * const d = d_func(); | - | ||||||||||||||||||
| 453 | d->setRegularExpression(re); | - | ||||||||||||||||||
| 454 | } | - | ||||||||||||||||||
| 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(([]() -> QString { enum { Size = sizeof(u"" "\\A(?:")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeofQLatin1String(QStringData) }, u"" "\\A(?:"}; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) + re.pattern() + ([]() -> QString { enum { Size = sizeof(u"" ")\\z")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeofQLatin1String(QStringData) }, u"" ")\\z"}; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));)); | - | ||||||||||||||||||
| 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 |