Skip to content

Commit

Permalink
[composer] Some small fixes to svg layers export, naming improvements…
Browse files Browse the repository at this point in the history
…, additional comments
  • Loading branch information
nyalldawson committed Apr 16, 2014
1 parent 0c19945 commit 122034a
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 79 deletions.
15 changes: 9 additions & 6 deletions python/core/composer/qgscomposeritem.sip
Expand Up @@ -401,14 +401,17 @@ class QgsComposerItem : QObject, QGraphicsRectItem
@note there is not setter since one can't manually set the id*/
QString uuid() const;

/**Get the number of layers that this item exports
@returns 0 if this item is to be placed on the same layer as the previous item
@note this method was added in version 2.4 */
/**Get the number of layers that this item requires for exporting as layers
* @returns 0 if this item is to be placed on the same layer as the previous item,
* 1 if it should be placed on its own layer, and >1 if it requires multiple export layers
* @note this method was added in version 2.4
*/
int numberExportLayers() const;

/**Set the layer to export
@param layerIdx can be set to -1 to export all layerr and must be less than numberExportLayers()
@note this method was added in version 2.4 */
/**Sets the current layer to draw for exporting
* @param layerIdx can be set to -1 to draw all item layers, and must be less than numberExportLayers()
* @note this method was added in version 2.4
*/
void setCurrentExportLayer( int layerIdx = -1 );

public slots:
Expand Down
8 changes: 5 additions & 3 deletions python/core/composer/qgscomposermap.sip
Expand Up @@ -407,9 +407,11 @@ class QgsComposerMap : QgsComposerItem
/** Returns whether updates to the composer map are enabled. */
bool updatesEnabled() const;

/**Get the number of layers that this item exports
@returns 0 if this item is to be placed on the same layer as the previous item
@note this method was added in version 2.4 */
/**Get the number of layers that this item requires for exporting as layers
* @returns 0 if this item is to be placed on the same layer as the previous item,
* 1 if it should be placed on its own layer, and >1 if it requires multiple export layers
* @note this method was added in version 2.4
*/
int numberExportLayers() const;

signals:
Expand Down
15 changes: 9 additions & 6 deletions src/core/composer/qgscomposeritem.h
Expand Up @@ -361,14 +361,17 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
@note there is not setter since one can't manually set the id*/
QString uuid() const { return mUuid; }

/**Get the number of layers that this item exports
@returns 0 if this item is to be placed on the same layer as the previous item
@note this method was added in version 2.4 */
/**Get the number of layers that this item requires for exporting as layers
* @returns 0 if this item is to be placed on the same layer as the previous item,
* 1 if it should be placed on its own layer, and >1 if it requires multiple export layers
* @note this method was added in version 2.4
*/
virtual int numberExportLayers() const { return 0; }

/**Set the layer to export
@param layerIdx can be set to -1 to export all layerr and must be less than numberExportLayers()
@note this method was added in version 2.4 */
/**Sets the current layer to draw for exporting
* @param layerIdx can be set to -1 to draw all item layers, and must be less than numberExportLayers()
* @note this method was added in version 2.4
*/
virtual void setCurrentExportLayer( int layerIdx = -1 ) { mCurrentExportLayer = layerIdx; }

public slots:
Expand Down
51 changes: 37 additions & 14 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -185,11 +185,12 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
QStringList theLayerSet = layersToRender();
if ( -1 != mCurrentExportLayer )
{
//exporting with seperate layers (eg, to svg layers), so we only want to render a single map layer
const int layerIdx = mCurrentExportLayer - ( hasBackground() ? 1 : 0 );
theLayerSet =
theLayerSet =
( layerIdx >= 0 && layerIdx < theLayerSet.length() )
? QStringList( theLayerSet[ theLayerSet.length() - layerIdx - 1 ] )
: QStringList();
: QStringList(); //exporting decorations such as map frame/grid/overview, so no map layers required
}
jobMapSettings.setLayers( theLayerSet );
jobMapSettings.setDestinationCrs( ms.destinationCrs() );
Expand Down Expand Up @@ -364,7 +365,7 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
}

// Fill with background color
if ( exportLayer( Background ) )
if ( shouldDrawPart( Background ) )
{
drawBackground( painter );
}
Expand Down Expand Up @@ -407,19 +408,19 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i

