Skip to content

Commit

Permalink
implement updateLegend() in HistogramItem
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennesky committed Feb 22, 2014
1 parent 673f7ba commit 4c1e866
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/gui/raster/qwt5_histogram_item.h
Expand Up @@ -38,6 +38,8 @@ class HistogramItem: public QwtPlotItem
virtual void draw(QPainter *, const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QRect &) const;

virtual void updateLegend(QwtLegend *) const;

void setBaseline(double reference);
double baseline() const;

Expand Down Expand Up @@ -67,6 +69,7 @@ class HistogramItem: public QwtPlotItem
#include <qwt_interval_data.h>
#include <qwt_painter.h>
#include <qwt_scale_map.h>
#include <qwt_legend_item.h>

class HistogramItem::PrivateData
{
Expand Down Expand Up @@ -344,4 +347,63 @@ void HistogramItem::drawBar(QPainter *painter,
painter->restore();
}

//! Update the widget that represents the curve on the legend
// this was adapted from QwtPlotCurve::updateLegend()
void HistogramItem::updateLegend(QwtLegend *legend) const
{
if ( !legend )
return;

QwtPlotItem::updateLegend(legend);

QWidget *widget = legend->find(this);
if ( !widget || !widget->inherits("QwtLegendItem") )
return;

QwtLegendItem *legendItem = (QwtLegendItem *)widget;

#if QT_VERSION < 0x040000
const bool doUpdate = legendItem->isUpdatesEnabled();
#else
const bool doUpdate = legendItem->updatesEnabled();
#endif
legendItem->setUpdatesEnabled(false);

const int policy = legend->displayPolicy();

if (policy == QwtLegend::FixedIdentifier)
{
int mode = legend->identifierMode();

legendItem->setCurvePen(QPen(color()));

if (mode & QwtLegendItem::ShowText)
legendItem->setText(title());
else
legendItem->setText(QwtText());

legendItem->setIdentifierMode(mode);
}
else if (policy == QwtLegend::AutoIdentifier)
{
int mode = 0;

legendItem->setCurvePen(QPen(color()));
mode |= QwtLegendItem::ShowLine;
if ( !title().isEmpty() )
{
legendItem->setText(title());
mode |= QwtLegendItem::ShowText;
}
else
{
legendItem->setText(QwtText());
}
legendItem->setIdentifierMode(mode);
}

legendItem->setUpdatesEnabled(doUpdate);
legendItem->update();
}

#endif

0 comments on commit 4c1e866

Please sign in to comment.