Skip to content

Commit

Permalink
Fix some clazy/clang warnings in layout
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 13, 2018
1 parent 6920102 commit fa68041
Show file tree
Hide file tree
Showing 40 changed files with 141 additions and 134 deletions.
6 changes: 3 additions & 3 deletions python/core/auto_generated/layout/qgslayout.sip.in
Expand Up @@ -268,7 +268,7 @@ Returns the native units for the layout.
.. seealso:: :py:func:`convertToLayoutUnits`
%End

double convertToLayoutUnits( const QgsLayoutMeasurement &measurement ) const;
double convertToLayoutUnits( QgsLayoutMeasurement measurement ) const;
%Docstring
Converts a measurement into the layout's native units.

Expand Down Expand Up @@ -312,7 +312,7 @@ Converts a ``length`` measurement from the layout's native units to a specified
.. seealso:: :py:func:`units`
%End

QgsLayoutSize convertFromLayoutUnits( const QSizeF &size, QgsUnitTypes::LayoutUnit unit ) const;
QgsLayoutSize convertFromLayoutUnits( QSizeF size, QgsUnitTypes::LayoutUnit unit ) const;
%Docstring
Converts a ``size`` from the layout's native units to a specified target ``unit``.

Expand All @@ -323,7 +323,7 @@ Converts a ``size`` from the layout's native units to a specified target ``unit`
.. seealso:: :py:func:`units`
%End

QgsLayoutPoint convertFromLayoutUnits( const QPointF &point, QgsUnitTypes::LayoutUnit unit ) const;
QgsLayoutPoint convertFromLayoutUnits( QPointF point, QgsUnitTypes::LayoutUnit unit ) const;
%Docstring
Converts a ``point`` from the layout's native units to a specified target ``unit``.

Expand Down
Expand Up @@ -37,7 +37,7 @@ Constructor for QgsLayoutGridSettings.
virtual QgsLayout *layout();


void setResolution( const QgsLayoutMeasurement &resolution );
void setResolution( QgsLayoutMeasurement resolution );
%Docstring
Sets the page/snap grid ``resolution``.

Expand All @@ -55,7 +55,7 @@ Returns the page/snap grid resolution.
.. seealso:: :py:func:`offset`
%End

void setOffset( QgsLayoutPoint offset );
void setOffset( const QgsLayoutPoint &offset );
%Docstring
Sets the ``offset`` of the page/snap grid.

Expand Down
Expand Up @@ -21,7 +21,7 @@ Contains the configuration for a single snap guide used by a layout.
%End
public:

QgsLayoutGuide( Qt::Orientation orientation, const QgsLayoutMeasurement &position, QgsLayoutItemPage *page );
QgsLayoutGuide( Qt::Orientation orientation, QgsLayoutMeasurement position, QgsLayoutItemPage *page );
%Docstring
Constructor for a new guide with the specified ``orientation`` and
initial ``position``.
Expand Down Expand Up @@ -67,7 +67,7 @@ of the guide, depending on the guide's orientation().
.. seealso:: :py:func:`setPosition`
%End

void setPosition( const QgsLayoutMeasurement &position );
void setPosition( QgsLayoutMeasurement position );
%Docstring
Sets the guide's ``position`` within the page.

Expand Down
12 changes: 6 additions & 6 deletions python/core/auto_generated/layout/qgslayoutitem.sip.in
Expand Up @@ -382,7 +382,7 @@ content. Derived classes must not override this method, but instead implement
the pure virtual method QgsLayoutItem.draw.
%End

void setReferencePoint( const ReferencePoint &point );
void setReferencePoint( ReferencePoint point );
%Docstring
Sets the reference ``point`` for positioning of the layout item. This point is also
fixed during resizing of the item, and any size changes will be performed
Expand Down Expand Up @@ -661,7 +661,7 @@ Returns the frame's stroke color. This is only used if frameEnabled() returns tr
.. seealso:: :py:func:`setFrameStrokeColor`
%End

