mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[composer] Add function for getting a friendly display name for items
This commit is contained in:
parent
38d458ce5c
commit
3f076f0d30
@ -508,6 +508,15 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem
|
||||
*/
|
||||
QString uuid() const;
|
||||
|
||||
/**Get item display name. This is the item's id if set, and if
|
||||
* not, a user-friendly string identifying item type.
|
||||
* @returns display name for item
|
||||
* @see id
|
||||
* @see setId
|
||||
* @note added in version 2.5
|
||||
*/
|
||||
virtual QString displayName() const;
|
||||
|
||||
/**Returns whether this item is part of a group
|
||||
* @returns true if item is in a group
|
||||
* @note added in version 2.5
|
||||
|
@ -75,6 +75,9 @@ class QgsComposerLabel : QgsComposerItem
|
||||
* @param doc document
|
||||
*/
|
||||
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
|
||||
|
||||
//Overriden to contain part of label's text
|
||||
virtual QString displayName() const;
|
||||
|
||||
public slots:
|
||||
/* Sets rotation for the label
|
||||
|
@ -64,6 +64,9 @@ class QgsComposerShape: QgsComposerItem
|
||||
* QgsComposerItem as it needs to call updateBoundingRect after the shape's size changes
|
||||
*/
|
||||
void setSceneRect( const QRectF& rectangle );
|
||||
|
||||
//Overriden to return shape type
|
||||
virtual QString displayName() const;
|
||||
|
||||
protected:
|
||||
/* reimplement drawFrame, since it's not a rect, but a custom shape */
|
||||
|
@ -1288,3 +1288,44 @@ void QgsComposerItem::setIsGroupMember( const bool isGroupMember )
|
||||
mIsGroupMember = isGroupMember;
|
||||
setFlag( QGraphicsItem::ItemIsSelectable, !isGroupMember ); //item in groups cannot be selected
|
||||
}
|
||||
|
||||
QString QgsComposerItem::displayName() const
|
||||
{
|
||||
//return id, if it's not empty
|
||||
if ( ! id().isEmpty() )
|
||||
{
|
||||
return id();
|
||||
}
|
||||
|
||||
//for unnamed items, default to item type
|
||||
//(note some item types override this method to provide their own defaults)
|
||||
switch ( type() )
|
||||
{
|
||||
case ComposerArrow:
|
||||
return tr( "<arrow>" );
|
||||
case ComposerItemGroup:
|
||||
return tr( "<group>" );
|
||||
case ComposerLabel:
|
||||
return tr( "<label>" );
|
||||
case ComposerLegend:
|
||||
return tr( "<legend>" );
|
||||
case ComposerMap:
|
||||
return tr( "<map>" );
|
||||
case ComposerPicture:
|
||||
return tr( "<picture>" );
|
||||
case ComposerScaleBar:
|
||||
return tr( "<scale bar>" );
|
||||
case ComposerShape:
|
||||
return tr( "<shape>" );
|
||||
case ComposerTable:
|
||||
return tr( "<table>" );
|
||||
case ComposerAttributeTable:
|
||||
return tr( "<attribute table>" );
|
||||
case ComposerTextTable:
|
||||
return tr( "<text table>" );
|
||||
case ComposerFrame:
|
||||
return tr( "<frame>" );
|
||||
}
|
||||
|
||||
return tr( "<item>" );
|
||||
}
|
||||
|
@ -464,6 +464,15 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
|
||||
*/
|
||||
QString uuid() const { return mUuid; }
|
||||
|
||||
/**Get item display name. This is the item's id if set, and if
|
||||
* not, a user-friendly string identifying item type.
|
||||
* @returns display name for item
|
||||
* @see id
|
||||
* @see setId
|
||||
* @note added in version 2.5
|
||||
*/
|
||||
virtual QString displayName() const;
|
||||
|
||||
/**Returns whether this item is part of a group
|
||||
* @returns true if item is in a group
|
||||
* @note added in version 2.5
|
||||
|
19
src/core/composer/qgscomposerlabel.cpp
Executable file → Normal file
19
src/core/composer/qgscomposerlabel.cpp
Executable file → Normal file
@ -382,6 +382,25 @@ bool QgsComposerLabel::readXML( const QDomElement& itemElem, const QDomDocument&
|
||||
return true;
|
||||
}
|
||||
|
||||
QString QgsComposerLabel::displayName() const
|
||||
{
|
||||
if ( !id().isEmpty() )
|
||||
{
|
||||
return id();
|
||||
}
|
||||
|
||||
//if no id, default to portion of label text
|
||||
QString text = displayText();
|
||||
if ( text.length() > 25 )
|
||||
{
|
||||
return QString( tr( "%1..." ) ).arg( text.left( 25 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerLabel::itemShiftAdjustSize( double newWidth, double newHeight, double& xShift, double& yShift ) const
|
||||
{
|
||||
//keep alignment point constant
|
||||
|
@ -99,6 +99,9 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
|
||||
*/
|
||||
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
|
||||
|
||||
//Overriden to contain part of label's text
|
||||
virtual QString displayName() const;
|
||||
|
||||
public slots:
|
||||
void refreshExpressionContext();
|
||||
|
||||
|
@ -423,3 +423,26 @@ void QgsComposerShape::setSceneRect( const QRectF& rectangle )
|
||||
updateBoundingRect();
|
||||
update();
|
||||
}
|
||||
|
||||
QString QgsComposerShape::displayName() const
|
||||
{
|
||||
if ( !id().isEmpty() )
|
||||
{
|
||||
return id();
|
||||
}
|
||||
|
||||
switch ( mShape )
|
||||
{
|
||||
case Ellipse:
|
||||
return tr( "<ellipse>" );
|
||||
break;
|
||||
case Rectangle:
|
||||
return tr( "<rectangle>" );
|
||||
break;
|
||||
case Triangle:
|
||||
return tr( "<triangle>" );
|
||||
break;
|
||||
}
|
||||
|
||||
return tr( "<shape>" );
|
||||
}
|
||||
|
@ -89,6 +89,9 @@ class CORE_EXPORT QgsComposerShape: public QgsComposerItem
|
||||
*/
|
||||
void setSceneRect( const QRectF& rectangle );
|
||||
|
||||
//Overriden to return shape type
|
||||
virtual QString displayName() const;
|
||||
|
||||
protected:
|
||||
/* reimplement drawFrame, since it's not a rect, but a custom shape */
|
||||
virtual void drawFrame( QPainter* p );
|
||||
|
Loading…
x
Reference in New Issue
Block a user