mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Port item id and uuid code
This commit is contained in:
parent
a515e953b8
commit
3cf06db467
@ -55,6 +55,35 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem
|
|||||||
:rtype: str
|
:rtype: str
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
QString uuid() const;
|
||||||
|
%Docstring
|
||||||
|
Returns the item identification string. This is a unique random string set for the item
|
||||||
|
upon creation.
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
There is no corresponding setter for the uuid - it's created automatically.
|
||||||
|
.. seealso:: id()
|
||||||
|
.. seealso:: setId()
|
||||||
|
:rtype: str
|
||||||
|
%End
|
||||||
|
|
||||||
|
QString id() const;
|
||||||
|
%Docstring
|
||||||
|
Returns the item's ID name. This is not necessarily unique, and duplicate ID names may exist
|
||||||
|
for a layout.
|
||||||
|
.. seealso:: setId()
|
||||||
|
.. seealso:: uuid()
|
||||||
|
:rtype: str
|
||||||
|
%End
|
||||||
|
|
||||||
|
virtual void setId( const QString &id );
|
||||||
|
%Docstring
|
||||||
|
Set the item's ``id`` name. This is not necessarily unique, and duplicate ID names may exist
|
||||||
|
for a layout.
|
||||||
|
.. seealso:: id()
|
||||||
|
.. seealso:: uuid()
|
||||||
|
%End
|
||||||
|
|
||||||
virtual void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget );
|
virtual void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget );
|
||||||
|
|
||||||
%Docstring
|
%Docstring
|
||||||
|
@ -19,12 +19,14 @@
|
|||||||
#include "qgslayoututils.h"
|
#include "qgslayoututils.h"
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QStyleOptionGraphicsItem>
|
#include <QStyleOptionGraphicsItem>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
#define CACHE_SIZE_LIMIT 5000
|
#define CACHE_SIZE_LIMIT 5000
|
||||||
|
|
||||||
QgsLayoutItem::QgsLayoutItem( QgsLayout *layout )
|
QgsLayoutItem::QgsLayoutItem( QgsLayout *layout )
|
||||||
: QgsLayoutObject( layout )
|
: QgsLayoutObject( layout )
|
||||||
, QGraphicsRectItem( 0 )
|
, QGraphicsRectItem( 0 )
|
||||||
|
, mUuid( QUuid::createUuid().toString() )
|
||||||
{
|
{
|
||||||
// needed to access current view transform during paint operations
|
// needed to access current view transform during paint operations
|
||||||
setFlags( flags() | QGraphicsItem::ItemUsesExtendedStyleOption );
|
setFlags( flags() | QGraphicsItem::ItemUsesExtendedStyleOption );
|
||||||
@ -38,6 +40,28 @@ QgsLayoutItem::QgsLayoutItem( QgsLayout *layout )
|
|||||||
initConnectionsToLayout();
|
initConnectionsToLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsLayoutItem::setId( const QString &id )
|
||||||
|
{
|
||||||
|
if ( id == mId )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mId = id;
|
||||||
|
setToolTip( id );
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
#if 0
|
||||||
|
//inform model that id data has changed
|
||||||
|
if ( mComposition )
|
||||||
|
{
|
||||||
|
mComposition->itemsModel()->updateItemDisplayName( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
emit itemChanged();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void QgsLayoutItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget * )
|
void QgsLayoutItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget * )
|
||||||
{
|
{
|
||||||
if ( !painter || !painter->device() )
|
if ( !painter || !painter->device() )
|
||||||
@ -410,8 +434,8 @@ QPointF QgsLayoutItem::positionAtReferencePoint( const QgsLayoutItem::ReferenceP
|
|||||||
|
|
||||||
bool QgsLayoutItem::writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const
|
bool QgsLayoutItem::writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const
|
||||||
{
|
{
|
||||||
// element.setAttribute( "uuid", mUuid );
|
element.setAttribute( QStringLiteral( "uuid" ), mUuid );
|
||||||
// element.setAttribute( "id", mId );
|
element.setAttribute( QStringLiteral( "id" ), mId );
|
||||||
element.setAttribute( QStringLiteral( "referencePoint" ), QString::number( static_cast< int >( mReferencePoint ) ) );
|
element.setAttribute( QStringLiteral( "referencePoint" ), QString::number( static_cast< int >( mReferencePoint ) ) );
|
||||||
element.setAttribute( QStringLiteral( "position" ), mItemPosition.encodePoint() );
|
element.setAttribute( QStringLiteral( "position" ), mItemPosition.encodePoint() );
|
||||||
element.setAttribute( QStringLiteral( "size" ), mItemSize.encodeSize() );
|
element.setAttribute( QStringLiteral( "size" ), mItemSize.encodeSize() );
|
||||||
@ -448,8 +472,8 @@ bool QgsLayoutItem::readPropertiesFromElement( const QDomElement &element, const
|
|||||||
{
|
{
|
||||||
readObjectPropertiesFromElement( element, document, context );
|
readObjectPropertiesFromElement( element, document, context );
|
||||||
|
|
||||||
// mUuid = element.attribute( "uuid", QUuid::createUuid().toString() );
|
mUuid = element.attribute( QStringLiteral( "uuid" ), QUuid::createUuid().toString() );
|
||||||
// setId( element.attribute( "id" ) );
|
setId( element.attribute( QStringLiteral( "id" ) ) );
|
||||||
mReferencePoint = static_cast< ReferencePoint >( element.attribute( QStringLiteral( "referencePoint" ) ).toInt() );
|
mReferencePoint = static_cast< ReferencePoint >( element.attribute( QStringLiteral( "referencePoint" ) ).toInt() );
|
||||||
attemptMove( QgsLayoutPoint::decodePoint( element.attribute( QStringLiteral( "position" ) ) ) );
|
attemptMove( QgsLayoutPoint::decodePoint( element.attribute( QStringLiteral( "position" ) ) ) );
|
||||||
attemptResize( QgsLayoutSize::decodeSize( element.attribute( QStringLiteral( "size" ) ) ) );
|
attemptResize( QgsLayoutSize::decodeSize( element.attribute( QStringLiteral( "size" ) ) ) );
|
||||||
|
@ -73,6 +73,31 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
|
|||||||
*/
|
*/
|
||||||
virtual QString stringType() const = 0;
|
virtual QString stringType() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the item identification string. This is a unique random string set for the item
|
||||||
|
* upon creation.
|
||||||
|
* \note There is no corresponding setter for the uuid - it's created automatically.
|
||||||
|
* \see id()
|
||||||
|
* \see setId()
|
||||||
|
*/
|
||||||
|
QString uuid() const { return mUuid; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the item's ID name. This is not necessarily unique, and duplicate ID names may exist
|
||||||
|
* for a layout.
|
||||||
|
* \see setId()
|
||||||
|
* \see uuid()
|
||||||
|
*/
|
||||||
|
QString id() const { return mId; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the item's \a id name. This is not necessarily unique, and duplicate ID names may exist
|
||||||
|
* for a layout.
|
||||||
|
* \see id()
|
||||||
|
* \see uuid()
|
||||||
|
*/
|
||||||
|
virtual void setId( const QString &id );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles preparing a paint surface for the layout item and painting the item's
|
* Handles preparing a paint surface for the layout item and painting the item's
|
||||||
* content. Derived classes must not override this method, but instead implement
|
* content. Derived classes must not override this method, but instead implement
|
||||||
@ -300,6 +325,12 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
//! id (not necessarily unique)
|
||||||
|
QString mId;
|
||||||
|
|
||||||
|
//! Unique id
|
||||||
|
QString mUuid;
|
||||||
|
|
||||||
ReferencePoint mReferencePoint = UpperLeft;
|
ReferencePoint mReferencePoint = UpperLeft;
|
||||||
QgsLayoutSize mFixedSize;
|
QgsLayoutSize mFixedSize;
|
||||||
QgsLayoutSize mMinimumSize;
|
QgsLayoutSize mMinimumSize;
|
||||||
|
@ -131,7 +131,7 @@ bool QgsLayoutObject::writeObjectPropertiesToElement( QDomElement &parentElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
//create object element
|
//create object element
|
||||||
QDomElement objectElement = document.createElement( "LayoutObject" );
|
QDomElement objectElement = document.createElement( QStringLiteral( "LayoutObject" ) );
|
||||||
|
|
||||||
QDomElement ddPropsElement = document.createElement( QStringLiteral( "dataDefinedProperties" ) );
|
QDomElement ddPropsElement = document.createElement( QStringLiteral( "dataDefinedProperties" ) );
|
||||||
mDataDefinedProperties.writeXml( ddPropsElement, sPropertyDefinitions );
|
mDataDefinedProperties.writeXml( ddPropsElement, sPropertyDefinitions );
|
||||||
@ -152,7 +152,7 @@ bool QgsLayoutObject::readObjectPropertiesFromElement( const QDomElement &parent
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDomNodeList objectNodeList = parentElement.elementsByTagName( "LayoutObject" );
|
QDomNodeList objectNodeList = parentElement.elementsByTagName( QStringLiteral( "LayoutObject" ) );
|
||||||
if ( objectNodeList.size() < 1 )
|
if ( objectNodeList.size() < 1 )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -37,6 +37,8 @@ class TestQgsLayoutItem: public QObject
|
|||||||
void init();// will be called before each testfunction is executed.
|
void init();// will be called before each testfunction is executed.
|
||||||
void cleanup();// will be called after every testfunction.
|
void cleanup();// will be called after every testfunction.
|
||||||
void creation(); //test creation of QgsLayoutItem
|
void creation(); //test creation of QgsLayoutItem
|
||||||
|
void uuid();
|
||||||
|
void id();
|
||||||
void registry();
|
void registry();
|
||||||
void shouldDrawDebug();
|
void shouldDrawDebug();
|
||||||
void shouldDrawAntialiased();
|
void shouldDrawAntialiased();
|
||||||
@ -180,6 +182,26 @@ void TestQgsLayoutItem::creation()
|
|||||||
delete layout;
|
delete layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestQgsLayoutItem::uuid()
|
||||||
|
{
|
||||||
|
QgsProject p;
|
||||||
|
QgsLayout l( &p );
|
||||||
|
|
||||||
|
//basic test of uuid
|
||||||
|
TestItem item( &l );
|
||||||
|
TestItem item2( &l );
|
||||||
|
QVERIFY( item.uuid() != item2.uuid() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestQgsLayoutItem::id()
|
||||||
|
{
|
||||||
|
QgsProject p;
|
||||||
|
QgsLayout l( &p );
|
||||||
|
TestItem item( &l );
|
||||||
|
item.setId( QStringLiteral( "test" ) );
|
||||||
|
QCOMPARE( item.id(), QStringLiteral( "test" ) );
|
||||||
|
}
|
||||||
|
|
||||||
void TestQgsLayoutItem::registry()
|
void TestQgsLayoutItem::registry()
|
||||||
{
|
{
|
||||||
// test QgsLayoutItemRegistry
|
// test QgsLayoutItemRegistry
|
||||||
@ -1229,12 +1251,12 @@ void TestQgsLayoutItem::writeReadXmlProperties()
|
|||||||
original->attemptResize( QgsLayoutSize( 6, 8, QgsUnitTypes::LayoutCentimeters ) );
|
original->attemptResize( QgsLayoutSize( 6, 8, QgsUnitTypes::LayoutCentimeters ) );
|
||||||
original->attemptMove( QgsLayoutPoint( 0.05, 0.09, QgsUnitTypes::LayoutMeters ) );
|
original->attemptMove( QgsLayoutPoint( 0.05, 0.09, QgsUnitTypes::LayoutMeters ) );
|
||||||
original->setItemRotation( 45.0 );
|
original->setItemRotation( 45.0 );
|
||||||
//original->setId( QString( "test" ) );
|
original->setId( QStringLiteral( "test" ) );
|
||||||
|
|
||||||
QgsLayoutItem *copy = createCopyViaXml( &l, original );
|
QgsLayoutItem *copy = createCopyViaXml( &l, original );
|
||||||
|
|
||||||
//QCOMPARE( copy->uuid(), original->uuid() );
|
QCOMPARE( copy->uuid(), original->uuid() );
|
||||||
//QCOMPARE( copy->id(), original->id() );
|
QCOMPARE( copy->id(), original->id() );
|
||||||
QgsProperty dd = copy->dataDefinedProperties().property( QgsLayoutObject::TestProperty );
|
QgsProperty dd = copy->dataDefinedProperties().property( QgsLayoutObject::TestProperty );
|
||||||
QVERIFY( dd );
|
QVERIFY( dd );
|
||||||
QVERIFY( dd.isActive() );
|
QVERIFY( dd.isActive() );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user