41#include "moc_qgslayoutitemregistry.cpp"
43using namespace Qt::StringLiterals;
52 qDeleteAll( mMetadata );
53 qDeleteAll( mMultiFrameMetadata );
58 if ( !mMetadata.isEmpty() )
65 return new TestLayoutItem( layout );
102 return mMetadata.value( type );
107 return mMultiFrameMetadata.value( type );
112 if ( !metadata || mMetadata.contains( metadata->
type() ) )
115 mMetadata[metadata->
type()] = metadata;
122 if ( !mMetadata.contains( typeId ) )
124 mMetadata.remove( typeId );
136 if ( !metadata || mMultiFrameMetadata.contains( metadata->
type() ) )
139 mMultiFrameMetadata[metadata->
type()] = metadata;
146 if ( !mMultiFrameMetadata.contains( typeId ) )
148 mMultiFrameMetadata.remove( typeId );
160 if ( !mMetadata.contains( type ) )
163 return mMetadata[type]->createItem( layout );
168 if ( !mMultiFrameMetadata.contains( type ) )
171 return mMultiFrameMetadata[type]->createMultiFrame( layout );
176 if ( mMetadata.contains( type ) )
178 mMetadata[type]->resolvePaths( properties, pathResolver, saving );
180 else if ( mMultiFrameMetadata.contains( type ) )
182 mMultiFrameMetadata[type]->resolvePaths( properties, pathResolver, saving );
188 QMap<int, QString> types;
189 for (
auto it = mMetadata.constBegin(); it != mMetadata.constEnd(); ++it )
191 types.insert( it.key(), it.value()->visibleName() );
193 for (
auto it = mMultiFrameMetadata.constBegin(); it != mMultiFrameMetadata.constEnd(); ++it )
195 types.insert( it.key(), it.value()->visibleName() );
203TestLayoutItem::TestLayoutItem(
QgsLayout *layout )
206 int h =
static_cast< int >( 360.0 * qrand() / ( RAND_MAX + 1.0 ) );
207 int s = ( qrand() % ( 200 - 100 + 1 ) ) + 100;
208 int v = ( qrand() % ( 130 - 255 + 1 ) ) + 130;
209 mColor = QColor::fromHsv( h, s, v );
212 properties.insert( u
"color"_s, mColor.name() );
213 properties.insert( u
"style"_s, u
"solid"_s );
214 properties.insert( u
"style_border"_s, u
"solid"_s );
215 properties.insert( u
"color_border"_s, u
"black"_s );
216 properties.insert( u
"width_border"_s, u
"0.3"_s );
217 properties.insert( u
"joinstyle"_s, u
"miter"_s );
222void TestLayoutItem::draw(
QgsRenderContext &context,
const QStyleOptionGraphicsItem *itemStyle )
224 Q_UNUSED( itemStyle )
229 stack.
begin( context );
231 QPainter *painter = context.
painter();
234 painter->setRenderHint( QPainter::Antialiasing,
false );
235 painter->setPen( Qt::NoPen );
236 painter->setBrush( mColor );
240 QPolygonF shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ) );
241 QList<QPolygonF> rings;
243 mShapeStyleSymbol->startRender( context );
244 mShapeStyleSymbol->renderPolygon( shapePolygon, &rings,
nullptr, context );
245 mShapeStyleSymbol->stopRender( context );
249 stack.
end( context );
A paint effect which draws the source picture with minor or no alterations.
A paint effect which consists of a stack of other chained paint effects.
void appendEffect(QgsPaintEffect *effect)
Appends an effect to the end of the stack.
static std::unique_ptr< QgsFillSymbol > createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
A paint effect which draws a glow within a picture.
static QgsLayoutFrame * create(QgsLayout *layout)
Creates a new QgsLayoutFrame belonging to the specified layout.
static QgsLayoutItemAttributeTable * create(QgsLayout *layout)
Returns a new QgsLayoutItemAttributeTable for the specified parent layout.
static QgsLayoutItemChart * create(QgsLayout *layout)
Returns a new chart item for the specified layout.
static QgsLayoutItemElevationProfile * create(QgsLayout *layout)
Returns a new elevation profile item for the specified layout.
static QgsLayoutItemGroup * create(QgsLayout *layout)
Returns a new group item for the specified layout.
static QgsLayoutItemHtml * create(QgsLayout *layout)
Returns a new QgsLayoutItemHtml for the specified parent layout.
static QgsLayoutItemLabel * create(QgsLayout *layout)
Returns a new label item for the specified layout.
static QgsLayoutItemLegend * create(QgsLayout *layout)
Returns a new legend item for the specified layout.
static QgsLayoutItemManualTable * create(QgsLayout *layout)
Returns a new QgsLayoutItemManualTable for the specified parent layout.
static QgsLayoutItemMap * create(QgsLayout *layout)
Returns a new map item for the specified layout.
static QgsLayoutItemMarker * create(QgsLayout *layout)
Returns a new marker item for the specified layout.
static QgsLayoutItemPage * create(QgsLayout *layout)
Returns a new page item for the specified layout.
static QgsLayoutItemPicture * create(QgsLayout *layout)
Returns a new picture item for the specified layout.
static QgsLayoutItemPolygon * create(QgsLayout *layout)
Returns a new polygon item for the specified layout.
static QgsLayoutItemPolyline * create(QgsLayout *layout)
Returns a new polyline item for the specified layout.
QgsLayoutItemRegistry(QObject *parent=nullptr)
Creates a new empty item registry.
void resolvePaths(int type, QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving) const
Resolve paths in properties of a particular symbol layer.
bool addLayoutItemType(QgsLayoutItemAbstractMetadata *metadata)
Registers a new layout item type.
bool removeLayoutMultiFrameType(int typeId)
Unregisters a layout multiframe type.
bool removeLayoutItemType(int typeId)
Unregisters a layout item type.
void multiFrameTypeRemoved(int type)
Emitted whenever an multiframe type is removed from the registry with the specified type.
void typeAdded(int type, const QString &name)
Emitted whenever a new item type is added to the registry, with the specified type and visible name.
QgsLayoutItemAbstractMetadata * itemMetadata(int type) const
Returns the metadata for the specified item type.
bool addLayoutMultiFrameType(QgsLayoutMultiFrameAbstractMetadata *metadata)
Registers a new layout multiframe type.
@ LayoutManualTable
Manual (fixed) table.
@ LayoutElevationProfile
Elevation profile item.
@ LayoutPicture
Picture item.
@ LayoutGroup
Grouped item.
@ LayoutAttributeTable
Attribute table.
@ LayoutPolyline
Polyline shape item.
@ LayoutScaleBar
Scale bar item.
@ LayoutItem
Base class for items.
@ LayoutLegend
Legend item.
@ LayoutMarker
Marker item.
@ LayoutHtml
Html multiframe item.
@ LayoutTextTable
Preset text table.
@ LayoutFrame
Frame item, part of a QgsLayoutMultiFrame object.
@ LayoutPolygon
Polygon shape item.
QgsLayoutMultiFrameAbstractMetadata * multiFrameMetadata(int type) const
Returns the metadata for the specified multiframe type.
bool populate()
Populates the registry with standard item types.
void multiFrameTypeAdded(int type, const QString &name)
Emitted whenever a new multiframe type is added to the registry, with the specified type and visible ...
QgsLayoutItem * createItem(int type, QgsLayout *layout) const
Creates a new instance of a layout item given the item type, and target layout.
void typeRemoved(int type)
Emitted whenever an item type is removed from the registry with the specified type.
QMap< int, QString > itemTypes() const
Returns a map of available item types to translated name.
~QgsLayoutItemRegistry() override
QgsLayoutMultiFrame * createMultiFrame(int type, QgsLayout *layout) const
Creates a new instance of a layout multiframe given the multiframe type, and target layout.
static QgsLayoutItemScaleBar * create(QgsLayout *layout)
Returns a new scale bar item for the specified layout.
Layout item for basic filled shapes (e.g.
void setShapeType(QgsLayoutItemShape::Shape type)
Sets the type of shape (e.g.
@ Rectangle
Rectangle shape.
static QgsLayoutItemTextTable * create(QgsLayout *layout)
Returns a new QgsLayoutItemTextTable for the specified parent layout.
Base class for graphical items within a QgsLayout.
Abstract base class for layout items with the ability to distribute the content to several frames (Qg...
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
virtual void begin(QgsRenderContext &context)
Begins intercepting paint operations to a render context.
virtual void end(QgsRenderContext &context)
Ends interception of paint operations to a render context, and draws the result to the render context...
Resolves relative paths into absolute paths and vice versa.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
QMap< QString, QString > QgsStringMap