QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 }
The class is used as a container of context for various read/write operations on other objects...
QgsTableCell & operator=(const QgsTableCell &other)
Encapsulates the contents and formatting of a single table cell.
Definition: qgstablecell.h:34
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
void setProperties(const QVariantMap &properties, const QgsReadWriteContext &context)
Sets the properties for the cell.
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
void setNumericFormat(QgsNumericFormat *format)
Sets the numeric format used for numbers in the cell, or nullptr if no specific format is set...
QgsTableCell(const QVariant &content=QVariant())
Constructor for QgsTableCell, with the specified content.
QVariantMap properties(const QgsReadWriteContext &context) const
Returns the properties of the cell.
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for numbers in the cell, or nullptr if no format is set...