Skip to content

Commit c99a9bb

Browse files
author
mhugent
committedJan 21, 2011
WMS print: manual setting for exported label ids, display paper width and height in capabilities
git-svn-id: http://svn.osgeo.org/qgis/trunk@15064 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 95dfabf commit c99a9bb

File tree

9 files changed

+69
-45
lines changed

9 files changed

+69
-45
lines changed
 

‎python/core/qgscomposerlabel.sip

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class QgsComposerLabel: QgsComposerItem
4949
*/
5050
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
5151

52-
/**Get label identification number*/
53-
int id() const;
52+
/**Get label identification number
53+
@note this method was added in version 1.7*/
54+
QString id() const;
55+
56+
/**Set label identification number
57+
@note this method was added in version 1.7*/
58+
void setId( const QString& id );
5459
};

‎src/app/composer/qgscomposerlabelwidget.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ void QgsComposerLabelWidget::on_mMiddleRadioButton_clicked()
162162
}
163163
}
164164

165+
void QgsComposerLabelWidget::on_mLabelIdLineEdit_textChanged( const QString& text )
166+
{
167+
if ( mComposerLabel )
168+
{
169+
mComposerLabel->beginCommand( tr( "Label id changed" ), QgsComposerMergeCommand::ComposerLabelSetId );
170+
mComposerLabel->setId( text );
171+
mComposerLabel->endCommand();
172+
}
173+
}
174+
165175
void QgsComposerLabelWidget::setGuiElementValues()
166176
{
167177
blockAllSignals( true );
@@ -173,6 +183,7 @@ void QgsComposerLabelWidget::setGuiElementValues()
173183
mLeftRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignLeft );
174184
mCenterRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignHCenter );
175185
mRightRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignRight );
186+
mLabelIdLineEdit->setText( mComposerLabel->id() );
176187
blockAllSignals( false );
177188
}
178189

@@ -186,4 +197,5 @@ void QgsComposerLabelWidget::blockAllSignals( bool block )
186197
mLeftRadioButton->blockSignals( block );
187198
mCenterRadioButton->blockSignals( block );
188199
mRightRadioButton->blockSignals( block );
200+
mLabelIdLineEdit->blockSignals( block );
189201
}

‎src/app/composer/qgscomposerlabelwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class QgsComposerLabelWidget: public QWidget, private Ui::QgsComposerLabelWidget
4242
void on_mTopRadioButton_clicked();
4343
void on_mBottomRadioButton_clicked();
4444
void on_mMiddleRadioButton_clicked();
45+
void on_mLabelIdLineEdit_textChanged( const QString& text );
4546

4647
private slots:
4748
void setGuiElementValues();

‎src/core/composer/qgscomposeritemcommand.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
7171
Unknown = 0,
7272
//composer label
7373
ComposerLabelSetText,
74+
ComposerLabelSetId,
7475
//composer map
7576
ComposerMapRotation,
7677
ComposerMapAnnotationDistance,

‎src/core/composer/qgscomposerlabel.cpp

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ): QgsComposerIt
2525
{
2626
//default font size is 10 point
2727
mFont.setPointSizeF( 10 );
28-
29-
//get new id
30-
mId = maximumLabelId( composition ) + 1;
3128
}
3229

3330
QgsComposerLabel::~QgsComposerLabel()
@@ -173,7 +170,7 @@ bool QgsComposerLabel::readXML( const QDomElement& itemElem, const QDomDocument&
173170
mVAlignment = ( Qt::AlignmentFlag )( itemElem.attribute( "valign" ).toInt() );
174171

175172
//id
176-
mId = itemElem.attribute( "id", "0" ).toInt();
173+
mId = itemElem.attribute( "id", "" );
177174

178175
//font
179176
QDomNodeList labelFontList = itemElem.elementsByTagName( "LabelFont" );
@@ -208,27 +205,3 @@ bool QgsComposerLabel::readXML( const QDomElement& itemElem, const QDomDocument&
208205
emit itemChanged();
209206
return true;
210207
}
211-
212-
int QgsComposerLabel::maximumLabelId( const QgsComposition* c ) const
213-
{
214-
int id = -1;
215-
if ( !c )
216-
{
217-
return id;
218-
}
219-
220-
QList<QGraphicsItem *> itemList = c->items();
221-
QList<QGraphicsItem *>::const_iterator itemIt = itemList.constBegin();
222-
for ( ; itemIt != itemList.constEnd(); ++itemIt )
223-
{
224-
const QgsComposerLabel* label = dynamic_cast<const QgsComposerLabel *>( *itemIt );
225-
if ( label )
226-
{
227-
if ( label->id() > id )
228-
{
229-
id = label->id();
230-
}
231-
}
232-
}
233-
return id;
234-
}

‎src/core/composer/qgscomposerlabel.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
7272
*/
7373
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
7474

75-
/**Get label identification number*/
76-
int id() const { return mId; }
75+
/**Get label identification number
76+
@note this method was added in version 1.7*/
77+
QString id() const { return mId; }
78+
79+
/**Set label identification number
80+
@note this method was added in version 1.7*/
81+
void setId( const QString& id ) { mId = id; }
7782

7883
private:
7984
// Text
@@ -95,13 +100,10 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
95100
Qt::AlignmentFlag mVAlignment;
96101

97102
// Label id (unique within the same composition)
98-
int mId;
103+
QString mId;
99104

100105
/**Replaces replace '$CURRENT_DATE<(FORMAT)>' with the current date (e.g. $CURRENT_DATE(d 'June' yyyy)*/
101106
void replaceDateText( QString& text ) const;
102-
103-
/**Returns maximum id of all label items or -1 if no item is in the scene. Used to generate new ids in the constructor*/
104-
int maximumLabelId( const QgsComposition* c ) const;
105107
};
106108

