Home » U++ Library support » LineEdit, EditFields, DocEdit » Custom check for EditIntXxxx controls
Custom check for EditIntXxxx controls [message #37549] |
Tue, 16 October 2012 13:32  |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |

|
|
Hello! Sorry if my question is noobish, but I failed to find how to achieve what I need - add "checking ability" to a number of different controls (like EditIntSpin). This means that when user edits the value, the control is coloured red if value is inappropriate (with some calculations involving program logic from different classes).
If I instanitate my own classes from EditIntSpin and etc. - how could I switch control to "red" mode? Is there any better ways to achieve it not creating addtional classes?
Thanks in advance!
[Updated on: Tue, 16 October 2012 13:33] Report message to a moderator
|
|
|
Re: Custom check for EditIntXxxx controls [message #37550 is a reply to message #37549] |
Tue, 16 October 2012 15:09   |
|
Hi Pavel,
Edit*Spin ctrls are unfortunately not templates, so I'm afraid it is not really simple to "inject" them with custom value checking code (aside from the default min/max/notNull constraints).
For Edit* ctrls, you can achieve this simply by writing custom Convert based class and declare the type using typedef. E.g. for EditInt with your custom logic:typedef EditValue<int, MyConvert> MyEditInt; The input will be marked as invalid if your MyConvert class returns ErrorValue (see docs and/or Core/Convert.h). If you also want the spin buttons, you'll probably have to add them yourself, but it should be easy if you follow the code in original EditIntSpin class.
Best regards,
Honza
|
|
|
|
|
Re: Custom check for EditIntXxxx controls [message #37607 is a reply to message #37574] |
Thu, 25 October 2012 08:02  |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |

|
|
OK, finally a little report on results.
Sorry to say that ErrorValue doesn't work very well here. This happens due to the fact it doesn't convert too well into integer value. So you may return ErrorValue(FormatInt(...)) and it will work. But when user pressses (inc) or (dec) spin buttons, the value is immediately switched to -INT_MAX, and there is no way to change this behaviour from user code.
Concluding my experiments, the best way to make control customly checkable is this:
1) Derive MyCustomConvert from one of Convert classes (e.g. ConvertInt). Make any checks in there.
2) For MyCustomConvert provide reference to target EditField derived class. MyCustomConvert clears/sets error state with EditField::Error().
3) Use any Edit*** controls and set your MyCustomConvert with EditField::SetConvert function() providing reference to your Edit*** control.
[Updated on: Thu, 25 October 2012 08:03] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Tue Apr 29 09:29:46 CEST 2025
Total time taken to generate the page: 0.00767 seconds
|