Branch data Line data Source code
1 : : /*************************************************************************** 2 : : QgsLayoutTableColumn.h 3 : : ------------------ 4 : : begin : November 2017 5 : : copyright : (C) 2017 by Nyall Dawson 6 : : email : nyall dot dawson at gmail dot com 7 : : ***************************************************************************/ 8 : : 9 : : /*************************************************************************** 10 : : * * 11 : : * This program is free software; you can redistribute it and/or modify * 12 : : * it under the terms of the GNU General Public License as published by * 13 : : * the Free Software Foundation; either version 2 of the License, or * 14 : : * (at your option) any later version. * 15 : : * * 16 : : ***************************************************************************/ 17 : : 18 : : #ifndef QGSLAYOUTTABLECOLUMN_H 19 : : #define QGSLAYOUTTABLECOLUMN_H 20 : : 21 : : #include <QDomDocument> 22 : : #include <QDomElement> 23 : : #include <QColor> 24 : : 25 : : #include "qgis_core.h" 26 : : #include "qgis_sip.h" 27 : : 28 : : /** 29 : : * \ingroup core 30 : : * \brief Stores properties of a column for a QgsLayoutTable. 31 : : * 32 : : * Some properties of a QgsLayoutTableColumn are applicable only in certain contexts. 33 : : * For instance, the attribute and setAttribute methods only have an effect 34 : : * for QgsLayoutItemAttributeTables, and have no effect for QgsLayoutItemTextTables. 35 : : * \since QGIS 3.0 36 : : */ 37 : 0 : class CORE_EXPORT QgsLayoutTableColumn 38 : : { 39 : : public: 40 : : 41 : : /** 42 : : * Constructor for QgsLayoutTableColumn. 43 : : * \param heading column heading 44 : : */ 45 : : QgsLayoutTableColumn( const QString &heading = QString() ); 46 : : 47 : : /** 48 : : * Writes the column's properties to xml for storage. 49 : : * \param columnElem an existing QDomElement in which to store the column's properties. 50 : : * \param doc QDomDocument for the destination xml. 51 : : * \see readXml() 52 : : */ 53 : : bool writeXml( QDomElement &columnElem, QDomDocument &doc ) const; 54 : : 55 : : /** 56 : : * Reads the column's properties from xml. 57 : : * \param columnElem a QDomElement holding the column's desired properties. 58 : : * \see writeXml() 59 : : */ 60 : : bool readXml( const QDomElement &columnElem ); 61 : : 62 : : /** 63 : : * Returns the width for the column in mm, 64 : : * or 0 if column width is automatically calculated. 65 : : * \see setWidth() 66 : : */ 67 : 0 : double width() const { return mWidth; } 68 : : 69 : : /** 70 : : * Sets the width for a column in mm. Set the \a width to 0 if the column width is to be automatically calculated. 71 : : * \see width() 72 : : */ 73 : 0 : void setWidth( const double width ) { mWidth = width; } 74 : : 75 : : /** 76 : : * Returns the heading for a column, which is the value displayed in the column's 77 : : * header cell. 78 : : * \see setHeading() 79 : : */ 80 : 0 : QString heading() const { return mHeading; } 81 : : 82 : : /** 83 : : * Sets the \a heading for a column, which is the value displayed in the column's 84 : : * header cell. 85 : : * \see heading() 86 : : */ 87 : 0 : void setHeading( const QString &heading ) { mHeading = heading; } 88 : : 89 : : /** 90 : : * Returns the horizontal alignment for a column, which controls the alignment 91 : : * used for drawing column values within cells. 92 : : * \see setHAlignment() 93 : : * \see vAlignment() 94 : : */ 95 : 0 : Qt::AlignmentFlag hAlignment() const { return mHAlignment; } 96 : : 97 : : /** 98 : : * Sets the horizontal \a alignment for a column, which controls the alignment 99 : : * used for drawing column values within cells. 100 : : * \see hAlignment() 101 : : * \see setVAlignment() 102 : : */ 103 : : void setHAlignment( Qt::AlignmentFlag alignment ) { mHAlignment = alignment; } 104 : : 105 : : /** 106 : : * Returns the vertical alignment for a column, which controls the alignment 107 : : * used for drawing column values within cells. 108 : : * \see setVAlignment() 109 : : * \see hAlignment() 110 : : */ 111 : 0 : Qt::AlignmentFlag vAlignment() const { return mVAlignment; } 112 : : 113 : : /** 114 : : * Sets the vertical \a alignment for a column, which controls the alignment 115 : : * used for drawing column values within cells. 116 : : * \see vAlignment() 117 : : * \see setHAlignment() 118 : : */ 119 : : void setVAlignment( Qt::AlignmentFlag alignment ) { mVAlignment = alignment; } 120 : : 121 : : /** 122 : : * Returns the attribute name or expression used for the column's values. This property 123 : : * is only used when the column is part of a QgsLayoutItemAttributeTable. 124 : : * \note only applicable when used in a QgsLayoutItemAttributeTable 125 : : * \see setAttribute() 126 : : */ 127 : 0 : QString attribute() const { return mAttribute; } 128 : : 129 : : /** 130 : : * Sets the \a attribute name or expression used for the column's values. This property 131 : : * is only used when the column is part of a QgsLayoutItemAttributeTable. 132 : : * \note only applicable when used in a QgsLayoutItemAttributeTable 133 : : * \see attribute() 134 : : */ 135 : 0 : void setAttribute( const QString &attribute ) { mAttribute = attribute; } 136 : : 137 : : /** 138 : : * Returns the sort order for the column. This property is only used when the column 139 : : * is part of a QgsLayoutItemAttributeTable and when sortByRank is > 0. 140 : : * \note only applicable when used in a QgsLayoutItemAttributeTable 141 : : * \see setSortOrder() 142 : : * \see sortByRank() 143 : : */ 144 : 0 : Qt::SortOrder sortOrder() const { return mSortOrder; } 145 : : 146 : : /** 147 : : * Sets the sort \a order for the column. This property is only used when the column 148 : : * is part of a QgsLayoutItemAttributeTable and when sortByRank() is > 0. 149 : : * \note only applicable when used in a QgsLayoutItemAttributeTable 150 : : * \see sortOrder() 151 : : * \see setSortByRank() 152 : : */ 153 : : void setSortOrder( Qt::SortOrder order ) { mSortOrder = order; } 154 : : 155 : : /** 156 : : * Returns the sort rank for the column. If the sort rank is > 0 then the column 157 : : * will be sorted in the table. The sort rank specifies the priority given to the 158 : : * column when the table is sorted by multiple columns, with lower sort ranks 159 : : * having higher priority. This property is only used when the column 160 : : * is part of a QgsLayoutItemAttributeTable. 161 : : * 162 : : * If sort rank is <= 0 then the column is not being sorted. 163 : : * 164 : : * \note only applicable when used in a QgsLayoutItemAttributeTable 165 : : * \see setSortByRank() 166 : : * \see sortOrder() 167 : : * \deprecated since QGIS 3.14 the order is now hold in a dedicated model 168 : : */ 169 : 0 : Q_DECL_DEPRECATED int sortByRank() const SIP_DEPRECATED { return mSortByRank; } 170 : : 171 : : /** 172 : : * Sets the sort \a rank for the column. If the sort rank is > 0 then the column 173 : : * will be sorted in the table. The sort rank specifies the priority given to the 174 : : * column when the table is sorted by multiple columns, with lower sort ranks 175 : : * having higher priority. This property is only used when the column 176 : : * is part of a QgsLayoutItemAttributeTable. 177 : : * If the sort \a rank is <= 0 then the column is not being sorted. 178 : : * 179 : : * \note only applicable when used in a QgsLayoutItemAttributeTable 180 : : * \see sortByRank() 181 : : * \see setSortOrder() 182 : : * \deprecated since QGIS 3.14 the order is now hold in a dedicated model 183 : : */ 184 : : Q_DECL_DEPRECATED void setSortByRank( int rank ) SIP_DEPRECATED { mSortByRank = rank; } 185 : : 186 : : /** 187 : : * Creates a duplicate column which is a deep copy of this column. 188 : : * \returns a new QgsLayoutTableColumn with same properties as this column. 189 : : * \deprecated since QGIS 3.14 use a copy instead 190 : : */ 191 : : Q_DECL_DEPRECATED QgsLayoutTableColumn *clone() SIP_DEPRECATED SIP_FACTORY {return new QgsLayoutTableColumn( *this );} 192 : : 193 : : bool operator==( const QgsLayoutTableColumn &other ) 194 : : { 195 : : return mHeading == other.mHeading 196 : : && mAttribute == other.mAttribute 197 : : && mSortByRank == other.mSortByRank 198 : : && mSortOrder == other.mSortOrder 199 : : && mWidth == other.mWidth 200 : : && mHAlignment == other.mHAlignment 201 : : && mVAlignment == other.mVAlignment; 202 : : } 203 : : 204 : : private: 205 : : 206 : : QString mHeading; 207 : : QString mAttribute; 208 : : int mSortByRank = 0; 209 : : Qt::SortOrder mSortOrder = Qt::AscendingOrder; 210 : : double mWidth = 0.0; 211 : : QColor mBackgroundColor = Qt::transparent; //currently unused 212 : : Qt::AlignmentFlag mHAlignment = Qt::AlignLeft; 213 : : Qt::AlignmentFlag mVAlignment = Qt::AlignVCenter; 214 : : 215 : : friend class QgsCompositionConverter; 216 : : 217 : : }; 218 : : #endif //QGSLAYOUTTABLECOLUMN_H