improved display of graphs

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7614 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-10-16 19:17:17 +00:00
parent 01fdb95c30
commit b51c34d23b
7 changed files with 74 additions and 20 deletions

View file

@ -40,6 +40,7 @@ RSGraphSource::RSGraphSource()
_update_period_msecs = 1*1000 ;
_time_orig_msecs = QDateTime::currentMSecsSinceEpoch() ;
_timer = new QTimer ;
_digits = 2 ;
QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(update())) ;
}
@ -80,7 +81,7 @@ QString RSGraphSource::displayName(int i) const
QString RSGraphSource::displayValue(float v) const
{
return QString::number(v,'f',2) + " " + unitName() ;
return QString::number(v,'f',_digits) + " " + unitName() ;
}
void RSGraphSource::getCurrentValues(std::vector<float>& vals) const
@ -91,6 +92,11 @@ void RSGraphSource::getCurrentValues(std::vector<float>& vals) const
vals.push_back(it->second.back().second) ;
}
QString RSGraphSource::legend(int i,float v) const
{
return displayName(i) + " (" + displayValue(v) + " )";
}
void RSGraphSource::getDataPoints(int index,std::vector<QPointF>& pts) const
{
pts.clear() ;
@ -182,7 +188,6 @@ RSGraphWidget::RSGraphWidget(QWidget *parent)
_timer = new QTimer ;
QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(update())) ;
_precision_digits = 1 ;
_y_scale = 1.0f ;
_timer->start(1000);
}
@ -482,7 +487,7 @@ void RSGraphWidget::paintLegend()
{
qreal paintStep = 4+FONT_SIZE;
qreal pos = 20+i*paintStep;
QString text = _source->displayName(i) + " (" + _source->displayValue(vals[i]) + " )";
QString text = _source->legend(i,vals[i]) ;
QPen oldPen = _painter->pen();
_painter->setPen(QPen(getColor(i), Qt::SolidLine));

View file

@ -70,6 +70,9 @@ public:
// return the vector of last values up to date
virtual void getCurrentValues(std::vector<float>& vals) const ;
// returns what to display in the legend. Derive this to show additional info.
virtual QString legend(int i,float v) const ;
// Returns the n^th interpolated value at the given time in floating point seconds backward.
virtual void getDataPoints(int index, std::vector<QPointF>& pts) const ;
@ -82,6 +85,8 @@ public:
// Sets the time period for collecting new values. Units=milliseconds.
void setCollectionTimePeriod(qint64 msecs) ;
void setDigits(int d) { _digits = d ;}
protected slots:
// Calls the internal source for a new data points; called by the timer. You might want to overload this
// if the collection system needs it. Otherwise, the default method will call getValues()
@ -101,6 +106,7 @@ protected:
qint64 _time_limit_msecs ;
qint64 _update_period_msecs ;
qint64 _time_orig_msecs ;
int _digits ;
};
class RSGraphWidget: public QFrame
@ -139,8 +145,6 @@ class RSGraphWidget: public QFrame
/** Toggles display of data counters. */
//void setShowCounters(bool showRSDHT, bool showALLDHT);
void setScaleParams(int precision_digits) { _precision_digits = precision_digits ; }
void setFlags(uint32_t flag) { _flags |= flag ; }
void resetFlags(uint32_t flag) { _flags &= ~flag ; }
protected:
@ -190,7 +194,6 @@ class RSGraphWidget: public QFrame
qreal pixelsToValue(qreal) ;
qreal valueToPixels(qreal) ;
int _maxPoints;
int _precision_digits ;
qreal _time_scale ; // horizontal scale in pixels per sec.