Assuming that data in vector is in function of time then you can easily get first and last index of vector points on the edges of visible area:
curve->setSamples( x_vector.data(), y_vector.data(), qMin( x_vector.size(), y_vector.size() ) );
int idx_start = findIndex( zoomer->zoomRect().left(), curve );
int idx_end = findIndex( zoomer->zoomRect().right(), curve );
QVector< double > data = x_vector.mid( idx_start, idx_end );
int findIndex( double worldX, const QwtPlotCurve& curve ) const
{
int idx = 0;
int low = 0;
int high = curve.dataSize() - 1;
while( true )
{
int size = high-low;
int mid = low+size/2;
double mid_value = curve.sample( mid ).x();
if( size <= 1 || worldX == mid_value )
{
idx = mid;
break;
}
else
{
if( worldX < mid_value )
{
high -= size/2;
}
else
{
low += size/2;
}
}
}
return idx;
}
QwtPlotCurve* curve = new QwtPlotCurve();
curve->setSamples( x_vector.data(), y_vector.data(), qMin( x_vector.size(), y_vector.size() ) );
int idx_start = findIndex( zoomer->zoomRect().left(), curve );
int idx_end = findIndex( zoomer->zoomRect().right(), curve );
QVector< double > data = x_vector.mid( idx_start, idx_end );
int findIndex( double worldX, const QwtPlotCurve& curve ) const
{
int idx = 0;
int low = 0;
int high = curve.dataSize() - 1;
while( true )
{
int size = high-low;
int mid = low+size/2;
double mid_value = curve.sample( mid ).x();
if( size <= 1 || worldX == mid_value )
{
idx = mid;
break;
}
else
{
if( worldX < mid_value )
{
high -= size/2;
}
else
{
low += size/2;
}
}
}
return idx;
}
To copy to clipboard, switch view to plain text mode
Bookmarks