Ability to set id of any composer item moved from just qgscomposerlabel to qgscomposeritem

All items can now have a user set id.  Good for plugin automation eg mapbook builder
This commit is contained in:
NathanW 2011-07-04 20:07:57 +10:00 committed by Marco Hugentobler
parent b2c7bae948
commit 82d8cffb82
9 changed files with 55 additions and 45 deletions

View File

@ -150,9 +150,11 @@ void QgsComposerItemWidget::setValuesForGuiElements()
mOpacitySlider->blockSignals( true );
mOutlineWidthSpinBox->blockSignals( true );
mFrameCheckBox->blockSignals( true );
mItemIdLineEdit->blockSignals( true );
mOpacitySlider->setValue( mItem->brush().color().alpha() );
mOutlineWidthSpinBox->setValue( mItem->pen().widthF() );
mItemIdLineEdit->setText( mItem->id() );
if ( mItem->frame() )
{
mFrameCheckBox->setCheckState( Qt::Checked );
@ -165,7 +167,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
mOpacitySlider->blockSignals( false );
mOutlineWidthSpinBox->blockSignals( false );
mFrameCheckBox->blockSignals( false );
mItemIdLineEdit->blockSignals( false );
}
void QgsComposerItemWidget::on_mPositionButton_clicked()
@ -186,3 +188,13 @@ void QgsComposerItemWidget::on_mPositionButton_clicked()
mItem->cancelCommand();
}
}
void QgsComposerItemWidget::on_mItemIdLineEdit_textChanged(const QString &text)
{
if ( mItem )
{
mItem->beginCommand( tr( "Item id changed" ), QgsComposerMergeCommand::ComposerLabelSetId );
mItem->setId( text );
mItem->endCommand();
}
}

View File

@ -38,6 +38,7 @@ class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBa
void on_mOutlineWidthSpinBox_valueChanged( double d );
void on_mFrameCheckBox_stateChanged( int state );
void on_mPositionButton_clicked();
void on_mItemIdLineEdit_textChanged( const QString& text );
private:
QgsComposerItemWidget();

View File

@ -183,7 +183,6 @@ 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 );
}
@ -197,5 +196,5 @@ void QgsComposerLabelWidget::blockAllSignals( bool block )
mLeftRadioButton->blockSignals( block );
mCenterRadioButton->blockSignals( block );
mRightRadioButton->blockSignals( block );
mLabelIdLineEdit->blockSignals( block );
}

View File

@ -141,7 +141,7 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons
composerItemElem.setAttribute( "zValue", QString::number( zValue() ) );
composerItemElem.setAttribute( "outlineWidth", QString::number( pen().widthF() ) );
composerItemElem.setAttribute( "rotation", mRotation );
composerItemElem.setAttribute( "id", mId );
//position lock for mouse moves/resizes
if ( mItemPositionLocked )
{
@ -189,6 +189,9 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument&
//rotation
mRotation = itemElem.attribute( "rotation", "0" ).toDouble();
//id
mId = itemElem.attribute( "id", "" );
//frame
QString frame = itemElem.attribute( "frame" );
if ( frame.compare( "true", Qt::CaseInsensitive ) == 0 )

View File

@ -158,8 +158,6 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
/**Reads parameter that are not subclass specific in document. Usually called from readXML methods of subclasses*/
bool _readXML( const QDomElement& itemElem, const QDomDocument& doc );
bool frame() const {return mFrame;}
void setFrame( bool drawFrame ) {mFrame = drawFrame;}
@ -220,6 +218,16 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
/**Updates item, with the possibility to do custom update for subclasses*/
virtual void updateItem() { QGraphicsRectItem::update(); }
/**Get item identification name
@note this method was added in version 1.7*/
QString id() const { return mId; }
/**Set item identification name
@note this method was added in version 1.7
This method was moved from qgscomposerlabel so that every object can have a
id (NathanW)*/
void setId( const QString& id ) { mId = id; }
public slots:
virtual void setRotation( double r );
void repaint();
@ -322,6 +330,9 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
void rotationChanged( double newRotation );
/**Used e.g. by the item widgets to update the gui elements*/
void itemChanged();
private:
// Label id (unique within the same composition)
QString mId;
};
#endif

View File

@ -129,8 +129,6 @@ bool QgsComposerLabel::writeXML( QDomElement& elem, QDomDocument & doc ) const
composerLabelElem.setAttribute( "halign", mHAlignment );
composerLabelElem.setAttribute( "valign", mVAlignment );
composerLabelElem.setAttribute( "id", mId );
//font
QDomElement labelFontElem = doc.createElement( "LabelFont" );
@ -171,9 +169,6 @@ bool QgsComposerLabel::readXML( const QDomElement& itemElem, const QDomDocument&
//Vertical alignment
mVAlignment = ( Qt::AlignmentFlag )( itemElem.attribute( "valign" ).toInt() );
//id
mId = itemElem.attribute( "id", "" );
//font
QDomNodeList labelFontList = itemElem.elementsByTagName( "LabelFont" );
if ( labelFontList.size() > 0 )

View File

@ -72,14 +72,6 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
*/
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
/**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
QString mText;
@ -99,9 +91,6 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
// Vertical Alignment
Qt::AlignmentFlag mVAlignment;
// Label id (unique within the same composition)
QString mId;
/**Replaces replace '$CURRENT_DATE<(FORMAT)>' with the current date (e.g. $CURRENT_DATE(d 'June' yyyy)*/
void replaceDateText( QString& text ) const;
};

View File

@ -6,22 +6,22 @@
<rect>
<x>0</x>
<y>0</y>
<width>236</width>
<height>314</height>
<width>233</width>
<height>361</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<item row="0" column="0" colspan="2">
<widget class="QPushButton" name="mFrameColorButton">
<property name="text">
<string>Frame color...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="1" column="0" colspan="2">
<widget class="QPushButton" name="mBackgroundColorButton">
<property name="text">
<string>Background color...</string>
@ -41,7 +41,7 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="3" column="0" colspan="2">
<widget class="QSlider" name="mOpacitySlider">
<property name="maximum">
<number>255</number>
@ -51,7 +51,7 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="mOutlineWidthLabel">
<property name="text">
<string>Outline width</string>
@ -67,29 +67,39 @@
<item row="5" column="0">
<widget class="QDoubleSpinBox" name="mOutlineWidthSpinBox"/>
</item>
<item row="6" column="0">
<item row="6" column="0" colspan="2">
<widget class="QPushButton" name="mPositionButton">
<property name="text">
<string>Position and size...</string>
</property>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="mFrameCheckBox">
<property name="text">
<string>Show frame</string>
</property>
</widget>
</item>
<item row="8" column="0">
<item row="10" column="0">
<widget class="QLabel" name="mIdLabel">
<property name="text">
<string>Item ID</string>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<widget class="QLineEdit" name="mItemIdLineEdit"/>
</item>
<item row="12" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>215</width>
<height>57</height>
<width>143</width>
<height>87</height>
</size>
</property>
</spacer>

View File

@ -30,8 +30,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>513</width>
<height>402</height>
<width>529</width>
<height>376</height>
</rect>
</property>
<attribute name="label">
@ -141,16 +141,6 @@
</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>