Skip to content

Commit

Permalink
WMS print: manual setting for exported label ids, display paper width…
Browse files Browse the repository at this point in the history
… and height in capabilities

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15064 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 21, 2011
1 parent 521b2f1 commit a2650df
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 45 deletions.
9 changes: 7 additions & 2 deletions python/core/qgscomposerlabel.sip
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class QgsComposerLabel: QgsComposerItem
*/
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );

/**Get label identification number*/
int id() const;
/**Get label identification number
@note this method was added in version 1.7*/
QString id() const;

/**Set label identification number
@note this method was added in version 1.7*/
void setId( const QString& id );
};
12 changes: 12 additions & 0 deletions src/app/composer/qgscomposerlabelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ void QgsComposerLabelWidget::on_mMiddleRadioButton_clicked()
}
}

void QgsComposerLabelWidget::on_mLabelIdLineEdit_textChanged( const QString& text )
{
if ( mComposerLabel )
{
mComposerLabel->beginCommand( tr( "Label id changed" ), QgsComposerMergeCommand::ComposerLabelSetId );
mComposerLabel->setId( text );
mComposerLabel->endCommand();
}
}

void QgsComposerLabelWidget::setGuiElementValues()
{
blockAllSignals( true );
Expand All @@ -173,6 +183,7 @@ void QgsComposerLabelWidget::setGuiElementValues()
mLeftRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignLeft );
mCenterRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignHCenter );
mRightRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignRight );
mLabelIdLineEdit->setText( mComposerLabel->id() );
blockAllSignals( false );
}

Expand All @@ -186,4 +197,5 @@ void QgsComposerLabelWidget::blockAllSignals( bool block )
mLeftRadioButton->blockSignals( block );
mCenterRadioButton->blockSignals( block );
mRightRadioButton->blockSignals( block );
mLabelIdLineEdit->blockSignals( block );
}
1 change: 1 addition & 0 deletions src/app/composer/qgscomposerlabelwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class QgsComposerLabelWidget: public QWidget, private Ui::QgsComposerLabelWidget
void on_mTopRadioButton_clicked();
void on_mBottomRadioButton_clicked();
void on_mMiddleRadioButton_clicked();
void on_mLabelIdLineEdit_textChanged( const QString& text );

private slots:
void setGuiElementValues();
Expand Down
1 change: 1 addition & 0 deletions src/core/composer/qgscomposeritemcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
Unknown = 0,
//composer label
ComposerLabelSetText,
ComposerLabelSetId,
//composer map
ComposerMapRotation,
ComposerMapAnnotationDistance,
Expand Down
29 changes: 1 addition & 28 deletions src/core/composer/qgscomposerlabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ): QgsComposerIt
{
//default font size is 10 point
mFont.setPointSizeF( 10 );

//get new id
mId = maximumLabelId( composition ) + 1;
}

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

//id
mId = itemElem.attribute( "id", "0" ).toInt();
mId = itemElem.attribute( "id", "" );

//font
QDomNodeList labelFontList = itemElem.elementsByTagName( "LabelFont" );
Expand Down Expand Up @@ -208,27 +205,3 @@ bool QgsComposerLabel::readXML( const QDomElement& itemElem, const QDomDocument&
emit itemChanged();
return true;
}

int QgsComposerLabel::maximumLabelId( const QgsComposition* c ) const
{
int id = -1;
if ( !c )
{
return id;
}

QList<QGraphicsItem *> itemList = c->items();
QList<QGraphicsItem *>::const_iterator itemIt = itemList.constBegin();
for ( ; itemIt != itemList.constEnd(); ++itemIt )
{
const QgsComposerLabel* label = dynamic_cast<const QgsComposerLabel *>( *itemIt );
if ( label )
{
if ( label->id() > id )
{
id = label->id();
}
}
}
return id;
}
14 changes: 8 additions & 6 deletions src/core/composer/qgscomposerlabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
*/
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );

/**Get label identification number*/
int id() const { return mId; }
/**Get label identification number
@note this method was added in version 1.7*/
QString id() const { return mId; }

