简体   繁体   English

在Qt中创建复杂的树模型

[英]Creating a complex tree model in Qt

I'm writing an IRC Client (yes another one). 我正在写一个IRC客户端(是另一个)。 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. 我有3个不同的列表视图,分别用于网络,频道和地址。 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. 问题是我想为1个模型拥有3个视图,以最大程度地减少所有内存和数据加载。 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. 如果您看一下QColumnView,那是完全一样的东西。 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. 该信息存储在SQLite数据库中。 I already have the classes written to extract and store it. 我已经编写了提取和存储它的类。 Just the modelling is the painful part of this solution. 仅建模是该解决方案的痛苦部分。

我将制作一个TreeModel,然后使用QSortFilterProxyModel()在其上显示三个不同的视图。

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. 删除NetworkList中的所有项目,然后稍后重新填充并删除其中的所有网络。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM