Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
Mindtraveller is currently offline  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 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1781
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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 #37551 is a reply to message #37549] Tue, 16 October 2012 18:39 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1781
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

I couldn't resist Smile I just had to try to implement the templated version of *Spin ctrls. I proposed it to Mirek for inclusion into CtrlLib, you can see it here: http://www.ultimatepp.org/redmine/issues/336 and of course, you can use it even if Mirek deems it unusable for U++...

Honza
Re: Custom check for EditIntXxxx controls [message #37574 is a reply to message #37551] Fri, 19 October 2012 12:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13442
Registered: November 2005
Ultimate Member
Generic WithSpin template now available...

Mirek
Re: Custom check for EditIntXxxx controls [message #37607 is a reply to message #37574] Thu, 25 October 2012 08:02 Go to previous message
Mindtraveller is currently offline  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

Previous Topic: BUG?: EditString Text rendering not stable with some Strings
Next Topic: need some expert advice to extend the LineEdit
Goto Forum:
  


Current Time: Sat Oct 23 15:46:17 CEST 2021

Total time taken to generate the page: 0.01497 seconds