/**Set label identification number
@note this method was added in version 1.7*/
void setId( const QString& id ) { mId = id; }

private:
// Text
Expand All @@ -95,13 +100,10 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
Qt::AlignmentFlag mVAlignment;

// Label id (unique within the same composition)
int mId;
QString mId;

/**Replaces replace '$CURRENT_DATE<(FORMAT)>' with the current date (e.g. $CURRENT_DATE(d 'June' yyyy)*/
void replaceDateText( QString& text ) const;

/**Returns maximum id of all label items or -1 if no item is in the scene. Used to generate new ids in the constructor*/
int maximumLabelId( const QgsComposition* c ) const;
};

#endif
Expand Down
9 changes: 7 additions & 2 deletions src/mapserver/qgsconfigparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,15 @@ QgsComposition* QgsConfigParser::createPrintComposition( const QString& composer
for ( ; labelIt != composerLabels.constEnd(); ++labelIt )
{
currentLabel = *labelIt;
QMap< QString, QString >::const_iterator titleIt = parameterMap.find( "LABEL" + QString::number( currentLabel->id() ) );
QMap< QString, QString >::const_iterator titleIt = parameterMap.find( currentLabel->id().toUpper() );
if ( titleIt == parameterMap.constEnd() )
{
//keep label with default text and size
//remove exported labels not referenced in the request
if ( !currentLabel->id().isEmpty() )
{
c->removeItem( currentLabel );
delete( currentLabel );
}
continue;
}

Expand Down
17 changes: 16 additions & 1 deletion src/mapserver/qgsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,16 @@ void QgsProjectParser::printCapabilities( QDomElement& parentElement, QDomDocume
composerTemplateElem.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
composerTemplateElem.setAttribute( "xsi:type", "wms:_ExtendedCapabilities" );

//get paper width and hight in mm from composition
QDomElement compositionElem = currentComposerElem.firstChildElement( "Composition" );
if ( compositionElem.isNull() )
{
continue;
}
composerTemplateElem.setAttribute( "width", compositionElem.attribute( "paperWidth" ) );
composerTemplateElem.setAttribute( "height", compositionElem.attribute( "paperHeight" ) );


//add available composer maps and their size in mm
QDomNodeList composerMapList = currentComposerElem.elementsByTagName( "ComposerMap" );
for ( int j = 0; j < composerMapList.size(); ++j )
Expand All @@ -964,8 +974,13 @@ void QgsProjectParser::printCapabilities( QDomElement& parentElement, QDomDocume
for ( int j = 0; j < composerLabelList.size(); ++j )
{
QDomElement clabel = composerLabelList.at( j ).toElement();
QString id = clabel.attribute( "id" );
if ( id.isEmpty() ) //only export labels with ids for text replacement
{
continue;
}
QDomElement composerLabelElem = doc.createElement( "ComposerLabel" );
composerLabelElem.setAttribute( "name", "label" + clabel.attribute( "id" ) );
composerLabelElem.setAttribute( "name", id );
composerTemplateElem.appendChild( composerLabelElem );
}

Expand Down
22 changes: 16 additions & 6 deletions src/ui/qgscomposerlabelwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>519</width>
<height>362</height>
<width>547</width>
<height>425</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -30,8 +30,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>486</width>
<height>320</height>
<width>513</width>
<height>402</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -65,7 +65,7 @@
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QLabel" name="mMarginTextLabel">
<property name="text">
<string>Margin (mm)</string>
Expand All @@ -75,7 +75,7 @@
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QDoubleSpinBox" name="mMarginDoubleSpinBox"/>
</item>
<item row="3" column="0">
Expand Down Expand Up @@ -141,6 +141,16 @@
</layout>
</widget>
</item>
<item row="9" column="0">
<widget class="QLineEdit" name="mLabelIdLineEdit"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="mIdLabel">
<property name="text">
<string>Label id</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down

0 comments on commit a2650df

Please sign in to comment.