QT:使用状态机进行 UI 交互?
您好,
我们正在开发一个科学的 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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信状态机并不是代表用户交互的正确选择。它适合轻松地对用户界面本身的变化进行建模。
您可能需要的是状态机和命令设计模式,在 Qt 中由 QUndoStack 和 QUndoCommand 类部分实现。状态机跟踪用户界面本身的更改,命令类跟踪用户交互。我对检测单元格边界不太了解,也不知道您如何规划应用程序中的交互模型,但让我尝试一个虚构的示例来澄清。
示例
假设您的应用程序有两种不同的算法来从用户提供的粗略估计开始检测单元格边框。人们沿着细胞周围的一条粗略的逐点路径。另一种采用手绘轮廓。您还希望允许用户向单元格图像添加标注注释。假设您也不希望用户的屏幕上堆满她现在不会使用的工具。
然后,您将拥有三种不同的交互模式,每种模式都有用户可以使用的不同操作(或工具):
除了提供工具之外,前两种模式还可能允许用户调整算法的参数。
一种方法是将 1、2 和 3 中的每一个表示为状态机中的一个状态。进入其中一种状态后,工具就会变得可见。当退出状态时,它会隐藏其工具。例如,可以使用工具栏按钮来更改状态。
现在,当使用工具并更改底层模型时,它还会在 QUndoStack 中存储 QUndoCommand。假设用户处于徒手模式。现在,她切换到点对点模式,调整参数,添加两个点,移动一个点,然后删除它。撤消堆栈可能如下所示,从下到上:
请注意,状态更改已添加到撤消堆栈中,以便撤消一系列命令使用户准确地离开位置她发出这封信时就是这样。例如,如果她一直取消操作回到 1,她将回到徒手模式。
总而言之,
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:
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:
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
我们已经尝试使用 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.