I've implemented the way you suggested with invalidateCache(); But the problem is that when i run the program the real-time-axis is not updating!!! while the basebase time is updating and with that invalidateCache will be called. In the meanwhile when i for example open a dialog on plotter or make a right click on the graph, the real-time-axis will be updated!!! seems some things must be triggered !!! the replot didn't help me either.
Added after 20 minutes:
I've modified the cpuplot example the way i want it and attach it. i'll be very appreciated if take look at it. I've modified the cpuplot file. besides the attached project i've provided snapshots of the changes relative to native code:
sorry i forgot to attach:
cpuplot.cppcpuplot.h
{
public:
TimeScaleDraw
(const QTime &base
): baseTime(base)
{
}
virtual QwtText label
(double v
) const {
QTime upTime
= baseTime.
addSecs((int)v
);
return upTime.toString();
}
void setBaseTime
( const QTime &time
) {
baseTime = time;
invalidateCache();
}
private:
};
//timer event in cpuplot class
{
for ( int i = dataCount; i > 0; i-- )
{
for ( int c = 0; c < NCpuData; c++ )
{
if ( i < HISTORY )
data[c].data[i] = data[c].data[i-1];
}
}
cpuStat.statistic(data[User].data[0], data[System].data[0]);
data[Total].data[0] = data[User].data[0] +
data[System].data[0];
data[Idle].data[0] = 100.0 - data[Total].data[0];
if ( dataCount < HISTORY )
dataCount++;
//---I've commented below codes to instead of incrementing array send current time
// for ( int j = 0; j < HISTORY; j++ )
// timeData[j]++;
scaleDraw->setBaseTime(currentTime);
timeData[HISTORY - 1], timeData[0]);
for ( int c = 0; c < NCpuData; c++ )
{
data[c].curve->setRawSamples(
timeData, data[c].data, dataCount);
}
replot();
}
class TimeScaleDraw: public QwtScaleDraw
{
public:
TimeScaleDraw(const QTime &base):
baseTime(base)
{
}
virtual QwtText label(double v) const
{
QTime upTime = baseTime.addSecs((int)v);
return upTime.toString();
}
void setBaseTime( const QTime &time )
{
baseTime = time;
invalidateCache();
}
private:
QTime baseTime;
};
//timer event in cpuplot class
void CpuPlot::timerEvent(QTimerEvent *)
{
for ( int i = dataCount; i > 0; i-- )
{
for ( int c = 0; c < NCpuData; c++ )
{
if ( i < HISTORY )
data[c].data[i] = data[c].data[i-1];
}
}
cpuStat.statistic(data[User].data[0], data[System].data[0]);
data[Total].data[0] = data[User].data[0] +
data[System].data[0];
data[Idle].data[0] = 100.0 - data[Total].data[0];
if ( dataCount < HISTORY )
dataCount++;
//---I've commented below codes to instead of incrementing array send current time
// for ( int j = 0; j < HISTORY; j++ )
// timeData[j]++;
scaleDraw->setBaseTime(currentTime);
setAxisScale(QwtPlot::xBottom,
timeData[HISTORY - 1], timeData[0]);
for ( int c = 0; c < NCpuData; c++ )
{
data[c].curve->setRawSamples(
timeData, data[c].data, dataCount);
}
replot();
}
To copy to clipboard, switch view to plain text mode
Bookmarks