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

Refactor/preferences enums #12798

Merged
merged 5 commits into from
May 21, 2024
Merged

Conversation

Swiftb0y
Copy link
Member

Alternative to #12796 along with a little extra refactoring

@Swiftb0y Swiftb0y force-pushed the refactor/preferences-enums branch 4 times, most recently from 3daa394 to 89e4f89 Compare February 12, 2024 17:39
@Swiftb0y
Copy link
Member Author

okay, enough force pushing now. I'd appreciate a review.

@ronso0
Copy link
Member

ronso0 commented Feb 13, 2024

Looks good as far as I can tell, though I'd prefer to keep the constants compact therefore I removed the nested constants namespace (and tweaked some vars etc.)

Commit is b771309, or Swiftb0y#18, as you prefer.

@Swiftb0y
Copy link
Member Author

I'd prefer to keep the constants compact therefore I removed the nested constants namespace

I'd prefer to remove that too, but its required to work around QTBUG-68611 (as pointed out in the comment above). If we remove the constants namespace, all other members of the preferences namespace would have to be declared in that file as well.

@ronso0
Copy link
Member

ronso0 commented Feb 13, 2024

Hmkay, which other members are you referring to? Future extension?
My PR is build without issues, or when would we notice issues?

@Swiftb0y
Copy link
Member Author

Swiftb0y commented Feb 13, 2024

Hmkay, which other members are you referring to? Future extension?

Yes, future additions. In can imagine that this will happen as the QML transition progresses and we'll want to expose enums to it.

My PR is build without issues, or when would we notice issues?

You'll notice issues when you will try to add the following to some file (other than preferences/constants.h):

namespace mixxx {
namespace preferences {
Q_NAMESPACE
// add any members here that need the Q_NAMESPACE (eg Q_ENUM_NS)
}}

The same goes for the constants namespace, but I think its unlikely that you'll want to add something to that namespace from a file other than preferences/constants.h.

@ronso0
Copy link
Member

ronso0 commented Feb 13, 2024

okay.

#include <QtGlobal>

#include "control/controlobject.h"
#include "control/controlproxy.h"
#include "defs_urls.h"
#include "moc_dlgprefinterface.cpp"
#include "preferences/constants.h"
Copy link
Member

Choose a reason for hiding this comment

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

can be moved to preferences/dialog/dlgpreferencepage.h to include it only once

Copy link
Member

Choose a reason for hiding this comment

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

... and be removed from src/mixxxmainwindow.cpp

Copy link
Member Author

Choose a reason for hiding this comment

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

are you sure about dlgpreferencepage.h? its not used in there anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

That's the baseclass of all pref pages, would it increase the include 'load' including it there?
If so, just leave as it is.

Copy link
Member Author

Choose a reason for hiding this comment

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

not really, but its bad practice as well. It also wouldn't make any difference in terms of compilation time. In general its best to include what you use at the point of usage and nowhere else...

Copy link
Member

Choose a reason for hiding this comment

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

okay. it's already included in the header

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, so the cppcoreguidelines don't say much about that. If you insist, I'll remove the header from the .cpp.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, please remove it. It'd be removed anyway with the next include cleanup.

Copy link
Member

Choose a reason for hiding this comment

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

Umm, this got a little mixed up, I was referring to the include in src/mixxxmainwindow.cpp.
Anyway, clean this up as much you like, I don't mind too much, just noticed it when looking for places where constants.h is included.

Copy link
Member Author

Choose a reason for hiding this comment

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

yup sorry. I don't think anymore cleanup is needed now.

@Swiftb0y
Copy link
Member Author

friendly ping @ronso0. If you're happy with the current state, I'll squash the fixup.

@ronso0
Copy link
Member

ronso0 commented Feb 27, 2024

No one else reviewed this, and my c++/enum knowledge can't compete with yours, so... it LGTM, it builds, it works AFAICT.
Ready for merge IMO.
If there are no objections within the next 24h I'll press the button @mixxxdj/developers

@ronso0
Copy link
Member

ronso0 commented Feb 27, 2024

Can you squash the fixups and push?

Comment on lines 3 to 15
// required for Qt-Macros
#include <QObject>

