Skip to content

(release_30)refactor: eliminate duplicated set of pointers in dlgTriggerEditor class#352

Merged
SlySven merged 1 commit intoMudlet:release_30from
SlySven:(release_30)refactor_deduplicatePointersInDlgTriggerEditorClass
Dec 4, 2016
Merged

(release_30)refactor: eliminate duplicated set of pointers in dlgTriggerEditor class#352
SlySven merged 1 commit intoMudlet:release_30from
SlySven:(release_30)refactor_deduplicatePointersInDlgTriggerEditorClass

Conversation

@SlySven
Copy link
Copy Markdown
Member

@SlySven SlySven commented Nov 17, 2016

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 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_cast in C++ code.

Signed-off-by: Stephen Lyons slysven@virginmedia.com

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>
@SlySven SlySven changed the title Refactor: eliminate duplicated set of pointers in dlgTriggerEditor class (release_30)refactor: eliminate duplicated set of pointers in dlgTriggerEditor class Nov 17, 2016
@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Nov 23, 2016

@Chris7 mind having a look?

QStringList sL;
sL << "Triggers";
mpTriggerBaseItem = new QTreeWidgetItem( (QTreeWidgetItem*)0, sL );
mpTriggerBaseItem = new QTreeWidgetItem( static_cast<QTreeWidgetItem *>(0), sL );
Copy link
Copy Markdown
Member Author

@SlySven SlySven Nov 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this always be initialized?

Copy link
Copy Markdown
Member Author

@SlySven SlySven Dec 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...!

@Chris7
Copy link
Copy Markdown
Member

Chris7 commented Dec 1, 2016

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.

@SlySven
Copy link
Copy Markdown
Member Author

SlySven commented Dec 3, 2016

False alarm - it wasn't broken after all! 😀

Copy link
Copy Markdown
Member

@vadi2 vadi2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@SlySven SlySven merged commit b065e62 into Mudlet:release_30 Dec 4, 2016
@SlySven SlySven deleted the (release_30)refactor_deduplicatePointersInDlgTriggerEditorClass branch March 16, 2017 00:36
@SlySven SlySven restored the (release_30)refactor_deduplicatePointersInDlgTriggerEditorClass branch June 22, 2020 17:58
@SlySven SlySven deleted the (release_30)refactor_deduplicatePointersInDlgTriggerEditorClass branch June 22, 2020 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants