Skip to content

Commit

Permalink
Port more scalebar functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent 7e7770b commit 5b1c690
Show file tree
Hide file tree
Showing 11 changed files with 1,680 additions and 114 deletions.
14 changes: 14 additions & 0 deletions python/core/layout/qgslayoutitem.sip
Expand Up @@ -105,6 +105,20 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
UndoLegendGroupFont,
UndoLegendLayerFont,
UndoLegendItemFont,
UndoScaleBarLineWidth,
UndoScaleBarSegmentSize,
UndoScaleBarSegmentsLeft,
UndoScaleBarSegments,
UndoScaleBarHeight,
UndoScaleBarFontColor,
UndoScaleBarFillColor,
UndoScaleBarFillColor2,
UndoScaleBarStrokeColor,
UndoScaleBarUnitText,
UndoScaleBarMapUnitsSegment,
UndoScaleBarLabelBarSize,
UndoScaleBarBoxContentSpace,

UndoCustomCommand,
};

Expand Down
9 changes: 3 additions & 6 deletions python/core/layout/qgslayoutitemscalebar.sip
Expand Up @@ -24,7 +24,6 @@ class QgsLayoutItemScaleBar: QgsLayoutItem
%Docstring
Constructor for QgsLayoutItemScaleBar, with the specified parent ``layout``.
%End
~QgsLayoutItemScaleBar();

virtual int type() const;

Expand All @@ -38,6 +37,8 @@ class QgsLayoutItemScaleBar: QgsLayoutItem
The caller takes responsibility for deleting the returned object.
:rtype: QgsLayoutItemScaleBar
%End
virtual QgsLayoutSize minimumSize() const;


int numberOfSegments() const;
%Docstring
Expand Down Expand Up @@ -413,15 +414,11 @@ class QgsLayoutItemScaleBar: QgsLayoutItem
:rtype: str
%End

void adjustBoxSize();
%Docstring
Sets the scale bar box size to a size suitable for the scalebar content.
%End

void update();
%Docstring
Adjusts the scale bar box size and updates the item.
%End

virtual void refreshDataDefinedProperty( const QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties );


Expand Down
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -193,6 +193,7 @@ SET(QGIS_APP_SRCS
layout/qgslayoutpolygonwidget.cpp
layout/qgslayoutpolylinewidget.cpp
layout/qgslayoutpropertieswidget.cpp
layout/qgslayoutscalebarwidget.cpp
layout/qgslayoutshapewidget.cpp

locator/qgsinbuiltlocatorfilters.cpp
Expand Down Expand Up @@ -402,6 +403,7 @@ SET (QGIS_APP_MOC_HDRS
layout/qgslayoutpolygonwidget.h
layout/qgslayoutpolylinewidget.h
layout/qgslayoutpropertieswidget.h
layout/qgslayoutscalebarwidget.h
layout/qgslayoutshapewidget.h

locator/qgsinbuiltlocatorfilters.h
Expand Down
5 changes: 3 additions & 2 deletions src/app/layout/qgslayoutapputils.cpp
Expand Up @@ -37,6 +37,7 @@
#include "qgslayoutframe.h"
#include "qgslayoutitemhtml.h"
#include "qgslayouthtmlwidget.h"
#include "qgslayoutscalebarwidget.h"
#include "qgisapp.h"
#include "qgsmapcanvas.h"

Expand Down Expand Up @@ -143,10 +144,10 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()

// scalebar item

auto scalebarItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutScaleBar, QObject::tr( "Scale Bar" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddScalebar.svg" ) ),
auto scalebarItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutScaleBar, QObject::tr( "Scale Bar" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionScaleBar.svg" ) ),
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
{
return nullptr;//new QgsLayoutLegendWidget( qobject_cast< QgsLayoutItemLegend * >( item ) );
return new QgsLayoutScaleBarWidget( qobject_cast< QgsLayoutItemScaleBar * >( item ) );
}, createRubberBand );
scalebarItemMetadata->setItemAddedToLayoutFunction( [ = ]( QgsLayoutItem * item )
{
Expand Down

0 comments on commit 5b1c690

Please sign in to comment.