namespace mixxx {

namespace preferences {

namespace constants {
Q_NAMESPACE

// In order for this Q_NAMESPACE to work, all members of the namespace must
// be declared here. see QTBUG-68611

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 think for the other devs, this would be most controversial aspect. Putting a QObject header into this header just for the enums is not great in terms of compile-time overhead, but I think its a necessary evil anyways in order to make these enums usable from within QML.

Copy link
Member

Choose a reason for hiding this comment

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

Q_NAMESPACE is defined in qobjectdefs.h

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried that, but I got MOC errors.

Copy link
Member

Choose a reason for hiding this comment

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

I cannot confirm this. Which Qt version did you try? I tried 6.2.3 and 5.12.8.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried 5.15.12. Though I may be misremembering what header I tried.

@ronso0
Copy link
Member

ronso0 commented Mar 12, 2024

@mixxxdj/developers Does someone have time to take a look at this?

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

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

Thank you. I have just two comments.

@@ -1159,14 +1160,14 @@ bool MixxxMainWindow::eventFilter(QObject* obj, QEvent* event) {
"DlgPreferences") {
// return true for no tool tips
switch (m_toolTipsCfg) {
case mixxx::TooltipsPreference::TOOLTIPS_ONLY_IN_LIBRARY:
case mixxx::preferences::constants::Tooltips::OnlyInLibrary:
Copy link
Member

Choose a reason for hiding this comment

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

All the double :: look cluttered. Can we remove the "constants" namespace?

Copy link
Member

Choose a reason for hiding this comment

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

we discussed that here #12798 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I just read it. I can however not follow the reasoning. This PR introduces both "preferences::constants" there is no need to make it that long just to safe the "preferences" namespace for future use. We can introduce another independent namespace all the time.

Btw: We have no policy of folder matching namespaces like in C#

Copy link
Member Author

Choose a reason for hiding this comment

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

We can introduce another independent namespace all the time.

Right, but what if you want to use the preferences namespace? If its really about characters being typed/read, I can rename it to prefs::c I guess... but I really doubt that avoiding long namespaces here has any value. Avoiding nesting here also wouldn't have much value IMO.

We have no policy of folder matching namespaces like in C#

I'm aware, but the restriction on Q_NAMESPACE does force us to us to only declare the namespace in a single file, which is why it make sense to name it the same as the filename.

Copy link
Member

Choose a reason for hiding this comment

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

I have just checked how others do this:
They define a namespace each type and than class less enums:
https://github.com/zhuzichu520/FluentUI/blob/f830d5a9bfc0f6836e6e2aa7c80d7201b730013f/src/Def.h#L95
https://github.com/KDE/kdenlive/blob/7283b739900a01ef3caf86d458bedcf418ce1f60/src/definitions.h#L119

Lets follow them and not introduce preferences and constants namespace. Just mixxx is sufficient IMHO.

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 don't like the class-less enums though. There is no reason to open up this enum to implicit conversions to int etc. wbout

namespace mixxx {
namespace Tooltips {
Q_NAMESPACE
enum class TooltipsOptions {...}
Q_ENUM_NS(TooltipsOptions)
using enum TooltipsOptions;
}
}

would that work for you?

Copy link
Member

Choose a reason for hiding this comment

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

The reason is to get rid of the enum class namespace when using the enum in QML and use the extra namespace instead.

But it also works for me if we get rid of at least one of the extra namespaces as you like.

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 reason is to get rid of the enum class namespace when using the enum in QML and use the extra namespace instead.

Well, QML is a different discussion here. IIUC we can rename the type as we'd like. I'm primarily focused on the C++ ergonomics right now.

Comment on lines 3 to 15
// required for Qt-Macros
#include <QObject>

namespace mixxx {

namespace preferences {

namespace constants {
Q_NAMESPACE

// In order for this Q_NAMESPACE to work, all members of the namespace must
// be declared here. see QTBUG-68611

Copy link
Member

Choose a reason for hiding this comment

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

Q_NAMESPACE is defined in qobjectdefs.h

@github-actions github-actions bot added the qml label Mar 20, 2024
@Swiftb0y
Copy link
Member Author

friendly ping @daschuer

@Swiftb0y Swiftb0y force-pushed the refactor/preferences-enums branch from 5cfa85e to 25f796f Compare May 16, 2024 13:17
@Swiftb0y
Copy link
Member Author

I removed the namespace naming requirement by use of an inline namespace. wdyt @daschuer?

Comment on lines 151 to 153
mixxx::TooltipsPreference m_toolTipsCfg;
mixxx::Tooltips m_toolTipsCfg;

mixxx::ScreenSaverPreference m_inhibitScreensaver;
mixxx::ScreenSaver m_inhibitScreensaver;
Copy link
Member Author

Choose a reason for hiding this comment

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

this looks a little short now, wdyt about reintroducing the preferences namespace again? Adding it to the enum name looks a little clunky.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, mixxx:screensaver would imply a subsystem about screensaver handling. something like mixxx::preferences::screensaver make sense

@daschuer
Copy link
Member

I removed the namespace naming requirement by use of an inline namespace. wdyt @daschuer?

Interesting. I didn't even know this feature exists.

Works for me:

            case mixxx::TooltipsPreference::TOOLTIPS_ONLY_IN_LIBRARY: // original 
            case mixxx::preferences::Tooltips::OnlyInLibrary: // proposal 

@Swiftb0y Swiftb0y force-pushed the refactor/preferences-enums branch from e43dc15 to ae28ae4 Compare May 17, 2024 08:31
@Swiftb0y
Copy link
Member Author

@daschuer I think I addressed everything

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

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

LGTM, Thank you for polishing this.

@daschuer daschuer merged commit 8e4d26e into mixxxdj:main May 21, 2024
13 checks passed
@Swiftb0y Swiftb0y deleted the refactor/preferences-enums branch May 21, 2024 08:59
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.

4 participants