[英]Python PyQt QTableWidet: How to implement an “advanced search” function
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? 假设有一个QTableWidget填充了用户的数据,他/她希望能够使用多个用户定义的条件语句对其执行“高级搜索”:一个(程序员,而不是用户)如何实现一个功能中的代码,使用户能够执行此搜索?
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. 首先,编写一个解析器 ,然后定义一个函数/语法
column
,该列根据当前行为您提供表的列内容。 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 . 有关如何编写解析器的更多信息,请参见例如递归下降解析器 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.