可以将代码进行相应的修改以实现你的筛选原则。以下是修改后的代码示例:
def load_combobox_data(self):
self.setup_combobox_level1()
def setup_combobox_level1(self):
self.combobox_1.clear()
self.combobox_1.addItem("请选择")
filtered_data = self.data_model[self.data_model['level'] == 1]
for index, row in filtered_data.iterrows():
name = row['name']
code = row['code']
self.combobox_1.addItem(name, code)
def setup_combobox_level2(self, selected_code):
self.combobox_2.clear()
self.combobox_2.addItem("请选择")
filtered_data = self.data_model[self.data_model['code'].str[:2] == selected_code[:2]]
for index, row in filtered_data.iterrows():
name = row['name']
code = row['code']
self.combobox_2.addItem(name, code)
def setup_combobox_level3(self, selected_code):
self.combobox_3.clear()
self.combobox_3.addItem("请选择")
filtered_data = self.data_model[self.data_model['code'].str[:4] == selected_code[:4]]
for index, row in filtered_data.iterrows():
name = row['name']
code = row['code']
self.combobox_3.addItem(name, code)
def setup_combobox_level4(self, selected_code):
self.combobox_4.clear()
self.combobox_4.addItem("请选择")
filtered_data = self.data_model[self.data_model['code'].str[:6] == selected_code[:6]]
for index, row in filtered_data.iterrows():
name = row['name']
code = row['code']
self.combobox_4.addItem(name, code)
def setup_combobox_level5(self, selected_code):
self.combobox_5.clear()
self.combobox_5.addItem("请选择")
filtered_data = self.data_model[self.data_model['code'].str[:9] == selected_code[:9]]
for index, row in filtered_data.iterrows():
name = row['name']
code = row['code']
self.combobox_5.addItem(name, code)
然后在`setup_area_selection`函数中调用这些新的函数来加载数据:
def setup_area_selection(self, comboboxes, data_model):
self.data_model = pd.read_excel(self.Region_file)
# ...
# 这里省略了其他部分代码
self.setup_combobox_level1()
self.combobox_1.currentIndexChanged.connect(lambda: self.setup_combobox_level2(self.combobox_1.currentData()))
self.combobox_2.currentIndexChanged.connect(lambda: self.setup_combobox_level3(self.combobox_2.currentData()))
self.combobox_3.currentIndexChanged.connect(lambda: self.setup_combobox_level4(self.combobox_3.currentData()))
self.combobox_4.currentIndexChanged.connect(lambda: self.setup_combobox_level5(self.combobox_4.currentData()))
通过这样的修改,你可以根据不同的级别和区划代码进行筛选并加载相应的数据到不同的QComboBox中。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |