-
Notifications
You must be signed in to change notification settings - Fork 7
/
criteriabuilder.cpp
53 lines (42 loc) · 1.48 KB
/
criteriabuilder.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
#include "criteriabuilder.h"
#include <QStringList>
QStringList CriteriaBuilder::toList()
{
return m_list;
}
void CriteriaBuilder::insert(const QString key, const QVariant value) {
QString typeName = value.typeName();
QString format;
bool isInt;
value.toInt(&isInt);
if(typeName.compare("QString")==0 && !isInt)
format = "%1='%2'";
else
format = "%1=%2";
m_list << QString(format).arg(key).arg(value.toString());
}
void CriteriaBuilder::insertLessOrEq(const QString key, const QVariant value) {
if(!isNumeric(value)) return;
m_list << QString("%1<=%2").arg(key).arg(value.toString());
}
void CriteriaBuilder::insertGrtOrEq(const QString key, const QVariant value) {
if(!isNumeric(value)) return;
m_list << QString("%1>=%2").arg(key).arg(value.toString());
}
void CriteriaBuilder::insertLess(const QString key, const QVariant value) {
if(!isNumeric(value)) return;
m_list << QString("%1<%2").arg(key).arg(value.toString());
}
void CriteriaBuilder::insertGrtr(const QString key, const QVariant value) {
if(!isNumeric(value)) return;
m_list << QString("%1>%2").arg(key).arg(value.toString());
}
bool CriteriaBuilder::isNumeric(QVariant value)
{
QString typeName = QString(value.typeName());
bool isInt = (typeName == "int");
bool isDouble = (typeName == "double");
bool isFloat = (typeName == "float");
bool isLong = (typeName == "long");
return isInt || isDouble || isFloat || isLong;
}