cginternals / libzeug

deprecated: C++ sanctuary for small but powerful and frequently required, stand alone features.
MIT License
16 stars 13 forks source link

add prefix and suffix option to NumberProperty ref #69 #80

Closed kateyy closed 10 years ago

kateyy commented 10 years ago

This adds prefix and suffix options for the SpinEdits, as discussed in #69

kateyy commented 10 years ago

Is that what you want? Seems to work with the property(gui) examples. It doesn't look so great to have this "duplicated" function, but i don't see a better solution in the moment.

sbusch42 commented 10 years ago

This is getting too complicated, there should be no such distinction. There is a toString() method that returns the value of a property as a string - nothing more, nothing less. If there are options like "prefix" and "suffix", it's the responsibility of the GUI to respect those and concatenate a string with prefix, value and postfix before displaying it.

sbusch42 commented 10 years ago

Also, keep in mind that the value has to be kept separate from the prefix/postfix when editing. For example, when a string property is edited, and there is a prefix and/or postfix set, those values must not end up in the string. But when we just call setText(prefix + value + postfix) on the text box, we cannot distinguish later what the user meant when changing the string, and the prefix and postfix will get into the actual property value. I'm not sure if this has already been considered in the current implementation.

edit: I see that this feature currently is only implemented for number properties, so this remark should not be relevant in that case. However, if the option should later be available for other types, we have to think about that.

kateyy commented 10 years ago

Yep this would be much easier implemented in PropertyPainter::drawValue (?). Btw the QSpinBox implement these post/prefixes, just not for longlong value.

So for this PR, I could fix this code for floating point properties. Implementing the post/prefix as you would expect them to work in the Qt implementation would need some more LOC..

kateyy commented 10 years ago

Okay i reverted the changes in reflectionzeug, the PropertyPainter now takes care of rendering the sufix/prefixes. For editing, the options are only supported in floating point properties, the integral editors contain only the value itself.

kateyy commented 10 years ago

I think the QAbstractSpinBox actually implements the affixes in its private class. Maybe we can subclass it to use this feature, but I didn't find a way how to do this. (http://qt-project.org/wiki/Dpointer might help...)

mjendruk commented 10 years ago

Unfortunately no. The spin boxes already inherit from QAbstractSpinBox, but it doesn't support prefixes and suffixes.

kateyy commented 10 years ago

So what about this PR? This adds affixes for NumberProperties. When editing, the affixes are only shown for floating point values, as supported by QDoubleSpinBox.

mjendruk commented 10 years ago

I think it's fine for now. But it's adding affixes for all properties at the moment. However, we should create an issue for refining it another day.

sbusch42 commented 10 years ago

:shipit:

kateyy commented 10 years ago

Can you please merge this? I don't have write access :smiley:

kateyy commented 10 years ago

Thanks!