[1/5] Access readOnly state of FormWidgets dynamically
ClosedPublic

Authored by aheinecke on Feb 26 2018, 2:31 PM.

Details

Summary

This is more of a cleanup patch that removes the obsolete m_canBeEnabled
member variable which was a leftover IMO from a time where readOnly fields were
shown as disabled. readOnly fields are invisible, not disabled, and the code no longer assumes that
readOnly does not change over time.

Test Plan

Tested manually and with a unittest which is part of the series.

Diff Detail

Repository
R223 Okular
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
aheinecke added inline comments.Feb 26 2018, 2:35 PM
ui/pageview.cpp
1002 ↗(On Diff #28113)

Without this change the PartTest::testSaveAsUndoStackForms would segfault because the underlying fields are destroyed but setCanBeFilled now accesses them to check for readOnly.

aacid added a subscriber: aacid.Mar 3 2018, 10:45 PM

BTW next time please use arc so phabricator shows the context of the diff.

ui/formwidgets.cpp
304

i would really prefer this to be moved to whoever calls setVisiblity, it's kind of weird for setVisiblity to sometimes not do what you ask it to do.

310

Do we need this at all? the widget won't ge visible when it's readonly, so what do we care if it's enabled or not?

ui/pageview.cpp
1002 ↗(On Diff #28113)

If we remove the use of visiblity as i commented already we can get this back to how it was?

BTW next time please use arc so phabricator shows the context of the diff.

Apologies, I'll try. While I like phabricator I'm not very skilled with arcanist, yet. :-}

ui/formwidgets.cpp
304

Yes, Indeed. I'll update the Differential accordingly.

310

As I understand it there is a case where Forms are bisible, but disabled.
This is if in "PageView::notifySetup" the check for:

const bool allowfillforms = d->document->isAllowed( Okular::AllowFillForms );

Returns false.
Then Okular will show all FormWidgets which are not readOnly disabled. I'm not sure if that makes much sense but as there is the extra code with "setCanBeFilled" I thought I should better leave that behavior because someone intended it that way at some point ;-)

ui/pageview.cpp
1002 ↗(On Diff #28113)

No, setCanBeFilled accesses isReadOnly. This crashes if the formWidgets are not yet updated with the new fields.

I also think that it is better to only modify the field here and not earlier to avoid working with formWidgets that have dangling pointers to deleted fields in them.

aheinecke updated this revision to Diff 28706.Mar 5 2018, 1:09 PM

Removed implicit readOnly handling in setVisiblitiy and updated
callers instead.

Also the differential is now published with arcanist ;-)

aacid added inline comments.Mar 13 2018, 11:03 PM
ui/formwidgets.cpp
310

sure, if allowfillforms is false, we will call setCanBeFilled with false and it will be setEnabled to false.

What I am asking is why do we need to call isReadOnly here. As far as i understand if the field is readonly, it won't be shown, so the enabled status of it doesn't matter, no?

aheinecke added inline comments.Mar 14 2018, 8:42 AM
ui/formwidgets.cpp
310

Oh, Sorry. I misunderstood your first comment and thought you questioned the need for the allowFillForms in general.

As for the read only check according to git blame this check was added ( 8e70c16f ) at a time where readOnly fields were visible but disabled and now that they are invisible it should indeed no longer be needed.

I tried to think of a way how a readOnly field could / should be visible but disabled and also can't think of a way. I'll remove the check.

aheinecke updated this revision to Diff 29471.Mar 14 2018, 8:43 AM

Removed check for readOnly in setCanBeFilled

aacid added inline comments.Mar 14 2018, 10:36 PM
ui/pageview.cpp
1002 ↗(On Diff #28113)

Ok, so now that setCanBeFilled doesn't access the form, do we really need this extra if?

aheinecke added inline comments.Mar 15 2018, 5:56 AM
ui/pageview.cpp
1002 ↗(On Diff #28113)

No. :-)

aheinecke updated this revision to Diff 29566.Mar 15 2018, 5:58 AM

Remove superfluous check / reorder in PageView::notifySetup

As noted by aacid we don't need the check anymore now that
setCanBeFilled does not access the underlying fields.

aacid accepted this revision.Mar 20 2018, 10:25 PM
This revision is now accepted and ready to land.Mar 20 2018, 10:25 PM
This revision was automatically updated to reflect the committed changes.