Skip to content

Commit

Permalink
Drop generic option, go with custom property specific for GeoPDF exports
Browse files Browse the repository at this point in the history
It's too messy to try to handle this in a format-agnostic way, as
the requirement for GeoPDF is very unique to GeoPDF (ie SVG and other
formats don't export as mini-read-only-projects with custom layer
trees like GeoPDF does)
  • Loading branch information
nyalldawson committed Jul 10, 2024
1 parent 09f08b7 commit c236af4
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 172 deletions.
34 changes: 0 additions & 34 deletions python/PyQt6/core/auto_generated/layout/qgslayoutitem.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -442,40 +442,6 @@ Returns the behavior of this item during exporting to layered exports (e.g. SVG
.. seealso:: :py:func:`exportLayerName`

.. versionadded:: 3.10
%End

QString exportLayerName() const;
%Docstring
Returns the name for this item during exporting to layered exports (e.g. SVG or GeoPDF).

By default this is an empty string, which indicates that the item does not need to be placed in any specific
layer and will automatically be grouped with other items where possible.

If the layer name is non-empty, then the item will be placed in a group with the corresponding name
during layered exports.

.. seealso:: :py:func:`setExportLayerName`

.. seealso:: :py:func:`exportLayerBehavior`

.. versionadded:: 3.40
%End

void setExportLayerName( const QString &name );
%Docstring
Sets the ``name`` for this item during exporting to layered exports (e.g. SVG or GeoPDF).

If ``name`` is an empty string then the item does not need to be placed in any specific
layer and will automatically be grouped with other items where possible.

If the layer ``name`` is non-empty, then the item will be placed in a group with the corresponding name
during layered exports.

.. seealso:: :py:func:`exportLayerName`

.. seealso:: :py:func:`exportLayerBehavior`

.. versionadded:: 3.40
%End

virtual int numberExportLayers() const /Deprecated/;
Expand Down
34 changes: 0 additions & 34 deletions python/core/auto_generated/layout/qgslayoutitem.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -442,40 +442,6 @@ Returns the behavior of this item during exporting to layered exports (e.g. SVG
.. seealso:: :py:func:`exportLayerName`

.. versionadded:: 3.10
%End

QString exportLayerName() const;
%Docstring
Returns the name for this item during exporting to layered exports (e.g. SVG or GeoPDF).

By default this is an empty string, which indicates that the item does not need to be placed in any specific
layer and will automatically be grouped with other items where possible.

If the layer name is non-empty, then the item will be placed in a group with the corresponding name
during layered exports.

.. seealso:: :py:func:`setExportLayerName`

.. seealso:: :py:func:`exportLayerBehavior`

.. versionadded:: 3.40
%End

void setExportLayerName( const QString &name );
%Docstring
Sets the ``name`` for this item during exporting to layered exports (e.g. SVG or GeoPDF).

If ``name`` is an empty string then the item does not need to be placed in any specific
layer and will automatically be grouped with other items where possible.

If the layer ``name`` is non-empty, then the item will be placed in a group with the corresponding name
during layered exports.

.. seealso:: :py:func:`exportLayerName`

.. seealso:: :py:func:`exportLayerBehavior`

.. versionadded:: 3.40
%End

virtual int numberExportLayers() const /Deprecated/;
Expand Down
17 changes: 13 additions & 4 deletions src/core/layout/qgslayoutexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,11 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::exportToPdf( const QString &f
p.end();
return layerExportResult;
};
result = handleLayeredExport( items, exportFunc );
auto getExportGroupNameFunc = []( QgsLayoutItem * item )->QString
{
return item->customProperty( QStringLiteral( "pdfExportGroup" ) ).toString();
};
result = handleLayeredExport( items, exportFunc, getExportGroupNameFunc );
if ( result != Success )
return result;

Expand Down Expand Up @@ -1113,7 +1117,11 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::exportToSvg( const QString &f
{
return renderToLayeredSvg( settings, width, height, i, bounds, fileName, layerId, layerDetail.name, svg, svgDocRoot, settings.exportMetadata );
};
ExportResult res = handleLayeredExport( items, exportFunc );
auto getExportGroupNameFunc = []( QgsLayoutItem * )->QString
{
return QString();
};
ExportResult res = handleLayeredExport( items, exportFunc, getExportGroupNameFunc );
if ( res != Success )
return res;

Expand Down Expand Up @@ -1771,7 +1779,8 @@ QString nameForLayerWithItems( const QList< QGraphicsItem * > &items, unsigned i
}

QgsLayoutExporter::ExportResult QgsLayoutExporter::handleLayeredExport( const QList<QGraphicsItem *> &items,
const std::function<QgsLayoutExporter::ExportResult( unsigned int, const QgsLayoutItem::ExportLayerDetail & )> &exportFunc )
const std::function<QgsLayoutExporter::ExportResult( unsigned int, const QgsLayoutItem::ExportLayerDetail & )> &exportFunc,
const std::function<QString( QgsLayoutItem *item )> &getItemExportGroupFunc )
{
LayoutItemHider itemHider( items );
( void )itemHider;
Expand All @@ -1793,7 +1802,7 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::handleLayeredExport( const QL
if ( layoutItem )
{
QgsLayoutItem::ExportLayerBehavior itemExportBehavior = layoutItem->exportLayerBehavior();
thisItemExportGroupName = layoutItem->exportLayerName();
thisItemExportGroupName = getItemExportGroupFunc( layoutItem );
if ( !thisItemExportGroupName.isEmpty() )
{
if ( thisItemExportGroupName != previousItemGroup && !currentLayerItems.empty() )
Expand Down
5 changes: 4 additions & 1 deletion src/core/layout/qgslayoutexporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,10 @@ class CORE_EXPORT QgsLayoutExporter
bool georeferenceOutputPrivate( const QString &file, QgsLayoutItemMap *referenceMap = nullptr,
const QRectF &exportRegion = QRectF(), double dpi = -1, bool includeGeoreference = true, bool includeMetadata = false ) const;

ExportResult handleLayeredExport( const QList<QGraphicsItem *> &items, const std::function<QgsLayoutExporter::ExportResult( unsigned int layerId, const QgsLayoutItem::ExportLayerDetail &layerDetails )> &exportFunc );
ExportResult handleLayeredExport( const QList<QGraphicsItem *> &items,
const std::function<QgsLayoutExporter::ExportResult( unsigned int layerId, const QgsLayoutItem::ExportLayerDetail &layerDetails )> &exportFunc,
const std::function<QString( QgsLayoutItem *item )> &getItemExportGroupFunc
);

static QgsVectorSimplifyMethod createExportSimplifyMethod();
static QgsMaskRenderSettings createExportMaskSettings();
Expand Down
12 changes: 0 additions & 12 deletions src/core/layout/qgslayoutitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,6 @@ QgsLayoutItem::ExportLayerBehavior QgsLayoutItem::exportLayerBehavior() const
return CanGroupWithAnyOtherItem;
}

QString QgsLayoutItem::exportLayerName() const
{
return mExportLayerName;
}

void QgsLayoutItem::setExportLayerName( const QString &name )
{
mExportLayerName = name;
}

int QgsLayoutItem::numberExportLayers() const
{
return 0;
Expand Down Expand Up @@ -643,7 +633,6 @@ bool QgsLayoutItem::writeXml( QDomElement &parentElement, QDomDocument &doc, con
element.setAttribute( QStringLiteral( "size" ), mItemSize.encodeSize() );
element.setAttribute( QStringLiteral( "itemRotation" ), QString::number( mItemRotation ) );
element.setAttribute( QStringLiteral( "groupUuid" ), mParentGroupUuid );
element.setAttribute( QStringLiteral( "exportLayer" ), mExportLayerName );

element.setAttribute( QStringLiteral( "zValue" ), QString::number( zValue() ) );
element.setAttribute( QStringLiteral( "visibility" ), isVisible() );
Expand Down Expand Up @@ -834,7 +823,6 @@ bool QgsLayoutItem::readXml( const QDomElement &element, const QDomDocument &doc

mExcludeFromExports = element.attribute( QStringLiteral( "excludeFromExports" ), QStringLiteral( "0" ) ).toInt();
mEvaluatedExcludeFromExports = mExcludeFromExports;
mExportLayerName = element.attribute( QStringLiteral( "exportLayer" ) );

const bool result = readPropertiesFromElement( element, doc, context );

Expand Down
32 changes: 0 additions & 32 deletions src/core/layout/qgslayoutitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,36 +475,6 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
*/
virtual ExportLayerBehavior exportLayerBehavior() const;

/**
* Returns the name for this item during exporting to layered exports (e.g. SVG or GeoPDF).
*
* By default this is an empty string, which indicates that the item does not need to be placed in any specific
* layer and will automatically be grouped with other items where possible.
*
* If the layer name is non-empty, then the item will be placed in a group with the corresponding name
* during layered exports.
*
* \see setExportLayerName()
* \see exportLayerBehavior()
* \since QGIS 3.40
*/
QString exportLayerName() const;

/**
* Sets the \a name for this item during exporting to layered exports (e.g. SVG or GeoPDF).
*
* If \a name is an empty string then the item does not need to be placed in any specific
* layer and will automatically be grouped with other items where possible.
*
* If the layer \a name is non-empty, then the item will be placed in a group with the corresponding name
* during layered exports.
*
* \see exportLayerName()
* \see exportLayerBehavior()
* \since QGIS 3.40
*/
void setExportLayerName( const QString &name );

/**
* Returns the number of layers that this item requires for exporting during layered exports (e.g. SVG).
* Returns 0 if this item is to be placed on the same layer as the previous item,
Expand Down Expand Up @@ -1348,8 +1318,6 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
//! Whether item should be excluded in exports
bool mExcludeFromExports = false;

QString mExportLayerName;

/**
* Temporary evaluated item exclusion. Data defined properties may mean
* this value differs from mExcludeFromExports.
Expand Down
9 changes: 5 additions & 4 deletions src/gui/layout/qgslayoutitemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ void QgsLayoutItemPropertiesWidget::setValuesForGuiNonPositionElements()
whileBlocking( mOpacityWidget )->setOpacity( mItem->itemOpacity() );
whileBlocking( mItemRotationSpinBox )->setValue( mItem->itemRotation() );
whileBlocking( mExcludeFromPrintsCheckBox )->setChecked( mItem->excludeFromExports() );
whileBlocking( mExportGroupNameCombo )->setCurrentText( mItem->exportLayerName() );
whileBlocking( mExportGroupNameCombo )->setCurrentText( mItem->customProperty( QStringLiteral( "pdfExportGroup" ) ).toString() );
}

void QgsLayoutItemPropertiesWidget::initializeDataDefinedButtons()
Expand Down Expand Up @@ -795,8 +795,9 @@ void QgsLayoutItemPropertiesWidget::setValuesForGuiElements()
QStringList existingGroups;
for ( const QgsLayoutItem *item : std::as_const( items ) )
{
if ( !item->exportLayerName().isEmpty() && !existingGroups.contains( item->exportLayerName() ) )
existingGroups.append( item->exportLayerName() );
const QString groupName = item->customProperty( QStringLiteral( "pdfExportGroup" ) ).toString();
if ( !groupName.isEmpty() && !existingGroups.contains( groupName ) )
existingGroups.append( groupName );
}

std::sort( existingGroups.begin(), existingGroups.end(), [ = ]( const QString & a, const QString & b ) -> bool
Expand Down Expand Up @@ -852,7 +853,7 @@ void QgsLayoutItemPropertiesWidget::exportGroupNameEditingFinished()
if ( mItem )
{
mItem->layout()->undoStack()->beginCommand( mItem, tr( "Change Export Group Name" ), QgsLayoutItem::UndoExportLayerName );
mItem->setExportLayerName( mExportGroupNameCombo->currentText() );
mItem->setCustomProperty( QStringLiteral( "pdfExportGroup" ), mExportGroupNameCombo->currentText() );
mItem->layout()->undoStack()->endCommand();
}
}
Expand Down
Loading

0 comments on commit c236af4

Please sign in to comment.