#include <PlotCurve.h>
List of all members.
Constructor & Destructor Documentation
PlotCurve::PlotCurve |
( |
const QwtText & |
title |
) |
|
PlotCurve::PlotCurve |
( |
const QString & |
title |
) |
|
PlotCurve::~PlotCurve |
( |
|
) |
|
Member Function Documentation
void PlotCurve::attach |
( |
Plot * |
plot |
) |
|
int PlotCurve::closestPoint |
( |
const QPoint & |
pos, |
|
|
double * |
dist | |
|
) |
| | const |
Reimplemented from QwtPlotCurve.
{
if ( plot() == NULL || dataSize() <= 0 )
return -1;
const QwtScaleMap xMap = plot()->canvasMap( xAxis() );
const QwtScaleMap yMap = plot()->canvasMap( yAxis() );
int index = -1;
double dmin = 1.0e10;
const double x0 = pos.x();
const double y0 = pos.y();
for ( int i = 0; i < dataSize() - 1; i++ )
{
const double x1 = xMap.xTransform( x( i ) );
const double x2 = xMap.xTransform( x( i + 1 ) );
if ( x1 == x2 ) continue;
const double y1 = yMap.xTransform( y( i ) );
const double y2 = yMap.xTransform( y( i + 1 ) );
const double y2miny1 = y2 - y1;
const double x2minx1 = x2 - x1;
const double m = y2miny1 / x2minx1;
const double b = y1 - m * x1;
const double mmplus1 = m * m + 1;
const double xp = ( m * y0 + x0 - m * b ) / ( mmplus1 );
const double yp = ( m * m * y0 + m * x0 + b ) / ( mmplus1 );
if ( !( ( xp > x1 && xp < x2 ) || ( yp > y2 && yp < y1 ) ) ) continue;
const double f = fabs( ( x2minx1 ) * ( y1 - y0 ) - ( x1 - x0 ) * ( y2miny1 ) )
/ sqrt( qwtSqr( x2minx1 ) + qwtSqr( y2miny1 ) );
if ( f < dmin )
{
index = i;
dmin = f;
}
}
if ( dist )
*dist = dmin;
return index;
}
void PlotCurve::itemChanged |
( |
|
) |
[inline, slot] |
QWidget* PlotCurve::legendItem |
( |
|
) |
const [inline] |
Referenced by updateLegend().
{
if (axis == QwtPlot::xTop || axis == QwtPlot::xBottom){
setXAxis(axis);
return;
}
if (axis == QwtPlot::yLeft || axis == QwtPlot::yRight){
setYAxis(axis);
return;
}
Q_ASSERT(false);
}
void PlotCurve::setColor |
( |
QColor |
color |
) |
[inline, slot] |
void PlotCurve::signal_curveAttached |
( |
PlotCurve * |
curve |
) |
[signal] |
void PlotCurve::updateLegend |
( |
QwtLegend * |
legend |
) |
const [inline] |
Reimplemented from QwtPlotCurve.
{
if (!legend) return;
Q_ASSERT(testItemAttribute(QwtPlotItem::Legend));
LegendItem *lgdItem = dynamic_cast<LegendItem*>(legend->find(this));
if (!lgdItem){
lgdItem = dynamic_cast<LegendItem*>(legendItem());
Q_ASSERT(lgdItem);
connect(lgdItem, SIGNAL(colorChanged(QColor)),
this, SLOT(setColor(QColor)), Qt::QueuedConnection);
connect(lgdItem, SIGNAL(axisChanged(QwtPlot::Axis)),
this, SLOT(setAxis(QwtPlot::Axis)), Qt::QueuedConnection);
QList<QColor> usedColors;
foreach(QWidget *wItem, legend->legendItems()){
LegendItem *item = dynamic_cast<LegendItem*>(wItem);
Q_ASSERT(item);
usedColors << item->currentColor();
}
Q_ASSERT(lgdItem->color(0).isValid());
lgdItem->setCurrentColor(lgdItem->color(0));
int i = 0;
while(lgdItem->color(i).isValid()){
if (usedColors.contains(lgdItem->color(i))) {
i++;
continue;
} else {
lgdItem->setCurrentColor(lgdItem->color(i));
break;
}
}
legend->insert(this, lgdItem);
}
Q_ASSERT(lgdItem);
Q_ASSERT(lgdItem->updatesEnabled());
lgdItem->setText(title().text());
}
The documentation for this class was generated from the following files: