mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -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*/
|
||||
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();
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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(); }
|
||||
|
@ -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 )
|
||||
|
@ -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:
|
||||
|
@ -22,12 +22,14 @@
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QGraphicsView>
|
||||
#include <QPainter>
|
||||
#include <QUuid>
|
||||
|
||||
#include "qgsproject.h"
|
||||
|
||||
#include "qgscomposition.h"
|
||||
#include "qgscomposeritem.h"
|
||||
#include "qgscomposerframe.h"
|
||||
|
||||
|
||||
#include <limits>
|
||||
#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;
|
||||
}
|
||||
|
@ -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 );
|
||||
};
|
||||
|
@ -436,6 +436,17 @@ bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QS
|
||||
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( importDoc.documentElement(), importDoc, 0, addUndoCommands, 0 );
|
||||
|
||||
|
@ -481,6 +481,22 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
|
||||
}
|
||||
}
|
||||
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;
|
||||
mimeData->setData( "text/xml", doc.toByteArray() );
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
|
@ -351,16 +351,30 @@
|
||||
<property name="labelAlignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="mIdLabel">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="mItemUuidLabel">
|
||||
<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>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="mItemIdLineEdit"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="mItemIdLabel">
|
||||
<property name="text">
|
||||
<string>Id</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user