RE: Why are draw() and renderImade() declared as "const"?
David Stranz <david_stranz <at> MassSpec.com>
2008-10-20 22:33:06 GMT
Shane,
You can always use one of two methods for changing member data
from within a const method:
1 - Declare the members you want to change as "mutable".
2 - Use the trick of const-casting "this" inside the const method:
MySpectrogram * pSpec = const_cast< MySpectrogram * >( this );
pSpec->changeSomething();
That said, in my opinion, if you think you need to change things
from within the draw() or renderImage() methods, then you have
probably overlooked a more appropriate place to update your member
variables.
QwtPlot is extremely hard to understand if you wish to do anything
out of the ordinary, so I have no idea where this more appropriate
place might be. Perhaps Uwe has a suggestion.
Regards,
David
_______________________________________________________________
David Stranz, Ph.D. david_stranz <at> MassSpec.com
Sierra Analytics, Inc.
5815 Stoddard Road, Suite 601
Modesto, CA 95356
Tel: (209) 545-8508
http://www.massspec.com
_______________________________________________________________
> -----Original Message-----
> From: Hill, Shane [mailto:Shane.Hill <at> dsto.defence.gov.au]
> Sent: Monday, October 20, 2008 3:19 PM
> To: List for both Qwt users and developers
> Cc: qwt-support <at> tigertal.de
> Subject: Why are draw() and renderImade() declared as "const"?
>
> G'day All,
>
> Just a general question about why the QwtPlotItem /
> QwtPlotSpectrogram /
> QwtPlotRasterItem draw() and renderImage() functions are declared as
> "const"? This prevents any data within the class from being updated
> unless you use a convoluted method of creating private data as an
> external structure. Is there some good logic behind making these
> functions "const"?
>
> Sorry if I sound frustrated, but I'm trying to implement my
> own version
> of the QwtSpectrogram class where I inherit a number of different sub
> classes to manage contours, labels and images. But I can't
> update any of
> the subclass information while these functions are declared const. The
> only function I can work with at the moment is updateScaleDiv().
>
> Have Fun !!
>
> Shane Hill
>
> -----------------------------------------------------
> Shane D. Hill (B.E. Aero. Hons.)
> Science Team Leader: Aircraft Flight Dynamics, Modelling & Simulation
> Aircraft Vehicles Division
> Defence Science & Technology Organisation
> 506 Lorimer St, Fishermens Bend, Vic. 3207 AUSTRALIA
> Email: Shane.Hill <at> dsto.defence.gov.au
> Voice: +61 3 9626 7811
> FAX: +61 3 9626 7705
> -----------------------------------------------------
>
> IMPORTANT: This email remains the property of the Australian
> Defence Organisation and is subject to the jurisdiction of
> section 70 of the CRIMES ACT 1914. If you have received this
> email in error, you are requested to contact the sender and
> delete the email.
>
>
>
> --------------------------------------------------------------
> -----------
> This SF.Net email is sponsored by the Moblin Your Move
> Developer's challenge
> Build the coolest Linux based applications with Moblin SDK &
> win great prizes
> Grand prize is a trip for two to an Open Source event
> anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> qwt-interest mailing list
> qwt-interest <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/qwt-interest
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/