Bug 161012 - KRestrictedLine needs API changes to support multi-char input (due to keyevent compression or input method events)
Summary: KRestrictedLine needs API changes to support multi-char input (due to keyeven...
Status: RESOLVED WORKSFORME
Alias: None
Product: kdelibs
Classification: Unmaintained
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Dario Andres
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-19 15:09 UTC by Tomas Mecir
Modified: 2020-12-08 04:34 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
patch (767 bytes, patch)
2008-04-19 15:10 UTC, Tomas Mecir
Details
(Old) patch to use a QValidator (3.43 KB, patch)
2009-09-01 14:12 UTC, Dario Andres
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tomas Mecir 2008-04-19 15:09:35 UTC
Version:            (using Devel)
Installed from:    Compiled sources
Compiler:          gcc (GCC) 4.1.2 20061115 (prerelease) (SUSE Linux) 
OS:                Linux

I tried to use KRestrictedLine in my application, only to find out that the current version of KRestrictedLine doesn't work at all - setting any set of valid characters has no effect, it's still possible to write anything into the input line.

The attached patch should fix this problem - partially at least, as it's still possible to copy/paste wrong characters.

I don't know if KRestrictedLine is meant to be deprecated or not, either way, I suppose I'm going to use KLineEdit with a validator instead.

The patch:

Index: kdeui/widgets/krestrictedline.cpp
===================================================================
--- kdeui/widgets/krestrictedline.cpp   (revision 798773)
+++ kdeui/widgets/krestrictedline.cpp   (working copy)
@@ -49,7 +49,7 @@
 {
   // let KLineEdit process "special" keys and return/enter
   // so that we still can use the default key binding
-  if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Delete || e->text().length() < 32)
+  if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace || (e->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::GroupSwitchModifier)))
     {
       KLineEdit::keyPressEvent(e);
       return;
Comment 1 Tomas Mecir 2008-04-19 15:10:31 UTC
Created attachment 24405 [details]
patch

Attaching the patch as a file.
Comment 2 Markus Lohse 2009-03-30 20:37:02 UTC
Any progress/info on this bug? I just encountered the same problem in my application.
Comment 3 Dario Andres 2009-05-11 01:46:58 UTC
The patch works but the general implementation is not the best, as it can't filter out characters like "á" ('+a) as they aren't detected in the keyPressEvent

I managed to write a better implementation that will work with every key using a custom QValidator. However it breaks the current behaviour of the "invalidChar(int)" signal as it returns a keycode, and such isn't possible when using the QValidator method

I'm going to apply the patch until I can manage to improve the QValidator approach
Regards
Comment 4 Dario Andres 2009-05-11 01:51:06 UTC
SVN commit 966333 by darioandres:

Fix the broken behaviour of KRestrictedLine
(this needs a better implementation)

BUG: 161012


 M  +3 -1      krestrictedline.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=966333
Comment 5 Dario Andres 2009-05-11 01:53:01 UTC
SVN commit 966335 by darioandres:

Backport to 4.2branch of:
SVN commit 966333 by darioandres:

Fix the broken behaviour of KRestrictedLine
(this needs a better implementation)

CCBUG: 161012



 M  +3 -1      krestrictedline.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=966335
Comment 6 Dario Andres 2009-05-11 01:53:49 UTC
Reopening as this is not fully fixed. (but it should work as the older versions)
Comment 7 David Faure 2009-08-21 13:56:39 UTC
SVN commit 1014077 by dfaure:

Fix KRestrictedLine to not let composed characters like éèú etc. go through, if they're not wanted.

And add test code for KRestrictedLine in klineedittest.
But with possible event compression in keyPressEvent and the way inputMethodEvent works, we really
get QStrings as input, not "int key" like the API assumes here.
So we should really use a validator instead, so we can remove unwanted chars and
keep the others, which means a different signal signature.
Dario, can you commit your validator, commented out, for kde5? :-)
CCBUG: 161012


 M  +22 -1     tests/klineedittest.cpp  
 M  +6 -1      tests/klineedittest.h  
 M  +38 -20    widgets/krestrictedline.cpp  
 M  +3 -3      widgets/krestrictedline.h  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1014077
Comment 8 Dario Andres 2009-09-01 14:12:31 UTC
Created attachment 36616 [details]
(Old) patch to use a QValidator

The patch it is a bit old and I have already discovered some errors (small style issues), the invalidChar signal not being connected properly. But that can wait for KDE5.
Comment 9 Justin Zobel 2020-11-08 00:36:23 UTC
Thanks for the report Tomas. Are you able to confirm if this is still an issue when building using KRestricedLine, thanks.
Comment 10 Bug Janitor Service 2020-11-23 04:33:47 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 11 Bug Janitor Service 2020-12-08 04:34:11 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!