virtual void setFrameStrokeWidth( const QgsLayoutMeasurement &width );
virtual void setFrameStrokeWidth( QgsLayoutMeasurement width );
%Docstring
Sets the frame stroke ``width``.

Expand Down Expand Up @@ -948,7 +948,7 @@ If ``adjustPosition`` is false, rotation occurs around the item origin.
.. seealso:: :py:func:`rotateItem`
%End

virtual void rotateItem( double angle, const QPointF &transformOrigin );
virtual void rotateItem( double angle, QPointF transformOrigin );
%Docstring
Rotates the item by a specified ``angle`` in degrees clockwise around a specified reference point.

Expand Down Expand Up @@ -1031,7 +1031,7 @@ resized.
.. seealso:: :py:func:`setFixedSize`
%End

virtual QSizeF applyItemSizeConstraint( const QSizeF &targetSize );
virtual QSizeF applyItemSizeConstraint( QSizeF targetSize );
%Docstring
Applies any item-specific size constraint handling to a given ``targetSize`` in layout units.
Subclasses can override this method if they need to apply advanced logic regarding item
Expand Down Expand Up @@ -1102,13 +1102,13 @@ after the frame color is set and a later call to update() must be made.
Refresh item's blend mode, considering data defined blend mode.
%End

QPointF adjustPointForReferencePosition( const QPointF &point, const QSizeF &size, const ReferencePoint &reference ) const;
QPointF adjustPointForReferencePosition( QPointF point, QSizeF size, ReferencePoint reference ) const;
%Docstring
Adjusts the specified ``point`` at which a ``reference`` position of the item
sits and returns the top left corner of the item, if reference point were placed at the specified position.
%End

QPointF positionAtReferencePoint( const ReferencePoint &reference ) const;
QPointF positionAtReferencePoint( ReferencePoint reference ) const;
%Docstring
Returns the current position (in layout units) of a ``reference`` point for the item.
%End
Expand Down
Expand Up @@ -49,7 +49,7 @@ when converting measurements to and from pixels.
.. seealso:: :py:func:`setDpi`
%End

QgsLayoutMeasurement convert( const QgsLayoutMeasurement &measurement, QgsUnitTypes::LayoutUnit targetUnits ) const;
QgsLayoutMeasurement convert( QgsLayoutMeasurement measurement, QgsUnitTypes::LayoutUnit targetUnits ) const;
%Docstring
Converts a measurement from one unit to another.

Expand Down
Expand Up @@ -66,15 +66,15 @@ Returns the page number for the specified ``page``, or -1 if the page
is not contained in the collection.
%End

QList< QgsLayoutItemPage * > visiblePages( QRectF region ) const;
QList< QgsLayoutItemPage * > visiblePages( const QRectF &region ) const;
%Docstring
Returns a list of the pages which are visible within the specified
``region`` (in layout coordinates).

.. seealso:: :py:func:`visiblePageNumbers`
%End

QList< int > visiblePageNumbers( QRectF region ) const;
QList< int > visiblePageNumbers( const QRectF &region ) const;
%Docstring
Returns a list of the page numbers which are visible within the specified
``region`` (in layout coordinates).
Expand Down
4 changes: 2 additions & 2 deletions src/core/layout/qgscompositionconverter.cpp
Expand Up @@ -128,7 +128,7 @@ std::unique_ptr< QgsPrintLayout > QgsCompositionConverter::createLayoutFromCompo
// Guides
layout->guides().setVisible( composerElement.attribute( QStringLiteral( "guidesVisible" ), QStringLiteral( "1" ) ).toInt() != 0 );

int printResolution = composerElement.attribute( "printResolution", "300" ).toInt();
int printResolution = composerElement.attribute( QStringLiteral( "printResolution" ), QStringLiteral( "300" ) ).toInt();
layout->renderContext().setDpi( printResolution );

// Create pages
Expand Down Expand Up @@ -1563,7 +1563,7 @@ bool QgsCompositionConverter::readXml( QgsLayoutItem *layoutItem, const QDomElem
group->addItem( layoutItem );
}
}
layoutItem->mTemplateUuid = itemElem.attribute( "templateUuid" );
layoutItem->mTemplateUuid = itemElem.attribute( QStringLiteral( "templateUuid" ) );


