Qt6 QML Book/模型视图/概念

Concept

概念

A common pattern when developing user interfaces is to keep the representation of the data separate from the visualization. This makes it possible to show the same data in different ways depending on what task the user is performing. For instance, a phone book could be arranged as a vertical list of text entries, or as a grid of pictures of the contacts. In both cases, the data is identical: the phone book, but the visualization differs. This division is commonly referred to as the model-view pattern. In this pattern, the data is referred to as the model, while the visualization is handled by the view.

开发用户界面时,一种常见模式是将数据的表示与可视化分开。这使得可以根据用户正在执行的任务,以不同的方式显示相同的数据。例如,电话簿可以放在一个垂直的文本条目列表中,或者是一个联系人图片网格。在这两种情况下,数据是相同的,都是电话簿,但可视化显示不同。这种划分通常称为模型视图模式。在此模式中,数据称为模型,而可视化由视图完成。

In QML, the model and view are joined by the delegate. The responsibilities are divided as follows: The model provides the data. For each data item, there might be multiple values. In the example above, each phone book entry has a name, a picture, and a number. The data is arranged in a view, in which each item is visualized using a delegate. The task of the view is to arrange the delegates, while each delegate shows the values of each model item to the user.

在QML中,模型model和视图view由委托delegate连接。职责划分如下:模型为每个数据项提供数据,可能有多个值。在上面的示例中,每个电话簿条目都有一个姓名、一张图片和一个电话号码。数据被安排在一个视图中,在该视图中,每个项目都使用委托进行可视化。视图的任务是安排委托,而每个委托向用户显示每个模型项的值。

This means that the delegate knows about the contents of the model and how to visualize it. The view knows about the concept of delegates and how to lay them out. The model only knows about the data it is representing.

这意味着委托知道模型的数据以及如何可视化模型数据。视图了解委托的概念以及如何安排它们。模型只知道它拥有的数据。

Qt6 QML Book/模型视图/概念

 

上一篇:Java数组


下一篇:20200121 专题:莫队(咕~~~)