3 Attachment(s)
QwtPolar change scale steps problem
Hello everyone!
I ran into a problem with scaling.
This is my code to change scale:
Code:
// class Scale : public QDockWidget
// QComboBox::m_cbScale;
// QComboBox::m_cbAzimuth;
// QComboBox::m_cbDistance;
// QwtPolarPlot::m_screen
const double MAX_DISPLAY_FACTOR = 0.99; // for squared displaying
void Scale::changedScale()
{
// Azimuth scale
m_screen->setScale(QwtPolar::Azimuth, 360, 0, m_cbAzimuth->currentText().toDouble());
// Distance scale
m_screen->setScale(QwtPolar::Radius, 0, 600.0, m_cbDistance->currentText().toDouble());
m_screen->setScaleMaxMajor(QwtPolar::Radius, 600.0 / m_cbDistance->currentText().toDouble());
// Zoom scale
if(qFuzzyCompare(m_cbScale->currentText().toDouble(), 600.0)) {
m_screen->zoom(QwtPointPolar(0, 0), MAX_DISPLAY_FACTOR);
} else {
m_screen->zoom(QwtPointPolar(0, 0), m_cbScale->currentText().toDouble() / 600.0);
}
m_screen->replot();
}
How to set major ticks to be fixed - not auto calculated.
Scale 200 steps 100 - good.
Attachment 12465
Scale 150 steps 100 - bad - steps setted to 100, but displaying 50. In here I want to be displayed only 100 without 50 and 150.
Attachment 12466
Scale 50 steps 100 - bad - steps setted to 100, but displaying 20. In here I want to be displayed nothing. If I change distance step to 50 - only 50 major tick are displayed. If I change distance step to 10, I want to be displayed 10, 20, 30, 40 and 50.
Attachment 12467
Re: QwtPolar change scale steps problem
If you want to set the ticks manually you can use setScaleDiv.
Uwe
Re: QwtPolar change scale steps problem
setScaleDiv didn't help.
I found out that this is due to zoom. When I commented out zooming all major ticks are become perfect.
How to fix it?
Code:
// class Scale : public QDockWidget
// QComboBox::m_cbScale;
// QComboBox::m_cbAzimuth;
// QComboBox::m_cbDistance;
// QwtPolarPlot::m_screen
const double MAX_DISPLAY_FACTOR = 0.99; // for squared displaying
void Scale::changedScale()
{
// Azimuth scale
m_screen->setScale(QwtPolar::Azimuth, 360, 0, m_cbAzimuth->currentText().toDouble());
// Distance scale
m_screen->setScale(QwtPolar::Radius, 0, 600.0, m_cbDistance->currentText().toDouble());
m_screen->setScaleMaxMajor(QwtPolar::Radius, 600.0 / m_cbDistance->currentText().toDouble());
// Zoom scale
// if(qFuzzyCompare(m_cbScale->currentText().toDouble(), 600.0)) {
// m_screen->zoom(QwtPointPolar(0, 0), MAX_DISPLAY_FACTOR);
// } else {
// m_screen->zoom(QwtPointPolar(0, 0), m_cbScale->currentText().toDouble() / 600.0);
// }
m_screen->replot();
}
Re: QwtPolar change scale steps problem
The zoom call does 2 things:
1) Putting the previous intervals on the zoom stack
2) calling setScale
The only reason for calling zoom manually might be 1, so that the user can navigate to the initial scale ranges easily.
But even then: you can set an initial zoomStack by QwtPlotZoomer::setZoomStack.
In case you need more control about how ticks are set when zooming you have to overload QwtPlotZoomer::rescale().
Uwe
Re: QwtPolar change scale steps problem
I'm not using QwtPlotZoomer, just only QwtPolarPlot::zoom. How does this class relate to QwtPolarPlot::zoom ?
Re: QwtPolar change scale steps problem
Nothing helped :(
Code:
void Scale::changedScale()
{
// Zoom scale
// if(qFuzzyCompare(m_cbScale->currentText().toDouble(), 600.0)) {
// m_screen->zoom(QwtPointPolar(0, 0), MAX_DISPLAY_FACTOR);
// } else {
// m_screen->zoom(m_screen->zoomPos(), m_cbScale->currentText().toDouble() / 600.0);
// }
// Azimuth scale
m_screen->setScale(QwtPolar::Azimuth, 360, 0, m_cbAzimuth->currentText().toDouble());
// Distance scale
m_scaleDiv.setLowerBound(0);
m_scaleDiv.setUpperBound(m_cbScale->currentText().toDouble());
m_scaleDiv.
setTicks(QwtScaleDiv::MinorTick, getTicks
(m_cbDistance
->currentText
().
toDouble()));
m_scaleDiv.
setTicks(QwtScaleDiv::MediumTick, getTicks
(m_cbDistance
->currentText
().
toDouble()));
m_scaleDiv.
setTicks(QwtScaleDiv::MajorTick, getTicks
(m_cbDistance
->currentText
().
toDouble()));
m_screen->setScaleDiv(QwtPolar::Radius, m_scaleDiv);
m_screen->setScale(QwtPolar::Radius, 0, m_cbScale->currentText().toDouble());
m_screen->replot();
}
QList<double> Scale::getTicks(double step) const
{
QList<double> ticks;
if(qFuzzyCompare(step, 0)) {
return ticks;
}
for(double i = 0; i <= m_cbScale->currentText().toDouble(); i += step) {
ticks.append(i);
}
return ticks;
}
Code:
void Scale::changedScale()
{
// Azimuth scale
m_screen->setScale(QwtPolar::Azimuth, 360, 0, m_cbAzimuth->currentText().toDouble());
// Distance scale
m_screen->setScale(QwtPolar::Radius, 0, 600.0);
double maxMajor = 600.0 / m_cbDistance->currentText().toDouble();
m_screen->setScaleMaxMajor(QwtPolar::Radius,
qFuzzyCompare(maxMajor, static_cast<int>(maxMajor))
? maxMajor : maxMajor + 1);
// Zoom scale <-- This spoils everything!!!
if(qFuzzyCompare(m_cbScale->currentText().toDouble(), 600.0)) {
m_screen->zoom(QwtPointPolar(0, 0), MAX_DISPLAY_FACTOR);
} else {
m_screen->zoom(m_screen->zoomPos(), m_cbScale->currentText().toDouble() / 600.0);
}
m_screen->replot();
}
Re: QwtPolar change scale steps problem
Code:
void Scale::changedScale()
{
....
m_screen->setScaleDiv(QwtPolar::Radius, m_scaleDiv);
// m_screen->setScale(QwtPolar::Radius, 0, m_cbScale->currentText().toDouble());
}
setScale calculates a QwtScaleDiv using the algo of the scale engine and then assigns it. So the second call is bad as it invalidates the effect of the first one.
Uwe
Re: QwtPolar change scale steps problem
Hello,
I also had similar problems with the QwtPolar::Radius scale steps.
The solution : disabling the auto-scaling attribute of the QwtPolarGrid :
... .setGridAttribute( QwtPolarGrid::AutoScaling, false );