Skip to content

Commit 86a45d4

Browse files
committed
Tweak appearance of histogram titles and hide value title to make
more space for plot itself.
1 parent bcab4ae commit 86a45d4

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

python/gui/qgshistogramwidget.sip

+26
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,32 @@ class QgsHistogramWidget : QWidget
7979
*/
8080
QgsRangeList graduatedRanges() const;
8181

82+
/** Returns the title for the histogram's x-axis.
83+
* @see setXAxisTitle
84+
* @see yAxisTitle
85+
*/
86+
QString xAxisTitle() const;
87+
88+
/** Sets the title for the histogram's x-axis.
89+
* @param title x-axis title, or empty string to remove title
90+
* @see xAxisTitle
91+
* @see setYAxisTitle
92+
*/
93+
void setXAxisTitle( const QString& title );
94+
95+
/** Returns the title for the histogram's y-axis.
96+
* @see setYAxisTitle
97+
* @see xAxisTitle
98+
*/
99+
QString yAxisTitle() const;
100+
101+
/** Sets the title for the histogram's y-axis.
102+
* @param title y-axis title, or empty string to remove title
103+
* @see yAxisTitle
104+
* @see setXAxisTitle
105+
*/
106+
void setYAxisTitle( const QString& title );
107+
82108
public slots:
83109

84110
/** Triggers a refresh of the histogram when the widget is next repainted.

src/gui/qgshistogramwidget.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ QgsHistogramWidget::QgsHistogramWidget( QWidget *parent, QgsVectorLayer* layer,
4747
, mRedrawRequired( true )
4848
, mVectorLayer( layer )
4949
, mSourceFieldExp( fieldOrExp )
50+
, mXAxisTitle( QObject::tr("Value"))
51+
, mYAxisTitle( QObject::tr("Count"))
5052
{
5153
setupUi( this );
5254

@@ -163,8 +165,20 @@ void QgsHistogramWidget::drawHistogram()
163165
//ensure all children get removed
164166
mpPlot->setAutoDelete( true );
165167
// Set axis titles
166-
mpPlot->setAxisTitle( QwtPlot::xBottom, QObject::tr( "Value" ) );
167-
mpPlot->setAxisTitle( QwtPlot::yLeft, QObject::tr( "Count" ) );
168+
if ( !mXAxisTitle.isEmpty() )
169+
mpPlot->setAxisTitle( QwtPlot::xBottom, mXAxisTitle );
170+
if ( !mYAxisTitle.isEmpty() )
171+
mpPlot->setAxisTitle( QwtPlot::yLeft, mYAxisTitle );
172+
mpPlot->setAxisFont( QwtPlot::xBottom, this->font() );
173+
mpPlot->setAxisFont( QwtPlot::yLeft, this->font() );
174+
QFont titleFont = this->font();
175+
titleFont.setBold( true );
176+
QwtText xAxisText = mpPlot->axisTitle( QwtPlot::xBottom );
177+
xAxisText.setFont( titleFont );
178+
mpPlot->setAxisTitle( QwtPlot::xBottom, xAxisText );
179+
QwtText yAxisText = mpPlot->axisTitle( QwtPlot::yLeft );
180+
yAxisText.setFont( titleFont );
181+
mpPlot->setAxisTitle( QwtPlot::yLeft, yAxisText );
168182
mpPlot->setAxisAutoScale( QwtPlot::yLeft );
169183
mpPlot->setAxisAutoScale( QwtPlot::xBottom );
170184

src/gui/qgshistogramwidget.h

+28
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,32 @@ class GUI_EXPORT QgsHistogramWidget : public QWidget, private Ui::QgsHistogramWi
118118
*/
119119
QgsRangeList graduatedRanges() const { return mRanges; }
120120

121+
/** Returns the title for the histogram's x-axis.
122+
* @see setXAxisTitle
123+
* @see yAxisTitle
124+
*/
125+
QString xAxisTitle() const { return mXAxisTitle; }
126+
127+
/** Sets the title for the histogram's x-axis.
128+
* @param title x-axis title, or empty string to remove title
129+
* @see xAxisTitle
130+
* @see setYAxisTitle
131+
*/
132+
void setXAxisTitle( const QString& title ) { mXAxisTitle = title; }
133+
134+
/** Returns the title for the histogram's y-axis.
135+
* @see setYAxisTitle
136+
* @see xAxisTitle
137+
*/
138+
QString yAxisTitle() const { return mYAxisTitle; }
139+
140+
/** Sets the title for the histogram's y-axis.
141+
* @param title y-axis title, or empty string to remove title
142+
* @see yAxisTitle
143+
* @see setXAxisTitle
144+
*/
145+
void setYAxisTitle( const QString& title ) { mYAxisTitle = title; }
146+
121147
public slots:
122148

123149
/** Triggers a refresh of the histogram when the widget is next repainted.
@@ -166,6 +192,8 @@ class GUI_EXPORT QgsHistogramWidget : public QWidget, private Ui::QgsHistogramWi
166192
QPen mMeanPen;
167193
QPen mStdevPen;
168194
QPen mGridPen;
195+
QString mXAxisTitle;
196+
QString mYAxisTitle;
169197

170198
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
171199
QwtPlotHistogram* createPlotHistogram( const QString& title, const QBrush &brush, const QPen &pen = Qt::NoPen ) const;

src/gui/symbology-ng/qgsgraduatedhistogramwidget.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ QgsGraduatedHistogramWidget::QgsGraduatedHistogramWidget( QWidget *parent )
5050
, mHistoPicker( 0 )
5151
, mPressedValue( 0 )
5252
{
53+
//clear x axis title to make more room for graph
54+
setXAxisTitle( QString() );
5355

5456
mFilter = new QgsGraduatedHistogramEventFilter( mPlot );
5557

0 commit comments

Comments
 (0)