Skip to content
Permalink
Browse files

Port text table

  • Loading branch information
nyalldawson committed Nov 21, 2017
1 parent 9cf6e0a commit 3a0f94389c945b7a06d2b2633a37ce734904a727
@@ -425,6 +425,7 @@
%Include layout/qgslayoutitemregistry.sip
%Include layout/qgslayoutitemscalebar.sip
%Include layout/qgslayoutitemshape.sip
%Include layout/qgslayoutitemtexttable.sip
%Include layout/qgslayoutmodel.sip
%Include layout/qgslayoutmultiframe.sip
%Include layout/qgslayoutpagecollection.sip
@@ -0,0 +1,61 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitemtexttable.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsLayoutItemTextTable : QgsLayoutTable
{
%Docstring
A text table item that reads text from string lists
.. versionadded:: 3.0
%End

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

QgsLayoutItemTextTable( QgsLayout *layout );
%Docstring
Constructor for QgsLayoutItemTextTable, for the specified ``layout``.
%End

void addRow( const QStringList &row );
%Docstring
Adds a row to the table
\param row list of strings to use for each cell's value in the newly added row
.. note::

If row is shorter than the number of columns in the table than blank cells
will be inserted at the end of the row. If row contains more strings then the number
of columns in the table then these extra strings will be ignored.
.. note::

if adding many rows, setContents() is much faster
%End

void setContents( const QVector< QStringList > &contents );
%Docstring
Sets the contents of the text table.
\param contents list of table rows
.. seealso:: addRow
%End

virtual bool getTableContents( QgsLayoutTableContents &contents );


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitemtexttable.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -388,6 +388,7 @@ SET(QGIS_CORE_SRCS
layout/qgslayoutitemregistry.cpp
layout/qgslayoutitemscalebar.cpp
layout/qgslayoutitemshape.cpp
layout/qgslayoutitemtexttable.cpp
layout/qgslayoutitemundocommand.cpp
layout/qgslayoutmeasurement.cpp
layout/qgslayoutmeasurementconverter.cpp
@@ -755,6 +756,7 @@ SET(QGIS_CORE_MOC_HDRS
layout/qgslayoutitemregistry.h
layout/qgslayoutitemscalebar.h
layout/qgslayoutitemshape.h
layout/qgslayoutitemtexttable.h
layout/qgslayoutmodel.h
layout/qgslayoutmultiframe.h
layout/qgslayoutpagecollection.h
@@ -0,0 +1,65 @@
/***************************************************************************
qgslayoutitemtexttable.cpp
--------------------------
begin : November 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgslayoutitemtexttable.h"
#include "qgslayouttablecolumn.h"
#include "qgslayoutframe.h"
#include "qgslayout.h"

QgsLayoutItemTextTable::QgsLayoutItemTextTable( QgsLayout *layout )
: QgsLayoutTable( layout )
{

}

void QgsLayoutItemTextTable::addRow( const QStringList &row )
{
mRowText.append( row );
refreshAttributes();
}

void QgsLayoutItemTextTable::setContents( const QVector<QStringList> &contents )
{
mRowText = contents;
refreshAttributes();
}

bool QgsLayoutItemTextTable::getTableContents( QgsLayoutTableContents &contents )
{
contents.clear();

for ( const QStringList &row : qgis::as_const( mRowText ) )
{
QgsLayoutTableRow currentRow;

for ( int i = 0; i < mColumns.count(); ++i )
{
if ( i < row.count() )
{
currentRow << row.at( i );
}
else
{
currentRow << QString();
}
}
contents << currentRow;
}

recalculateTableSize();
return true;
}
@@ -0,0 +1,66 @@
/***************************************************************************
qgslayoutitemtexttable.h
----------------------
begin : November 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSLAYOUTTEXTTABLE_H
#define QGSLAYOUTTEXTTABLE_H

#include "qgis_core.h"
#include "qgis.h"
#include "qgslayouttable.h"

/**
* \ingroup core
* A text table item that reads text from string lists
* \since QGIS 3.0
*/
class CORE_EXPORT QgsLayoutItemTextTable : public QgsLayoutTable
{

Q_OBJECT

public:

/**
* Constructor for QgsLayoutItemTextTable, for the specified \a layout.
*/
QgsLayoutItemTextTable( QgsLayout *layout );

/**
* Adds a row to the table
* \param row list of strings to use for each cell's value in the newly added row
* \note If row is shorter than the number of columns in the table than blank cells
* will be inserted at the end of the row. If row contains more strings then the number
* of columns in the table then these extra strings will be ignored.
* \note if adding many rows, setContents() is much faster
*/
void addRow( const QStringList &row );

/**
* Sets the contents of the text table.
* \param contents list of table rows
* \see addRow
*/
void setContents( const QVector< QStringList > &contents );

bool getTableContents( QgsLayoutTableContents &contents ) override;

private:
//! One stringlist per row
QVector< QStringList > mRowText;
};

#endif // QGSLAYOUTTEXTTABLE_H

0 comments on commit 3a0f943

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