QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgstablecell.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgstablecell.h
3  --------------
4  begin : January 2020
5  copyright : (C) 2020 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgstablecell.h"
17 #include "qgsapplication.h"
19 #include "qgsnumericformat.h"
20 
21 QgsTableCell::QgsTableCell( const QVariant &content )
22  : mContent( content )
23 {}
24 
26  : mContent( other.mContent )
27  , mBackgroundColor( other.mBackgroundColor )
28  , mForegroundColor( other.mForegroundColor )
29  , mFormat( other.mFormat ? other.mFormat->clone() : nullptr )
30 {}
31 
32 QgsTableCell::~QgsTableCell() = default;
33 
35 {
36  mContent = other.mContent;
37  mBackgroundColor = other.mBackgroundColor;
38  mForegroundColor = other.mForegroundColor;
39  mFormat.reset( other.mFormat ? other.mFormat->clone() : nullptr );
40  return *this;
41 }
42 
44 {
45  return mFormat.get();
46 }
47 
49 {
50  mFormat.reset( format );
51 }
52 
53 QVariantMap QgsTableCell::properties( const QgsReadWriteContext &context ) const
54 {
55  QVariantMap res;
56  res.insert( QStringLiteral( "content" ), mContent );
57  res.insert( QStringLiteral( "foreground" ), mForegroundColor );
58  res.insert( QStringLiteral( "background" ), mBackgroundColor );
59  if ( mFormat )
60  {
61  res.insert( QStringLiteral( "format_type" ), mFormat->id() );
62  res.insert( QStringLiteral( "format" ), mFormat->configuration( context ) );
63  }
64  return res;
65 }
66 
67 void QgsTableCell::setProperties( const QVariantMap &properties, const QgsReadWriteContext &context )
68 {
69  mContent = properties.value( QStringLiteral( "content" ) );
70  mForegroundColor = properties.value( QStringLiteral( "foreground" ) ).value< QColor >();
71  mBackgroundColor = properties.value( QStringLiteral( "background" ) ).value< QColor >();
72  if ( properties.contains( QStringLiteral( "format_type" ) ) )
73  {
74 
75  mFormat.reset( QgsApplication::numericFormatRegistry()->create( properties.value( QStringLiteral( "format_type" ) ).toString(),
76  properties.value( QStringLiteral( "format" ) ).toMap(),
77  context ) );
78  }
79  else
80  {
81  mFormat.reset();
82  }
83 }
qgsnumericformatregistry.h
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsTableCell::QgsTableCell
QgsTableCell(const QVariant &content=QVariant())
Constructor for QgsTableCell, with the specified content.
Definition: qgstablecell.cpp:21
QgsTableCell::~QgsTableCell
~QgsTableCell()
QgsTableCell::operator=
QgsTableCell & operator=(const QgsTableCell &other)
Definition: qgstablecell.cpp:34
QgsNumericFormat
Definition: qgsnumericformat.h:217
qgsapplication.h
QgsTableCell::numericFormat
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for numbers in the cell, or nullptr if no format is set.
Definition: qgstablecell.cpp:43
QgsTableCell
Encapsulates the contents and formatting of a single table cell.
Definition: qgstablecell.h:34
QgsTableCell::setNumericFormat
void setNumericFormat(QgsNumericFormat *format)
Sets the numeric format used for numbers in the cell, or nullptr if no specific format is set.
Definition: qgstablecell.cpp:48
qgstablecell.h
QgsNumericFormatRegistry::create
QgsNumericFormat * create(const QString &id, const QVariantMap &configuration, const QgsReadWriteContext &context) const
Creates a new numeric format by id, using the supplied configuration.
Definition: qgsnumericformatregistry.cpp:72
QgsTableCell::properties
QVariantMap properties(const QgsReadWriteContext &context) const
Returns the properties of the cell.
Definition: qgstablecell.cpp:53
qgsnumericformat.h
QgsTableCell::setProperties
void setProperties(const QVariantMap &properties, const QgsReadWriteContext &context)
Sets the properties for the cell.
Definition: qgstablecell.cpp:67
QgsApplication::numericFormatRegistry
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
Definition: qgsapplication.cpp:2214