Say there's a QTableWidget filled with a user's data, and he/she wants to be able to perform an "advanced search" on it using multiple user-defined conditional statements: how would one (the programmer, not the user) go about implementing a function in the code that enables the user to perform this search?
For example, let's say the user wants results of the following search:
(column1 > 20 AND column2 < 50) OR column3 = "cloud"
The first approach that comes to mind would be to somehow take the user's search criteria and generate some kind of 'metacode', but I have no idea how this would work.
First you write a parser and then you define a function/grammar
column
that gives you the content of a column of your table depending on the current row. Then you go through every row, evaluate the parsed expression and return all the rows that evaluated positively.For more information on how to write a parser see for example Recursive descent parser.