Conversation
6e3c7d5 to
e790495
Compare
angela28chen
left a comment
There was a problem hiding this comment.
Thanks for making this effort to make Dive ui code use "new" in a more intentioned way
src/dive/ui/forward.h
Outdated
|
|
||
| // Forward declarations for UI. | ||
|
|
||
| class OverlayHelper; |
There was a problem hiding this comment.
this seems repeated (line 74)
There was a problem hiding this comment.
Eh, I probably selected the wrong range when running sort+deduplicate in the editor.
| return ptr; // NOLINT | ||
| } | ||
|
|
||
| // Create a new Qt object. |
There was a problem hiding this comment.
I like the examples section for how to create new layouts using LayoutHelper. Can we have a similar brief example section for QtNew and QtNewUnowned?
There was a problem hiding this comment.
They are just new with static_assert.
Will add a bit more document.
| #include "ui/overlay.h" | ||
| #include "ui/settings.h" | ||
|
|
||
| using DiveLint::QtNew; |
There was a problem hiding this comment.
Is there any downside to avoiding "using" and just calling the full DiveLint::QtNew() when using this or is it just wordy? I slightly prefer the wordy version since I think it makes it clearer that QtNew() isn't something defined by Qt despite the prefix
There was a problem hiding this comment.
Though I guess it might be confusing to see the word "Lint" in there. Could it not just be Dive::QtNew() or DiveQt::QtNew or something?
There was a problem hiding this comment.
Those are annotations, and more specifically lint annotations. They don't do anything other than doing additional lint checks.
Also regarding to using alias https://google.github.io/styleguide/cppguide.html#Aliases
Had a bit offline chat earlier with @footballhead , instead of disable lint check for pointer ownership, it seems sensible to explicitly annotate allocations. |
src/dive/lint/gsl.h
Outdated
| namespace gsl | ||
| { | ||
|
|
||
| template<class T, std::enable_if_t<std::is_pointer_v<T>, bool> = true> // |
There was a problem hiding this comment.
why the trailing //?
There was a problem hiding this comment.
We probably wan to remove clang-format rule AlwaysBreakTemplateDeclarations: MultiLine
| - "-cppcoreguidelines-avoid-non-const-global-variables" # ABSL_FLAG | ||
| - "-cppcoreguidelines-use-enum-class" | ||
| - "-readability-redundant-access-specifiers" # qt | ||
| - "-cppcoreguidelines-pro-bounds-avoid-unchecked-container-access" # https://abseil.io/tips/224 |
There was a problem hiding this comment.
+1 love adding the justification in the comment
| using DiveLint::QtNew; | ||
| using DiveLint::QtNewUnowned; |
There was a problem hiding this comment.
nit, likely not an issue here since the using isn't inside the namespace but (in general) prefer to fully qualify https://abseil.io/tips/119
| using DiveLint::QtNew; | |
| using DiveLint::QtNewUnowned; | |
| using ::DiveLint::QtNew; | |
| using ::DiveLint::QtNewUnowned; |
(https://abseil.io/tips/119 also recommends putting this in a namespace but I can see that there isn't one here :)
| m_available_metrics(available_metrics) | ||
| { | ||
| qDebug() << "AnalyzeDialog created."; | ||
| InitializeLayout(); |
There was a problem hiding this comment.
Is it worth documenting somewhere that this is called from the constructor so should not be made virtual?
There was a problem hiding this comment.
It should be a factory function
auto Create() {
auto dialog = new AnalyzeDialog;
if (!AnalyzeDialog->InitializeLayout()) { delete dialog; return nullptr; }
return dialog;
}however the rest of the code are not capable of handling creation failure at the moment.
There was a problem hiding this comment.
Until that happens, document that this is called from the constructor so should not be made virtual?
|
|
||
| // Left Panel Layout | ||
| m_left_panel_layout = new QVBoxLayout(); | ||
| m_left_panel_layout = QtNewUnowned<QVBoxLayout>(); |
There was a problem hiding this comment.
Should we look at using the layout helper here as well?
There was a problem hiding this comment.
Yes. Although that's a lot of reordering probably fitted for the next PR.
I intentionally did not add AddWidget and AddLayout since they encourage having unparented elements.
a3afd32 to
a73af62
Compare
| m_available_metrics(available_metrics) | ||
| { | ||
| qDebug() << "AnalyzeDialog created."; | ||
| InitializeLayout(); |
There was a problem hiding this comment.
Until that happens, document that this is called from the constructor so should not be made virtual?
6b4fffe to
c4ca939
Compare
4920263 to
ffcb8a7
Compare
- Created a tiny Guidelines Support Library - Add some helper function to make sure we do qt ownership correctly.
Fix two memory leak, and many lint warning.