PDA

View Full Version : Lining up Inner and Outer Ticks



bigjoeystud
25th September 2012, 17:03
I've got a problem and I realize it is a long shot at being able to fix without seeing code, but here's the deal:

I have inner ticks (QwtPlotScaleItem) and outer ticks plotting together, but when I first render my plot, the inner/outer scales are not lined up. The instant I resize my plot, they shift and line up correctly.

I am using my own versions of QwtScaleDraw's, but I am using the standard QwtScaleWidget's though. I have setScaleDivFromAxis (true) and have plotLayout ()->setAlignCanvasToScales (true) also set. I'm not even sure if that's relevant.

I also have all axes enabled, but in some cases I disable the labels and ticks. In every case where they are not lined up, it is when the major tick is not at the beginning of the axis. I also always use setAttribute (QwtScaleEngine::Floating, true) on the scale engine which I set for every axis. I only use linear and log scales.

I feel like it might be an order of operations thing that I am not getting, but I really have no idea of where to look at trying to debug this.

Anyway, like I said, this may be a long shot, but if you have any ideas, I'd love to hear them!

Thanks,
Joey

Uwe
25th September 2012, 21:31
I'm aware of a bug that can be responsible for 1 pixel difference between an inner and outer scale - but your situation looks more like an update problem.
Hard to say something useful without having a demo application.

Uwe

bigjoeystud
26th September 2012, 21:23
Ok! I think I made an example program by merging the timescale example in playground with my program.

When you start it up, the scales on the left are a little off. You resize the plot and they are fine.

Joey

Here's my diff:



Index: mainwindow.cpp
================================================== =================
--- mainwindow.cpp (revision 1453)
+++ mainwindow.cpp (working copy)
@@ -9,7 +9,7 @@
QMainWindow( parent )
{
Settings settings;
- settings.startDateTime = QDateTime( QDate( 2012, 3, 10 ), QTime( 0, 5, 0 ) );
+ settings.startDateTime = QDateTime( QDate( 2011, 1, 17 ), QTime( 0, 5, 0 ) );
settings.endDateTime = QDateTime( QDate( 2012, 3, 10 ), QTime( 0, 6, 0, 5 ) );
settings.maxMajorSteps = 10;
settings.maxMinorSteps = 8;
Index: plot.cpp
================================================== =================
--- plot.cpp (revision 1453)
+++ plot.cpp (working copy)
@@ -5,6 +5,7 @@
#include "timescaledraw.h"
#include <qwt_plot_panner.h>
#include <qwt_plot_magnifier.h>
+#include <qwt_plot_scaleitem.h>

Plot::Plot( QWidget *parent ):
QwtPlot( parent )
@@ -25,9 +26,53 @@
const bool on = ( i == axis );
panner->setAxisEnabled( i, on );
magnifier->setAxisEnabled( i, on );
+ _innerTicks [i] = NULL;
}
+ InnerTicks (QwtPlot::yLeft, true, true);
+ InnerTicks (QwtPlot::xBottom, true, true);
}

+void
+Plot::InnerTicks (int axisId, bool showMajor, bool showMinor)
+{
+ QwtScaleDraw::Alignment align;
+ if (showMajor || showMinor) {
+ if (_innerTicks [axisId] == NULL) {
+ _innerTicks [axisId] = new QwtPlotScaleItem ();
+ switch (axisId) {
+ case QwtPlot::yLeft : align = QwtScaleDraw::RightScale;
+ _innerTicks [axisId]->setAxes (QwtPlot::xBottom, QwtPlot::yLeft);
+ break;
+ case QwtPlot::yRight : align = QwtScaleDraw::LeftScale;
+ _innerTicks [axisId]->setAxes (QwtPlot::xBottom, QwtPlot::yRight);
+ break;
+ case QwtPlot::xBottom : align = QwtScaleDraw::TopScale;
+ _innerTicks [axisId]->setAxes (QwtPlot::xBottom, QwtPlot::yLeft);
+ break;
+ case QwtPlot::xTop : align = QwtScaleDraw::BottomScale;
+ if (axisScaleDraw (axisId)->hasComponent (QwtAbstractScaleDraw::Labels))
+ _innerTicks [axisId]->setAxes (QwtPlot::xTop, QwtPlot::yLeft);
+ else _innerTicks [axisId]->setAxes (QwtPlot::xBottom, QwtPlot::yLeft);
+ break;
+ }
+ _innerTicks [axisId]->setAlignment (align);
+ _innerTicks [axisId]->setBorderDistance (0); // attach to border
+ _innerTicks [axisId]->scaleDraw ()->enableComponent (QwtAbstractScaleDraw::Labels, false);
+ }
+ if (showMajor) _innerTicks [axisId]->scaleDraw ()->setTickLength (QwtScaleDiv::MajorTick, 8);
+ else _innerTicks [axisId]->scaleDraw ()->setTickLength (QwtScaleDiv::MajorTick, 0);
+ if (showMinor) _innerTicks [axisId]->scaleDraw ()->setTickLength (QwtScaleDiv::MinorTick, 4);
+ else _innerTicks [axisId]->scaleDraw ()->setTickLength (QwtScaleDiv::MinorTick, 0);
+
+ _innerTicks [axisId]->setScaleDivFromAxis (true);
+ _innerTicks [axisId]->attach (this);
+ } else {
+ if (_innerTicks [axisId] != NULL) {
+ _innerTicks [axisId]->detach ();
+ }
+ }
+}
+
void Plot::applySettings( const Settings &settings )
{
const int axis = QwtPlot::yLeft;
Index: plot.h
================================================== =================
--- plot.h (revision 1453)
+++ plot.h (working copy)
@@ -4,6 +4,7 @@
#include <qwt_plot.h>

class Settings;
+class QwtPlotScaleItem;

class Plot: public QwtPlot
{
@@ -14,6 +15,11 @@

public Q_SLOTS:
void applySettings( const Settings & );
+
+private:
+
+ void InnerTicks(int, bool, bool);
+ QwtPlotScaleItem *_innerTicks [4];
};

#endif

Uwe
27th September 2012, 07:31
An issue with an internal cache of the scale item: fixed in SVN ( trunk + 6.0 branch )

Uwe