Skip to content

Commit cca7c74

Browse files
committed
Start hooking up tables to app
1 parent f29eb7b commit cca7c74

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

src/app/layout/qgslayoutapputils.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "qgslayoutitemhtml.h"
3939
#include "qgslayouthtmlwidget.h"
4040
#include "qgslayoutscalebarwidget.h"
41+
#include "qgslayoutitemattributetable.h"
4142
#include "qgisapp.h"
4243
#include "qgsmapcanvas.h"
4344

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

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() );
282313
}

src/core/layout/qgslayoutitemattributetable.cpp

+1-23
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,6 @@ class CORE_EXPORT QgsLayoutAttributeTableCompare
7575
QgsLayoutItemAttributeTable::QgsLayoutItemAttributeTable( QgsLayout *layout )
7676
: QgsLayoutTable( layout )
7777
{
78-
#if 0 //TODO - move to app
79-
//set first vector layer from layer registry as default one
80-
QMap<QString, QgsMapLayer *> layerMap = mComposition->project()->mapLayers();
81-
QMap<QString, QgsMapLayer *>::const_iterator mapIt = layerMap.constBegin();
82-
for ( ; mapIt != layerMap.constEnd(); ++mapIt )
83-
{
84-
QgsVectorLayer *vl = dynamic_cast<QgsVectorLayer *>( mapIt.value() );
85-
if ( vl )
86-
{
87-
mVectorLayer.setLayer( vl );
88-
break;
89-
}
90-
}
91-
#endif
92-
93-
if ( mVectorLayer )
94-
{
95-
resetColumns();
96-
//listen for modifications to layer and refresh table when they occur
97-
connect( mVectorLayer.get(), &QgsVectorLayer::layerModified, this, &QgsLayoutTable::refreshAttributes );
98-
}
99-
10078
if ( mLayout )
10179
{
10280
connect( mLayout->project(), static_cast < void ( QgsProject::* )( const QString & ) >( &QgsProject::layerWillBeRemoved ), this, &QgsLayoutItemAttributeTable::removeLayer );
@@ -129,7 +107,7 @@ QgsLayoutItemAttributeTable *QgsLayoutItemAttributeTable::create( QgsLayout *lay
129107

130108
QString QgsLayoutItemAttributeTable::displayName() const
131109
{
132-
return tr( "<attribute table>" );
110+
return tr( "<Attribute table frame>" );
133111
}
134112

135113
void QgsLayoutItemAttributeTable::setVectorLayer( QgsVectorLayer *layer )

src/core/layout/qgslayoutitemtexttable.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ QString QgsLayoutItemTextTable::stringType() const
3838

3939
QString QgsLayoutItemTextTable::displayName() const
4040
{
41-
return tr( "<text table>" );
41+
return tr( "<Text table frame>" );
4242
}
4343

4444
QgsLayoutItemTextTable *QgsLayoutItemTextTable::create( QgsLayout *layout )

0 commit comments

Comments
 (0)