Extract KPasswordLineEdit class
ClosedPublic

Authored by mlaurent on Jul 31 2017, 5:33 AM.

Details

Summary

Now we can use lineedit password outside kpassworddialog.
It's useful in kdepim for example.

Test Plan

I added autotest and test apps.

Diff Detail

Repository
R236 KWidgetsAddons
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
There are a very large number of changes, so older changes are hidden. Show Older Changes
cfeck added inline comments.Jul 31 2017, 3:55 PM
autotests/knewpasswordwidgettest.cpp
63

Does using setPassword() not work for these tests?

src/knewpasswordwidget.cpp
75

See discussion about properies.

src/knewpasswordwidget.ui
81

Why this sizeHint?

src/passwordlineedit.h
29 ↗(On Diff #17420)

Please add a Q_PROPERTY for password, including passwordChanged() signal (NOTIFY method).

Applications should not have to deal with the passwordLineEdit() function in the regular use-case, but having the accessor function for special purpose is a good idea.

46 ↗(On Diff #17420)

Either remove the 'p', or name it 'password'.

cfeck requested changes to this revision.Jul 31 2017, 3:57 PM
kossebau added inline comments.
src/passwordlineedit.h
27 ↗(On Diff #17420)

Surprised to see no K-prefix being used here? Why that?

Please add one and rename to KPasswordLineEdit:

  • for consistency with the existing classes from kwidgetaddons/kde frameworks
  • to protect against potential clashes, even if rare chance, with existing code linking to kwidgetaddons, which assumes using unprefixed/namespace-less names is safe in own code and might use that name for something else already.
  • namespace-less class name lack any hint to origin, but rather used for project-internal code, so confuses code readers
mlaurent added inline comments.Jul 31 2017, 4:36 PM
autotests/knewpasswordwidgettest.cpp
63

Nope as setPassword not authorize to see icon (it's a security when we setPassword from apps you don't want to see it)

src/knewpasswordwidget.ui
81

designer bug :)

src/kpassworddialog.ui
191

manual ? :) nope it's designer which added it

src/passwordlineedit.h
27 ↗(On Diff #17420)

Just for info LineEditUrlDropEventFilter has not K prefix
but ok I will rename it

mlaurent marked 5 inline comments as done.Jul 31 2017, 6:08 PM
kossebau added inline comments.Jul 31 2017, 9:57 PM
autotests/knewpasswordwidgettest.cpp
63

Could you add this as comment to this line? it is not directly obvious, so would be good to store this knowledge directly in the code, so the next code reader gets why the code is like this.

src/passwordlineedit.h
24 ↗(On Diff #17420)

Can be removed, given the QLineEdit include (for QLineEdit::EchoMode)

27 ↗(On Diff #17420)

Thanks :) Yes, seems LineEditUrlDropEventFilter slipped in without somebody catching that.

When you do could you please also adapt PasswordLineEditPrivate? Even the test best would follow the naming pattern, so when scanning the dir with tests to find the matching test, it is found where expected (with default sorting by names).

27 ↗(On Diff #17420)

Please also add API dox comment in front of the class, otherwise kapidox and ecm_add_qch will not pick up this class, given their doxygen settings.

33 ↗(On Diff #17420)

@since should go to central class api dox comment (see other comment), or be behind the @param (see https://community.kde.org/Frameworks/Frameworks_Documentation_Policy#Document_Public_and_Protected_Members).

61 ↗(On Diff #17420)

For a complete API this would also have isClearButtonEnabled() const here, and making this a clearButtonEnabled property.

With these properties e.g. integration in Qt Designer can be improved.

66 ↗(On Diff #17420)

getter missing as well for balanced api, and should become a property as well.

94 ↗(On Diff #17420)

Please add api dox for this signal. Which echo mode is triggered here? and can't it be reverted?

97 ↗(On Diff #17420)

can be removed, class already forward-declared at the beginning, as normal non-nested one (as helpful for avoing visibility inheritance).

mlaurent updated this revision to Diff 17469.Aug 1 2017, 5:04 AM
mlaurent marked 7 inline comments as done.
mlaurent edited edge metadata.

I renamed class/test apps/autotests as requested
I fixed autotest with new autotest from master
I fixed all comment on this review
etc.

kossebau added inline comments.Aug 1 2017, 5:25 AM
src/kpasswordlineedit.cpp
31

Make this a normal class KPasswordLineEditPrivate here, following fixes proposed above for the header.

src/kpasswordlineedit.h
26

change to KPasswordLineEditPrivate, so it is the forward declaration of the non-nested private class which KPasswordLineEdit should use.

50

better name this property clearButtonEnabled instead of clearButton, following the property name in qlinedit

129

Thanks for the docs. Hm, the name "echoModeTriggered" by itself is telling me that some "echomode" is triggered. While actually the signal tells that the echomode has been toggled/changed. So I would propose to rename it.

And ideally the signal would also carry the new echo mode, so the slot does not need to query again what the new mode is.
Just an suggestion while you expose this as public API, I see the old internal code was fine to just query again. But not really matching the typical Qt-style API that we all so like :)

Perhaps consider changing this to
void echoModeChanged(QLineEdit::EchoMode echoMode);

134

Remove this embedded class forward declaration -> results in leaked symbols due to visibility inherited.

mlaurent updated this revision to Diff 17470.Aug 1 2017, 6:46 AM

Create a real class for private class as requested
+ fix signal
etc.

mlaurent retitled this revision from Extract lineedit password to Extract KPasswordLineEdit class.Aug 1 2017, 7:16 AM
mlaurent updated this revision to Diff 17471.Aug 1 2017, 7:19 AM

Rename method as lineEdit as requested by David

mlaurent updated this revision to Diff 17533.Aug 2 2017, 4:54 AM

Fix copyright

kossebau added inline comments.Aug 2 2017, 5:11 AM
src/knewpasswordwidget.ui
88

rather extends QWidget now? unsure what exactly the consequences are

src/kpassworddialog.ui
163

Again QWidget?

src/kpasswordlineedit.h
7

Should this not be rather lgpl2_+_?
see https://community.kde.org/Policies/Licensing_Policy

mlaurent added inline comments.Aug 2 2017, 5:36 AM
src/knewpasswordwidget.ui
88

The consequence is that we don't see it in designer :)
So why not but it's better to show a lineedit no ?

src/kpasswordlineedit.h
7

I copied same license as knewpasswordwidget so I think it was ok.
So license is not the same in all kwidgetaddons ?

mlaurent updated this revision to Diff 17535.Aug 2 2017, 6:06 AM

Use a correct license (I copied a header from david class so I think it's ok now) as in kwidgetaddons there is lgpl2 lgpl2.1 lgpl3 lgpl...

I didn't change ui file a QWidget otherwise we can't see qlineedit in designer.

dfaure edited edge metadata.Aug 2 2017, 7:15 AM

But if you use QLineEdit as a base class, the developer can set properties for a QLineEdit, which might not apply to KPasswordLineEdit.

Better add the widget to the kdesigner plugin framework, then you'll have proper integration with Qt Designer.

mlaurent updated this revision to Diff 17541.Aug 2 2017, 7:40 AM

I created a designer plugin for it, I will put url here after create review
I add property for echo mode
Now we can see lineedit in designer (created from a plugin)

cfeck added inline comments.Aug 2 2017, 7:42 PM
autotests/CMakeLists.txt
21

If that file is sorted (at least a bit), try to insert instead of append. Same for other places.

src/knewpasswordwidget.cpp
118

Can you double-check this change? To me, the echoMode() checks are now reversed compared to the original code.

I have not tested the code yet :)

src/kpasswordlineedit.cpp
31

Does this class need to be a QObject? If not, remove the QObject stuff.

src/kpasswordlineedit.h
134

Also needs the const QString &password argument.

Or if I misunderstand it, what is the difference between passwordChanged() and textChanged()? This class has no text() property, so having a textChanged() looks unexpected.

mlaurent marked 3 inline comments as done.Aug 3 2017, 4:42 AM
mlaurent added inline comments.
src/knewpasswordwidget.cpp
118

Nope it's ok as code is called after changing echomode
I created an autotest for testing it

mlaurent updated this revision to Diff 17606.Aug 3 2017, 4:43 AM
mlaurent marked an inline comment as done.

Fix include order, remove textChanged, add argument to signal etc.

elvisangelaccio added inline comments.Aug 3 2017, 8:42 AM
src/knewpasswordwidget.cpp
118

Then please rename the slot to _k_echoModeToggled, otherwise is confusing.

cfeck added inline comments.Aug 3 2017, 8:50 AM
src/kpasswordlineedit.cpp
31

Ping?

src/kpasswordlineedit.h
54

NOTIFY echoModeChanged

84

Document default value.

94

Please document the default value. If it is indeed QLineEdit::Password (which I would expect), remove the properties from the .ui files.

cfeck added inline comments.Aug 3 2017, 8:54 AM
src/knewpasswordwidget.cpp
118

Ah, now I understand. Also, use the passed echoMode, instead of accessing lineEdit().

cfeck added inline comments.Aug 3 2017, 9:07 AM
src/knewpasswordwidget.cpp
75

While you are at renaming slots: -> _k_passwordChanged

src/kpasswordlineedit.h
122

Please move the documentation for public functions above the documentation for internal functions (for those that read .h files, instead of apidox).

cfeck added inline comments.Aug 3 2017, 9:14 AM
src/knewpasswordwidget.cpp
75

Ah wait, you are using the same slot for the verify widget, so maybe scratch that comment.

mlaurent marked 4 inline comments as done.Aug 3 2017, 9:46 AM
mlaurent added inline comments.
src/knewpasswordwidget.cpp
118

we can't as we use it in :
connect(toggleEchoModeAction, &QAction::triggered, this, &KPasswordLineEditPrivate::_k_echoModeToggled);

mlaurent updated this revision to Diff 17615.Aug 3 2017, 9:47 AM

Fix all comment reported

cfeck added inline comments.Aug 3 2017, 9:59 AM
src/kpasswordlineedit.cpp
31

You made it a namespaced class again. Why?

mlaurent added inline comments.Aug 3 2017, 10:01 AM
src/kpasswordlineedit.cpp
31

Otherwise it failed to using Q_PRIVATE_SLOT...

cfeck added inline comments.Aug 3 2017, 10:09 AM
src/kpasswordlineedit.cpp
31

That's fishy. I just checked a single class (KColumnResizer), and it has just "class KColumnResizerPrivate" (no namespace, no QObject), and still has a Q_PRIVATE_SLOT in its KColumnResizer class.

mlaurent added inline comments.Aug 3 2017, 10:41 AM
src/kpasswordlineedit.cpp
31

wierd it didn't want to build, but after a make clean it works...
next patch will come soon (12)

kfunk added a subscriber: kfunk.Aug 3 2017, 10:41 AM
kfunk added inline comments.
src/kpasswordlineedit.cpp
31

+1. Don't use nested private classes. Nested classes/structs inherit the symbols visibility.

Also see: https://phabricator.kde.org/D6927

PS: In times of Qt5 & lambda-connects, you don't need Q_PRIVATE_SLOT anymore, anyway:
Just remove the Q_PRIVATE_SLOT marker and ...:
connect(..., this, [this](...) { d->myPrivateSlot(...); });

mlaurent updated this revision to Diff 17620.Aug 3 2017, 11:17 AM

Remove Q_PRIVATE_SLOT

cfeck added inline comments.Aug 3 2017, 11:25 AM
src/kpasswordlineedit.cpp
4

Elvis, you wrote the "visibilityAction" stuff, right? If yes, needs to be mentioned here.

27

QLineEdit is included in the .h file, can be removed here.

37

Remove empty line.

61

Remove doubled empty line.

117

Does this need a protection for not emitting if the value did not actually change? I think it helps to prevent recursion.

cfeck added inline comments.Aug 3 2017, 11:32 AM
src/kpasswordlineedit.cpp
31

Oh, that would make a nice "junior job" to get those cleaned out everywhere. Is removing a private slot considered API/ABI compatible?

cfeck added a comment.Aug 3 2017, 11:47 AM

Looks good to go from my side. Let's wait a bit if someone has more objections.

Thanks Laurent, it was a needed change considering the code duplication that was present before.

+1, looks good to me now.

dfaure accepted this revision.Aug 3 2017, 2:45 PM
cfeck accepted this revision.Aug 3 2017, 3:37 PM

Together with the Designer stuff, please.

This revision is now accepted and ready to land.Aug 3 2017, 3:38 PM
This revision was automatically updated to reflect the committed changes.