Skip to content
Permalink
Browse files

QgsLayoutTableColumn is not a QObject anymore

  • Loading branch information
3nids committed May 6, 2020
1 parent e7fe141 commit ee686b5bdb3ccbd51cdb2be9cba27435d62ac48f
@@ -15,9 +15,9 @@ typedef QVector< QVariant > QgsLayoutTableRow;
typedef QVector< QVector< QVariant > > QgsLayoutTableContents;


typedef QVector< QgsLayoutTableColumn * > QgsLayoutTableColumns;
typedef QVector<QgsLayoutTableColumn> QgsLayoutTableColumns;

typedef QVector< QgsLayoutTableColumn * > QgsLayoutTableSortColumns;
typedef QVector<QgsLayoutTableColumn> QgsLayoutTableSortColumns;



@@ -10,7 +10,7 @@



class QgsLayoutTableColumn : QObject
class QgsLayoutTableColumn
{
%Docstring
Stores properties of a column for a QgsLayoutTable.
@@ -218,13 +218,18 @@ If the sort ``rank`` is <= 0 then the column is not being sorted.
the order is now hold in a dedicated model
%End

QgsLayoutTableColumn *clone() /Factory/;
QgsLayoutTableColumn *clone() /Deprecated,Factory/;
%Docstring
Creates a duplicate column which is a deep copy of this column.

:return: a new QgsLayoutTableColumn with same properties as this column.

.. deprecated:: QGIS 3.14
use a copy instead
%End

bool operator==( const QgsLayoutTableColumn &other );

};
/************************************************************************
* This file has been generated automatically from *
@@ -1428,9 +1428,7 @@ bool QgsCompositionConverter::readTableXml( QgsLayoutItemAttributeTable *layoutI
layoutItem->setWrapBehavior( static_cast<QgsLayoutTable::WrapBehavior>( itemElem.attribute( QStringLiteral( "wrapBehavior" ), QStringLiteral( "0" ) ).toInt() ) );

//restore column specifications
qDeleteAll( layoutItem->mColumns );
layoutItem->mColumns.clear();
qDeleteAll( layoutItem->mSortColumns );
layoutItem->mSortColumns.clear();

QDomNodeList columnsList = itemElem.elementsByTagName( QStringLiteral( "displayColumns" ) );
@@ -1441,14 +1439,14 @@ bool QgsCompositionConverter::readTableXml( QgsLayoutItemAttributeTable *layoutI
for ( int i = 0; i < columnEntryList.size(); ++i )
{
QDomElement columnElem = columnEntryList.at( i ).toElement();
QgsLayoutTableColumn *column = new QgsLayoutTableColumn;
column->mHAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "hAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
column->mVAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "vAlignment" ), QString::number( Qt::AlignVCenter ) ).toInt() );
column->mHeading = columnElem.attribute( QStringLiteral( "heading" ), QString() );
column->mAttribute = columnElem.attribute( QStringLiteral( "attribute" ), QString() );
column->mSortByRank = columnElem.attribute( QStringLiteral( "sortByRank" ), QStringLiteral( "0" ) ).toInt();
column->mSortOrder = static_cast< Qt::SortOrder >( columnElem.attribute( QStringLiteral( "sortOrder" ), QString::number( Qt::AscendingOrder ) ).toInt() );
column->mWidth = columnElem.attribute( QStringLiteral( "width" ), QStringLiteral( "0.0" ) ).toDouble();
QgsLayoutTableColumn column;
column.mHAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "hAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
column.mVAlignment = static_cast< Qt::AlignmentFlag >( columnElem.attribute( QStringLiteral( "vAlignment" ), QString::number( Qt::AlignVCenter ) ).toInt() );
column.mHeading = columnElem.attribute( QStringLiteral( "heading" ), QString() );
column.mAttribute = columnElem.attribute( QStringLiteral( "attribute" ), QString() );
column.mSortByRank = columnElem.attribute( QStringLiteral( "sortByRank" ), QStringLiteral( "0" ) ).toInt();
column.mSortOrder = static_cast< Qt::SortOrder >( columnElem.attribute( QStringLiteral( "sortOrder" ), QString::number( Qt::AscendingOrder ) ).toInt() );
column.mWidth = columnElem.attribute( QStringLiteral( "width" ), QStringLiteral( "0.0" ) ).toDouble();

QDomNodeList bgColorList = columnElem.elementsByTagName( QStringLiteral( "backgroundColor" ) );
if ( !bgColorList.isEmpty() )
@@ -1462,17 +1460,17 @@ bool QgsCompositionConverter::readTableXml( QgsLayoutItemAttributeTable *layoutI
bgAlpha = bgColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
if ( redOk && greenOk && blueOk && alphaOk )
{
column->mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
column.mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
}
}
layoutItem->mColumns.append( column );

// sorting columns are now (QGIS 3.14+) handled in a dedicated list
Q_NOWARN_DEPRECATED_PUSH
for ( QgsLayoutTableColumn *col : qgis::as_const( layoutItem->mColumns ) )
if ( col->sortByRank() > 0 )
layoutItem->mSortColumns.append( col->clone() );
std::sort( layoutItem->mSortColumns.begin(), layoutItem->mSortColumns.end(), []( QgsLayoutTableColumn * a, QgsLayoutTableColumn * b ) {return a->sortByRank() < b->sortByRank();} );
for ( const QgsLayoutTableColumn &col : qgis::as_const( layoutItem->mColumns ) )
if ( col.sortByRank() > 0 )
layoutItem->mSortColumns.append( col );
std::sort( layoutItem->mSortColumns.begin(), layoutItem->mSortColumns.end(), []( const QgsLayoutTableColumn & a, const QgsLayoutTableColumn & b ) {return a.sortByRank() < b.sortByRank();} );
Q_NOWARN_DEPRECATED_POP
}
}
@@ -170,9 +170,7 @@ void QgsLayoutItemAttributeTable::resetColumns()
}

//remove existing columns
qDeleteAll( mColumns );
mColumns.clear();
qDeleteAll( mSortColumns );
mSortColumns.clear();

//rebuild columns list from vector layer fields
@@ -181,10 +179,10 @@ void QgsLayoutItemAttributeTable::resetColumns()
for ( const auto &field : sourceFields )
{
QString currentAlias = source->attributeDisplayName( idx );
std::unique_ptr< QgsLayoutTableColumn > col = qgis::make_unique< QgsLayoutTableColumn >();
col->setAttribute( field.name() );
col->setHeading( currentAlias );
mColumns.append( col.release() );
QgsLayoutTableColumn col;
col.setAttribute( field.name() );
col.setHeading( currentAlias );
mColumns.append( col );
idx++;
}
}
@@ -321,7 +319,6 @@ void QgsLayoutItemAttributeTable::setDisplayedFields( const QStringList &fields,
}

//rebuild columns list, taking only fields contained in supplied list
qDeleteAll( mColumns );
mColumns.clear();

const QgsFields layerFields = source->fields();
@@ -335,10 +332,10 @@ void QgsLayoutItemAttributeTable::setDisplayedFields( const QStringList &fields,
continue;

QString currentAlias = source->attributeDisplayName( attrIdx );
std::unique_ptr< QgsLayoutTableColumn > col = qgis::make_unique< QgsLayoutTableColumn >();
col->setAttribute( layerFields.at( attrIdx ).name() );
col->setHeading( currentAlias );
mColumns.append( col.release() );
QgsLayoutTableColumn col;
col.setAttribute( layerFields.at( attrIdx ).name() );
col.setHeading( currentAlias );
mColumns.append( col );
}
}
else
@@ -348,10 +345,10 @@ void QgsLayoutItemAttributeTable::setDisplayedFields( const QStringList &fields,
for ( const QgsField &field : layerFields )
{
QString currentAlias = source->attributeDisplayName( idx );
std::unique_ptr< QgsLayoutTableColumn > col = qgis::make_unique< QgsLayoutTableColumn >();
col->setAttribute( field.name() );
col->setHeading( currentAlias );
mColumns.append( col.release() );
QgsLayoutTableColumn col;
col.setAttribute( field.name() );
col.setHeading( currentAlias );
mColumns.append( col );
idx++;
}
}
@@ -370,16 +367,16 @@ void QgsLayoutItemAttributeTable::restoreFieldAliasMap( const QMap<int, QString>
return;
}

for ( QgsLayoutTableColumn *column : qgis::as_const( mColumns ) )
for ( QgsLayoutTableColumn &column : mColumns )
{
int attrIdx = source->fields().lookupField( column->attribute() );
int attrIdx = source->fields().lookupField( column.attribute() );
if ( map.contains( attrIdx ) )
{
column->setHeading( map.value( attrIdx ) );
column.setHeading( map.value( attrIdx ) );
}
else
{
column->setHeading( source->attributeDisplayName( attrIdx ) );
column.setHeading( source->attributeDisplayName( attrIdx ) );
}
}
}
@@ -482,9 +479,9 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont
req.setFilterFid( atlasFeature.id() );
}

for ( const QgsLayoutTableColumn *column : qgis::as_const( mSortColumns ) )
for ( const QgsLayoutTableColumn &column : qgis::as_const( mSortColumns ) )
{
req = req.addOrderBy( column->attribute(), column->sortOrder() == Qt::AscendingOrder );
req = req.addOrderBy( column.attribute(), column.sortOrder() == Qt::AscendingOrder );
}

QgsFeature f;
@@ -550,9 +547,9 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont
QgsLayoutTableRow rowContents;
rowContents.reserve( mColumns.count() );

for ( QgsLayoutTableColumn *column : qgis::as_const( mColumns ) )
for ( const QgsLayoutTableColumn &column : qgis::as_const( mColumns ) )
{
int idx = layer->fields().lookupField( column->attribute() );
int idx = layer->fields().lookupField( column.attribute() );

QgsConditionalStyle style;

@@ -575,7 +572,7 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont
else
{
// Lets assume it's an expression
std::unique_ptr< QgsExpression > expression = qgis::make_unique< QgsExpression >( column->attribute() );
std::unique_ptr< QgsExpression > expression = qgis::make_unique< QgsExpression >( column.attribute() );
context.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "row_number" ), counter + 1, true ) );
expression->prepare( &context );
QVariant value = expression->evaluate( &context );
@@ -717,7 +714,6 @@ void QgsLayoutItemAttributeTable::removeLayer( const QString &layerId )
{
mVectorLayer.setLayer( nullptr );
//remove existing columns
qDeleteAll( mColumns );
mColumns.clear();
}
}
@@ -35,7 +35,6 @@ QgsLayoutItemManualTable::QgsLayoutItemManualTable( QgsLayout *layout )

QgsLayoutItemManualTable::~QgsLayoutItemManualTable()
{
qDeleteAll( mHeaders );
}

int QgsLayoutItemManualTable::type() const
@@ -160,7 +159,6 @@ QgsLayoutTableColumns &QgsLayoutItemManualTable::headers()

void QgsLayoutItemManualTable::setHeaders( const QgsLayoutTableColumns &headers )
{
qDeleteAll( mHeaders );
mHeaders.clear();

mHeaders.append( headers );
@@ -177,10 +175,10 @@ bool QgsLayoutItemManualTable::writePropertiesToElement( QDomElement &tableElem,

//headers
QDomElement headersElem = doc.createElement( QStringLiteral( "headers" ) );
for ( QgsLayoutTableColumn *header : mHeaders )
for ( const QgsLayoutTableColumn &header : qgis::as_const( mHeaders ) )
{
QDomElement headerElem = doc.createElement( QStringLiteral( "header" ) );
header->writeXml( headerElem, doc );
header.writeXml( headerElem, doc );
headersElem.appendChild( headerElem );
}
tableElem.appendChild( headersElem );
@@ -228,7 +226,6 @@ bool QgsLayoutItemManualTable::readPropertiesFromElement( const QDomElement &ite

mIncludeHeader = itemElem.attribute( QStringLiteral( "includeHeader" ) ).toInt();
//restore header specifications
qDeleteAll( mHeaders );
mHeaders.clear();
QDomNodeList headersList = itemElem.elementsByTagName( QStringLiteral( "headers" ) );
if ( !headersList.isEmpty() )
@@ -238,8 +235,8 @@ bool QgsLayoutItemManualTable::readPropertiesFromElement( const QDomElement &ite
for ( int i = 0; i < headerEntryList.size(); ++i )
{
QDomElement headerElem = headerEntryList.at( i ).toElement();
QgsLayoutTableColumn *header = new QgsLayoutTableColumn;
header->readXml( headerElem );
QgsLayoutTableColumn header;
header.readXml( headerElem );
mHeaders.append( header );
}
}
@@ -319,9 +316,9 @@ void QgsLayoutItemManualTable::refreshColumns()
for ( const QgsTableCell &cell : firstRow )
{
( void )cell;
std::unique_ptr< QgsLayoutTableColumn > newCol = qgis::make_unique< QgsLayoutTableColumn >( mHeaders.value( colIndex ) ? mHeaders.value( colIndex )->heading() : QString() );
newCol->setWidth( mColumnWidths.value( colIndex ) );
columns << newCol.release();
QgsLayoutTableColumn newCol( mHeaders.value( colIndex ).heading() );
newCol.setWidth( mColumnWidths.value( colIndex ) );
columns << newCol;
colIndex++;
}
}

0 comments on commit ee686b5

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