QT:使用状态机进行 UI 交互?

发布于 2024-09-08 22:02:27 字数 495 浏览 10 评论 0原文

您好,

我们正在开发一个科学的 QT 应用程序,用于检测单元格的边界。请参阅以下原型快照。

在此处输入图像描述 在此处输入图像描述

现在,我们将把它开发为具有良好设计和架构的开源产品。我们认为它有许多复杂的动作和流程。 例如:移动轮廓节点、删除轮廓节点、添加轮廓节点、绘制障碍、选择多个节点...等

我们希望使用 QT 状态机框架进行 UI,并想知道是否为每个流程使用多个状态机实例/动作还是使用一个“巨大”的状态机? 我们需要撤消/重做操作,是否可以将 QT 状态机框架与 QT 撤消/重做框架交互?

[edit] 真的可以使用 QT SM Frameworkkwork 来处理 UI 交互吗? 他们在 GIMP 或 CAD 应用程序中使用什么样的设计?

提前致谢, 乌曼加

Greetings,

We are developing a scientific QT Application which detect the border of a cell.Please refer to following prototype snapshots.

enter image description here
enter image description here

Now ,we are going to develop this as a opensource product with a good design and architecture.We reconed that it has many complex actions and flows.
Eg: move contour node,delete coutour node,add contour node,draw barrier,select multiple nodes...etc

We were hoping to use QT State Machine Framework for UI, and wondering whether to use several state-machine instances for each flow/action or use one "huge" state-machine?
We need unde/redo operations and is it possible to interate QT State-Machine Framework with QT Undo/Redo Framework?

[edit] Is it really possible to use QT SM Framekwork to handle UI interactions?
What kind of design they use in GIMP or CAD applications ?

Thanks in advance,
umanga

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可是我不能没有你 2024-09-15 22:02:27

我相信状态机并不是代表用户交互的正确选择。它适合轻松地对用户界面本身的变化进行建模。

您可能需要的是状态机和命令设计模式,在 Qt 中由 QUndoStack 和 QUndoCommand 类部分实现。状态机跟踪用户界面本身的更改,命令类跟踪用户交互。我对检测单元格边界不太了解,也不知道您如何规划应用程序中的交互模型,但让我尝试一个虚构的示例来澄清。

示例

假设您的应用程序有两种不同的算法来从用户提供的粗略估计开始检测单元格边框。人们沿着细胞周围的一条粗略的逐点路径。另一种采用手绘轮廓。您还希望允许用户向单元格图像添加标注注释。假设您也不希望用户的屏幕上堆满她现在不会使用的工具。

然后,您将拥有三种不同的交互模式,每种模式都有用户可以使用的不同操作(或工具):

  1. 逐点。用户可以添加点、删除点、移动点、选择点,并细化边界。
  2. 徒手。用户可以使用“铅笔”和“橡皮擦”进行绘制并细化边框。
  3. 标注注释。用户可以添加注释、删除注释、移动注释、重新定位注释箭头以及编辑注释文本。

除了提供工具之外,前两种模式还可能允许用户调整算法的参数。

一种方法是将 1、2 和 3 中的每一个表示为状态机中的一个状态。进入其中一种状态后,工具就会变得可见。当退出状态时,它会隐藏其工具。例如,可以使用工具栏按钮来更改状态。

现在,当使用工具并更改底层模型时,它还会在 QUndoStack 中存储 QUndoCommand。假设用户处于徒手模式。现在,她切换到点对点模式,调整参数,添加两个点,移动一个点,然后删除它。撤消堆栈可能如下所示,从下到上:

  1. 从徒手模式切换到点对点模式
  2. 将参数 ε 从 0.00001
  3. 更改为 0.002 在 (120, 40)
  4. 添加点 #1 2 at (403, 11)
  5. 将点 #1 从 (120, 40) 移动到 (350, 120)
  6. 删除点 #1

请注意,状态更改已添加到撤消堆栈中,以便撤消一系列命令使用户准确地离开位置她发出这封信时就是这样。例如,如果她一直取消操作回到 1,她将回到徒手模式。

总而言之,

  • Qt 中的状态机适合跟踪用户界面的变化。
  • 命令设计模式适合跟踪用户在底层模型中所做的更改。

I believe the state machine wouldn’t really be the right choice to represent the user interaction. It is suited to easily model changes in the user interface itself.

What you probably need is a combination of the state machine and the Command design pattern, which in Qt is partially implemented by the QUndoStack and QUndoCommand classes. The state machine tracks changes to the user interface itself, and the Command classes track user interaction. I don’t know a lot about detecting cell borders and I don’t know how you are planning the interaction model in your app, but let me try a make-believe example just to clarify.

Example

Suppose your app has two different algorithms to detect a cell border starting from a rough estimate provided by the user. One takes a rough point-by-point path around the cell. The other takes a freehand contour. You also want to allow the user to add callout notes to the cell image. Suppose you also don’t want to clutter the user’s screen with tools she won’t be using right now.

You then have three different interaction modes and each has different actions (or tools) the user can employ:

  1. Point by point. The user can add a point, remove a point, move a point around, select points, and refine the border.
  2. Freehand. The user can draw with a “pencil” and an “eraser” and refine the border.
  3. Callout notes. The user can add a note, remove a note, move the note around, reposition the note’s arrow, and edit the note’s text.

Besides providing tools, the first two modes might also allow the user to tune the algorithm’s parameters.

An approach would be to represent each of 1, 2, and 3 as a state in a state machine. On entering one of the states, it causes the tools to become visible. When a state is exited, it hides its tools. Changing states can be accomplished with toolbar buttons, for example.

Now, when a tool is used and changes the model underneath, it also stores a QUndoCommand in the QUndoStack. Suppose the user is in freehand mode. Now she switches to point-to-point mode, tweaks a parameter, adds two points, moves a point, and then deletes it. The undo stack might look like this, bottom to top:

  1. Switch from freehand mode to point-to-point mode
  2. Change Parameter ε from 0.00001 to 0.002
  3. Add Point #1 at (120, 40)
  4. Add Point #2 at (403, 11)
  5. Move Point #1 from (120, 40) to (350, 120)
  6. Delete Point #1

Notice that the state change was added to the undo stack so that undoing a series of commands leaves the user exactly where she was when she issued it. For example, if she un-did all the way back to 1, she would be back in the freehand mode.

To sum it all

  • The state machine in Qt is appropriate to track changes in the user interface.
  • The command design pattern is appropriate to track changes made by the user in the underlying model.
筑梦 2024-09-15 22:02:27

我们已经尝试使用 Qt 的状态机框架和动画框架来实现简单的 UI 转换。我相信他们的文档或网站上有关于如何执行此操作的教程或示例。所以是的,这是可能的。

我不知道它的扩展性如何或最好的架构。如果是我,我会尝试使用大量简单的状态机,利用它们的分层功能。

We have experimented with Qt's State Machine Framework and the Animation Framework for simple UI transitions. I believe there are tutorials or examples of how to do this in their docs or on their site. So yes, it is possible.

I don't know how well it would scale or the best architecture. If it were me, I would try to use lots of simple state machines, making use of their hierarchical capabilities.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文