mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 08:29:26 -05:00
improved graph widget
This commit is contained in:
parent
e6a7168122
commit
6484ea66f7
@ -259,6 +259,7 @@ RSGraphWidget::RSGraphWidget(QWidget *parent)
|
||||
_maxPoints = getNumPoints();
|
||||
_maxValue = MINUSER_SCALE;
|
||||
|
||||
_linewidthscale = 1.0f;
|
||||
_opacity = 0.6 ;
|
||||
_flags = 0;
|
||||
_time_scale = 5.0f ; // in pixels per second.
|
||||
@ -414,12 +415,16 @@ void RSGraphWidget::paintData()
|
||||
|
||||
/* Plot the bandwidth as solid lines. If the graph style is currently an
|
||||
* area graph, we end up outlining the integrals. */
|
||||
paintLine(points, getColor(i));
|
||||
|
||||
if(_flags & RSGRAPH_FLAGS_PAINT_STYLE_DOTS)
|
||||
paintDots(points, getColor(i));
|
||||
else
|
||||
paintLine(points, getColor(i));
|
||||
}
|
||||
if(_maxValue > 0.0f)
|
||||
{
|
||||
if(_flags & RSGRAPH_FLAGS_LOG_SCALE_Y)
|
||||
_y_scale = _rec.height()*0.8 / log(_maxValue) ;
|
||||
_y_scale = _rec.height()*0.8 / log(std::max(2.0,_maxValue)) ;
|
||||
else
|
||||
_y_scale = _rec.height()*0.8/_maxValue ;
|
||||
}
|
||||
@ -539,11 +544,27 @@ void RSGraphWidget::paintLine(const QVector<QPointF>& points, QColor color, Qt::
|
||||
{
|
||||
/* Save the current brush, plot the line, and restore the old brush */
|
||||
QPen oldPen = _painter->pen();
|
||||
_painter->setPen(QPen(color, lineStyle));
|
||||
|
||||
QPen newPen(color, lineStyle);
|
||||
newPen.setWidth(2.0f*_linewidthscale);
|
||||
_painter->setPen(newPen);
|
||||
_painter->drawPolyline(points.data(), points.size());
|
||||
_painter->setPen(oldPen);
|
||||
}
|
||||
void RSGraphWidget::paintDots(const QVector<QPointF>& points, QColor color)
|
||||
{
|
||||
/* Save the current brush, plot the line, and restore the old brush */
|
||||
QPen oldPen = _painter->pen();
|
||||
_painter->setPen(QPen(color, oldPen.style()));
|
||||
QBrush oldBrush = _painter->brush();
|
||||
_painter->setBrush(QBrush(color));
|
||||
|
||||
for(int i=0;i<points.size();++i)
|
||||
_painter->drawEllipse(QRect(points[i].x(),points[i].y(),5*_linewidthscale,5*_linewidthscale)) ;
|
||||
|
||||
_painter->setPen(oldPen);
|
||||
_painter->setBrush(oldBrush);
|
||||
}
|
||||
/** Paints selected total indicators on the graph. */
|
||||
void RSGraphWidget::paintTotals()
|
||||
{
|
||||
@ -641,6 +662,11 @@ void RSGraphWidget::wheelEvent(QWheelEvent *e)
|
||||
_time_filter *= 1.1 ;
|
||||
else
|
||||
_time_filter /= 1.1 ;
|
||||
else if(e->modifiers() & Qt::ControlModifier)
|
||||
if(e->delta() > 0)
|
||||
_linewidthscale *= 1.2 ;
|
||||
else
|
||||
_linewidthscale /= 1.2 ;
|
||||
else
|
||||
if(e->delta() > 0)
|
||||
_time_scale *= 1.1 ;
|
||||
|
@ -126,6 +126,7 @@ public:
|
||||
static const uint32_t RSGRAPH_FLAGS_SHOW_LEGEND = 0x0010 ;// show legend in the graph
|
||||
static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_FLAT = 0x0020 ;// do not interpolate, and draw flat colored boxes
|
||||
static const uint32_t RSGRAPH_FLAGS_LEGEND_CUMULATED = 0x0040 ;// show the total in the legend rather than current values
|
||||
static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_DOTS = 0x0080 ;// use dots
|
||||
|
||||
/** Bandwidth graph style. */
|
||||
enum GraphStyle
|
||||
@ -191,8 +192,11 @@ private:
|
||||
void pointsFromData(const std::vector<QPointF>& values, QVector<QPointF> &points ) ;
|
||||
|
||||
/** Paints a line with the data in <b>points</b>. */
|
||||
void paintLine(const QVector<QPointF>& points, QColor color,
|
||||
Qt::PenStyle lineStyle = Qt::SolidLine);
|
||||
void paintLine(const QVector<QPointF>& points, QColor color, Qt::PenStyle lineStyle = Qt::SolidLine);
|
||||
|
||||
/** Paint a series of large dots **/
|
||||
void paintDots(const QVector<QPointF>& points, QColor color);
|
||||
|
||||
/** Paints an integral using the supplied data. */
|
||||
void paintIntegral(const QVector<QPointF>& points, QColor color, qreal alpha = 1.0);
|
||||
|
||||
@ -214,6 +218,7 @@ private:
|
||||
|
||||
qreal _time_scale ; // horizontal scale in pixels per sec.
|
||||
qreal _time_filter ; // time filter. Goes from 0 to infinity. Will be converted into 1-1/(1+f)
|
||||
float _linewidthscale ;
|
||||
|
||||
/** Show the respective lines and counters. */
|
||||
//bool _showRSDHT;
|
||||
|
@ -201,11 +201,13 @@ void BandwidthStatsWidget::updateUnitSelection(int n)
|
||||
if(n==0)
|
||||
{
|
||||
ui.bwgraph_BW->setUnit(BWGraphSource::UNIT_KILOBYTES) ;
|
||||
ui.bwgraph_BW->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_DOTS);
|
||||
ui.legend_CB->setItemText(1,tr("Average"));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.bwgraph_BW->setUnit(BWGraphSource::UNIT_COUNT) ;
|
||||
ui.bwgraph_BW->setFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_DOTS);
|
||||
ui.legend_CB->setItemText(1,tr("Total"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user