QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgstablecell.h
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 #ifndef QGSTABLECELL_H
16 #define QGSTABLECELL_H
17 
18 #include "qgis_core.h"
19 #include "qgis_sip.h"
20 #include "qgstextformat.h"
21 #include <QVariant>
22 #include <QColor>
23 #include <memory>
24 
25 class QgsNumericFormat;
27 
35 class CORE_EXPORT QgsTableCell
36 {
37 
38  public:
39 
43  QgsTableCell( const QVariant &content = QVariant() );
44 
46  QgsTableCell( const QgsTableCell &other );
47 
49 
50  QgsTableCell &operator=( const QgsTableCell &other );
51 
57  QVariant content() const { return mContent; }
58 
64  void setContent( const QVariant &content ) { mContent = content; }
65 
71  QColor backgroundColor() const { return mBackgroundColor; }
72 
80  void setBackgroundColor( const QColor &color ) { mBackgroundColor = color; }
81 
87  QColor foregroundColor() const { return mForegroundColor; }
88 
96  void setForegroundColor( const QColor &color ) { mForegroundColor = color; }
97 
106  QgsTextFormat textFormat() const { return mTextFormat; }
107 
116  void setTextFormat( const QgsTextFormat &format ) { mTextFormat = format; }
117 
123  const QgsNumericFormat *numericFormat() const;
124 
132  void setNumericFormat( QgsNumericFormat *format SIP_TRANSFER );
133 
141  Qt::Alignment horizontalAlignment() const;
142 
150  void setHorizontalAlignment( Qt::Alignment alignment );
151 
159  Qt::Alignment verticalAlignment() const;
160 
168  void setVerticalAlignment( Qt::Alignment alignment );
169 
175  QVariantMap properties( const QgsReadWriteContext &context ) const;
176 
182  void setProperties( const QVariantMap &properties, const QgsReadWriteContext &context );
183 
184 
185 #ifdef SIP_RUN
186  SIP_PYOBJECT __repr__();
187  % MethodCode
188  QString str = QStringLiteral( "<QgsTableCell: %1>" ).arg( sipCpp->content().toString() );
189  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
190  % End
191 #endif
192 
193  private:
194 
195  QVariant mContent;
196  QColor mBackgroundColor;
197  QColor mForegroundColor;
198  QgsTextFormat mTextFormat;
199  std::unique_ptr< QgsNumericFormat > mFormat;
200 
201  Qt::Alignment mHAlign = Qt::AlignLeft;
202  Qt::Alignment mVAlign = Qt::AlignVCenter;
203 
204 };
205 
211 typedef QVector<QgsTableCell> QgsTableRow;
212 
213 #ifndef SIP_RUN
214 
220 typedef QVector<QgsTableRow> QgsTableContents;
221 #else
222 
228 typedef QVector<QVector<QgsTableRow>> QgsTableContents;
229 #endif
230 
231 
232 #endif // QGSTABLECELL_H
QgsTableCell::setTextFormat
void setTextFormat(const QgsTextFormat &format)
Sets the cell's text format.
Definition: qgstablecell.h:116
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsTableCell::~QgsTableCell
~QgsTableCell()
QgsTableCell::backgroundColor
QColor backgroundColor() const
Returns the cell's background color, or an invalid color if a default color should be used for the ba...
Definition: qgstablecell.h:71
QgsNumericFormat
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
Definition: qgsnumericformat.h:218
QgsTableCell::setContent
void setContent(const QVariant &content)
Sets the cell's content.
Definition: qgstablecell.h:64
QgsTableContents
QVector< QgsTableRow > QgsTableContents
A set of table rows.
Definition: qgstablecell.h:220
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
QgsTableCell::setForegroundColor
void setForegroundColor(const QColor &color)
Sets the cell's foreground color.
Definition: qgstablecell.h:96
QgsTableCell
Encapsulates the contents and formatting of a single table cell.
Definition: qgstablecell.h:36
QgsTableCell::foregroundColor
QColor foregroundColor() const
Returns the cell's foreground color, or an invalid color if a default color should be used for the fo...
Definition: qgstablecell.h:87
qgis_sip.h
QgsTableCell::setBackgroundColor
void setBackgroundColor(const QColor &color)
Sets the cell's background color.
Definition: qgstablecell.h:80
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsTableCell::textFormat
QgsTextFormat textFormat() const
Returns the cell's text format.
Definition: qgstablecell.h:106
QgsTableRow
QVector< QgsTableCell > QgsTableRow
A row of table cells.
Definition: qgstablecell.h:211
qgstextformat.h
QgsTableCell::content
QVariant content() const
Returns the cell's content.
Definition: qgstablecell.h:57