PDA

View Full Version : Rotating Y Axis Title



bigjoeystud
3rd June 2015, 22:17
Hello Uwe,

Is it possible to add an interface to rotating the title of an axis?

Right now, the value is hard coded based on which axis it is. It would be nice to have a method where we could change that angle. Right now, I'd like to just rotate the title by 90, but I suppose there be some value to having any angle in there.

Or is there another way to do it? Or is there a better reason not to do it?

I could subclass QwtScaleWidget and overload drawTitle, but seems like a method might be nice.

Thanks,
Joey

Uwe
4th June 2015, 09:58
There is already a feature request ( http://sourceforge.net/p/qwt/feature-requests/38 ) but I have not scheduled anything so far.
I remember there once was another request for rotating the axis title by 180° ( according to some DIN norm left and right axis need to be in the same orientation ), but I never heard from a use case, where a random angle is useful.

Uwe

bigjoeystud
9th June 2015, 20:51
Yes, I suppose there really isn't a use case for any angle, but it seemed like just changing the angle in drawTitle would be enough. Unfortunately, that wasn't the case!

Anyway, here's a start for just rotating the title horizontal in case anyone else needs it. Would be nice to have at least this in the distribution:


Index: src/qwt_scale_widget.cpp
================================================== =================
--- src/qwt_scale_widget.cpp (revision 2242)
+++ src/qwt_scale_widget.cpp (working copy)
@@ -670,6 +670,20 @@
}
}

+ if ( d_data->layoutFlags & TitleHorizontal )
+ {
+ if ( align == QwtScaleDraw::LeftScale )
+ {
+ angle += 90;
+ r.setRect( r.x (), r.y () - r.width (), r.height (), r.width () );
+ }
+ else if ( align == QwtScaleDraw::RightScale )
+ {
+ angle -= 90;
+ r.setRect( d_data->titleOffset, r.y (), r.height (), r.width () );
+ }
+ }
+
painter->save();
painter->setFont( font() );
painter->setPen( palette().color( QPalette::Text ) );
@@ -747,7 +761,8 @@

int QwtScaleWidget::titleHeightForWidth( int width ) const
{
- return qCeil( d_data->title.heightForWidth( width, font() ) );
+ if ( d_data->layoutFlags & TitleHorizontal ) return qCeil ( d_data->title.textSize ().width () );
+ else return qCeil( d_data->title.heightForWidth( width, font() ) );
}

/*!
Index: src/qwt_scale_widget.h
================================================== =================
--- src/qwt_scale_widget.h (revision 2242)
+++ src/qwt_scale_widget.h (working copy)
@@ -42,7 +42,8 @@
The title of vertical scales is painted from top to bottom.
Otherwise it is painted from bottom to top.
*/
- TitleInverted = 1
+ TitleInverted = 1,
+ TitleHorizontal = 2
};

//! Layout flags of the title

Uwe
9th June 2015, 20:57
Please upload your patch at sourceforge - otherwise it might get lost.

Uwe