Skip to content
Permalink
Browse files

Start hooking up tables to app

  • Loading branch information
nyalldawson committed Nov 22, 2017
1 parent f29eb7b commit cca7c74ddfc26fa670db416368bd3f70ad98eb8f
@@ -38,6 +38,7 @@
#include "qgslayoutitemhtml.h"
#include "qgslayouthtmlwidget.h"
#include "qgslayoutscalebarwidget.h"
#include "qgslayoutitemattributetable.h"
#include "qgisapp.h"
#include "qgsmapcanvas.h"

@@ -279,4 +280,34 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
} );
registry->addLayoutItemGuiMetadata( htmlItemMetadata.release() );

// attribute table item

auto attributeTableItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutAttributeTable, QObject::tr( "Attribute Table" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddTable.svg" ) ),
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
{
return nullptr; //new QgsLayoutHtmlWidget( qobject_cast< QgsLayoutFrame * >( item ) );
}, createRubberBand );
attributeTableItemMetadata->setItemCreationFunction( [ = ]( QgsLayout * layout )->QgsLayoutItem*
{
std::unique_ptr< QgsLayoutItemAttributeTable > tableMultiFrame = qgis::make_unique< QgsLayoutItemAttributeTable >( layout );
QgsLayoutItemAttributeTable *table = tableMultiFrame.get();

//set first vector layer from layer registry as table source
QMap<QString, QgsMapLayer *> layerMap = layout->project()->mapLayers();
for ( auto it = layerMap.constBegin() ; it != layerMap.constEnd(); ++it )
{
if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
{
table->setVectorLayer( vl );
break;
}
}

layout->addMultiFrame( tableMultiFrame.release() );
std::unique_ptr< QgsLayoutFrame > frame = qgis::make_unique< QgsLayoutFrame >( layout, table );
QgsLayoutFrame *f = frame.get();
table->addFrame( frame.release() );
return f;
} );
registry->addLayoutItemGuiMetadata( attributeTableItemMetadata .release() );
}
@@ -75,28 +75,6 @@ class CORE_EXPORT QgsLayoutAttributeTableCompare
QgsLayoutItemAttributeTable::QgsLayoutItemAttributeTable( QgsLayout *layout )
: QgsLayoutTable( layout )
{
#if 0 //TODO - move to app
//set first vector layer from layer registry as default one
QMap<QString, QgsMapLayer *> layerMap = mComposition->project()->mapLayers();
QMap<QString, QgsMapLayer *>::const_iterator mapIt = layerMap.constBegin();
for ( ; mapIt != layerMap.constEnd(); ++mapIt )
{
QgsVectorLayer *vl = dynamic_cast<QgsVectorLayer *>( mapIt.value() );
if ( vl )
{
mVectorLayer.setLayer( vl );
break;
}
}
#endif

if ( mVectorLayer )
{
resetColumns();
//listen for modifications to layer and refresh table when they occur
connect( mVectorLayer.get(), &QgsVectorLayer::layerModified, this, &QgsLayoutTable::refreshAttributes );
}

if ( mLayout )
{
connect( mLayout->project(), static_cast < void ( QgsProject::* )( const QString & ) >( &QgsProject::layerWillBeRemoved ), this, &QgsLayoutItemAttributeTable::removeLayer );
@@ -129,7 +107,7 @@ QgsLayoutItemAttributeTable *QgsLayoutItemAttributeTable::create( QgsLayout *lay

QString QgsLayoutItemAttributeTable::displayName() const
{
return tr( "<attribute table>" );
return tr( "<Attribute table frame>" );
}

void QgsLayoutItemAttributeTable::setVectorLayer( QgsVectorLayer *layer )
@@ -38,7 +38,7 @@ QString QgsLayoutItemTextTable::stringType() const

QString QgsLayoutItemTextTable::displayName() const
{
return tr( "<text table>" );
return tr( "<Text table frame>" );
}

QgsLayoutItemTextTable *QgsLayoutItemTextTable::create( QgsLayout *layout )

0 comments on commit cca7c74

Please sign in to comment.
You can’t perform that action at this time.