|
38 | 38 | #include "qgslayoutitemhtml.h"
|
39 | 39 | #include "qgslayouthtmlwidget.h"
|
40 | 40 | #include "qgslayoutscalebarwidget.h"
|
| 41 | +#include "qgslayoutitemattributetable.h" |
41 | 42 | #include "qgisapp.h"
|
42 | 43 | #include "qgsmapcanvas.h"
|
43 | 44 |
|
@@ -279,4 +280,34 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
|
279 | 280 | } );
|
280 | 281 | registry->addLayoutItemGuiMetadata( htmlItemMetadata.release() );
|
281 | 282 |
|
| 283 | + // attribute table item |
| 284 | + |
| 285 | + auto attributeTableItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutAttributeTable, QObject::tr( "Attribute Table" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddTable.svg" ) ), |
| 286 | + [ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget * |
| 287 | + { |
| 288 | + return nullptr; //new QgsLayoutHtmlWidget( qobject_cast< QgsLayoutFrame * >( item ) ); |
| 289 | + }, createRubberBand ); |
| 290 | + attributeTableItemMetadata->setItemCreationFunction( [ = ]( QgsLayout * layout )->QgsLayoutItem* |
| 291 | + { |
| 292 | + std::unique_ptr< QgsLayoutItemAttributeTable > tableMultiFrame = qgis::make_unique< QgsLayoutItemAttributeTable >( layout ); |
| 293 | + QgsLayoutItemAttributeTable *table = tableMultiFrame.get(); |
| 294 | + |
| 295 | + //set first vector layer from layer registry as table source |
| 296 | + QMap<QString, QgsMapLayer *> layerMap = layout->project()->mapLayers(); |
| 297 | + for ( auto it = layerMap.constBegin() ; it != layerMap.constEnd(); ++it ) |
| 298 | + { |
| 299 | + if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) ) |
| 300 | + { |
| 301 | + table->setVectorLayer( vl ); |
| 302 | + break; |
| 303 | + } |
| 304 | + } |
| 305 | + |
| 306 | + layout->addMultiFrame( tableMultiFrame.release() ); |
| 307 | + std::unique_ptr< QgsLayoutFrame > frame = qgis::make_unique< QgsLayoutFrame >( layout, table ); |
| 308 | + QgsLayoutFrame *f = frame.get(); |
| 309 | + table->addFrame( frame.release() ); |
| 310 | + return f; |
| 311 | + } ); |
| 312 | + registry->addLayoutItemGuiMetadata( attributeTableItemMetadata .release() ); |
282 | 313 | }
|
0 commit comments