mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Implemented ComposerItem's Uuids
- uuid are kept on cut/paste, but deleted on import template or copy/paste - removed obsolete id reference in QgsComposerLabelWidget
This commit is contained in:
parent
b513674fa8
commit
00c832b151
@ -292,16 +292,19 @@ class QgsComposerItem: QObject, QGraphicsRectItem
|
|||||||
/**Updates item, with the possibility to do custom update for subclasses*/
|
/**Updates item, with the possibility to do custom update for subclasses*/
|
||||||
virtual void updateItem();
|
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*/
|
@note this method was added in version 1.7*/
|
||||||
QString id() const;
|
QString id() const;
|
||||||
|
|
||||||
/**Set item identification name
|
/**Set item's id (which is not necessarly unique)
|
||||||
@note this method was added in version 1.7
|
@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 );
|
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:
|
public slots:
|
||||||
virtual void setRotation( double r );
|
virtual void setRotation( double r );
|
||||||
void repaint();
|
void repaint();
|
||||||
|
@ -349,6 +349,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
|
|||||||
mFrameGroupBox->blockSignals( true );
|
mFrameGroupBox->blockSignals( true );
|
||||||
mBackgroundGroupBox->blockSignals( true );
|
mBackgroundGroupBox->blockSignals( true );
|
||||||
mItemIdLineEdit->blockSignals( true );
|
mItemIdLineEdit->blockSignals( true );
|
||||||
|
mItemUuidLineEdit->blockSignals( true );
|
||||||
mTransparencySpinBox->blockSignals( true );
|
mTransparencySpinBox->blockSignals( true );
|
||||||
|
|
||||||
int alphaPercent = ( 255 - mItem->brush().color().alpha() ) / 2.55;
|
int alphaPercent = ( 255 - mItem->brush().color().alpha() ) / 2.55;
|
||||||
@ -356,6 +357,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
|
|||||||
mTransparencySlider->setValue( alphaPercent );
|
mTransparencySlider->setValue( alphaPercent );
|
||||||
mOutlineWidthSpinBox->setValue( mItem->pen().widthF() );
|
mOutlineWidthSpinBox->setValue( mItem->pen().widthF() );
|
||||||
mItemIdLineEdit->setText( mItem->id() );
|
mItemIdLineEdit->setText( mItem->id() );
|
||||||
|
mItemUuidLineEdit->setText( mItem->uuid() );
|
||||||
mFrameGroupBox->setChecked( mItem->hasFrame() );
|
mFrameGroupBox->setChecked( mItem->hasFrame() );
|
||||||
mBackgroundGroupBox->setChecked( mItem->hasBackground() );
|
mBackgroundGroupBox->setChecked( mItem->hasBackground() );
|
||||||
|
|
||||||
@ -364,15 +366,18 @@ void QgsComposerItemWidget::setValuesForGuiElements()
|
|||||||
mFrameGroupBox->blockSignals( false );
|
mFrameGroupBox->blockSignals( false );
|
||||||
mBackgroundGroupBox->blockSignals( false );
|
mBackgroundGroupBox->blockSignals( false );
|
||||||
mItemIdLineEdit->blockSignals( false );
|
mItemIdLineEdit->blockSignals( false );
|
||||||
|
mItemUuidLineEdit->blockSignals( false );
|
||||||
mTransparencySpinBox->blockSignals( false );
|
mTransparencySpinBox->blockSignals( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsComposerItemWidget::on_mItemIdLineEdit_textChanged( const QString &text )
|
|
||||||
|
void QgsComposerItemWidget::on_mItemIdLineEdit_editingFinished()
|
||||||
{
|
{
|
||||||
if ( mItem )
|
if ( mItem )
|
||||||
{
|
{
|
||||||
mItem->beginCommand( tr( "Item id changed" ), QgsComposerMergeCommand::ComposerLabelSetId );
|
mItem->beginCommand( tr( "Item id changed" ), QgsComposerMergeCommand::ComposerLabelSetId );
|
||||||
mItem->setId( text );
|
mItem->setId( mItemIdLineEdit->text() );
|
||||||
|
mItemIdLineEdit->setText( mItem->id() );
|
||||||
mItem->endCommand();
|
mItem->endCommand();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBa
|
|||||||
void on_mOutlineWidthSpinBox_valueChanged( double d );
|
void on_mOutlineWidthSpinBox_valueChanged( double d );
|
||||||
void on_mFrameGroupBox_toggled( bool state );
|
void on_mFrameGroupBox_toggled( bool state );
|
||||||
void on_mBackgroundGroupBox_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
|
//adjust coordinates in line edits
|
||||||
void on_mXLineEdit_editingFinished() { changeItemPosition(); }
|
void on_mXLineEdit_editingFinished() { changeItemPosition(); }
|
||||||
|
@ -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 )
|
void QgsComposerLabelWidget::on_mRotationSpinBox_valueChanged( double v )
|
||||||
{
|
{
|
||||||
if ( mComposerLabel )
|
if ( mComposerLabel )
|
||||||
|
@ -44,7 +44,6 @@ class QgsComposerLabelWidget: public QWidget, private Ui::QgsComposerLabelWidget
|
|||||||
void on_mTopRadioButton_clicked();
|
void on_mTopRadioButton_clicked();
|
||||||
void on_mBottomRadioButton_clicked();
|
void on_mBottomRadioButton_clicked();
|
||||||
void on_mMiddleRadioButton_clicked();
|
void on_mMiddleRadioButton_clicked();
|
||||||
void on_mLabelIdLineEdit_textChanged( const QString& text );
|
|
||||||
void on_mRotationSpinBox_valueChanged( double v );
|
void on_mRotationSpinBox_valueChanged( double v );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -22,12 +22,14 @@
|
|||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
#include "qgsproject.h"
|
||||||
|
|
||||||
#include "qgscomposition.h"
|
#include "qgscomposition.h"
|
||||||
#include "qgscomposeritem.h"
|
#include "qgscomposeritem.h"
|
||||||
#include "qgscomposerframe.h"
|
#include "qgscomposerframe.h"
|
||||||
|
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
#include "qgsrectangle.h" //just for debugging
|
#include "qgsrectangle.h" //just for debugging
|
||||||
@ -51,6 +53,8 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue
|
|||||||
, mLastValidViewScaleFactor( -1 )
|
, mLastValidViewScaleFactor( -1 )
|
||||||
, mRotation( 0 )
|
, mRotation( 0 )
|
||||||
, mLastUsedPositionMode( UpperLeft )
|
, mLastUsedPositionMode( UpperLeft )
|
||||||
|
, mId( "" )
|
||||||
|
, mUuid( QUuid::createUuid().toString() )
|
||||||
{
|
{
|
||||||
init( manageZValue );
|
init( manageZValue );
|
||||||
}
|
}
|
||||||
@ -68,6 +72,8 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
|
|||||||
, mLastValidViewScaleFactor( -1 )
|
, mLastValidViewScaleFactor( -1 )
|
||||||
, mRotation( 0 )
|
, mRotation( 0 )
|
||||||
, mLastUsedPositionMode( UpperLeft )
|
, mLastUsedPositionMode( UpperLeft )
|
||||||
|
, mId( "" )
|
||||||
|
, mUuid( QUuid::createUuid().toString() )
|
||||||
{
|
{
|
||||||
init( manageZValue );
|
init( manageZValue );
|
||||||
QTransform t;
|
QTransform t;
|
||||||
@ -153,6 +159,7 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons
|
|||||||
composerItemElem.setAttribute( "zValue", QString::number( zValue() ) );
|
composerItemElem.setAttribute( "zValue", QString::number( zValue() ) );
|
||||||
composerItemElem.setAttribute( "outlineWidth", QString::number( pen().widthF() ) );
|
composerItemElem.setAttribute( "outlineWidth", QString::number( pen().widthF() ) );
|
||||||
composerItemElem.setAttribute( "rotation", QString::number( mRotation ) );
|
composerItemElem.setAttribute( "rotation", QString::number( mRotation ) );
|
||||||
|
composerItemElem.setAttribute( "uuid", mUuid );
|
||||||
composerItemElem.setAttribute( "id", mId );
|
composerItemElem.setAttribute( "id", mId );
|
||||||
//position lock for mouse moves/resizes
|
//position lock for mouse moves/resizes
|
||||||
if ( mItemPositionLocked )
|
if ( mItemPositionLocked )
|
||||||
@ -201,8 +208,12 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument&
|
|||||||
//rotation
|
//rotation
|
||||||
mRotation = itemElem.attribute( "rotation", "0" ).toDouble();
|
mRotation = itemElem.attribute( "rotation", "0" ).toDouble();
|
||||||
|
|
||||||
|
//uuid
|
||||||
|
mUuid = itemElem.attribute( "uuid", QUuid::createUuid().toString() );
|
||||||
|
|
||||||
//id
|
//id
|
||||||
mId = itemElem.attribute( "id", "" );
|
QString id = itemElem.attribute( "id", "" );
|
||||||
|
setId(id);
|
||||||
|
|
||||||
//frame
|
//frame
|
||||||
QString frame = itemElem.attribute( "frame" );
|
QString frame = itemElem.attribute( "frame" );
|
||||||
@ -1255,3 +1266,9 @@ void QgsComposerItem::repaint()
|
|||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsComposerItem::setId( const QString& id )
|
||||||
|
{
|
||||||
|
setToolTip( id );
|
||||||
|
mId = id;
|
||||||
|
}
|
||||||
|
@ -261,15 +261,18 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
|
|||||||
/**Updates item, with the possibility to do custom update for subclasses*/
|
/**Updates item, with the possibility to do custom update for subclasses*/
|
||||||
virtual void updateItem() { QGraphicsRectItem::update(); }
|
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*/
|
@note this method was added in version 1.7*/
|
||||||
QString id() const { return mId; }
|
QString id() const { return mId; }
|
||||||
|
|
||||||
/**Set item identification name
|
/**Set item's id (which is not necessarly unique)
|
||||||
@note this method was added in version 1.7
|
@note this method was added in version 1.7*/
|
||||||
This method was moved from qgscomposerlabel so that every object can have a
|
virtual void setId( const QString& id );
|
||||||
id (NathanW)*/
|
|
||||||
void setId( const QString& id ) { mId = 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:
|
public slots:
|
||||||
virtual void setRotation( double r );
|
virtual void setRotation( double r );
|
||||||
@ -392,8 +395,10 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
|
|||||||
/**Emitted if the rectangle changes*/
|
/**Emitted if the rectangle changes*/
|
||||||
void sizeChanged();
|
void sizeChanged();
|
||||||
private:
|
private:
|
||||||
// Label id (unique within the same composition)
|
// id (not unique)
|
||||||
QString mId;
|
QString mId;
|
||||||
|
// name (unique)
|
||||||
|
QString mUuid;
|
||||||
|
|
||||||
void init( bool manageZValue );
|
void init( bool manageZValue );
|
||||||
};
|
};
|
||||||
|
@ -436,6 +436,17 @@ bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QS
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove all uuid attributes since we don't want duplicates UUIDS
|
||||||
|
QDomNodeList composerItemsNodes = importDoc.elementsByTagName("ComposerItem");
|
||||||
|
for (int i=0; i<composerItemsNodes.count(); ++i)
|
||||||
|
{
|
||||||
|
QDomNode composerItemNode = composerItemsNodes.at(i);
|
||||||
|
if( composerItemNode.isElement() )
|
||||||
|
{
|
||||||
|
composerItemNode.toElement().removeAttribute("uuid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//addItemsFromXML
|
//addItemsFromXML
|
||||||
addItemsFromXML( importDoc.documentElement(), importDoc, 0, addUndoCommands, 0 );
|
addItemsFromXML( importDoc.documentElement(), importDoc, 0, addUndoCommands, 0 );
|
||||||
|
|
||||||
|
@ -481,6 +481,22 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
doc.appendChild( documentElement );
|
doc.appendChild( documentElement );
|
||||||
|
|
||||||
|
//if it's a copy, we have to remove the UUIDs since we don't want any duplicate UUID
|
||||||
|
if ( e->matches( QKeySequence::Copy ) )
|
||||||
|
{
|
||||||
|
// remove all uuid attributes
|
||||||
|
QDomNodeList composerItemsNodes = doc.elementsByTagName("ComposerItem");
|
||||||
|
for (int i=0; i<composerItemsNodes.count(); ++i)
|
||||||
|
{
|
||||||
|
QDomNode composerItemNode = composerItemsNodes.at(i);
|
||||||
|
if( composerItemNode.isElement() )
|
||||||
|
{
|
||||||
|
composerItemNode.toElement().removeAttribute("uuid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QMimeData *mimeData = new QMimeData;
|
QMimeData *mimeData = new QMimeData;
|
||||||
mimeData->setData( "text/xml", doc.toByteArray() );
|
mimeData->setData( "text/xml", doc.toByteArray() );
|
||||||
QClipboard *clipboard = QApplication::clipboard();
|
QClipboard *clipboard = QApplication::clipboard();
|
||||||
|
@ -351,16 +351,30 @@
|
|||||||
<property name="labelAlignment">
|
<property name="labelAlignment">
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="mIdLabel">
|
<widget class="QLabel" name="mItemUuidLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Item ID</string>
|
<string>Uuid (read-only)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="mItemUuidLineEdit">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLineEdit" name="mItemIdLineEdit"/>
|
<widget class="QLineEdit" name="mItemIdLineEdit"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="mItemIdLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Id</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user