Design pattern for an inspector widget
-
Currently, I am making an app with vtk and qt. This app has an inspector (properties) widget. This widget is a qtable and allows the user to edit and see information about the shape that is selected. Currently, I have one huge if statement for when the values are changed in the qtable. I also have a lot of the vtk framework mixed in the widget for when the values are changed. What are some design patterns that could help me reduce the coupling to vtk and reduce the size of my update value function? I'm a novice so anything helps.
-
Currently, I am making an app with vtk and qt. This app has an inspector (properties) widget. This widget is a qtable and allows the user to edit and see information about the shape that is selected. Currently, I have one huge if statement for when the values are changed in the qtable. I also have a lot of the vtk framework mixed in the widget for when the values are changed. What are some design patterns that could help me reduce the coupling to vtk and reduce the size of my update value function? I'm a novice so anything helps.
@Joe_climber
Hello and welcome.A bit hard to answer because the question is general. You should separate off the "vtx" code from the UI code handling the table changes, not have it mixed in. You might well leverage Qt's signals and slots for this: the UI raises signal(s) when a value is changed and the vtk code is in slots when are run when the signal is emitted. You might do this as each value gets changed in the UI individually, or you might allow the user to change lots of values and then have an "OK" button which emits a single signal and all values are dealt with at one time.
For the
ifstatement it's a bit harder. You might use aswitchstatement instead for neatness but that doesn't really change the situation. If you need to do unrelated, different things in vtk for each property it may be unavoidable (unless each UI widget fires a distinct slot for one property).