mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-24 03:35:54 +01:00
Added missing error handling
This commit is contained in:
parent
9bf28563fa
commit
8109e705c6
@ -14,63 +14,90 @@
|
|||||||
Style::Layer::Filter::Filter(const QJsonArray &json)
|
Style::Layer::Filter::Filter(const QJsonArray &json)
|
||||||
: _type(Unknown), _not(false)
|
: _type(Unknown), _not(false)
|
||||||
{
|
{
|
||||||
|
#define INVALID_FILTER(json) \
|
||||||
|
{qWarning() << json << ": invalid filter"; return;}
|
||||||
|
|
||||||
if (json.isEmpty())
|
if (json.isEmpty())
|
||||||
return;
|
INVALID_FILTER(json);
|
||||||
|
|
||||||
QString type = json.at(0).toString();
|
QString type = json.at(0).toString();
|
||||||
|
|
||||||
if (type == "==") {
|
if (type == "==") {
|
||||||
|
if (json.size() != 3)
|
||||||
|
INVALID_FILTER(json);
|
||||||
_type = EQ;
|
_type = EQ;
|
||||||
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
||||||
json.at(2).toVariant());
|
json.at(2).toVariant());
|
||||||
} else if (type == "!=") {
|
} else if (type == "!=") {
|
||||||
|
if (json.size() != 3)
|
||||||
|
INVALID_FILTER(json);
|
||||||
_type = NE;
|
_type = NE;
|
||||||
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
||||||
json.at(2).toVariant());
|
json.at(2).toVariant());
|
||||||
} else if (type == "<") {
|
} else if (type == "<") {
|
||||||
|
if (json.size() != 3)
|
||||||
|
INVALID_FILTER(json);
|
||||||
_type = LT;
|
_type = LT;
|
||||||
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
||||||
json.at(2).toVariant());
|
json.at(2).toVariant());
|
||||||
} else if (type == "<=") {
|
} else if (type == "<=") {
|
||||||
|
if (json.size() != 3)
|
||||||
|
INVALID_FILTER(json);
|
||||||
_type = LE;
|
_type = LE;
|
||||||
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
||||||
json.at(2).toVariant());
|
json.at(2).toVariant());
|
||||||
} else if (type == ">") {
|
} else if (type == ">") {
|
||||||
|
if (json.size() != 3)
|
||||||
|
INVALID_FILTER(json);
|
||||||
_type = GT;
|
_type = GT;
|
||||||
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
||||||
json.at(2).toVariant());
|
json.at(2).toVariant());
|
||||||
} else if (type == ">=") {
|
} else if (type == ">=") {
|
||||||
|
if (json.size() != 3)
|
||||||
|
INVALID_FILTER(json);
|
||||||
_type = GE;
|
_type = GE;
|
||||||
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
||||||
json.at(2).toVariant());
|
json.at(2).toVariant());
|
||||||
} else if (type == "all") {
|
} else if (type == "all") {
|
||||||
|
if (json.size() < 2)
|
||||||
|
INVALID_FILTER(json);
|
||||||
_type = All;
|
_type = All;
|
||||||
for (int i = 1; i < json.size(); i++)
|
for (int i = 1; i < json.size(); i++)
|
||||||
_filters.append(Filter(json.at(i).toArray()));
|
_filters.append(Filter(json.at(i).toArray()));
|
||||||
} else if (type == "any") {
|
} else if (type == "any") {
|
||||||
|
if (json.size() < 2)
|
||||||
|
INVALID_FILTER(json);
|
||||||
_type = Any;
|
_type = Any;
|
||||||
for (int i = 1; i < json.size(); i++)
|
for (int i = 1; i < json.size(); i++)
|
||||||
_filters.append(Filter(json.at(i).toArray()));
|
_filters.append(Filter(json.at(i).toArray()));
|
||||||
} else if (type == "in") {
|
} else if (type == "in") {
|
||||||
|
if (json.size() < 3)
|
||||||
|
INVALID_FILTER(json);
|
||||||
_type = In;
|
_type = In;
|
||||||
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
|
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
|
||||||
for (int i = 2; i < json.size(); i++)
|
for (int i = 2; i < json.size(); i++)
|
||||||
_set.insert(json.at(i).toString());
|
_set.insert(json.at(i).toString());
|
||||||
} else if (type == "!in") {
|
} else if (type == "!in") {
|
||||||
|
if (json.size() < 3)
|
||||||
|
INVALID_FILTER(json);
|
||||||
_type = In;
|
_type = In;
|
||||||
_not = true;
|
_not = true;
|
||||||
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
|
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
|
||||||
for (int i = 2; i < json.size(); i++)
|
for (int i = 2; i < json.size(); i++)
|
||||||
_set.insert(json.at(i).toString());
|
_set.insert(json.at(i).toString());
|
||||||
} else if (type == "has") {
|
} else if (type == "has") {
|
||||||
|
if (json.size() < 2)
|
||||||
|
INVALID_FILTER(json);
|
||||||
_type = Has;
|
_type = Has;
|
||||||
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
|
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
|
||||||
} else if (type == "!has") {
|
} else if (type == "!has") {
|
||||||
|
if (json.size() < 2)
|
||||||
|
INVALID_FILTER(json);
|
||||||
_type = Has;
|
_type = Has;
|
||||||
_not = true;
|
_not = true;
|
||||||
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
|
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
|
||||||
} else
|
} else
|
||||||
qWarning() << json << ": invalid filter";
|
INVALID_FILTER(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Style::Layer::Filter::match(const QVariantMap &tags) const
|
bool Style::Layer::Filter::match(const QVariantMap &tags) const
|
||||||
|
Loading…
Reference in New Issue
Block a user