Skip to content

Commit 82d8cff

Browse files
NathanW2mhugent
authored andcommitted
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
1 parent b2c7bae commit 82d8cff

9 files changed

+55
-45
lines changed

src/app/composer/qgscomposeritemwidget.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ void QgsComposerItemWidget::setValuesForGuiElements()
150150
mOpacitySlider->blockSignals( true );
151151
mOutlineWidthSpinBox->blockSignals( true );
152152
mFrameCheckBox->blockSignals( true );
153+
mItemIdLineEdit->blockSignals( true );
153154

154155
mOpacitySlider->setValue( mItem->brush().color().alpha() );
155156
mOutlineWidthSpinBox->setValue( mItem->pen().widthF() );
157+
mItemIdLineEdit->setText( mItem->id() );
156158
if ( mItem->frame() )
157159
{
158160
mFrameCheckBox->setCheckState( Qt::Checked );
@@ -165,7 +167,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
165167
mOpacitySlider->blockSignals( false );
166168
mOutlineWidthSpinBox->blockSignals( false );
167169
mFrameCheckBox->blockSignals( false );
168-
170+
mItemIdLineEdit->blockSignals( false );
169171
}
170172

171173
void QgsComposerItemWidget::on_mPositionButton_clicked()
@@ -186,3 +188,13 @@ void QgsComposerItemWidget::on_mPositionButton_clicked()
186188
mItem->cancelCommand();
187189
}
188190
}
191+
192+
void QgsComposerItemWidget::on_mItemIdLineEdit_textChanged(const QString &text)
193+
{
194+
if ( mItem )
195+
{
196+
mItem->beginCommand( tr( "Item id changed" ), QgsComposerMergeCommand::ComposerLabelSetId );
197+
mItem->setId( text );
198+
mItem->endCommand();
199+
}
200+
}

src/app/composer/qgscomposeritemwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBa
3838
void on_mOutlineWidthSpinBox_valueChanged( double d );
3939
void on_mFrameCheckBox_stateChanged( int state );
4040
void on_mPositionButton_clicked();
41+
void on_mItemIdLineEdit_textChanged( const QString& text );
4142

4243
private:
4344
QgsComposerItemWidget();

src/app/composer/qgscomposerlabelwidget.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ void QgsComposerLabelWidget::setGuiElementValues()
183183
mLeftRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignLeft );
184184
mCenterRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignHCenter );
185185
mRightRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignRight );
186-
mLabelIdLineEdit->setText( mComposerLabel->id() );
187186
blockAllSignals( false );
188187
}
189188

@@ -197,5 +196,5 @@ void QgsComposerLabelWidget::blockAllSignals( bool block )
197196
mLeftRadioButton->blockSignals( block );
198197
mCenterRadioButton->blockSignals( block );
199198
mRightRadioButton->blockSignals( block );
200-
mLabelIdLineEdit->blockSignals( block );
199+
201200
}

src/core/composer/qgscomposeritem.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons
141141
composerItemElem.setAttribute( "zValue", QString::number( zValue() ) );
142142
composerItemElem.setAttribute( "outlineWidth", QString::number( pen().widthF() ) );
143143
composerItemElem.setAttribute( "rotation", mRotation );
144-
144+
composerItemElem.setAttribute( "id", mId );
145145
//position lock for mouse moves/resizes
146146
if ( mItemPositionLocked )
147147
{
@@ -189,6 +189,9 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument&
189189
//rotation
190190
mRotation = itemElem.attribute( "rotation", "0" ).toDouble();
191191

192+
//id
193+
mId = itemElem.attribute( "id", "" );
194+
192195
//frame
193196
QString frame = itemElem.attribute( "frame" );
194197
if ( frame.compare( "true", Qt::CaseInsensitive ) == 0 )

src/core/composer/qgscomposeritem.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
158158
/**Reads parameter that are not subclass specific in document. Usually called from readXML methods of subclasses*/
159159
bool _readXML( const QDomElement& itemElem, const QDomDocument& doc );
160160

161-
162-
163161
bool frame() const {return mFrame;}
164162
void setFrame( bool drawFrame ) {mFrame = drawFrame;}
165163

@@ -220,6 +218,16 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
220218
/**Updates item, with the possibility to do custom update for subclasses*/
221219
virtual void updateItem() { QGraphicsRectItem::update(); }
222220

221+
/**Get item identification name
222+
@note this method was added in version 1.7*/
223+
QString id() const { return mId; }
224+
225+
/**Set item identification name
226+
@note this method was added in version 1.7
227+
This method was moved from qgscomposerlabel so that every object can have a
228+
id (NathanW)*/
229+
void setId( const QString& id ) { mId = id; }
230+
223231
public slots:
224232
virtual void setRotation( double r );
225233
void repaint();
@@ -322,6 +330,9 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
322330
void rotationChanged( double newRotation );
323331
/**Used e.g. by the item widgets to update the gui elements*/
324332
void itemChanged();
333+
private:
334+
// Label id (unique within the same composition)
335+
QString mId;
325336
};
326337

