PDA

View Full Version : How to Handle an Optional User Interface



Toddeburch
24th December 2013, 13:49
Hi everyone,

I'm in the planning stages of a Qt application that supports undo/redo, scripting, and an optional UI. (The user will be able to run a script using a back-end with no interface, if the user desires).

During normal use (meaning with a UI displayed), executing commands (likes selecting a menu command) not only performs the command's action (which must be undoable) but also adds the scripting command to a script log. This allows the user to basically write a script while using the program normally (essentially macro recording capability).

Obviously, I'd like the menu command and the script command to execute the same code to maximize code reuse.

My question is this: since the code for the command may be running with a user interface or without, how do I handle the UI-related code? Since the UI won't exist if the user is running the script in non-UI mode, do i just have to check for null pointers all over and put the UI-related code in if statements? Another example: if the UI is not visible, none of the graphics updating code needs to be executed. More if statements?

Although I know I can put this code in if statements, I wonder if there is a more elegant way. (I wish methods acting on null pointers in C++ were a no-op like they are in Objective-C!