painter->setClipRect( thisPaintRect , Qt::NoClip );

if ( mGridEnabled && exportLayer( Grid ) )
if ( mGridEnabled && shouldDrawPart( Grid ) )
{
drawGrid( painter );
}
if ( mOverviewFrameMapId != -1 && exportLayer( OverviewMapExtent ) )
if ( mOverviewFrameMapId != -1 && shouldDrawPart( OverviewMapExtent ) )
{
drawOverviewMapExtent( painter );
}
if ( exportLayer( Frame ) )
if ( shouldDrawPart( Frame ) )
{
drawFrame( painter );
}
if ( isSelected() && exportLayer( SelectionBoxes ) )
if ( isSelected() && shouldDrawPart( SelectionBoxes ) )
{
drawSelectionBoxes( painter );
}
Expand All @@ -439,34 +440,56 @@ int QgsComposerMap::numberExportLayers() const
;
}

bool QgsComposerMap::exportLayer( ItemType type ) const
bool QgsComposerMap::shouldDrawPart( PartType part ) const
{
if ( -1 == mCurrentExportLayer ) return true;
if ( -1 == mCurrentExportLayer )
{
//all parts of the composer map are visible
return true;
}

int idx = numberExportLayers();
if ( isSelected() )
{
--idx;
if ( SelectionBoxes == type ) return mCurrentExportLayer == idx;
if ( SelectionBoxes == part )
{
return mCurrentExportLayer == idx;
}
}

if ( hasFrame() )
{
--idx;
if ( Frame == type ) return mCurrentExportLayer == idx;
if ( Frame == part )
{
return mCurrentExportLayer == idx;
}
}
if ( mOverviewFrameMapId )
{
--idx;
if ( OverviewMapExtent == type ) return mCurrentExportLayer == idx;
if ( OverviewMapExtent == part )
{
return mCurrentExportLayer == idx;
}
}
if ( mGridEnabled )
{
--idx;
if ( Grid == type ) return mCurrentExportLayer == idx;
if ( Grid == part )
{
return mCurrentExportLayer == idx;
}
}
if ( hasBackground() )
{
if ( Background == type ) return mCurrentExportLayer == 0;
if ( Background == part )
{
return mCurrentExportLayer == 0;
}
}

return true; // for Layer
}

Expand Down
14 changes: 8 additions & 6 deletions src/core/composer/qgscomposermap.h
Expand Up @@ -445,9 +445,11 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
/** Returns whether updates to the composer map are enabled. */
bool updatesEnabled() const { return mUpdatesEnabled; }

/**Get the number of layers that this item exports
@returns 0 if this item is to be placed on the same layer as the previous item
@note this method was added in version 2.4 */
/**Get the number of layers that this item requires for exporting as layers
* @returns 0 if this item is to be placed on the same layer as the previous item,
* 1 if it should be placed on its own layer, and >1 if it requires multiple export layers
* @note this method was added in version 2.4
*/
int numberExportLayers() const;

signals:
Expand Down Expand Up @@ -670,7 +672,7 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
void createDefaultGridLineSymbol();
void initGridAnnotationFormatFromProject();

enum ItemType
enum PartType
{
Background,
Layer,
Expand All @@ -680,8 +682,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
SelectionBoxes
};

/**Test if this item needs to be exported considering mCurrentExportLayer*/
bool exportLayer( ItemType type ) const;
/**Test if a part of the copmosermap needs to be drawn, considering mCurrentExportLayer*/
bool shouldDrawPart( PartType part ) const;
};

#endif
Expand Down
85 changes: 41 additions & 44 deletions src/ui/qgssvgexportoptions.ui
Expand Up @@ -6,55 +6,52 @@
<rect>
<x>0</x>
<y>0</y>
<width>675</width>
<height>170</height>
<width>463</width>
<height>103</height>
</rect>
</property>
<property name="windowTitle">
<string>SVG export options</string>
</property>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>604</width>
<height>101</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="chkMapLayersAsGroup">
<property name="text">
<string>Export map layers as svg groups (may affect label placement)</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkTextAsOutline">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Render text as outline</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="chkMapLayersAsGroup">
<property name="text">
<string>Export map layers as svg groups (may affect label placement)</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkTextAsOutline">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Render text as outline</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
Expand Down

0 comments on commit 122034a

Please sign in to comment.