Skip to content

Commit

Permalink
[FEATURE] Add new layout item type for manually created tables
Browse files Browse the repository at this point in the history
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 14, 2020
1 parent 5704412 commit 49d56f6
Show file tree
Hide file tree
Showing 18 changed files with 1,920 additions and 1 deletion.
75 changes: 75 additions & 0 deletions python/core/auto_generated/layout/qgslayoutitemmanualtable.sip.in
@@ -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 *
************************************************************************/
Expand Up @@ -191,6 +191,8 @@ of layout items.

Layout3DMap,

LayoutManualTable,

// item types provided by plugins
PluginItem,
};
Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/layout/qgslayoutmultiframe.sip.in
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -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
Expand Down
31 changes: 30 additions & 1 deletion src/app/layout/qgslayoutapputils.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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.