From 00c832b15185a7110a8e19d188de99b3772680da Mon Sep 17 00:00:00 2001 From: olivierdalang Date: Wed, 20 Feb 2013 21:13:05 +0100 Subject: [PATCH] Implemented ComposerItem's Uuids - uuid are kept on cut/paste, but deleted on import template or copy/paste - removed obsolete id reference in QgsComposerLabelWidget --- python/core/composer/qgscomposeritem.sip | 13 ++++++++----- src/app/composer/qgscomposeritemwidget.cpp | 9 +++++++-- src/app/composer/qgscomposeritemwidget.h | 2 +- src/app/composer/qgscomposerlabelwidget.cpp | 10 ---------- src/app/composer/qgscomposerlabelwidget.h | 1 - src/core/composer/qgscomposeritem.cpp | 21 +++++++++++++++++++-- src/core/composer/qgscomposeritem.h | 19 ++++++++++++------- src/core/composer/qgscomposition.cpp | 11 +++++++++++ src/gui/qgscomposerview.cpp | 16 ++++++++++++++++ src/ui/qgscomposeritemwidgetbase.ui | 20 +++++++++++++++++--- 10 files changed, 91 insertions(+), 31 deletions(-) diff --git a/python/core/composer/qgscomposeritem.sip b/python/core/composer/qgscomposeritem.sip index c4612422c56..b7ef9de36bc 100644 --- a/python/core/composer/qgscomposeritem.sip +++ b/python/core/composer/qgscomposeritem.sip @@ -292,16 +292,19 @@ class QgsComposerItem: QObject, QGraphicsRectItem /**Updates item, with the possibility to do custom update for subclasses*/ virtual void updateItem(); - /**Get item identification name + /**Get item's id (which is not necessarly unique) @note this method was added in version 1.7*/ QString id() const; - /**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)*/ + /**Set item's id (which is not necessarly unique) + @note this method was added in version 1.7*/ void setId( const QString& id ); + /**Get item identification name + @note this method was added in version 2.0 + @note there is not setter since one can't manually set the id*/ + QString uuid() const; + public slots: virtual void setRotation( double r ); void repaint(); diff --git a/src/app/composer/qgscomposeritemwidget.cpp b/src/app/composer/qgscomposeritemwidget.cpp index 5a3a4fb9f47..507afff8b42 100644 --- a/src/app/composer/qgscomposeritemwidget.cpp +++ b/src/app/composer/qgscomposeritemwidget.cpp @@ -349,6 +349,7 @@ void QgsComposerItemWidget::setValuesForGuiElements() mFrameGroupBox->blockSignals( true ); mBackgroundGroupBox->blockSignals( true ); mItemIdLineEdit->blockSignals( true ); + mItemUuidLineEdit->blockSignals( true ); mTransparencySpinBox->blockSignals( true ); int alphaPercent = ( 255 - mItem->brush().color().alpha() ) / 2.55; @@ -356,6 +357,7 @@ void QgsComposerItemWidget::setValuesForGuiElements() mTransparencySlider->setValue( alphaPercent ); mOutlineWidthSpinBox->setValue( mItem->pen().widthF() ); mItemIdLineEdit->setText( mItem->id() ); + mItemUuidLineEdit->setText( mItem->uuid() ); mFrameGroupBox->setChecked( mItem->hasFrame() ); mBackgroundGroupBox->setChecked( mItem->hasBackground() ); @@ -364,15 +366,18 @@ void QgsComposerItemWidget::setValuesForGuiElements() mFrameGroupBox->blockSignals( false ); mBackgroundGroupBox->blockSignals( false ); mItemIdLineEdit->blockSignals( false ); + mItemUuidLineEdit->blockSignals( false ); mTransparencySpinBox->blockSignals( false ); } -void QgsComposerItemWidget::on_mItemIdLineEdit_textChanged( const QString &text ) + +void QgsComposerItemWidget::on_mItemIdLineEdit_editingFinished() { if ( mItem ) { mItem->beginCommand( tr( "Item id changed" ), QgsComposerMergeCommand::ComposerLabelSetId ); - mItem->setId( text ); + mItem->setId( mItemIdLineEdit->text() ); + mItemIdLineEdit->setText( mItem->id() ); mItem->endCommand(); } } diff --git a/src/app/composer/qgscomposeritemwidget.h b/src/app/composer/qgscomposeritemwidget.h index 4712cf4891f..8bc704264b8 100644 --- a/src/app/composer/qgscomposeritemwidget.h +++ b/src/app/composer/qgscomposeritemwidget.h @@ -44,7 +44,7 @@ class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBa void on_mOutlineWidthSpinBox_valueChanged( double d ); void on_mFrameGroupBox_toggled( bool state ); void on_mBackgroundGroupBox_toggled( bool state ); - void on_mItemIdLineEdit_textChanged( const QString& text ); + void on_mItemIdLineEdit_editingFinished(); //adjust coordinates in line edits void on_mXLineEdit_editingFinished() { changeItemPosition(); } diff --git a/src/app/composer/qgscomposerlabelwidget.cpp b/src/app/composer/qgscomposerlabelwidget.cpp index e945b7bac43..2ca37b6d53a 100644 --- a/src/app/composer/qgscomposerlabelwidget.cpp +++ b/src/app/composer/qgscomposerlabelwidget.cpp @@ -227,16 +227,6 @@ 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::on_mRotationSpinBox_valueChanged( double v ) { if ( mComposerLabel ) diff --git a/src/app/composer/qgscomposerlabelwidget.h b/src/app/composer/qgscomposerlabelwidget.h index 005bc130b47..f300482bf19 100644 --- a/src/app/composer/qgscomposerlabelwidget.h +++ b/src/app/composer/qgscomposerlabelwidget.h @@ -44,7 +44,6 @@ 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 ); void on_mRotationSpinBox_valueChanged( double v ); private slots: diff --git a/src/core/composer/qgscomposeritem.cpp b/src/core/composer/qgscomposeritem.cpp index 6f89d53ff18..0c9a8a4e682 100644 --- a/src/core/composer/qgscomposeritem.cpp +++ b/src/core/composer/qgscomposeritem.cpp @@ -22,12 +22,14 @@ #include #include #include +#include + +#include "qgsproject.h" #include "qgscomposition.h" #include "qgscomposeritem.h" #include "qgscomposerframe.h" - #include #include "qgsapplication.h" #include "qgsrectangle.h" //just for debugging @@ -51,6 +53,8 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue , mLastValidViewScaleFactor( -1 ) , mRotation( 0 ) , mLastUsedPositionMode( UpperLeft ) + , mId( "" ) + , mUuid( QUuid::createUuid().toString() ) { init( manageZValue ); } @@ -68,6 +72,8 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q , mLastValidViewScaleFactor( -1 ) , mRotation( 0 ) , mLastUsedPositionMode( UpperLeft ) + , mId( "" ) + , mUuid( QUuid::createUuid().toString() ) { init( manageZValue ); QTransform t; @@ -153,6 +159,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", QString::number( mRotation ) ); + composerItemElem.setAttribute( "uuid", mUuid ); composerItemElem.setAttribute( "id", mId ); //position lock for mouse moves/resizes if ( mItemPositionLocked ) @@ -201,8 +208,12 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument& //rotation mRotation = itemElem.attribute( "rotation", "0" ).toDouble(); + //uuid + mUuid = itemElem.attribute( "uuid", QUuid::createUuid().toString() ); + //id - mId = itemElem.attribute( "id", "" ); + QString id = itemElem.attribute( "id", "" ); + setId(id); //frame QString frame = itemElem.attribute( "frame" ); @@ -1255,3 +1266,9 @@ void QgsComposerItem::repaint() { update(); } + +void QgsComposerItem::setId( const QString& id ) +{ + setToolTip( id ); + mId = id; +} diff --git a/src/core/composer/qgscomposeritem.h b/src/core/composer/qgscomposeritem.h index 145d57598e3..d68daf3bbca 100644 --- a/src/core/composer/qgscomposeritem.h +++ b/src/core/composer/qgscomposeritem.h @@ -261,15 +261,18 @@ 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 + /**Get item's id (which is not necessarly unique) @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; } + /**Set item's id (which is not necessarly unique) + @note this method was added in version 1.7*/ + virtual void setId( const QString& id ); + + /**Get item identification name + @note this method was added in version 2.0 + @note there is not setter since one can't manually set the id*/ + QString uuid() const { return mUuid; } public slots: virtual void setRotation( double r ); @@ -392,8 +395,10 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem /**Emitted if the rectangle changes*/ void sizeChanged(); private: - // Label id (unique within the same composition) + // id (not unique) QString mId; + // name (unique) + QString mUuid; void init( bool manageZValue ); }; diff --git a/src/core/composer/qgscomposition.cpp b/src/core/composer/qgscomposition.cpp index bd40f0744e9..ccb5accb2bb 100644 --- a/src/core/composer/qgscomposition.cpp +++ b/src/core/composer/qgscomposition.cpp @@ -436,6 +436,17 @@ bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMapmatches( QKeySequence::Copy ) ) + { + // remove all uuid attributes + QDomNodeList composerItemsNodes = doc.elementsByTagName("ComposerItem"); + for (int i=0; isetData( "text/xml", doc.toByteArray() ); QClipboard *clipboard = QApplication::clipboard(); diff --git a/src/ui/qgscomposeritemwidgetbase.ui b/src/ui/qgscomposeritemwidgetbase.ui index 46f4caeb026..4c91e9224a2 100644 --- a/src/ui/qgscomposeritemwidgetbase.ui +++ b/src/ui/qgscomposeritemwidgetbase.ui @@ -351,16 +351,30 @@ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - + + - Item ID + Uuid (read-only) + + + + + + + true + + + + Id + + +