80 lines
1.8 KiB
C++
80 lines
1.8 KiB
C++
#pragma execution_character_set("utf-8")
|
|
|
|
|
|
#include"filter.h"
|
|
#include"DataRow.h"
|
|
|
|
|
|
Filter::Filter() {
|
|
field = "";
|
|
condition = "";
|
|
value = "";
|
|
}
|
|
|
|
Filter::~Filter()
|
|
{}
|
|
|
|
bool Filter::checkRow(DataRow* data, int type)
|
|
{
|
|
switch (type)
|
|
{//1 int 2 string 3 double
|
|
case 1:
|
|
{
|
|
int tableV = data->getValue(field).toInt();
|
|
if (condition.compare("等于") == 0)
|
|
return (tableV == value.toInt());
|
|
else if (condition.compare("不等于") == 0)
|
|
return (tableV != value.toInt());
|
|
else if (condition.compare("大于") == 0)
|
|
return (tableV > value.toInt());
|
|
else if (condition.compare("大于或等于")==0)
|
|
return (tableV >= value.toInt());
|
|
else if (condition.compare("小于")==0)
|
|
return (tableV < value.toInt());
|
|
else if (condition.compare("小于或等于") == 0)
|
|
return (tableV <= value.toInt());
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
QString tableV = data->getValue(field).toString();
|
|
if (condition.compare("包含") == 0)
|
|
{
|
|
return (tableV.contains(value));
|
|
}
|
|
else if (condition.compare("不包含") == 0)
|
|
{
|
|
return (!tableV.contains(value));
|
|
}
|
|
else if (condition.contains("以XX开始") == 0)
|
|
{
|
|
return (tableV.startsWith(value));
|
|
}
|
|
else if (condition.contains("不以XX开始") == 0)
|
|
{
|
|
return (!tableV.startsWith(value));
|
|
}
|
|
}
|
|
break;
|
|
case 3:
|
|
{
|
|
double tableV = data->getValue(field).toDouble();
|
|
if (condition.compare("等于") == 0)
|
|
return (tableV == value.toDouble());
|
|
else if (condition.compare("不等于") == 0)
|
|
return (tableV != value.toDouble());
|
|
else if (condition.compare("大于") == 0)
|
|
return (tableV > value.toDouble());
|
|
else if (condition.compare("大于或等于") == 0)
|
|
return (tableV >= value.toDouble());
|
|
else if (condition.compare("小于") == 0)
|
|
return (tableV < value.toDouble());
|
|
else if (condition.compare("小于或等于") == 0)
|
|
return (tableV <= value.toDouble());
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
} |