Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove boilerplate and duplication in controller setting definition #13920

Merged
merged 2 commits into from
Feb 12, 2025

Conversation

acolombier
Copy link
Member

As discussed in #13669, this PR introduced a refactor of the setting definition with a generic to remove code duplication and the needed boilerplate when introduced new setting type.

@acolombier acolombier marked this pull request as draft November 22, 2024 22:57
@acolombier acolombier force-pushed the feat/refactor-controller-setting branch from 172c8df to d4182ef Compare November 22, 2024 23:43
@acolombier acolombier marked this pull request as ready for review November 22, 2024 23:43
@acolombier acolombier force-pushed the feat/refactor-controller-setting branch from d4182ef to e6dbe5b Compare November 22, 2024 23:44
@acolombier acolombier requested a review from Swiftb0y November 22, 2024 23:46
src/controllers/legacycontrollersettings.h Outdated Show resolved Hide resolved
src/controllers/legacycontrollersettings.h Outdated Show resolved Hide resolved
Comment on lines -36 to +37
doc.setContent(QString(kValidBoolean).arg("false").toLatin1());
{
doc.setContent(QString(kValidBoolean).arg("false").toLatin1());
Copy link
Member

Choose a reason for hiding this comment

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

Was the removal of the heap allocation performance-motivated? If so I think there is a lot more we can improve here. Would you like some suggestions for that?

Copy link
Member Author

@acolombier acolombier Jan 18, 2025

Choose a reason for hiding this comment

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

Not really performance motivated since those tests are already sufficiently performant IMO (the whole suite run in ~1s on my machine), this is only because there was no need for it to be dynamically allocated

Copy link
Member Author

@acolombier acolombier Jan 18, 2025

Choose a reason for hiding this comment

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

Would you be okay to submit a commit to improve the tests?

Comment on lines +145 to +149
void reset() override {
m_editedValue = m_defaultValue;
emit valueReset();
}

Copy link
Member

Choose a reason for hiding this comment

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

I think there are some more members we could try to implement conditionally. For example we could automatically implement stringify if the underlying type supports that (using C++20 concepts of SFINAE). Same goes for value(). Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds like a great idea, although I wouldn't know how to do it. Would you be interested in submitting a commit to address that?

Copy link
Member

Choose a reason for hiding this comment

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

Still don't have time to do a proper commit, but you can simply leverage the duck-typing nature of templates to do it. Something like this demo I came up with. The compiler message is not pretty in the error-case, but that could be rectified by guarding the print with a concept Printable = ... and a requires or static_assert.

Comment on lines 236 to 242
using LegacyControllerSettingBase<SettingType>::m_savedValue;
using LegacyControllerSettingBase<SettingType>::m_defaultValue;
using LegacyControllerSettingBase<SettingType>::m_editedValue;
using LegacyControllerSettingBase<SettingType>::save;
using LegacyControllerSettingBase<SettingType>::reset;
using LegacyControllerSettingBase<SettingType>::connect;
using LegacyControllerSettingBase<SettingType>::changed;
Copy link
Member

Choose a reason for hiding this comment

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

can you explain why this is needed? The member functions should already be public while the member variables shouldn't be.

Copy link
Member Author

Choose a reason for hiding this comment

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

Without this, I get error: ‘m_...’ was not declared in this scope
I believe this has to do with the multiple inheritance but I'm not quite sure tbh. Any better fix for that?

Copy link
Member

Choose a reason for hiding this comment

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

thats weird, especially considering the other classes don't seem to need that. I'd love to see the full error message on that. I'll try to find some time to look into it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll try and post the full error here when I get the time

Copy link
Member Author

Choose a reason for hiding this comment

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

The exact error is

error: ‘<reference>’ was not declared in this scope

My gut feeling is that it has to do with the multiple inheritance causing issue with visibility, but not entirely sure

Copy link
Member

Choose a reason for hiding this comment

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

does it say <reference> verbatim? I've never seen that.

Copy link
Member Author

Choose a reason for hiding this comment

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

No it gives me the error for m_savedValue, m_defaultValue, m_editedValue, etc... at every lines referencing this symbol, e.g:

...: error: ‘m_savedValue’ was not declared in this scope
...
...: error: ‘m_defaultValue’ was not declared in this scope
...

Copy link
Member

Choose a reason for hiding this comment

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

Ah yeah, that makes more sense. I'll try to look into it when I inevitably stumble over this in the future.

src/controllers/legacycontrollersettings.cpp Outdated Show resolved Hide resolved
@acolombier
Copy link
Member Author

Friendly ping @Swiftb0y :)

Appreciate this is not perfect, but it feels like an improvement from where we are at. Are you happy to merge it as is after fixup squash?

}

protected:
LegacyControllerSettingMixin(const QDomElement& element)
Copy link
Member

Choose a reason for hiding this comment

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

What mm means "Mixin" ?

Copy link
Member Author

Choose a reason for hiding this comment

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

https://en.m.wikipedia.org/wiki/Mixin

I must confess I didn't know it either a few seconds ago 😃

@acolombier acolombier force-pushed the feat/refactor-controller-setting branch from 14fef57 to 277af1f Compare February 12, 2025 20:27
@acolombier acolombier force-pushed the feat/refactor-controller-setting branch from 277af1f to 5b9dfa5 Compare February 12, 2025 20:27
@acolombier
Copy link
Member Author

@Swiftb0y I took the freedom to squash the fixup already and push a minor fix for #14315, so we can hopefully merge this one ahead of the 2.6 beta!

@acolombier acolombier force-pushed the feat/refactor-controller-setting branch from 5b9dfa5 to f45cd37 Compare February 12, 2025 21:13
@acolombier
Copy link
Member Author

Removing the last commit as it doesn't seem to be the fix for the warning. Further work will be required to investigate #14315

Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

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

I'm fine with the current state. Any blockers I'm not aware of or can we merge?

@acolombier
Copy link
Member Author

I'm not aware of any blocker,s so I think this can go in! Thanks for looking into it

@Swiftb0y
Copy link
Member

Great. Thanks.

@Swiftb0y Swiftb0y merged commit 898ef6d into mixxxdj:main Feb 12, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants