Skip to content

Commit 122034a

Browse files
committedApr 16, 2014
[composer] Some small fixes to svg layers export, naming improvements, additional comments
1 parent 0c19945 commit 122034a

File tree

6 files changed

+109
-79
lines changed

6 files changed

+109
-79
lines changed
 

‎python/core/composer/qgscomposeritem.sip

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,17 @@ class QgsComposerItem : QObject, QGraphicsRectItem
401401
@note there is not setter since one can't manually set the id*/
402402
QString uuid() const;
403403

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

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

414417
public slots:

‎python/core/composer/qgscomposermap.sip

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,11 @@ class QgsComposerMap : QgsComposerItem
407407
/** Returns whether updates to the composer map are enabled. */
408408
bool updatesEnabled() const;
409409

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

415417
signals:

‎src/core/composer/qgscomposeritem.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,17 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
361361
@note there is not setter since one can't manually set the id*/
362362
QString uuid() const { return mUuid; }
363363

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

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

374377
public slots:

‎src/core/composer/qgscomposermap.cpp

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,12 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
185185
QStringList theLayerSet = layersToRender();
186186
if ( -1 != mCurrentExportLayer )
187187
{
188+
//exporting with seperate layers (eg, to svg layers), so we only want to render a single map layer
188189
const int layerIdx = mCurrentExportLayer - ( hasBackground() ? 1 : 0 );
189-
theLayerSet =
190+
theLayerSet =
190191
( layerIdx >= 0 && layerIdx < theLayerSet.length() )
191192
? QStringList( theLayerSet[ theLayerSet.length() - layerIdx - 1 ] )
192-
: QStringList();
193+
: QStringList(); //exporting decorations such as map frame/grid/overview, so no map layers required
193194
}
194195
jobMapSettings.setLayers( theLayerSet );
195196
jobMapSettings.setDestinationCrs( ms.destinationCrs() );
@@ -364,7 +365,7 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
364365
}
365366

366367
// Fill with background color
367-
if ( exportLayer( Background ) )
368+
if ( shouldDrawPart( Background ) )
368369
{
369370
drawBackground( painter );
370371
}
@@ -407,19 +408,19 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
407408

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

410-
if ( mGridEnabled && exportLayer( Grid ) )
411+
if ( mGridEnabled && shouldDrawPart( Grid ) )
411412
{
412413
drawGrid( painter );
413414
}
414-
if ( mOverviewFrameMapId != -1 && exportLayer( OverviewMapExtent ) )
415+
if ( mOverviewFrameMapId != -1 && shouldDrawPart( OverviewMapExtent ) )
415416
{
416417
drawOverviewMapExtent( painter );
417418
}
418-
if ( exportLayer( Frame ) )
419+
if ( shouldDrawPart( Frame ) )
419420
{
420421
drawFrame( painter );
421422
}
422-
if ( isSelected() && exportLayer( SelectionBoxes ) )
423+
if ( isSelected() && shouldDrawPart( SelectionBoxes ) )
423424
{
424425
drawSelectionBoxes( painter );
425426
}
@@ -439,34 +440,56 @@ int QgsComposerMap::numberExportLayers() const
439440
;
440441
}
441442

442-
bool QgsComposerMap::exportLayer( ItemType type ) const
443+
bool QgsComposerMap::shouldDrawPart( PartType part ) const
443444
{
444-
if ( -1 == mCurrentExportLayer ) return true;
445+
if ( -1 == mCurrentExportLayer )
446+
{
447+
//all parts of the composer map are visible
448+
return true;
449+
}
450+
445451
int idx = numberExportLayers();
446452
if ( isSelected() )
447453
{
448454
--idx;
449-
if ( SelectionBoxes == type ) return mCurrentExportLayer == idx;
455+
if ( SelectionBoxes == part )
456+
{
457+
return mCurrentExportLayer == idx;
458+
}
450459
}
460+
451461
if ( hasFrame() )
452462
{
453463
--idx;
454-
if ( Frame == type ) return mCurrentExportLayer == idx;
464+
if ( Frame == part )
465+
{
466+
return mCurrentExportLayer == idx;
467+
}
455468
}
456469
if ( mOverviewFrameMapId )
457470
{
458471
--idx;
459-
if ( OverviewMapExtent == type ) return mCurrentExportLayer == idx;
472+
if ( OverviewMapExtent == part )
473+
{
474+
return mCurrentExportLayer == idx;
475+
}
460476
}
461477
if ( mGridEnabled )
462478
{
463479
--idx;
464-
if ( Grid == type ) return mCurrentExportLayer == idx;
480+
if ( Grid == part )
481+
{
482+
return mCurrentExportLayer == idx;
483+
}
465484
}
466485
if ( hasBackground() )
467486
{
468-
if ( Background == type ) return mCurrentExportLayer == 0;
487+
if ( Background == part )
488+
{
489+
return mCurrentExportLayer == 0;
490+
}
469491
}
492+
470493
return true; // for Layer
471494
}
472495

