[Qt-components] Validation of properties in the proposed Calendar API

Mitch Curtis mitch.curtis at digia.com
Fri Jan 18 14:44:29 CET 2013


On Wednesday, January 16, 2013 02:01:09 PM Mitch Curtis wrote:
> Hi.
> 
> I'm currently working on the Calendar component [1]. I'd like to consult any
> interested parties regarding validation of its properties.
> 
> The proposed API provides selectedDate, minimumDate and maximumDate
> properties. The selectedDate property reflects the date currently displayed
> by the calendar, and can be set either programmatically or through the
> Calendar UI itself. This property should, in my opinion, be validated
> against dates outside the range of minimumDate and maximumDate. I'm not so
> sure about validation against "undefined", but have included that in my
> examples for completeness.
> 
> Since I can't validate the selectedDate property in its own onChanged
> handler (results in binding loops), I have to take another approach. From
> talking with a few developers, I can see two options:
> 
> a) Have two properties (See [2]):
>     - inputDate - Its only purpose is to be set programmatically.
>     - selectedDate - Read-only. The result of inputDate after validation or
> the date chosen through the UI.
> 
> This has the advantage of being declarative, but could be a bit confusing.
> 
> b) Have one property and a setter "setSelectedDate" (See [3]).
> 
> This has the advantage of being straightforward, but is not as declarative.
> 
> I'd also like to see the chosen approach applied to the minimumDate and
> maximumDate properties; minimumDate should not be larger than maximumDate
> and vice versa, minimumDate and maximumDate should be within the valid JS
> date range. These properties would then also be in the "_private" scope,
> with their public properties exposed through one of the approaches listed
> above.
> 
> Cheers.
> 
> [1] https://codereview.qt-project.org/#change,44899
> [2] http://paste.kde.org/648524/
> [3] http://paste.kde.org/648530/
> _______________________________________________
> Qt-components mailing list
> Qt-components at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/qt-components

After some discussions with developers here in Oslo, we've decided to add a 
RangedDate component (see the patch above). The options I listed above are not 
good enough, really. The validator mentioned by Michael is interesting, but I 
am yet to see how it would work (and I'm pretty sure that you can achieve the 
same thing with RangedDate by binding to some date property outside the 
RangedDate component). The C++ backend mentioned by Alan is better, and I was 
going to do it that way, but Jens rightly said we should make something 
reusable. For now, RangedDate is private and will stay that way until we come 
up with a permanent solution, but I'll let Jens speculate on what that will be 
if he wants to.



More information about the Qt-components mailing list