QRectF position = itemPosition( layoutItem, itemElem );
Expand Down
8 changes: 4 additions & 4 deletions src/core/layout/qgslayout.cpp
Expand Up @@ -322,7 +322,7 @@ QgsLayoutItem *QgsLayout::layoutItemAt( QPointF position, const QgsLayoutItem *b
return nullptr;
}

double QgsLayout::convertToLayoutUnits( const QgsLayoutMeasurement &measurement ) const
double QgsLayout::convertToLayoutUnits( QgsLayoutMeasurement measurement ) const
{
return mRenderContext->measurementConverter().convert( measurement, mUnits ).length();
}
Expand All @@ -342,12 +342,12 @@ QgsLayoutMeasurement QgsLayout::convertFromLayoutUnits( const double length, con
return mRenderContext->measurementConverter().convert( QgsLayoutMeasurement( length, mUnits ), unit );
}

QgsLayoutSize QgsLayout::convertFromLayoutUnits( const QSizeF &size, const QgsUnitTypes::LayoutUnit unit ) const
QgsLayoutSize QgsLayout::convertFromLayoutUnits( QSizeF size, const QgsUnitTypes::LayoutUnit unit ) const
{
return mRenderContext->measurementConverter().convert( QgsLayoutSize( size.width(), size.height(), mUnits ), unit );
}

