Allow different comparison operators in the new filter row

Allow other comparison methods than just the LIKE operator when using
the new filter row.
This commit is contained in:
Martin Kleusberg
2013-04-09 19:28:21 +02:00
parent 6742f5632d
commit 44a635167d
2 changed files with 34 additions and 3 deletions

View File

@@ -225,13 +225,44 @@ void SqliteTableModel::buildQuery()
setQuery(sql);
}
void SqliteTableModel::updateFilter(int column, QString value)
void SqliteTableModel::updateFilter(int column, const QString& value)
{
// Check for any special comparison operators at the beginning of the value string. If there are none default to LIKE.
QString op = "LIKE";
QString val;
if(value.left(2) == ">=" || value.left(2) == "<=" || value.left(2) == "<>")
{
bool ok;
value.mid(2).toFloat(&ok);
if(ok)
{
op = value.left(2);
val = value.mid(2);
}
} else if(value.left(1) == ">" || value.left(1) == "<") {
bool ok;
value.mid(1).toFloat(&ok);
if(ok)
{
op = value.left(1);
val = value.mid(1);
}
} else {
if(value.left(1) == "=")
{
op = "=";
val = value.mid(1);
} else {
val = value;
}
val = QString("'%1'").arg(val.replace("'", ""));
}
// If the value was set to an empty string remove any filter for this column. Otherwise insert a new filter rule or replace the old one if there is already one
if(value.isEmpty())
m_mWhere.remove(column);
else
m_mWhere.insert(column, QString("LIKE '%1'").arg(value.replace('\'', ""))); // TODO: Add some code here to detect fancy filter values like '>5' and change the operator in these cases
m_mWhere.insert(column, QString("%1 %2").arg(op).arg(val));
// Build the new query
buildQuery();

View File

@@ -35,7 +35,7 @@ public:
signals:
public slots:
void updateFilter(int column, QString value);
void updateFilter(int column, const QString& value);
private:
void fetchData(unsigned int from, unsigned to);