25 #include <QtCore/QStringList>
26 #include <QtCore/QMetaEnum>
30 class Predicate::Private
36 operand1(0), operand2(0) {}
64 const QString &property,
const QVariant &value,
69 d->ifaceType = ifaceType;
70 d->property = property;
72 d->compOperator = compOperator;
76 const QString &property,
const QVariant &value,
82 if (((
int)ifaceType)!=-1)
85 d->ifaceType = ifaceType;
86 d->property = property;
88 d->compOperator = compOperator;
97 d->ifaceType = ifaceType;
105 if (((
int)ifaceType)!=-1)
109 d->ifaceType = ifaceType;
115 if (d->type!=PropertyCheck && d->type!=InterfaceCheck) {
126 d->type = other.d->type;
128 if (d->type!=PropertyCheck && d->type!=InterfaceCheck)
132 d->operand1 = operand1;
135 d->operand2 = operand2;
139 d->ifaceType = other.d->ifaceType;
140 d->property = other.d->property;
141 d->value = other.d->value;
142 d->compOperator = other.d->compOperator;
152 result.d->isValid =
true;
153 result.d->type = Conjunction;
154 result.d->operand1 =
new Predicate(*
this);
155 result.d->operand2 =
new Predicate(other);
162 *
this = *
this & other;
170 result.d->isValid =
true;
171 result.d->type = Disjunction;
172 result.d->operand1 =
new Predicate(*
this);
173 result.d->operand2 =
new Predicate(other);
180 *
this = *
this | other;
191 if (!d->isValid)
return false;
196 return d->operand1->matches(device)
197 || d->operand2->matches(device);
199 return d->operand1->matches(device)
200 && d->operand2->matches(device);
207 const int index = iface->metaObject()->indexOfProperty(d->property.toLatin1());
208 QMetaProperty metaProp = iface->metaObject()->property(index);
209 QVariant value = metaProp.isReadable() ? metaProp.read(iface) : QVariant();
210 QVariant expected = d->value;
212 if (metaProp.isEnumType() && expected.type()==QVariant::String) {
213 QMetaEnum metaEnum = metaProp.enumerator();
214 int value = metaEnum.keysToValue(d->value.toString().toLatin1());
218 expected = QVariant();
222 if (d->compOperator==Mask) {
224 int v = value.toInt(&v_ok);
226 int e = expected.toInt(&e_ok);
228 return (e_ok && v_ok && (v &e));
230 return (value == expected);
244 QSet<DeviceInterface::Type> res;
252 res+= d->operand1->usedTypes();
253 res+= d->operand2->usedTypes();
269 if (!d->isValid)
return "False";
271 if (d->type!=PropertyCheck && d->type!=InterfaceCheck)
273 QString op =
" AND ";
274 if (d->type==Disjunction) op =
" OR ";
276 return '['+d->operand1->toString()+op+d->operand2->toString()+
']';
282 if (ifaceName.isEmpty()) ifaceName =
"Unknown";
284 if (d->type==InterfaceCheck) {
285 return "IS "+ifaceName;
290 switch (d->value.type())
292 case QVariant::StringList:
296 const QStringList list = d->value.toStringList();
298 QStringList::ConstIterator it = list.begin();
299 QStringList::ConstIterator end = list.end();
301 for (; it!=end; ++it)
303 value+=
'\''+ *it+
'\'';
315 value = (d->value.toBool()?
"true":
"false");
319 case QVariant::LongLong:
320 case QVariant::ULongLong:
321 value = d->value.toString();
324 value =
'\''+d->value.toString()+
'\'';
328 QString str_operator =
"==";
329 if (d->compOperator!=Equals) str_operator =
" &";
332 return ifaceName+
'.'+d->property+
' '+str_operator+
' '+value;
358 return d->compOperator;