Skip to content
Permalink
Browse files

Restore ui for configuring labels

  • Loading branch information
nyalldawson committed Oct 24, 2017
1 parent 83f177c commit 585a8b70bac3bee8104ddffcc30043766b93df4b
@@ -80,6 +80,10 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
UndoPictureStrokeColor,
UndoPictureStrokeWidth,
UndoPictureNorthOffset,
UndoLabelText,
UndoLabelFont,
UndoLabelMargin,
UndoLabelFontColor,
UndoCustomCommand,
};

@@ -50,6 +50,14 @@ class QgsLayoutItemLabel: QgsLayoutItem
void adjustSizeToText();
%Docstring
Resizes the item so that the label's text fits to the item. Keeps the top left point stationary.
.. seealso:: sizeForText()
%End

QSizeF sizeForText() const;
%Docstring
Returns the required item size (in layout units) for the label's text to fill the item.
.. seealso:: adjustSizeToText()
:rtype: QSizeF
%End

QString text();
@@ -179,6 +179,7 @@ SET(QGIS_APP_SRCS
layout/qgslayoutguidewidget.cpp
layout/qgslayoutitemslistview.cpp
layout/qgslayoutappmenuprovider.cpp
layout/qgslayoutlabelwidget.cpp
layout/qgslayoutmapwidget.cpp
layout/qgslayoutmapgridwidget.cpp
layout/qgslayoutpagepropertieswidget.cpp
@@ -381,6 +382,7 @@ SET (QGIS_APP_MOC_HDRS
layout/qgslayoutdesignerdialog.h
layout/qgslayoutguidewidget.h
layout/qgslayoutitemslistview.h
layout/qgslayoutlabelwidget.h
layout/qgslayoutmapwidget.h
layout/qgslayoutmapgridwidget.h
layout/qgslayoutpagepropertieswidget.h
@@ -29,6 +29,8 @@
#include "qgslayoutpolylinewidget.h"
#include "qgslayoutpicturewidget.h"
#include "qgslayoutitempicture.h"
#include "qgslayoutitemlabel.h"
#include "qgslayoutlabelwidget.h"
#include "qgisapp.h"
#include "qgsmapcanvas.h"

@@ -83,6 +85,31 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
}, createRubberBand ) );


// label item

auto labelItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutLabel, QObject::tr( "Label" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionLabel.svg" ) ),
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
{
return new QgsLayoutLabelWidget( qobject_cast< QgsLayoutItemLabel * >( item ) );
}, createRubberBand );
labelItemMetadata->setItemAddedToLayoutFunction( [ = ]( QgsLayoutItem * item )
{
QgsLayoutItemLabel *label = qobject_cast< QgsLayoutItemLabel * >( item );
Q_ASSERT( label );

label->setText( QObject::tr( "Lorem ipsum" ) );
QSizeF minSize = label->sizeForText();
QSizeF currentSize = label->rect().size();

//make sure label size is sufficient to fit text
double labelWidth = std::max( minSize.width(), currentSize.width() );
double labelHeight = std::max( minSize.height(), currentSize.height() );
label->attemptSetSceneRect( QRectF( label->pos().x(), label->pos().y(), labelWidth, labelHeight ) );
} );

registry->addLayoutItemGuiMetadata( labelItemMetadata.release() );


// shape items

auto createShapeWidget =

0 comments on commit 585a8b7

Please sign in to comment.
You can’t perform that action at this time.