-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_validators.cpp
More file actions
37 lines (35 loc) · 923 Bytes
/
custom_validators.cpp
File metadata and controls
37 lines (35 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "custom_validators.h"
QIntPowerOf2Validator::QIntPowerOf2Validator(QObject *parent) {
}
QValidator::State QIntPowerOf2Validator::validate (QString& input,int& pos) const {
if (input.isEmpty()) {
emit setError("", 1);
return Intermediate;
}
bool b;
int val = input.toInt(&b);
if (!b) {
emit setError(QString("Invalid integer format"), 1000);
return Invalid;
};
switch (val) {
case 1:
case 2:
case 4:
case 8:
case 16:
case 32:
case 64:
case 128:
emit setError("", 1);
return Acceptable;
case 3:
case 6:
case 12:
emit setError(QString("The number should be in range [1;128] and should be power of 2"), 1000);
return Intermediate;
default:
emit setError(QString("The number should be in range [1;128] and should be power of 2"), 1000);
return Invalid;
}
}