327338
#endif

src/core/composer/qgscomposerlabel.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ bool QgsComposerLabel::writeXML( QDomElement& elem, QDomDocument & doc ) const
129129

130130
composerLabelElem.setAttribute( "halign", mHAlignment );
131131
composerLabelElem.setAttribute( "valign", mVAlignment );
132-
composerLabelElem.setAttribute( "id", mId );
133-
134132

135133
//font
136134
QDomElement labelFontElem = doc.createElement( "LabelFont" );
@@ -171,9 +169,6 @@ bool QgsComposerLabel::readXML( const QDomElement& itemElem, const QDomDocument&
171169
//Vertical alignment
172170
mVAlignment = ( Qt::AlignmentFlag )( itemElem.attribute( "valign" ).toInt() );
173171

174-
//id
175-
mId = itemElem.attribute( "id", "" );
176-
177172
//font
178173
QDomNodeList labelFontList = itemElem.elementsByTagName( "LabelFont" );
179174
if ( labelFontList.size() > 0 )

src/core/composer/qgscomposerlabel.h

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

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; }
82-
8375
private:
8476
// Text
8577
QString mText;
@@ -99,9 +91,6 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
9991
// Vertical Alignment
10092
Qt::AlignmentFlag mVAlignment;
10193

102-
// Label id (unique within the same composition)
103-
QString mId;
104-
10594
/**Replaces replace '$CURRENT_DATE<(FORMAT)>' with the current date (e.g. $CURRENT_DATE(d 'June' yyyy)*/
10695
void replaceDateText( QString& text ) const;
10796
};

src/ui/qgscomposeritemwidgetbase.ui

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>236</width>
10-
<height>314</height>
9+
<width>233</width>
10+
<height>361</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Form</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout">
17-
<item row="0" column="0">
17+
<item row="0" column="0" colspan="2">
1818
<widget class="QPushButton" name="mFrameColorButton">
1919
<property name="text">
2020
<string>Frame color...</string>
2121
</property>
2222
</widget>
2323
</item>
24-
<item row="1" column="0">
24+
<item row="1" column="0" colspan="2">
2525
<widget class="QPushButton" name="mBackgroundColorButton">
2626
<property name="text">
2727
<string>Background color...</string>
@@ -41,7 +41,7 @@
4141
</property>
4242
</widget>
4343
</item>
44-
<item row="3" column="0">
44+
<item row="3" column="0" colspan="2">
4545
<widget class="QSlider" name="mOpacitySlider">
4646
<property name="maximum">
4747
<number>255</number>
@@ -51,7 +51,7 @@
5151
</property>
5252
</widget>
5353
</item>
54-
<item row="4" column="0">
54+
<item row="4" column="0" colspan="2">
5555
<widget class="QLabel" name="mOutlineWidthLabel">
5656
<property name="text">
5757
<string>Outline width</string>
@@ -67,29 +67,39 @@
6767
<item row="5" column="0">
6868
<widget class="QDoubleSpinBox" name="mOutlineWidthSpinBox"/>
6969
</item>
70-
<item row="6" column="0">
70+
<item row="6" column="0" colspan="2">
7171
<widget class="QPushButton" name="mPositionButton">
7272
<property name="text">
7373
<string>Position and size...</string>
7474
</property>
7575
</widget>
7676
</item>
77-
<item row="7" column="0">
77+
<item row="8" column="0" colspan="2">
7878
<widget class="QCheckBox" name="mFrameCheckBox">
7979
<property name="text">
8080
<string>Show frame</string>
8181
</property>
8282
</widget>
8383
</item>
84-
<item row="8" column="0">
84+
<item row="10" column="0">
85+
<widget class="QLabel" name="mIdLabel">
86+
<property name="text">
87+
<string>Item ID</string>
88+
</property>
89+
</widget>
90+
</item>
91+
<item row="11" column="0" colspan="2">
92+
<widget class="QLineEdit" name="mItemIdLineEdit"/>
93+
</item>
94+
<item row="12" column="0" colspan="2">
8595
<spacer name="verticalSpacer">
8696
<property name="orientation">
8797
<enum>Qt::Vertical</enum>
8898
</property>
8999
<property name="sizeHint" stdset="0">
90100
<size>
91-
<width>215</width>
92-
<height>57</height>
101+
<width>143</width>
102+
<height>87</height>
93103
</size>
94104
</property>
95105
</spacer>

src/ui/qgscomposerlabelwidgetbase.ui

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
<rect>
3131
<x>0</x>
3232
<y>0</y>
33-
<width>513</width>
34-
<height>402</height>
33+
<width>529</width>
34+
<height>376</height>
3535
</rect>
3636
</property>
3737
<attribute name="label">
@@ -141,16 +141,6 @@
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>
154144
</layout>
155145
</widget>
156146
</widget>

0 commit comments

Comments
 (0)