Skip to content

Commit

Permalink
Fix diagram printing
Browse files Browse the repository at this point in the history
When units are set to mm convert first to units that PAL expects for arrangement.
  • Loading branch information
m-kuhn committed Aug 17, 2012
1 parent 55b5dcb commit bf23608
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
14 changes: 13 additions & 1 deletion src/core/diagram/qgsdiagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,24 @@ void QgsDiagram::setPenWidth( QPen& pen, const QgsDiagramSettings& s, const QgsR
}
}

QSizeF QgsDiagram::sizeForPAL( const QSizeF& size, const QgsDiagramSettings& s, const QgsRenderContext& c )
{
if ( s.sizeType == QgsDiagramSettings::MM )
{
return QSizeF( size.width() / c.rasterScaleFactor(), size.height() / c.rasterScaleFactor() );
}
else
{
return QSizeF( size );
}
}

QSizeF QgsDiagram::sizePainterUnits( const QSizeF& size, const QgsDiagramSettings& s, const QgsRenderContext& c )
{
Q_UNUSED( size );
if ( s.sizeType == QgsDiagramSettings::MM )
{
return QSizeF( s.size.width() * c.scaleFactor(), s.size.height() * c.scaleFactor() );
return QSizeF( s.size.width() * c.scaleFactor() * c.rasterScaleFactor(), s.size.height() * c.scaleFactor() * c.rasterScaleFactor());
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/core/diagram/qgsdiagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CORE_EXPORT QgsDiagram
protected:
void setPenWidth( QPen& pen, const QgsDiagramSettings& s, const QgsRenderContext& c );
QSizeF sizePainterUnits( const QSizeF& size, const QgsDiagramSettings& s, const QgsRenderContext& c );
QSizeF sizeForPAL( const QSizeF& size, const QgsDiagramSettings& s, const QgsRenderContext& c );
float sizePainterUnits( float l, const QgsDiagramSettings& s, const QgsRenderContext& c );
QFont scaledFont( const QgsDiagramSettings& s, const QgsRenderContext& c );
};
Expand Down
22 changes: 15 additions & 7 deletions src/core/diagram/qgshistogramdiagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,24 @@ QSizeF QgsHistogramDiagram::diagramSize( const QgsAttributeMap& attributes, cons
case QgsDiagramSettings::Up:
case QgsDiagramSettings::Down:
mScaleFactor = ( ( is.upperSize.width() - is.lowerSize.height() ) / ( is.upperValue - is.lowerValue ) );
return QSizeF( s.barWidth * attributes.size(), maxValue * mScaleFactor );
size.scale( s.barWidth * attributes.size(), maxValue * mScaleFactor, Qt::IgnoreAspectRatio );
break;

case QgsDiagramSettings::Right:
case QgsDiagramSettings::Left:
mScaleFactor = ( ( is.upperSize.width() - is.lowerSize.width() ) / ( is.upperValue - is.lowerValue ) );
return QSizeF( maxValue * mScaleFactor, s.barWidth * attributes.size() );
size.scale( maxValue * mScaleFactor, s.barWidth * attributes.size(), Qt::IgnoreAspectRatio );
break;
}

return QSizeF();
QSizeF scaledSize = sizeForPAL( size, s, c );
return scaledSize;
}

QSizeF QgsHistogramDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s )
{
Q_UNUSED( c );
QSizeF size;

QgsAttributeMap::const_iterator attIt = attributes.constBegin();
if ( attIt == attributes.constEnd() )
{
Expand All @@ -88,15 +92,19 @@ QSizeF QgsHistogramDiagram::diagramSize( const QgsAttributeMap& attributes, cons
case QgsDiagramSettings::Up:
case QgsDiagramSettings::Down:
mScaleFactor = maxValue / s.size.height();
return QSizeF( s.barWidth * attributes.size(), s.size.height() );
size.scale( s.barWidth * attributes.size(), s.size.height(), Qt::IgnoreAspectRatio );
break;

case QgsDiagramSettings::Right:
case QgsDiagramSettings::Left:
default: // just in case...
mScaleFactor = maxValue / s.size.width();
return QSizeF( s.size.width(), s.barWidth * attributes.size() );
size.scale( s.size.width(), s.barWidth * attributes.size(), Qt::IgnoreAspectRatio );
break;
}

return QSizeF();
QSizeF scaledSize = sizeForPAL( size, s, c );
return scaledSize;
}

void QgsHistogramDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position )
Expand Down
8 changes: 6 additions & 2 deletions src/core/diagram/qgspiediagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ QSizeF QgsPieDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsR
size.scale( s.minimumSize, s.minimumSize, Qt::KeepAspectRatio );
}

return size;
QSizeF scaledSize = sizeForPAL( size, s, c );
return scaledSize;
}

QSizeF QgsPieDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s )
{
return s.size;
QSizeF scaledSize = sizeForPAL( s.size, s, c );
return scaledSize;
}

int QgsPieDiagram::sCount = 0;

void QgsPieDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position )
{
QPainter* p = c.painter();
Expand Down
2 changes: 2 additions & 0 deletions src/core/diagram/qgspiediagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class CORE_EXPORT QgsPieDiagram: public QgsDiagram
private:
QBrush mCategoryBrush;
QPen mPen;

static int sCount;
};

#endif // QGSPIEDIAGRAM_H
6 changes: 4 additions & 2 deletions src/core/diagram/qgstextdiagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ QSizeF QgsTextDiagram::diagramSize( const QgsAttributeMap& attributes, const Qgs
size.scale( s.minimumSize, s.minimumSize, Qt::KeepAspectRatio );
}

return size;
QSizeF scaledSize = sizeForPAL( size, s, c );
return scaledSize;
}

QSizeF QgsTextDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s )
{
return s.size;
QSizeF scaledSize = sizeForPAL( s.size, s, c );
return scaledSize;
}

void QgsTextDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position )
Expand Down

0 comments on commit bf23608

Please sign in to comment.