Skip to content

Commit

Permalink
Start hooking up tables to app
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent f29eb7b commit cca7c74
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
31 changes: 31 additions & 0 deletions src/app/layout/qgslayoutapputils.cpp
Expand Up @@ -38,6 +38,7 @@
#include "qgslayoutitemhtml.h"
#include "qgslayouthtmlwidget.h"
#include "qgslayoutscalebarwidget.h"
#include "qgslayoutitemattributetable.h"
#include "qgisapp.h"
#include "qgsmapcanvas.h"

Expand Down Expand Up @@ -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() );
}
24 changes: 1 addition & 23 deletions src/core/layout/qgslayoutitemattributetable.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutitemtexttable.cpp
Expand Up @@ -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 )
Expand Down

0 comments on commit cca7c74

Please sign in to comment.