QgsLayoutPoint QgsLayout::convertFromLayoutUnits( const QPointF &point, const QgsUnitTypes::LayoutUnit unit ) const
QgsLayoutPoint QgsLayout::convertFromLayoutUnits( QPointF point, const QgsUnitTypes::LayoutUnit unit ) const
{
return mRenderContext->measurementConverter().convert( QgsLayoutPoint( point.x(), point.y(), mUnits ), unit );
}
Expand Down Expand Up @@ -839,7 +839,7 @@ bool QgsLayout::readXmlLayoutSettings( const QDomElement &layoutElement, const Q
mCustomProperties.readXml( layoutElement );
setUnits( QgsUnitTypes::decodeLayoutUnit( layoutElement.attribute( QStringLiteral( "units" ) ) ) );
mWorldFileMapId = layoutElement.attribute( QStringLiteral( "worldFileMap" ) );
mRenderContext->setDpi( layoutElement.attribute( QStringLiteral( "printResolution" ), "300" ).toDouble() );
mRenderContext->setDpi( layoutElement.attribute( QStringLiteral( "printResolution" ), QStringLiteral( "300" ) ).toDouble() );
emit changed();

return true;
Expand Down
6 changes: 3 additions & 3 deletions src/core/layout/qgslayout.h
Expand Up @@ -333,7 +333,7 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
* \see convertFromLayoutUnits()
* \see units()
*/
double convertToLayoutUnits( const QgsLayoutMeasurement &measurement ) const;
double convertToLayoutUnits( QgsLayoutMeasurement measurement ) const;

/**
* Converts a size into the layout's native units.
Expand Down Expand Up @@ -365,15 +365,15 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
* \see convertToLayoutUnits()
* \see units()
*/
QgsLayoutSize convertFromLayoutUnits( const QSizeF &size, QgsUnitTypes::LayoutUnit unit ) const;
QgsLayoutSize convertFromLayoutUnits( QSizeF size, QgsUnitTypes::LayoutUnit unit ) const;

/**
* Converts a \a point from the layout's native units to a specified target \a unit.
* \returns point in specified units
* \see convertToLayoutUnits()
* \see units()
*/
QgsLayoutPoint convertFromLayoutUnits( const QPointF &point, QgsUnitTypes::LayoutUnit unit ) const;
QgsLayoutPoint convertFromLayoutUnits( QPointF point, QgsUnitTypes::LayoutUnit unit ) const;

/**
* Returns a reference to the layout's render context, which stores information relating to the
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutatlas.cpp
Expand Up @@ -304,7 +304,7 @@ int QgsLayoutAtlas::updateFeatures()
if ( !mFeatureKeys.isEmpty() )
{
AtlasFeatureSorter sorter( mFeatureKeys, mSortAscending );
std::sort( mFeatureIds.begin(), mFeatureIds.end(), sorter );
std::sort( mFeatureIds.begin(), mFeatureIds.end(), sorter ); // clazy:exclude=detaching-member
}

emit numberFeaturesChanged( mFeatureIds.size() );
Expand Down
27 changes: 15 additions & 12 deletions src/core/layout/qgslayoutexporter.cpp
Expand Up @@ -264,8 +264,8 @@ QImage QgsLayoutExporter::renderRegionToImage( const QRectF &region, QSize image
QImage image( QSize( width, height ), QImage::Format_ARGB32 );
if ( !image.isNull() )
{
image.setDotsPerMeterX( resolution / 25.4 * 1000 );
image.setDotsPerMeterY( resolution / 25.4 * 1000 );
image.setDotsPerMeterX( static_cast< int >( std::round( resolution / 25.4 * 1000 ) ) );
image.setDotsPerMeterY( static_cast< int>( std::round( resolution / 25.4 * 1000 ) ) );
image.fill( Qt::transparent );
QPainter imagePainter( &image );
renderRegion( &imagePainter, region );
Expand Down Expand Up @@ -807,9 +807,9 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::exportToSvg( const QString &f
}

//width in pixel
int width = ( int )( bounds.width() * settings.dpi / inchesToLayoutUnits );
int width = static_cast< int >( bounds.width() * settings.dpi / inchesToLayoutUnits );
//height in pixel
int height = ( int )( bounds.height() * settings.dpi / inchesToLayoutUnits );
int height = static_cast< int >( bounds.height() * settings.dpi / inchesToLayoutUnits );
if ( width == 0 || height == 0 )
{
//invalid size, skip this page
Expand Down Expand Up @@ -899,7 +899,7 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::exportToSvg( const QString &f
generator.setOutputDevice( &svgBuffer );
generator.setSize( QSize( width, height ) );
generator.setViewBox( QRect( 0, 0, width, height ) );
generator.setResolution( settings.dpi );
generator.setResolution( static_cast< int >( std::round( settings.dpi ) ) );

QPainter p;
bool createOk = p.begin( &generator );
Expand Down Expand Up @@ -1024,7 +1024,7 @@ void QgsLayoutExporter::preparePrint( QgsLayout *layout, QPrinter &printer, bool
printer.setColorMode( QPrinter::Color );

//set user-defined resolution
printer.setResolution( layout->renderContext().dpi() );
printer.setResolution( static_cast< int>( std::round( layout->renderContext().dpi() ) ) );

if ( setFirstPageSize )
{
Expand Down Expand Up @@ -1130,9 +1130,12 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::renderToLayeredSvg( const Svg
}

generator.setOutputDevice( &svgBuffer );
generator.setSize( QSize( width, height ) );
generator.setViewBox( QRect( 0, 0, width, height ) );
generator.setResolution( settings.dpi ); //because the rendering is done in mm, convert the dpi
generator.setSize( QSize( static_cast< int >( std::round( width ) ),
static_cast< int >( std::round( height ) ) ) );
generator.setViewBox( QRect( 0, 0,
static_cast< int >( std::round( width ) ),
static_cast< int >( std::round( height ) ) ) );
generator.setResolution( static_cast< int >( std::round( settings.dpi ) ) ); //because the rendering is done in mm, convert the dpi

QPainter svgPainter( &generator );
if ( settings.cropToContents )
Expand All @@ -1141,9 +1144,9 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::renderToLayeredSvg( const Svg
renderPage( &svgPainter, page );
}

// post-process svg output to create groups in a single svg file
// we create inkscape layers since it's nice and clean and free
// and fully svg compatible
// post-process svg output to create groups in a single svg file
// we create inkscape layers since it's nice and clean and free
// and fully svg compatible
{
svgBuffer.close();
svgBuffer.open( QIODevice::ReadOnly );
Expand Down
4 changes: 2 additions & 2 deletions src/core/layout/qgslayoutgridsettings.cpp
Expand Up @@ -36,14 +36,14 @@ QgsLayout *QgsLayoutGridSettings::layout()
return mLayout;
}

void QgsLayoutGridSettings::setResolution( const QgsLayoutMeasurement &resolution )
void QgsLayoutGridSettings::setResolution( QgsLayoutMeasurement resolution )
{
mLayout->undoStack()->beginCommand( this, QObject::tr( "Change Grid Resolution" ), UndoGridResolution );
mGridResolution = resolution;
mLayout->undoStack()->endCommand();
}

void QgsLayoutGridSettings::setOffset( const QgsLayoutPoint offset )
void QgsLayoutGridSettings::setOffset( const QgsLayoutPoint &offset )
{
mLayout->undoStack()->beginCommand( this, QObject::tr( "Change Grid Offset" ), UndoGridOffset );
mGridOffset = offset;
Expand Down
4 changes: 2 additions & 2 deletions src/core/layout/qgslayoutgridsettings.h
Expand Up @@ -58,7 +58,7 @@ class CORE_EXPORT QgsLayoutGridSettings : public QgsLayoutSerializableObject
* \see resolution()
* \see setOffset()
*/
void setResolution( const QgsLayoutMeasurement &resolution );
void setResolution( QgsLayoutMeasurement resolution );

/**
* Returns the page/snap grid resolution.
Expand All @@ -72,7 +72,7 @@ class CORE_EXPORT QgsLayoutGridSettings : public QgsLayoutSerializableObject
* \see offset()
* \see setResolution()
*/
void setOffset( QgsLayoutPoint offset );
void setOffset( const QgsLayoutPoint &offset );

/**
* Returns the offset of the page/snap grid.
Expand Down
6 changes: 3 additions & 3 deletions src/core/layout/qgslayoutguidecollection.cpp
Expand Up @@ -27,7 +27,7 @@
// QgsLayoutGuide
//

QgsLayoutGuide::QgsLayoutGuide( Qt::Orientation orientation, const QgsLayoutMeasurement &position, QgsLayoutItemPage *page )
QgsLayoutGuide::QgsLayoutGuide( Qt::Orientation orientation, QgsLayoutMeasurement position, QgsLayoutItemPage *page )
: QObject( nullptr )
, mOrientation( orientation )
, mPosition( position )
Expand All @@ -48,7 +48,7 @@ QgsLayoutMeasurement QgsLayoutGuide::position() const
return mPosition;
}

void QgsLayoutGuide::setPosition( const QgsLayoutMeasurement &position )
void QgsLayoutGuide::setPosition( QgsLayoutMeasurement position )
{
mPosition = position;
update();
Expand Down Expand Up @@ -299,7 +299,7 @@ bool QgsLayoutGuideCollection::setData( const QModelIndex &index, const QVariant
return false;

QgsLayoutMeasurement m = guide->position();
if ( m.length() == newPos )
if ( qgsDoubleNear( m.length(), newPos ) )
return true;

m.setLength( newPos );
Expand Down
4 changes: 2 additions & 2 deletions src/core/layout/qgslayoutguidecollection.h
Expand Up @@ -54,7 +54,7 @@ class CORE_EXPORT QgsLayoutGuide : public QObject
* Adding the guide to a QgsLayoutGuideCollection will automatically set
* the corresponding layout for you.
*/
QgsLayoutGuide( Qt::Orientation orientation, const QgsLayoutMeasurement &position, QgsLayoutItemPage *page );
QgsLayoutGuide( Qt::Orientation orientation, QgsLayoutMeasurement position, QgsLayoutItemPage *page );

~QgsLayoutGuide() override;

Expand Down Expand Up @@ -97,7 +97,7 @@ class CORE_EXPORT QgsLayoutGuide : public QObject
*
* \see position()
*/
void setPosition( const QgsLayoutMeasurement &position );
void setPosition( QgsLayoutMeasurement position );

/**
* Returns the page the guide is contained within.
Expand Down

0 comments on commit fa68041

Please sign in to comment.