Skip to content
Permalink
Browse files

[FEATURE] Add new layout item type for manually created tables

Allows for creation of tables with contents manually entered by users
(i.e. spreadsheet style), so that users can create completely custom
tables.

Supports control custom cell contents, foreground and background colors.
  • Loading branch information
nyalldawson committed Jan 10, 2020
1 parent 5704412 commit 49d56f6c1929d3fcf37cdabdecb3b63b57d0474c
@@ -0,0 +1,75 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitemmanualtable.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsLayoutItemManualTable: QgsLayoutTable
{
%Docstring
A layout table subclass that displays manually entered (and formatted) content.

.. versionadded:: 3.12
%End

%TypeHeaderCode
#include "qgslayoutitemmanualtable.h"
%End
public:

QgsLayoutItemManualTable( QgsLayout *layout /TransferThis/ );
%Docstring
Constructor for QgsLayoutItemManualTable, attached to the specified ``layout``.

Ownership is transferred to the layout.
%End

virtual int type() const;

virtual QIcon icon() const;

virtual QString displayName() const;


static QgsLayoutItemManualTable *create( QgsLayout *layout ) /Factory/;
%Docstring
Returns a new QgsLayoutItemManualTable for the specified parent ``layout``.
%End
virtual QgsConditionalStyle conditionalCellStyle( int row, int column ) const;


void setTableContents( const QgsTableContents &contents );
%Docstring
Sets the ``contents`` of the table.

.. seealso:: :py:func:`tableContents`
%End

QgsTableContents tableContents() const;
%Docstring
Returns the contents of the table.

.. seealso:: :py:func:`contents`
%End

protected:

virtual bool writePropertiesToElement( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const;

virtual bool readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context );


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitemmanualtable.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -191,6 +191,8 @@ of layout items.

Layout3DMap,

LayoutManualTable,

// item types provided by plugins
PluginItem,
};
@@ -23,6 +23,7 @@ several frames (QgsLayoutFrame items).
#include "qgslayoutmultiframe.h"
#include "qgslayoutitemhtml.h"
#include "qgslayoutitemattributetable.h"
#include "qgslayoutitemmanualtable.h"
#include "qgslayoutitemtexttable.h"
%End
%ConvertToSubClassCode
@@ -45,6 +46,10 @@ several frames (QgsLayoutFrame items).
sipType = sipType_QgsLayoutItemTextTable;
*sipCppRet = static_cast<QgsLayoutItemTextTable *>( sipCpp );
break;
case QGraphicsItem::UserType + 116:
sipType = sipType_QgsLayoutItemManualTable;
*sipCppRet = static_cast<QgsLayoutItemManualTable *>( sipCpp );
break;
default:
sipType = 0;
}
@@ -343,6 +343,7 @@
%Include auto_generated/layout/qgslayoutitemhtml.sip
%Include auto_generated/layout/qgslayoutitemlabel.sip
%Include auto_generated/layout/qgslayoutitemlegend.sip
%Include auto_generated/layout/qgslayoutitemmanualtable.sip
%Include auto_generated/layout/qgslayoutitemmap.sip
%Include auto_generated/layout/qgslayoutitemmapgrid.sip
%Include auto_generated/layout/qgslayoutitemmapitem.sip
@@ -209,6 +209,7 @@ SET(QGIS_APP_SRCS
layout/qgslayoutlegendlayersdialog.cpp
layout/qgslayoutlegendwidget.cpp
layout/qgslayoutmanagerdialog.cpp
layout/qgslayoutmanualtablewidget.cpp
layout/qgslayoutmapwidget.cpp
layout/qgslayoutmapgridwidget.cpp
layout/qgslayoutpagepropertieswidget.cpp
@@ -40,6 +40,8 @@
#include "qgslayoutscalebarwidget.h"
#include "qgslayoutitemattributetable.h"
#include "qgslayoutattributetablewidget.h"
#include "qgslayoutitemmanualtable.h"
#include "qgslayoutmanualtablewidget.h"
#include "qgisapp.h"
#include "qgsmapcanvas.h"

@@ -421,5 +423,32 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
table->addFrame( frame.release() );
return f;
} );
registry->addLayoutItemGuiMetadata( attributeTableItemMetadata .release() );
registry->addLayoutItemGuiMetadata( attributeTableItemMetadata.release() );

// manual table item

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

// initially start with a 2x2 empty table
QgsTableContents contents;
contents << ( QgsTableRow() << QgsTableCell() << QgsTableCell() );
contents << ( QgsTableRow() << QgsTableCell() << QgsTableCell() );
table->setTableContents( contents );

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( manualTableItemMetadata.release() );
}

0 comments on commit 49d56f6

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