Do not assign combobox currentIndex as it breaks binding.
ClosedPublic

Authored by crossi on Oct 28 2019, 9:43 AM.

Details

Summary

Binding with combobox index was broken, as discussed in D24916

As stated in Qt https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#delegate-prop
When using ItemDelegate no need to explicitly close the popup and set the currentIndex.

Test Plan

Use kcm_cursortheme

2 test case

  • In size combobx, change the value, hit apply, then press default, should reset combobox value to default
  • Also in size combobx, press and hold the mose, hover to change the value and then release mouse button to set the new value, hit apply, then hit default, combobox value should be set to default value.

Diff Detail

Repository
R858 Qt Quick Controls 2: Desktop Style
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
crossi created this revision.Oct 28 2019, 9:43 AM
Restricted Application added a project: Plasma. · View Herald TranscriptOct 28 2019, 9:43 AM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
crossi requested review of this revision.Oct 28 2019, 9:43 AM
crossi edited the summary of this revision. (Show Details)Oct 28 2019, 9:46 AM
crossi edited the test plan for this revision. (Show Details)
ervin added a comment.Oct 28 2019, 9:53 AM

Good start, there's one case still missing... which looks hard to reach, I wonder how to get there.

org.kde.desktop/ComboBox.qml
92

What about that one? :-)

crossi added inline comments.Oct 28 2019, 3:41 PM
org.kde.desktop/ComboBox.qml
92

Yes, this one breaks as well.

crossi updated this revision to Diff 69053.Oct 30 2019, 1:16 PM

Remove assignement to currentIndex.
Add a C++ bypass to setCurrentIndex without breaking the binding.

crossi edited the test plan for this revision. (Show Details)Oct 30 2019, 1:19 PM
ervin requested changes to this revision.Oct 30 2019, 2:01 PM

Almost there! Glad we're getting near a proper fix. Can you confirm this works with *and* without D24916 applied?
Can you also confirm this doesn't break the KScreen KCM? (as mentioned in Kai's comment on D24916).

I want to make sure we don't introduce a regression for those who had started to workaround that bug on their side.

plugin/kpropertywriter.h
1 ↗(On Diff #69053)

This file should be named kpropertywriter_p.h since it's not installed and the class not exported from a library.

39 ↗(On Diff #69053)

const QVariant &

43 ↗(On Diff #69053)

const QString &

47 ↗(On Diff #69053)

const QString &

50 ↗(On Diff #69053)

If you want to play like this, you could have had a "using QObject::QObject;" for the ctor declaration and have no ctor definition in the cpp file. ;-)

This revision now requires changes to proceed.Oct 30 2019, 2:01 PM
crossi updated this revision to Diff 69055.Oct 30 2019, 2:45 PM

Missing const ref, rename private header accordingly

There's a Plasma rule that if we're working round a Qt bug, there should be a Qt bug created and linked before accepting a workaround.

From the sounds of it we want a QQuickControls::ComboBox::setIndex(int) invokable that doesn't update the binding?
Or is it a more generic problem of somehow exposing QQmlPropertyData::WriteFlags ?

davidedmundson added inline comments.Oct 30 2019, 3:14 PM
plugin/kpropertywriter_p.h
27

Throwing out another option

class KPropertyWriter : public QObject, public QQmlPropertyValueSource
{
    Q_INVOKABLE bool writeProperty(QVariant value);
}

writeProperty(QVariant) {
  object()->setProperty(name(), value());
  // we can't use property().write() as that'll break the binding
}


PropertyWriter on currentIndex {
   id: controlRootWriter
}

Though it's basically the same thing, so don't feel you have to, just wanted to share the suggestion as it reduces two properties.

crossi edited the test plan for this revision. (Show Details)Oct 30 2019, 4:08 PM
ervin added a comment.Oct 30 2019, 5:39 PM

There's a Plasma rule that if we're working round a Qt bug, there should be a Qt bug created and linked before accepting a workaround.

From the sounds of it we want a QQuickControls::ComboBox::setIndex(int) invokable that doesn't update the binding?
Or is it a more generic problem of somehow exposing QQmlPropertyData::WriteFlags ?

It's the former, not the latter. And good luck having setIndex invokable, it would never go through a Qt review IMHO (and for good reason). Now we need this really because our own combo style insists on emulating a corner case of QComboBox behavior, it's fairly unusual and specific.
I don't think it warrants putting something in Qt directly.

ervin added inline comments.Oct 30 2019, 5:57 PM
plugin/kpropertywriter_p.h
27

Didn't think about that one, clever trick indeed. :-)

That being said I think it'd be more work in the end, indeed setTarget is pure virtual in there, and also I'm not sure that calling write() on QQmlProperty doesn't break bindings.

ervin accepted this revision.Oct 30 2019, 5:59 PM

Looks good to me. Please just wait a bit before pushing to give David a chance to object to my comments. ;-)

This revision is now accepted and ready to land.Oct 30 2019, 5:59 PM
crossi added inline comments.Oct 31 2019, 8:49 AM
plugin/kpropertywriter_p.h
27

Thank you for sharing other option, I didn't know this one.

This revision was automatically updated to reflect the committed changes.