- Reduce duplicate initializations (initializer lists are always
preferable).
- Initialize a few variables that were not initialized before
(m_hovered_Preset, ...)
Allocate QRect on the stack, heap allocations are expensive and were
mostly leaked.
scottpetrovic |
Krita |
preferable).
(m_hovered_Preset, ...)
Allocate QRect on the stack, heap allocations are expensive and were
mostly leaked.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
this seems fine. One question about when to put something on the stack or on the heap...
KisHighlightedToolButton* mirrorMode; KisHighlightedToolButton* canvasOnlyButton; QPushButton* zoomToOneHundredPercentButton; QSlider* zoomCanvasSlider;
These variables are still using pointers. Why not put these on the stack too?
Those are widgets, which are part of the widget hierarchy. Those need to be created on the heap, because the widgets that own them will delete them. If you would put them on the stack, they would be double-deleted when they go out of scope.
The way it works here is that they inherit QObject which is allowing an alternative way of memory management. QObjects (QWidget and friends) can have a "parent" to build a hierarchy. When deleting the parent, it deletes all it's children. That's how it's done for most of the UI things.
thanks for the advice. I knew about QWidgets having some type of inheritance that makes them memory management, but didn't realize all "Q" classes do not follow that same pattern (QRect, etc)