-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Refactor/preferences enums #12798
Conversation
3daa394
to
89e4f89
Compare
okay, enough force pushing now. I'd appreciate a review. |
Looks good as far as I can tell, though I'd prefer to keep the constants compact therefore I removed the nested Commit is b771309, or Swiftb0y#18, as you prefer. |
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 |
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.
You'll notice issues when you will try to add the following to some file (other than 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 |
okay. |
#include <QtGlobal> | ||
|
||
#include "control/controlobject.h" | ||
#include "control/controlproxy.h" | ||
#include "defs_urls.h" | ||
#include "moc_dlgprefinterface.cpp" | ||
#include "preferences/constants.h" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
82451d4
to
3898dca
Compare
friendly ping @ronso0. If you're happy with the current state, I'll squash the fixup. |
No one else reviewed this, and my c++/enum knowledge can't compete with yours, so... it LGTM, it builds, it works AFAICT. |
Can you squash the fixups and push? |
src/preferences/constants.h
Outdated
// 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 | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
3898dca
to
1a6ebd6
Compare
@mixxxdj/developers Does someone have time to take a look at this? |
There was a problem hiding this 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.
src/mixxxmainwindow.cpp
Outdated
@@ -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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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#
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/preferences/constants.h
Outdated
// 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 | ||
|
There was a problem hiding this comment.
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
friendly ping @daschuer |
5cfa85e
to
25f796f
Compare
I removed the namespace naming requirement by use of an |
src/mixxxmainwindow.h
Outdated
mixxx::TooltipsPreference m_toolTipsCfg; | ||
mixxx::Tooltips m_toolTipsCfg; | ||
|
||
mixxx::ScreenSaverPreference m_inhibitScreensaver; | ||
mixxx::ScreenSaver m_inhibitScreensaver; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Interesting. I didn't even know this feature exists. Works for me:
|
e43dc15
to
ae28ae4
Compare
ae28ae4
to
da7e474
Compare
@daschuer I think I addressed everything |
There was a problem hiding this 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.
Alternative to #12796 along with a little extra refactoring