Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ability to set id of any composer item moved from just qgscomposerlab…
…el to qgscomposeritem

All items can now have a user set id.  Good for plugin automation eg mapbook builder
  • Loading branch information
NathanW2 authored and mhugent committed Jul 4, 2011
1 parent b2c7bae commit 82d8cff
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 45 deletions.
14 changes: 13 additions & 1 deletion src/app/composer/qgscomposeritemwidget.cpp
Expand Up @@ -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 );
Expand All @@ -165,7 +167,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
mOpacitySlider->blockSignals( false );
mOutlineWidthSpinBox->blockSignals( false );
mFrameCheckBox->blockSignals( false );

mItemIdLineEdit->blockSignals( false );
}

void QgsComposerItemWidget::on_mPositionButton_clicked()
Expand All @@ -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();
}
}
1 change: 1 addition & 0 deletions src/app/composer/qgscomposeritemwidget.h
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/app/composer/qgscomposerlabelwidget.cpp
Expand Up @@ -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 );
}

Expand All @@ -197,5 +196,5 @@ void QgsComposerLabelWidget::blockAllSignals( bool block )
mLeftRadioButton->blockSignals( block );
mCenterRadioButton->blockSignals( block );
mRightRadioButton->blockSignals( block );
mLabelIdLineEdit->blockSignals( block );

}
5 changes: 4 additions & 1 deletion src/core/composer/qgscomposeritem.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
Expand Down
15 changes: 13 additions & 2 deletions src/core/composer/qgscomposeritem.h
Expand Up @@ -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;}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
5 changes: 0 additions & 5 deletions src/core/composer/qgscomposerlabel.cpp
Expand Up @@ -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" );
Expand Down Expand Up @@ -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 )
Expand Down
11 changes: 0 additions & 11 deletions src/core/composer/qgscomposerlabel.h
Expand Up @@ -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;
Expand All @@ -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;
};
Expand Down
32 changes: 21 additions & 11 deletions src/ui/qgscomposeritemwidgetbase.ui
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down
14 changes: 2 additions & 12 deletions src/ui/qgscomposerlabelwidgetbase.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 82d8cff

Please sign in to comment.