107109
#endif

‎src/mapserver/qgsconfigparser.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,15 @@ QgsComposition* QgsConfigParser::createPrintComposition( const QString& composer
383383
for ( ; labelIt != composerLabels.constEnd(); ++labelIt )
384384
{
385385
currentLabel = *labelIt;
386-
QMap< QString, QString >::const_iterator titleIt = parameterMap.find( "LABEL" + QString::number( currentLabel->id() ) );
386+
QMap< QString, QString >::const_iterator titleIt = parameterMap.find( currentLabel->id().toUpper() );
387387
if ( titleIt == parameterMap.constEnd() )
388388
{
389-
//keep label with default text and size
389+
//remove exported labels not referenced in the request
390+
if ( !currentLabel->id().isEmpty() )
391+
{
392+
c->removeItem( currentLabel );
393+
delete( currentLabel );
394+
}
390395
continue;
391396
}
392397

‎src/mapserver/qgsprojectparser.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,16 @@ void QgsProjectParser::printCapabilities( QDomElement& parentElement, QDomDocume
941941
composerTemplateElem.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
942942
composerTemplateElem.setAttribute( "xsi:type", "wms:_ExtendedCapabilities" );
943943

944+
//get paper width and hight in mm from composition
945+
QDomElement compositionElem = currentComposerElem.firstChildElement( "Composition" );
946+
if ( compositionElem.isNull() )
947+
{
948+
continue;
949+
}
950+
composerTemplateElem.setAttribute( "width", compositionElem.attribute( "paperWidth" ) );
951+
composerTemplateElem.setAttribute( "height", compositionElem.attribute( "paperHeight" ) );
952+
953+
944954
//add available composer maps and their size in mm
945955
QDomNodeList composerMapList = currentComposerElem.elementsByTagName( "ComposerMap" );
946956
for ( int j = 0; j < composerMapList.size(); ++j )
@@ -964,8 +974,13 @@ void QgsProjectParser::printCapabilities( QDomElement& parentElement, QDomDocume
964974
for ( int j = 0; j < composerLabelList.size(); ++j )
965975
{
966976
QDomElement clabel = composerLabelList.at( j ).toElement();
977+
QString id = clabel.attribute( "id" );
978+
if ( id.isEmpty() ) //only export labels with ids for text replacement
979+
{
980+
continue;
981+
}
967982
QDomElement composerLabelElem = doc.createElement( "ComposerLabel" );
968-
composerLabelElem.setAttribute( "name", "label" + clabel.attribute( "id" ) );
983+
composerLabelElem.setAttribute( "name", id );
969984
composerTemplateElem.appendChild( composerLabelElem );
970985
}
971986

‎src/ui/qgscomposerlabelwidgetbase.ui

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>519</width>
10-
<height>362</height>
9+
<width>547</width>
10+
<height>425</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">
@@ -30,8 +30,8 @@
3030
<rect>
3131
<x>0</x>
3232
<y>0</y>
33-
<width>486</width>
34-
<height>320</height>
33+
<width>513</width>
34+
<height>402</height>
3535
</rect>
3636
</property>
3737
<attribute name="label">
@@ -65,7 +65,7 @@
6565
</property>
6666
</widget>
6767
</item>
68-
<item row="5" column="0">
68+
<item row="6" column="0">
6969
<widget class="QLabel" name="mMarginTextLabel">
7070
<property name="text">
7171
<string>Margin (mm)</string>
@@ -75,7 +75,7 @@
7575
</property>
7676
</widget>
7777
</item>
78-
<item row="6" column="0">
78+
<item row="7" column="0">
7979
<widget class="QDoubleSpinBox" name="mMarginDoubleSpinBox"/>
8080
</item>
8181
<item row="3" column="0">
@@ -141,6 +141,16 @@
141141
</layout>
142142
</widget>
143143
</item>
144+
<item row="9" column="0">
145+
<widget class="QLineEdit" name="mLabelIdLineEdit"/>
146+
</item>
147+
<item row="8" column="0">
148+
<widget class="QLabel" name="mIdLabel">
149+
<property name="text">
150+
<string>Label id</string>
151+
</property>
152+
</widget>
153+
</item>
144154
</layout>
145155
</widget>
146156
</widget>

0 commit comments

Comments
 (0)
Please sign in to comment.