Skip to content

Commit

Permalink
Restore ui for configuring labels
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent 83f177c commit 585a8b7
Show file tree
Hide file tree
Showing 11 changed files with 848 additions and 10 deletions.
4 changes: 4 additions & 0 deletions python/core/layout/qgslayoutitem.sip
Expand Up @@ -80,6 +80,10 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
UndoPictureStrokeColor,
UndoPictureStrokeWidth,
UndoPictureNorthOffset,
UndoLabelText,
UndoLabelFont,
UndoLabelMargin,
UndoLabelFontColor,
UndoCustomCommand,
};

Expand Down
8 changes: 8 additions & 0 deletions python/core/layout/qgslayoutitemlabel.sip
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions src/app/layout/qgslayoutapputils.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 585a8b7

Please sign in to comment.