Skip to content
Permalink
Browse files

New class QgsTableCell

Encapsulates the contents and formatting options for a single cell
in a table (e.g. background and foreground color)
  • Loading branch information
nyalldawson committed Jan 10, 2020
1 parent be4f45e commit 5704412d96b5d4e218301ad9df77013c35632730
@@ -0,0 +1,134 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstablecell.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsTableCell
{
%Docstring
Encapsulates the contents and formatting of a single table cell.

.. versionadded:: 3.12
%End

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

QgsTableCell( const QVariant &content = QVariant() );
%Docstring
Constructor for QgsTableCell, with the specified ``content``.
%End

QgsTableCell( const QgsTableCell &other );
%Docstring
Copy constructor
%End

~QgsTableCell();


QVariant content() const;
%Docstring
Returns the cell's content.

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

void setContent( const QVariant &content );
%Docstring
Sets the cell's ``content``.

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

QColor backgroundColor() const;
%Docstring
Returns the cell's background color, or an invalid color if a default color should be used for the background.

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

void setBackgroundColor( const QColor &color );
%Docstring
Sets the cell's background ``color``.

Set an invalid ``color`` if a default color should be used for the background.

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

QColor foregroundColor() const;
%Docstring
Returns the cell's foreground color, or an invalid color if a default color should be used for the foreground.

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

void setForegroundColor( const QColor &color );
%Docstring
Sets the cell's foreground ``color``.

Set an invalid ``color`` if a default color should be used for the foreground.

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

const QgsNumericFormat *numericFormat() const;
%Docstring
Returns the numeric format used for numbers in the cell, or ``None`` if no format is set.

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

void setNumericFormat( QgsNumericFormat *format /Transfer/ );
%Docstring
Sets the numeric ``format`` used for numbers in the cell, or ``None`` if no specific format is set.

Ownership of ``format`` is transferred to the cell.

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

QVariantMap properties( const QgsReadWriteContext &context ) const;
%Docstring
Returns the properties of the cell.

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

void setProperties( const QVariantMap &properties, const QgsReadWriteContext &context );
%Docstring
Sets the ``properties`` for the cell.

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


SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsTableCell: %1>" ).arg( sipCpp->content().toString() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

};

typedef QVector<QgsTableCell> QgsTableRow;


typedef QVector<QVector<QgsTableRow>> QgsTableContents;


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstablecell.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -187,6 +187,7 @@
%Include auto_generated/qgsstoredexpressionmanager.sip
%Include auto_generated/qgsstringstatisticalsummary.sip
%Include auto_generated/qgsstringutils.sip
%Include auto_generated/qgstablecell.sip
%Include auto_generated/qgstaskmanager.sip
%Include auto_generated/qgstessellator.sip
%Include auto_generated/qgstestutils.sip
@@ -374,6 +374,7 @@ SET(QGIS_CORE_SRCS
qgsstoredexpressionmanager.cpp
qgsstringstatisticalsummary.cpp
qgsstringutils.cpp
qgstablecell.cpp
qgstaskmanager.cpp
qgstessellator.cpp
qgstextrenderer.cpp
@@ -882,6 +883,7 @@ SET(QGIS_CORE_HDRS
qgsstoredexpressionmanager.h
qgsstringstatisticalsummary.h
qgsstringutils.h
qgstablecell.h
qgstaskmanager.h
qgstessellator.h
qgstestutils.h
@@ -0,0 +1,83 @@
/***************************************************************************
qgstablecell.h
--------------
begin : January 2020
copyright : (C) 2020 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 "qgstablecell.h"
#include "qgsapplication.h"
#include "qgsnumericformatregistry.h"
#include "qgsnumericformat.h"

QgsTableCell::QgsTableCell( const QVariant &content )
: mContent( content )
{}

QgsTableCell::QgsTableCell( const QgsTableCell &other )
: mContent( other.mContent )
, mBackgroundColor( other.mBackgroundColor )
, mForegroundColor( other.mForegroundColor )
, mFormat( other.mFormat ? other.mFormat->clone() : nullptr )
{}

QgsTableCell::~QgsTableCell() = default;

QgsTableCell &QgsTableCell::operator=( const QgsTableCell &other )
{
mContent = other.mContent;
mBackgroundColor = other.mBackgroundColor;
mForegroundColor = other.mForegroundColor;
mFormat.reset( other.mFormat ? other.mFormat->clone() : nullptr );
return *this;
}

const QgsNumericFormat *QgsTableCell::numericFormat() const
{
return mFormat.get();
}

void QgsTableCell::setNumericFormat( QgsNumericFormat *format )
{
mFormat.reset( format );
}

QVariantMap QgsTableCell::properties( const QgsReadWriteContext &context ) const
{
QVariantMap res;
res.insert( QStringLiteral( "content" ), mContent );
res.insert( QStringLiteral( "foreground" ), mForegroundColor );
res.insert( QStringLiteral( "background" ), mBackgroundColor );
if ( mFormat )
{
res.insert( QStringLiteral( "format_type" ), mFormat->id() );
res.insert( QStringLiteral( "format" ), mFormat->configuration( context ) );
}
return res;
}

void QgsTableCell::setProperties( const QVariantMap &properties, const QgsReadWriteContext &context )
{
mContent = properties.value( QStringLiteral( "content" ) );
mForegroundColor = properties.value( QStringLiteral( "foreground" ) ).value< QColor >();
mBackgroundColor = properties.value( QStringLiteral( "background" ) ).value< QColor >();
if ( properties.contains( QStringLiteral( "format_type" ) ) )
{

mFormat.reset( QgsApplication::numericFormatRegistry()->create( properties.value( QStringLiteral( "format_type" ) ).toString(),
properties.value( QStringLiteral( "format" ) ).toMap(),
context ) );
}
else
{
mFormat.reset();
}
}

0 comments on commit 5704412

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