enum's & KConfigBase

Thomas Braxton thomas_braxton at cox.net
Tue Jan 17 22:09:07 GMT 2006


On Tuesday 17 January 2006 14:31, Waldo Bastian wrote:
> On Tuesday 17 January 2006 11:32, Frans Englich wrote:
> > On Tuesday 17 January 2006 16:17, Hans Meine wrote:
> > > On Monday 16 January 2006 23:58, Thomas Braxton wrote:
> > > > On Monday 16 January 2006 16:41, Dirk Mueller wrote:
> > > > > On Monday 16 January 2006 19:39, Thomas Braxton wrote:
> > > > > > What do you guys think of this macro?
> > > > >
> > > > > I'm not so sure if its a good idea to convert enums to integers and
> > > > > back. enum's tend to be reordered within applications, which break
> > > > > binary compatibility (not a problem usually for inner-apps usage)
> > > > > but then also breaks configuration reading. This is a major
> > > > > problem. KDE applications break already way too often their own
> > > > > configuration (I cannot remember how often already I had to redo
> > > > > the very same settings in e.g. konversation because the way the
> > > > > configuration key was stored was changed *yet another* time). We
> > > > > shouldn't make it too easy to keep that nasty habit.
> > > >
> > > > I could change it to something like Olivier Goffart suggested, but
> > > > not sure about Q_ENUM usage yet, have to look at it.  Thinking about
> > > > it, this would probably be best, since as you say enums get
> > > > reordered. Converting enums to integers is the way most code does it
> > > > now. I'll look at this tonight, and get back to you guys later.
> > >
> > > FWIW, I want to point out the enum<->string conversion macros which
> > > Neil Williams posted to pilot-link-devel in April/May of 2005,
> > > including this link to a related thread:
> > >
> > > https://lists.gnucash.org/pipermail/gnucash-devel/2005-March/012849.htm
> > >l
> > >
> > > These require a macro-ized marking up of enums, and would then allow to
> > > store its values as string.
> > >
> > > I guess at least *someone* will find this helpful for something..
> >
> > But adding Doxygen becomes tricky at best with that solution.
> >
> > But agreed, who doesn't want enum/string conversion in a intuitive way.

Looking around I haven't found another way to do this. So something along 
these lines is probably the best I'll be able to do.

> KConfigXT does such conversion for you.

For enums that are defined for KConfigXT, but what about all the rest? And 
with KConfigXT as far as I can tell the enum has to be defined in two places
1) the header to be used by code
2) the .kcfg file to be used for reading/writing
and that means they need to be kept in sync, or it defeats the purpose.

From looking at the code for ItemEnum it seems to treat  positive/negative 
enum values differently. So you couldn't have an enum with negative values 
and still read/write the name of the value to a config file. It read/writes 
negative values as ints instead of strings.




More information about the kde-core-devel mailing list