zhiyiYo / PyQt-Fluent-Widgets

A fluent design widgets library based on C++ Qt/PyQt/PySide. Make Qt Great Again.
https://qfluentwidgets.com
GNU General Public License v3.0
4.99k stars 464 forks source link

[Improvement] 支持多配置文件 #904

Closed kaka1909 closed 1 week ago

kaka1909 commented 2 weeks ago

问题描述

由于工具设计时,需要一个全局配置,和一个基于项目的输出导出配置,也就是需要两套独立的配置文件和管理。

但在使用 common/components/settings/....Card 和 common/config 的过程中发现每一个控件的数据set都是使用 qconfig 来设置

    def setValue(self, value):
        """ select button according to the value """
        qconfig.set(self.configItem, value)  # 这里只能往全局 qconfig 里设置配置数据

        for button in self.buttonGroup.buttons():
            isChecked = button.property(self.configName) == value
            button.setChecked(isChecked)

            if isChecked:
                self.choiceLabel.setText(button.text())
                self.choiceLabel.adjustSize()

也就是使用一个全局的 common/config 中的 qconfig实例进行保存,这导致无法使用多个 自定义config,因为无论

cfg1 = CustomConfig1()
qconfig.load('config/config.json', cfg1)

cfg2 = CustomConfig2()
qconfig.load('config/config.json', cfg2)

都会导致 qconfig 只能同时使用一套 _cfg 来进行数据的管理。

解决办法

抛砖引玉哈,说的不一定对。

  1. 当界面上引导用户对某一个自定义配置如 cfg2 进行操作时,将全局 qconfig 通过 load 方式加载进来 cfg2 。

  2. 可能需要对 config 和 各个 card 组件进行一定的重构,common/config.QConfig 拆分功能成 QConfig(负责管理) 和 QConfigSource(负责配置项定义可以是纯粹的数据型model)。仅做参考。

rainzee commented 2 weeks ago

每个 SettingCard 都有信号,你根据你的需求自己做配置导出不行吗

zhiyiYo commented 1 week ago

工程量有点大,建议自己写一个 qconfig 子类