Skip to content

Commit b67f92b

Browse files
committed
all: use BINDABLE only with trivial setters
Fixes various bugs caused by the QML engine bypassing setters when BINDABLE is specified (even if the bindable is const). Also restructures all properties using BINDABLE to have a default READ and WRITE to ensure this doesn't happen again.
1 parent 2e3c15f commit b67f92b

File tree

10 files changed

+168
-181
lines changed

10 files changed

+168
-181
lines changed

src/core/util.hpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,6 @@ bool setSimpleObjectHandle(auto* parent, auto* value) {
282282
return SimpleObjectHandleOps<member, destroyedSlot, changedSignal>::setObject(parent, value);
283283
}
284284

285-
// NOLINTBEGIN
286-
#define QS_TRIVIAL_GETTER(Type, member, getter) \
287-
[[nodiscard]] Type getter() { return this->member; }
288-
289-
#define QS_BINDABLE_GETTER(Type, member, getter, bindable) \
290-
[[nodiscard]] Type getter() { return this->member.value(); } \
291-
[[nodiscard]] QBindable<Type> bindable() { return &this->member; }
292-
// NOLINTEND
293-
294285
template <auto methodPtr>
295286
class MethodFunctor {
296287
using PtrMeta = MemberPointerTraits<decltype(methodPtr)>;

src/services/mpris/player.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ MprisPlayer::MprisPlayer(const QString& address, QObject* parent): QObject(paren
148148
}
149149

150150
void MprisPlayer::raise() {
151-
if (!this->canRaise()) {
151+
if (!this->bCanRaise) {
152152
qWarning() << "Cannot call raise() on" << this << "because canRaise is false.";
153153
return;
154154
}
@@ -157,7 +157,7 @@ void MprisPlayer::raise() {
157157
}
158158

159159
void MprisPlayer::quit() {
160-
if (!this->canQuit()) {
160+
if (!this->bCanQuit) {
161161
qWarning() << "Cannot call quit() on" << this << "because canQuit is false.";
162162
return;
163163
}
@@ -168,7 +168,7 @@ void MprisPlayer::quit() {
168168
void MprisPlayer::openUri(const QString& uri) { this->player->OpenUri(uri); }
169169

170170
void MprisPlayer::next() {
171-
if (!this->canGoNext()) {
171+
if (!this->bCanGoNext) {
172172
qWarning() << "Cannot call next() on" << this << "because canGoNext is false.";
173173
return;
174174
}
@@ -177,7 +177,7 @@ void MprisPlayer::next() {
177177
}
178178

179179
void MprisPlayer::previous() {
180-
if (!this->canGoPrevious()) {
180+
if (!this->bCanGoPrevious) {
181181
qWarning() << "Cannot call previous() on" << this << "because canGoPrevious is false.";
182182
return;
183183
}
@@ -186,7 +186,7 @@ void MprisPlayer::previous() {
186186
}
187187

188188
void MprisPlayer::seek(qreal offset) {
189-
if (!this->canSeek()) {
189+
if (!this->bCanSeek) {
190190
qWarning() << "Cannot call seek() on" << this << "because canSeek is false.";
191191
return;
192192
}
@@ -226,7 +226,7 @@ void MprisPlayer::setPosition(qreal position) {
226226
return;
227227
}
228228

229-
if (!this->canSeek()) {
229+
if (!this->bCanSeek) {
230230
qWarning() << "Cannot set position of" << this << "because canSeek is false.";
231231
return;
232232
}
@@ -275,7 +275,7 @@ bool MprisPlayer::lengthSupported() const { return this->bInternalLength != -1;
275275
bool MprisPlayer::volumeSupported() const { return this->pVolume.exists(); }
276276

277277
void MprisPlayer::setVolume(qreal volume) {
278-
if (!this->canControl()) {
278+
if (!this->bCanControl) {
279279
qWarning() << "Cannot set volume of" << this << "because canControl is false.";
280280
return;
281281
}
@@ -353,7 +353,7 @@ void MprisPlayer::setPlaybackState(MprisPlaybackState::Enum playbackState) {
353353

354354
switch (playbackState) {
355355
case MprisPlaybackState::Stopped:
356-
if (!this->canControl()) {
356+
if (!this->bCanControl) {
357357
qWarning() << "Cannot set playbackState of" << this
358358
<< "to Stopped because canControl is false.";
359359
return;
@@ -362,15 +362,15 @@ void MprisPlayer::setPlaybackState(MprisPlaybackState::Enum playbackState) {
362362
this->player->Stop();
363363
break;
364364
case MprisPlaybackState::Playing:
365-
if (!this->canPlay()) {
365+
if (!this->bCanPlay) {
366366
qWarning() << "Cannot set playbackState of" << this << "to Playing because canPlay is false.";
367367
return;
368368
}
369369

370370
this->player->Play();
371371
break;
372372
case MprisPlaybackState::Paused:
373-
if (!this->canPause()) {
373+
if (!this->bCanPause) {
374374
qWarning() << "Cannot set playbackState of" << this << "to Paused because canPause is false.";
375375
return;
376376
}
@@ -420,7 +420,7 @@ void MprisPlayer::onPlaybackStatusUpdated() {
420420
bool MprisPlayer::loopSupported() const { return this->pLoopStatus.exists(); }
421421

422422
void MprisPlayer::setLoopState(MprisLoopState::Enum loopState) {
423-
if (!this->canControl()) {
423+
if (!this->bCanControl) {
424424
qWarning() << "Cannot set loopState of" << this << "because canControl is false.";
425425
return;
426426
}
@@ -468,7 +468,7 @@ void MprisPlayer::setShuffle(bool shuffle) {
468468
return;
469469
}
470470

471-
if (!this->canControl()) {
471+
if (!this->bCanControl) {
472472
qWarning() << "Cannot set shuffle state of" << this << "because canControl is false.";
473473
return;
474474
}
@@ -478,7 +478,7 @@ void MprisPlayer::setShuffle(bool shuffle) {
478478
}
479479

480480
void MprisPlayer::setFullscreen(bool fullscreen) {
481-
if (!this->canSetFullscreen()) {
481+
if (!this->bCanSetFullscreen) {
482482
qWarning() << "Cannot set fullscreen for" << this << "because canSetFullscreen is false.";
483483
return;
484484
}

0 commit comments

Comments
 (0)