PDA

View Full Version : Changing the QwtScaleDraw depending on data values



kja
23rd February 2011, 00:07
Hi I need some help.

I have a QwtScaleDraw class that puts the day, month, year hour:min:sec on the xaxis of my plot. I like having all of this info, but when I zoom in to look at a single day I want this label to only show the hour:min:sec. The problem is that I don't understand how qwtScaleDraw works. I modeled my class off of the QWT examples and have:



class XaxisDates: public QwtScaleDraw
{
public:
XaxisDates(){
setLabelRotation(-11.0);
setSpacing(10);
}
virtual QwtText label(double value) const{
time_t time = value;
char *humanTime = ctime(&(time));
return QString(humanTime); //output looks like: "fri Jan 1 08:30:15 2010"
}
};


because "virtual QwtText label(double value) const" is constant I cannot put the code that I want in it to check if the date now equals the previous date. This is what I want to do:



virtual QwtText label(double value) const{
time_t time = value;
char *humanTime = ctime(&(time));

QDateTime dt = QDateTime::fromTime_t(time);
nowDate = dt.date(); //error here for redefining nowDate

if (nowDate == previousDate){
previousDate = nowDate; //error here for redefining previousDate
return dt.time()
}else
return QString(humantime);
}


If I try to do this I get an error saying I cannot change the value of a constant.

I am new to computer programing and could use some help dealing with this const function. I tried to simply make "virtual QwtText label(double value) const" not const but that interferes with the way QwtScaleDraw works (i guess) because if I do that the function just never gets called. I also tried to call a function from within "virtual QwtText label(double value) const" but I get the error "cannot convert this pointer from const xaxisdates to xaxisdates &."


Any help would be greatly appreciated.
Thanks!