在 Qt 中创建复杂的树模型
我正在编写一个 IRC 客户端(是的,另一个)。长话短说。我正在写一个服务器对话 保存了一个列表:
Identity Networks Channels Addresses
我有 3 个不同的列表视图,分别用于网络、通道和地址。 当用户更改身份(组合框)时。网络列表视图将查找该特定身份的所有网络。加载网络后,它将自动选择第一个网络,然后加载该特定网络的所有频道和地址。
问题是我想要 1 个模型有 3 个视图,以最小化所有内存和数据加载。这样管理起来就容易多了,而且不用做很多工作。
如果你看一下 QColumnView,它是同样的事情。但我不需要它位于一个确切的页面上,因为视图位于完全不同的选项卡上,以便更轻松地浏览服务器对话。
我想知道处理这种复杂性的最佳方法是什么。该信息存储在 SQLite 数据库中。我已经编写了用于提取和存储它的类。建模是这个解决方案中最痛苦的部分。
I'm writing an IRC Client (yes another one). Long story short. I'm writing a Server dialogue
that keeps a list of this:
Identity Networks Channels Addresses
I have 3 different list views that will be for the Networks, Channels and Addresses.
When the user changes the Identity (combo box). The network listview will lookup all the networks for that specific Identity. After it loads up the Networks it will automatically select the first network and then load all the channels and addresses for that specific network.
The problem is I want to have 3 views for 1 model, to minimise all the memory and the loading of data. So that it makes it much easier to manage and not do a bunch of work.
If you'd look at QColumnView it's the same exact thing. But I don't need it to be on one exact page since the views are on entirely different tabs to make it easier to go through the Server dialogue.
I'm wondering what will be the best way to go about handling this complexity. The information is stored in a SQLite database. I already have the classes written to extract and store it. Just the modelling is the painful part of this solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将创建一个 TreeModel,然后使用 QSortFilterProxyModel() 在其上显示三个不同的视图。
I would make a single TreeModel, and then use QSortFilterProxyModel() to display three different views on it.
做到这一点的最佳方法是动态加载模型。当组合框更改身份时。删除 NetworkList 中的所有项目,然后重新填充它并删除其中的所有网络。
The best way to doing this would be to just load the models dynamically. When the ComboBox changes Identities. Delete all the items in the NetworkList and just repopulate it afterwards and delete all the networks that were in there.