Skip to content

Commit

Permalink
Tweak appearance of histogram titles and hide value title to make
Browse files Browse the repository at this point in the history
more space for plot itself.
  • Loading branch information
nyalldawson committed Jun 12, 2015
1 parent bcab4ae commit 86a45d4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
26 changes: 26 additions & 0 deletions python/gui/qgshistogramwidget.sip
Expand Up @@ -79,6 +79,32 @@ class QgsHistogramWidget : QWidget
*/
QgsRangeList graduatedRanges() const;

/** Returns the title for the histogram's x-axis.
* @see setXAxisTitle
* @see yAxisTitle
*/
QString xAxisTitle() const;

/** Sets the title for the histogram's x-axis.
* @param title x-axis title, or empty string to remove title
* @see xAxisTitle
* @see setYAxisTitle
*/
void setXAxisTitle( const QString& title );

/** Returns the title for the histogram's y-axis.
* @see setYAxisTitle
* @see xAxisTitle
*/
QString yAxisTitle() const;

/** Sets the title for the histogram's y-axis.
* @param title y-axis title, or empty string to remove title
* @see yAxisTitle
* @see setXAxisTitle
*/
void setYAxisTitle( const QString& title );

public slots:

/** Triggers a refresh of the histogram when the widget is next repainted.
Expand Down
18 changes: 16 additions & 2 deletions src/gui/qgshistogramwidget.cpp
Expand Up @@ -47,6 +47,8 @@ QgsHistogramWidget::QgsHistogramWidget( QWidget *parent, QgsVectorLayer* layer,
, mRedrawRequired( true )
, mVectorLayer( layer )
, mSourceFieldExp( fieldOrExp )
, mXAxisTitle( QObject::tr("Value"))
, mYAxisTitle( QObject::tr("Count"))
{
setupUi( this );

Expand Down Expand Up @@ -163,8 +165,20 @@ void QgsHistogramWidget::drawHistogram()
//ensure all children get removed
mpPlot->setAutoDelete( true );
// Set axis titles
mpPlot->setAxisTitle( QwtPlot::xBottom, QObject::tr( "Value" ) );
mpPlot->setAxisTitle( QwtPlot::yLeft, QObject::tr( "Count" ) );
if ( !mXAxisTitle.isEmpty() )
mpPlot->setAxisTitle( QwtPlot::xBottom, mXAxisTitle );
if ( !mYAxisTitle.isEmpty() )
mpPlot->setAxisTitle( QwtPlot::yLeft, mYAxisTitle );
mpPlot->setAxisFont( QwtPlot::xBottom, this->font() );
mpPlot->setAxisFont( QwtPlot::yLeft, this->font() );
QFont titleFont = this->font();
titleFont.setBold( true );
QwtText xAxisText = mpPlot->axisTitle( QwtPlot::xBottom );
xAxisText.setFont( titleFont );
mpPlot->setAxisTitle( QwtPlot::xBottom, xAxisText );
QwtText yAxisText = mpPlot->axisTitle( QwtPlot::yLeft );
yAxisText.setFont( titleFont );
mpPlot->setAxisTitle( QwtPlot::yLeft, yAxisText );
mpPlot->setAxisAutoScale( QwtPlot::yLeft );
mpPlot->setAxisAutoScale( QwtPlot::xBottom );

Expand Down
28 changes: 28 additions & 0 deletions src/gui/qgshistogramwidget.h
Expand Up @@ -118,6 +118,32 @@ class GUI_EXPORT QgsHistogramWidget : public QWidget, private Ui::QgsHistogramWi
*/
QgsRangeList graduatedRanges() const { return mRanges; }

/** Returns the title for the histogram's x-axis.
* @see setXAxisTitle
* @see yAxisTitle
*/
QString xAxisTitle() const { return mXAxisTitle; }

/** Sets the title for the histogram's x-axis.
* @param title x-axis title, or empty string to remove title
* @see xAxisTitle
* @see setYAxisTitle
*/
void setXAxisTitle( const QString& title ) { mXAxisTitle = title; }

/** Returns the title for the histogram's y-axis.
* @see setYAxisTitle
* @see xAxisTitle
*/
QString yAxisTitle() const { return mYAxisTitle; }

/** Sets the title for the histogram's y-axis.
* @param title y-axis title, or empty string to remove title
* @see yAxisTitle
* @see setXAxisTitle
*/
void setYAxisTitle( const QString& title ) { mYAxisTitle = title; }

public slots:

/** Triggers a refresh of the histogram when the widget is next repainted.
Expand Down Expand Up @@ -166,6 +192,8 @@ class GUI_EXPORT QgsHistogramWidget : public QWidget, private Ui::QgsHistogramWi
QPen mMeanPen;
QPen mStdevPen;
QPen mGridPen;
QString mXAxisTitle;
QString mYAxisTitle;

#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
QwtPlotHistogram* createPlotHistogram( const QString& title, const QBrush &brush, const QPen &pen = Qt::NoPen ) const;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgsgraduatedhistogramwidget.cpp
Expand Up @@ -50,6 +50,8 @@ QgsGraduatedHistogramWidget::QgsGraduatedHistogramWidget( QWidget *parent )
, mHistoPicker( 0 )
, mPressedValue( 0 )
{
//clear x axis title to make more room for graph
setXAxisTitle( QString() );

mFilter = new QgsGraduatedHistogramEventFilter( mPlot );

Expand Down

0 comments on commit 86a45d4

Please sign in to comment.