QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
47 qDeleteAll( mMetadata );
48 qDeleteAll( mMultiFrameMetadata );
53 if ( !mMetadata.isEmpty() )
60 return new TestLayoutItem( layout );
94 return mMetadata.value( type );
99 return mMultiFrameMetadata.value( type );
104 if ( !metadata || mMetadata.contains( metadata->
type() ) )
107 mMetadata[metadata->
type()] = metadata;
114 if ( !metadata || mMultiFrameMetadata.contains( metadata->
type() ) )
117 mMultiFrameMetadata[metadata->
type()] = metadata;
124 if ( !mMetadata.contains( type ) )
127 return mMetadata[type]->createItem( layout );
132 if ( !mMultiFrameMetadata.contains( type ) )
135 return mMultiFrameMetadata[type]->createMultiFrame( layout );
140 if ( mMetadata.contains( type ) )
142 mMetadata[type]->resolvePaths( properties, pathResolver, saving );
144 else if ( mMultiFrameMetadata.contains( type ) )
146 mMultiFrameMetadata[type]->resolvePaths( properties, pathResolver, saving );
152 QMap<int, QString> types;
153 for (
auto it = mMetadata.constBegin(); it != mMetadata.constEnd(); ++it )
155 types.insert( it.key(), it.value()->visibleName() );
157 for (
auto it = mMultiFrameMetadata.constBegin(); it != mMultiFrameMetadata.constEnd(); ++it )
159 types.insert( it.key(), it.value()->visibleName() );
167 TestLayoutItem::TestLayoutItem(
QgsLayout *layout )
170 int h =
static_cast< int >( 360.0 * qrand() / ( RAND_MAX + 1.0 ) );
171 int s = ( qrand() % ( 200 - 100 + 1 ) ) + 100;
172 int v = ( qrand() % ( 130 - 255 + 1 ) ) + 130;
173 mColor = QColor::fromHsv( h, s, v );
176 properties.insert( QStringLiteral(
"color" ), mColor.name() );
177 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
178 properties.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"solid" ) );
179 properties.insert( QStringLiteral(
"color_border" ), QStringLiteral(
"black" ) );
180 properties.insert( QStringLiteral(
"width_border" ), QStringLiteral(
"0.3" ) );
181 properties.insert( QStringLiteral(
"joinstyle" ), QStringLiteral(
"miter" ) );
186 void TestLayoutItem::draw(
QgsRenderContext &context,
const QStyleOptionGraphicsItem *itemStyle )
188 Q_UNUSED( itemStyle )
193 stack.
begin( context );
195 QPainter *painter = context.
painter();
198 painter->setRenderHint( QPainter::Antialiasing,
false );
199 painter->setPen( Qt::NoPen );
200 painter->setBrush( mColor );
204 QPolygonF shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ) );
205 QList<QPolygonF> rings;
207 mShapeStyleSymbol->startRender( context );
208 mShapeStyleSymbol->renderPolygon( shapePolygon, &rings,
nullptr, context );
209 mShapeStyleSymbol->stopRender( context );
213 stack.
end( context );
@ LayoutPolygon
Polygon shape item.
Layout item for basic filled shapes (e.g. rectangles, ellipses).
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
void resolvePaths(int type, QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving) const
Resolve paths in properties of a particular symbol layer.
virtual void begin(QgsRenderContext &context)
Begins intercepting paint operations to a render context.
static QgsLayoutItemPolyline * create(QgsLayout *layout)
Returns a new polyline item for the specified layout.
A paint effect which draws the source picture with minor or no alterations.
QgsLayoutItem * createItem(int type, QgsLayout *layout) const
Creates a new instance of a layout item given the item type, and target layout.
@ RenderMillimeters
Millimeters.
QgsLayoutItemRegistry(QObject *parent=nullptr)
Creates a new empty item registry.
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.
@ LayoutGroup
Grouped item.
static QgsLayoutItemGroup * create(QgsLayout *layout)
Returns a new group item for the specified layout.
static QgsLayoutItemLegend * create(QgsLayout *layout)
Returns a new legend item for the specified layout.
static QgsLayoutItemMarker * create(QgsLayout *layout)
Returns a new marker item for the specified layout.
~QgsLayoutItemRegistry() override
static QgsLayoutItemTextTable * create(QgsLayout *layout)
Returns a new QgsLayoutItemTextTable for the specified parent layout.
bool addLayoutMultiFrameType(QgsLayoutMultiFrameAbstractMetadata *metadata)
Registers a new layout multiframe type.
bool addLayoutItemType(QgsLayoutItemAbstractMetadata *metadata)
Registers a new layout item type.
@ LayoutPolyline
Polyline shape item.
static QgsLayoutItemPicture * create(QgsLayout *layout)
Returns a new picture item for the specified layout.
static QgsLayoutFrame * create(QgsLayout *layout)
Creates a new QgsLayoutFrame belonging to the specified layout.
static QgsLayoutItemMap * create(QgsLayout *layout)
Returns a new map item for the specified layout.
virtual void end(QgsRenderContext &context)
Ends interception of paint operations to a render context, and draws the result to the render context...
Base class for graphical items within a QgsLayout.
bool populate()
Populates the registry with standard item types.
@ LayoutScaleBar
Scale bar item.
A paint effect which draws a glow within a picture.
@ Rectangle
Rectangle shape.
static QgsLayoutItemPage * create(QgsLayout *layout)
Returns a new page item for the specified layout.
static QgsLayoutItemAttributeTable * create(QgsLayout *layout)
Returns a new QgsLayoutItemAttributeTable for the specified parent layout.
QMap< QString, QString > QgsStringMap
QgsLayoutMultiFrameAbstractMetadata * multiFrameMetadata(int type) const
Returns the metadata for the specified multiframe type.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
static QgsLayoutItemLabel * create(QgsLayout *layout)
Returns a new label item for the specified layout.
@ LayoutPicture
Picture item.
void appendEffect(QgsPaintEffect *effect)
Appends an effect to the end of the stack.
@ LayoutMarker
Marker item.
void setShapeType(QgsLayoutItemShape::Shape type)
Sets the type of shape (e.g.
@ LayoutTextTable
Preset text table.
QMap< int, QString > itemTypes() const
Returns a map of available item types to translated name.
static QgsLayoutItemPolygon * create(QgsLayout *layout)
Returns a new polygon item for the specified layout.
static QgsFillSymbol * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
@ LayoutHtml
Html multiframe item.
QgsLayoutMultiFrame * createMultiFrame(int type, QgsLayout *layout) const
Creates a new instance of a layout multiframe given the multiframe type, and target layout.
QPainter * painter()
Returns the destination QPainter for the render operation.
@ LayoutFrame
Frame item, part of a QgsLayoutMultiFrame object.
static QgsLayoutItemHtml * create(QgsLayout *layout)
Returns a new QgsLayoutItemHtml for the specified parent layout.
@ LayoutItem
Base class for items.
static QgsLayoutItemManualTable * create(QgsLayout *layout)
Returns a new QgsLayoutItemManualTable for the specified parent layout.
@ LayoutAttributeTable
Attribute table.
@ LayoutManualTable
Manual (fixed) table.
@ LayoutLegend
Legend item.
void multiFrameTypeAdded(int type, const QString &name)
Emitted whenever a new multiframe type is added to the registry, with the specified type and visible ...
static QgsLayoutItemScaleBar * create(QgsLayout *layout)
Returns a new scale bar item for the specified layout.
A paint effect which consists of a stack of other chained paint effects.