(release_30)refactor: eliminate duplicated set of pointers in dlgTriggerEditor class#352
Conversation
Whilst looking at a different issue I spotted that there were two sets of
pointers in the dlgTriggerEditor class that were intended to track the
"current" item in each of Aliases, Buttons ("Actions"), Keys, Scripts,
Timers, Triggers and Variables. The more appropriately named
mpCurrentXXXXItem ones were largely unused and the mCurrentXXXX ones were
mainly used. However in the case of the ones for Variables the mixing of
the use of both of them, may, I thought, have resulted in some oddities in
hiding and un-hiding of variables that I previously remembered happening.
In fact it doesn't but that is another story...
Also:
* Found some systematic duplicate checks in code for Aliases, Keys etc.
for a QTreeWidgetItem pointer being non-null which I was able to remove.
I then spotted a similar test in some Variable handling code in:
(void) dlgTriggerEditor::slot_var_selected(QTreeWidgetItem *)
but there were several calls to other methods which used the pointer as
an argument and it was not immediately clear whether they would modify
the pointer value or it's pointee. Further investigation enable me to
add some const qualifiers to those methods which revealed that the
address stored in the pointer was not going to be changed so that the
second test in the method was redundent.
* There was some unneeded C-Style casts in this class and in the cases
where a cast was needed to resolve signature ambiguities for the compiler
it is better to use a static_cast in C++ code.
Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
|
@Chris7 mind having a look? |
| QStringList sL; | ||
| sL << "Triggers"; | ||
| mpTriggerBaseItem = new QTreeWidgetItem( (QTreeWidgetItem*)0, sL ); | ||
| mpTriggerBaseItem = new QTreeWidgetItem( static_cast<QTreeWidgetItem *>(0), sL ); |
There was a problem hiding this comment.
The cast is needed here and in other similar calls for other elements so the right constructor gets used...
| QTreeWidgetItem * pItem = (QTreeWidgetItem*)mCurrentVar; | ||
| if (!pItem || !pItem->parent() ) | ||
| QTreeWidgetItem * pItem = mpCurrentVarItem; | ||
| if (!pItem->parent()) |
There was a problem hiding this comment.
Oh, good catch!; it might be OK, but lets assume things can go wrong or the user can do things that we as developers don't consider reasonable!
I'll mark the PR as broken until I've tweaked this...
We've already checked the member variable (now mpCurrentVarItem; was mCurrentVar) in line (that is now 3941; was 3949) before we assign it's value to the local scope variable pItem...!
|
Looks like a good increase in code clarity, and in a part that if something was done wrong it'd probably seg fault pretty fast. I always hated the mXXX/mpXXX duplication so I'm glad to see that gone. I haven't tested it but I trust @SlySven actually played with the variables to make sure they still work. |
|
False alarm - it wasn't broken after all! 😀 |
Whilst looking at a different issue I spotted that there were two sets of pointers in the
dlgTriggerEditorclass that were intended to track the "current" item in each of Aliases, Buttons ("Actions"), Keys, Scripts, Timers, Triggers and Variables. The more appropriately namedmpCurrentXXXXItemones were largely unused and themCurrentXXXXones were mainly used. However in the case of the ones for Variables the mixing of the use of both of them, may, I thought, have resulted in some oddities in hiding and un-hiding of variables that I previously remembered happening.In fact it doesn't but that is another story...
Also:
Found some systematic duplicate checks in code for Aliases, Keys etc. for a
QTreeWidgetItempointer being non-null which I was able to remove. I then spotted a similar test in some Variable handling code in:(void) dlgTriggerEditor::slot_var_selected(QTreeWidgetItem *)but there were several calls to other methods which used the pointer as an argument and it was not immediately clear whether they would modify the pointer value or it's pointee. Further investigation enable me to add some
constqualifiers to those methods which revealed that the address stored in the pointer was not going to be changed so that the second test in the method was redundant.There was some unneeded C-Style casts in this class and in the cases where a cast was needed to resolve signature ambiguities for the compiler it is better to use a
static_castin C++ code.Signed-off-by: Stephen Lyons slysven@virginmedia.com