Imperative workflow in C++/Qml application
-
Hi,
I'm working on a desktop application written in C++ with UI code in Qml. It's a typical 3d (engineering) application (think something like autocad, 3dsmax,..., but smaller). There is one thing which often comes back and to which I didn't find a satisfying solution yet and that's handling "a workflow with questions to the user". To give an example: Let's say the user wants to start a new project when another one is open - if there are changes, ask whether to save them or not - if no, quit, start a new project and ask properties for this project to open, if yes, check if there is already a file/folder to save - if no, ask a file to save, if yes check the types of items in the project - Depending on the type of items, ask the user if they are needed to be saved in the project or not - if not, go to next type, if yes, check if this item type needs certain "save settings" (for instance compression factor of a picture, whether to save a 3d model binary or ascii,...), and so on and so on... .
Every time, i try to invent a new approach to solve such problems, but I never found a good solution. The reason is there is a lot of (already working) imperative code (and my mindset is probably to imperative :-)). Is there some sort of design pattern to follow to keep this clean? Or how do you solve such problems?
Thanks for the ideas,Jan
-
You can map out the behavior of your application using diagrams that define state and flow. Are you struggling on how to structure your program, or how to map a flow of events? There are design methods for structure:
https://towardsdatascience.com/10-common-software-architectural-patterns-in-a-nutshell-a0b47a1e9013
https://www.codementor.io/learn-development/what-makes-good-software-architecture-101There is also information for flow charting, uml diagrams, and state diagrams available on the web. These tools can be used to help get a clear mental picture of what needs to happen when. Qt Creator has UML and Flow Charting built in that you can use for that as well. Go to New File or Project -> Modeling (in Files and Classes section). This gives 3 types of tools that can be used for this.
Hope this helps.
-
The QWizard is more high level and not really a solution for my problem. I don't have an issue with the general design/structure of an application, and am quite familiar with the "what makes good software architecture" type of topics (though I'm not pretending I'm always following these - you know - time, pressure of deadline,... ;-)). I'm rather struggling with how to transform the type of "workflows" like i described, which are typically quite easy to solve in an imperative way (just some if - else with a blocking dialog), to a decent declarative methodology (my mindset is probably still too imperative). I think this topic also describes my problem a little bit (but it doesn't really have clear answers). These things happen very often in the typical desktop applications I'm working on - questions like "are you sure you want to quit" after you press the exit button, algorithms which decide they need some extra user input halfway through,...
In a normal Qt application you can just show a modal dialog and stop execution until the user gives his input (let's forget the issue of being in the gui thread or not) and continue. When using qml i kinda have to stop the method show a popup and continue somewhere else, but I'm not sure how to best deal with/structure it. I hope I make myself a little bit clear.
Thanks,Jan