Skip to content

Commit 5b1c690

Browse files
committed
Port more scalebar functionality
1 parent 7e7770b commit 5b1c690

11 files changed

+1680
-114
lines changed

python/core/layout/qgslayoutitem.sip

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
105105
UndoLegendGroupFont,
106106
UndoLegendLayerFont,
107107
UndoLegendItemFont,
108+
UndoScaleBarLineWidth,
109+
UndoScaleBarSegmentSize,
110+
UndoScaleBarSegmentsLeft,
111+
UndoScaleBarSegments,
112+
UndoScaleBarHeight,
113+
UndoScaleBarFontColor,
114+
UndoScaleBarFillColor,
115+
UndoScaleBarFillColor2,
116+
UndoScaleBarStrokeColor,
117+
UndoScaleBarUnitText,
118+
UndoScaleBarMapUnitsSegment,
119+
UndoScaleBarLabelBarSize,
120+
UndoScaleBarBoxContentSpace,
121+
108122
UndoCustomCommand,
109123
};
110124

python/core/layout/qgslayoutitemscalebar.sip

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class QgsLayoutItemScaleBar: QgsLayoutItem
2424
%Docstring
2525
Constructor for QgsLayoutItemScaleBar, with the specified parent ``layout``.
2626
%End
27-
~QgsLayoutItemScaleBar();
2827

2928
virtual int type() const;
3029

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

4243
int numberOfSegments() const;
4344
%Docstring
@@ -413,15 +414,11 @@ class QgsLayoutItemScaleBar: QgsLayoutItem
413414
:rtype: str
414415
%End
415416

416-
void adjustBoxSize();
417-
%Docstring
418-
Sets the scale bar box size to a size suitable for the scalebar content.
419-
%End
420-
421417
void update();
422418
%Docstring
423419
Adjusts the scale bar box size and updates the item.
424420
%End
421+
425422
virtual void refreshDataDefinedProperty( const QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties );
426423

427424

src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ SET(QGIS_APP_SRCS
193193
layout/qgslayoutpolygonwidget.cpp
194194
layout/qgslayoutpolylinewidget.cpp
195195
layout/qgslayoutpropertieswidget.cpp
196+
layout/qgslayoutscalebarwidget.cpp
196197
layout/qgslayoutshapewidget.cpp
197198

198199
locator/qgsinbuiltlocatorfilters.cpp
@@ -402,6 +403,7 @@ SET (QGIS_APP_MOC_HDRS
402403
layout/qgslayoutpolygonwidget.h
403404
layout/qgslayoutpolylinewidget.h
404405
layout/qgslayoutpropertieswidget.h
406+
layout/qgslayoutscalebarwidget.h
405407
layout/qgslayoutshapewidget.h
406408

407409
locator/qgsinbuiltlocatorfilters.h

src/app/layout/qgslayoutapputils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "qgslayoutframe.h"
3838
#include "qgslayoutitemhtml.h"
3939
#include "qgslayouthtmlwidget.h"
40+
#include "qgslayoutscalebarwidget.h"
4041
#include "qgisapp.h"
4142
#include "qgsmapcanvas.h"
4243

@@ -143,10 +144,10 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
143144

144145
// scalebar item
145146

146-
auto scalebarItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutScaleBar, QObject::tr( "Scale Bar" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddScalebar.svg" ) ),
147+
auto scalebarItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutScaleBar, QObject::tr( "Scale Bar" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionScaleBar.svg" ) ),
147148
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
148149
{
149-
return nullptr;//new QgsLayoutLegendWidget( qobject_cast< QgsLayoutItemLegend * >( item ) );
150+
return new QgsLayoutScaleBarWidget( qobject_cast< QgsLayoutItemScaleBar * >( item ) );
150151
}, createRubberBand );
151152
scalebarItemMetadata->setItemAddedToLayoutFunction( [ = ]( QgsLayoutItem * item )
152153
{

0 commit comments

Comments
 (0)