‎src/core/composer/qgscomposermap.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,11 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
445445
/** Returns whether updates to the composer map are enabled. */
446446
bool updatesEnabled() const { return mUpdatesEnabled; }
447447

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

453455
signals:
@@ -670,7 +672,7 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
670672
void createDefaultGridLineSymbol();
671673
void initGridAnnotationFormatFromProject();
672674

673-
enum ItemType
675+
enum PartType
674676
{
675677
Background,
676678
Layer,
@@ -680,8 +682,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
680682
SelectionBoxes
681683
};
682684

683-
/**Test if this item needs to be exported considering mCurrentExportLayer*/
684-
bool exportLayer( ItemType type ) const;
685+
/**Test if a part of the copmosermap needs to be drawn, considering mCurrentExportLayer*/
686+
bool shouldDrawPart( PartType part ) const;
685687
};
686688

687689
#endif

‎src/ui/qgssvgexportoptions.ui

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,52 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>675</width>
10-
<height>170</height>
9+
<width>463</width>
10+
<height>103</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>SVG export options</string>
1515
</property>
16-
<widget class="QWidget" name="layoutWidget">
17-
<property name="geometry">
18-
<rect>
19-
<x>10</x>
20-
<y>20</y>
21-
<width>604</width>
22-
<height>101</height>
23-
</rect>
24-
</property>
25-
<layout class="QVBoxLayout" name="verticalLayout">
26-
<item>
27-
<widget class="QCheckBox" name="chkMapLayersAsGroup">
28-
<property name="text">
29-
<string>Export map layers as svg groups (may affect label placement)</string>
30-
</property>
31-
</widget>
32-
</item>
33-
<item>
34-
<widget class="QCheckBox" name="chkTextAsOutline">
35-
<property name="enabled">
36-
<bool>false</bool>
37-
</property>
38-
<property name="text">
39-
<string>Render text as outline</string>
40-
</property>
41-
<property name="checked">
42-
<bool>true</bool>
43-
</property>
44-
</widget>
45-
</item>
46-
<item>
47-
<widget class="QDialogButtonBox" name="buttonBox">
48-
<property name="orientation">
49-
<enum>Qt::Horizontal</enum>
50-
</property>
51-
<property name="standardButtons">
52-
<set>QDialogButtonBox::Ok</set>
53-
</property>
54-
</widget>
55-
</item>
56-
</layout>
57-
</widget>
16+
<layout class="QFormLayout" name="formLayout">
17+
<item row="0" column="0">
18+
<layout class="QVBoxLayout" name="verticalLayout">
19+
<item>
20+
<widget class="QCheckBox" name="chkMapLayersAsGroup">
21+
<property name="text">
22+
<string>Export map layers as svg groups (may affect label placement)</string>
23+
</property>
24+
<property name="checked">
25+
<bool>false</bool>
26+
</property>
27+
</widget>
28+
</item>
29+
<item>
30+
<widget class="QCheckBox" name="chkTextAsOutline">
31+
<property name="enabled">
32+
<bool>false</bool>
33+
</property>
34+
<property name="text">
35+
<string>Render text as outline</string>
36+
</property>
37+
<property name="checked">
38+
<bool>true</bool>
39+
</property>
40+
</widget>
41+
</item>
42+
<item>
43+
<widget class="QDialogButtonBox" name="buttonBox">
44+
<property name="orientation">
45+
<enum>Qt::Horizontal</enum>
46+
</property>
47+
<property name="standardButtons">
48+
<set>QDialogButtonBox::Ok</set>
49+
</property>
50+
</widget>
51+
</item>
52+
</layout>
53+
</item>
54+
</layout>
5855
</widget>
5956
<resources/>
6057
<connections>

0 commit comments

Comments
 (0)
Please sign in to comment.