Implement type checking/validation for filters (#4364)
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -91,23 +91,39 @@ void FiltersPage::tableCellClicked(const QModelIndex &clicked,
|
||||
{
|
||||
QMessageBox popup(this->window());
|
||||
|
||||
filterparser::FilterParser f(
|
||||
view->getModel()->data(clicked.siblingAtColumn(1)).toString());
|
||||
auto filterText =
|
||||
view->getModel()->data(clicked.siblingAtColumn(1)).toString();
|
||||
auto filterResult = filters::Filter::fromString(filterText);
|
||||
|
||||
if (f.valid())
|
||||
if (std::holds_alternative<filters::Filter>(filterResult))
|
||||
{
|
||||
popup.setIcon(QMessageBox::Icon::Information);
|
||||
popup.setWindowTitle("Valid filter");
|
||||
popup.setText("Filter is valid");
|
||||
popup.setInformativeText(
|
||||
QString("Parsed as:\n%1").arg(f.filterString()));
|
||||
auto f = std::move(std::get<filters::Filter>(filterResult));
|
||||
if (f.returnType() == filters::Type::Bool)
|
||||
{
|
||||
popup.setIcon(QMessageBox::Icon::Information);
|
||||
popup.setWindowTitle("Valid filter");
|
||||
popup.setText("Filter is valid");
|
||||
popup.setInformativeText(
|
||||
QString("Parsed as:\n%1").arg(f.filterString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
popup.setIcon(QMessageBox::Icon::Warning);
|
||||
popup.setWindowTitle("Invalid filter");
|
||||
popup.setText(QString("Unexpected filter return type"));
|
||||
popup.setInformativeText(
|
||||
QString("Expected %1 but got %2")
|
||||
.arg(filters::typeToString(filters::Type::Bool))
|
||||
.arg(filters::typeToString(f.returnType())));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto err = std::move(std::get<filters::FilterError>(filterResult));
|
||||
popup.setIcon(QMessageBox::Icon::Warning);
|
||||
popup.setWindowTitle("Invalid filter");
|
||||
popup.setText(QString("Parsing errors occurred:"));
|
||||
popup.setInformativeText(f.errors().join("\n"));
|
||||
popup.setInformativeText(err.message);
|
||||
}
|
||||
|
||||
popup.exec();
|
||||
|
||||
Reference in New Issue
Block a user