Skip to content
Permalink
Browse files

WMS print: manual setting for exported label ids, display paper width…

… and height in capabilities

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15064 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Jan 21, 2011
1 parent 521b2f1 commit a2650dfd2544f29315cce5fb6d14ee346b5a23ef
@@ -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 );
};
@@ -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 );
@@ -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 );
}

@@ -186,4 +197,5 @@ void QgsComposerLabelWidget::blockAllSignals( bool block )
mLeftRadioButton->blockSignals( block );
mCenterRadioButton->blockSignals( block );
mRightRadioButton->blockSignals( block );
mLabelIdLineEdit->blockSignals( block );
}
@@ -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();
@@ -71,6 +71,7 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
Unknown = 0,
//composer label
ComposerLabelSetText,
ComposerLabelSetId,
//composer map
ComposerMapRotation,
ComposerMapAnnotationDistance,
@@ -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()
@@ -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" );
@@ -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;
}
@@ -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
@@ -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
@@ -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;
}

@@ -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 )
@@ -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 );
}

@@ -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">
@@ -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">
@@ -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>
@@ -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">
@@ -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>

0 comments on commit a2650df

Please sign in to comment.
You can’t perform that action at this time.