Skip to content

Commit

Permalink
Port text table
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent 9cf6e0a commit 3a0f943
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions python/core/layout/qgslayoutitemtexttable.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 *
************************************************************************/
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions src/core/layout/qgslayoutitemtexttable.cpp
@@ -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;
}
66 changes: 66 additions & 0 deletions src/core/layout/qgslayoutitemtexttable.h
@@ -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.