Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
do not use a specific class for the sort columns
for sake of simplicity this can live in the same class than the disaply columns
  • Loading branch information
3nids committed May 6, 2020
1 parent fcea343 commit 03f4cb9
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 242 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/layout/qgslayouttable.sip.in
Expand Up @@ -17,7 +17,7 @@ typedef QVector< QVector< QVariant > > QgsLayoutTableContents;

typedef QVector< QgsLayoutTableColumn * > QgsLayoutTableColumns;

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



Expand Down
115 changes: 4 additions & 111 deletions python/core/auto_generated/layout/qgslayouttablecolumn.sip.in
Expand Up @@ -147,7 +147,7 @@ is only used when the column is part of a :py:class:`QgsLayoutItemAttributeTable
.. seealso:: :py:func:`attribute`
%End

Qt::SortOrder sortOrder() const /Deprecated/;
Qt::SortOrder sortOrder() const;
%Docstring
Returns the sort order for the column. This property is only used when the column
is part of a QgsLayoutItemAttributeTable and when sortByRank is > 0.
Expand All @@ -159,12 +159,9 @@ is part of a QgsLayoutItemAttributeTable and when sortByRank is > 0.
.. seealso:: :py:func:`setSortOrder`

.. seealso:: :py:func:`sortByRank`

.. deprecated:: QGIS 3.14
the order is now hold in a distinct model
%End

void setSortOrder( Qt::SortOrder order ) /Deprecated/;
void setSortOrder( Qt::SortOrder order );
%Docstring
Sets the sort ``order`` for the column. This property is only used when the column
is part of a QgsLayoutItemAttributeTable and when sortByRank() is > 0.
Expand All @@ -176,9 +173,6 @@ is part of a QgsLayoutItemAttributeTable and when sortByRank() is > 0.
.. seealso:: :py:func:`sortOrder`

.. seealso:: :py:func:`setSortByRank`

.. deprecated:: QGIS 3.14
the order is now hold in a distinct model
%End

int sortByRank() const /Deprecated/;
Expand All @@ -200,7 +194,7 @@ If sort rank is <= 0 then the column is not being sorted.
.. seealso:: :py:func:`sortOrder`

.. deprecated:: QGIS 3.14
the order is now hold in a distinct model
the order is now hold in a dedicated model
%End

void setSortByRank( int rank ) /Deprecated/;
Expand All @@ -221,7 +215,7 @@ If the sort ``rank`` is <= 0 then the column is not being sorted.
.. seealso:: :py:func:`setSortOrder`

.. deprecated:: QGIS 3.14
the order is now hold in a distinct model
the order is now hold in a dedicated model
%End

QgsLayoutTableColumn *clone() /Factory/;
Expand All @@ -232,107 +226,6 @@ Creates a duplicate column which is a deep copy of this column.
%End

};

class QgsLayoutTableSortColumn : QObject
{
%Docstring
Stores properties of a column for the sorting of a :py:class:`QgsLayoutTable`.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgslayouttablecolumn.h"
%End
public:

QgsLayoutTableSortColumn();
%Docstring
Constructor for :py:class:`QgsLayoutTableColumn`.

:param heading: column heading
%End

bool writeXml( QDomElement &columnElem, QDomDocument &doc ) const;
%Docstring
Writes the column's properties to xml for storage.

:param columnElem: an existing QDomElement in which to store the column's properties.
:param doc: QDomDocument for the destination xml.

.. seealso:: :py:func:`readXml`
%End

bool readXml( const QDomElement &columnElem );
%Docstring
Reads the column's properties from xml.

:param columnElem: a QDomElement holding the column's desired properties.

.. seealso:: :py:func:`writeXml`
%End

QString attribute() const;
%Docstring
Returns the attribute name or expression used for the column's values. This property
is only used when the column is part of a :py:class:`QgsLayoutItemAttributeTable`.

.. note::

only applicable when used in a :py:class:`QgsLayoutItemAttributeTable`

.. seealso:: :py:func:`setAttribute`
%End

void setAttribute( const QString &attribute );
%Docstring
Sets the ``attribute`` name or expression used for the column's values. This property
is only used when the column is part of a :py:class:`QgsLayoutItemAttributeTable`.

.. note::

only applicable when used in a :py:class:`QgsLayoutItemAttributeTable`

.. seealso:: :py:func:`attribute`
%End

Qt::SortOrder sortOrder() const;
%Docstring
Returns the sort order for the column. This property is only used when the column
is part of a QgsLayoutItemAttributeTable and when sortByRank is > 0.

.. note::

only applicable when used in a :py:class:`QgsLayoutItemAttributeTable`

.. seealso:: :py:func:`setSortOrder`

.. seealso:: :py:func:`sortByRank`
%End

void setSortOrder( Qt::SortOrder order );
%Docstring
Sets the sort ``order`` for the column. This property is only used when the column
is part of a QgsLayoutItemAttributeTable and when sortByRank() is > 0.

.. note::

only applicable when used in a :py:class:`QgsLayoutItemAttributeTable`

.. seealso:: :py:func:`sortOrder`

.. seealso:: :py:func:`setSortByRank`
%End

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

:return: a new QgsLayoutTableSortColumn with same properties as this column.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutitemattributetable.cpp
Expand Up @@ -482,7 +482,7 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont
req.setFilterFid( atlasFeature.id() );
}

for ( const QgsLayoutTableSortColumn *column : qgis::as_const( mSortColumns ) )
for ( const QgsLayoutTableColumn *column : qgis::as_const( mSortColumns ) )
{
req = req.addOrderBy( column->attribute(), column->sortOrder() == Qt::AscendingOrder );
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/layout/qgslayouttable.cpp
Expand Up @@ -107,7 +107,7 @@ bool QgsLayoutTable::writePropertiesToElement( QDomElement &elem, QDomDocument &
elem.appendChild( displayColumnsElem );
// sort columns
QDomElement sortColumnsElem = doc.createElement( QStringLiteral( "sortColumns" ) );
for ( QgsLayoutTableSortColumn *column : qgis::as_const( mSortColumns ) )
for ( QgsLayoutTableColumn *column : qgis::as_const( mSortColumns ) )
{
QDomElement columnElem = doc.createElement( QStringLiteral( "column" ) );
column->writeXml( columnElem, doc );
Expand Down Expand Up @@ -187,7 +187,7 @@ bool QgsLayoutTable::readPropertiesFromElement( const QDomElement &itemElem, con
for ( int i = 0; i < columnEntryList.size(); ++i )
{
QDomElement columnElem = columnEntryList.at( i ).toElement();
QgsLayoutTableSortColumn *column = new QgsLayoutTableSortColumn;
QgsLayoutTableColumn *column = new QgsLayoutTableColumn;
column->readXml( columnElem );
mSortColumns.append( column );
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/layout/qgslayouttable.h
Expand Up @@ -27,7 +27,7 @@
#include <QPair>

class QgsLayoutTableColumn;
class QgsLayoutTableSortColumn;
class QgsLayoutTableColumn;

/**
* \ingroup core
Expand Down Expand Up @@ -62,7 +62,7 @@ typedef QVector< QgsLayoutTableColumn * > QgsLayoutTableColumns;
* List of column definitions for sorting a QgsLayoutTable
* \since QGIS 3.14
*/
typedef QVector< QgsLayoutTableSortColumn * > QgsLayoutTableSortColumns;
typedef QVector< QgsLayoutTableColumn * > QgsLayoutTableSortColumns;



Expand Down
29 changes: 1 addition & 28 deletions src/core/layout/qgslayouttablecolumn.cpp
Expand Up @@ -85,35 +85,8 @@ QgsLayoutTableColumn *QgsLayoutTableColumn::clone()
newColumn->setVAlignment( mVAlignment );
Q_NOWARN_DEPRECATED_PUSH
newColumn->setSortByRank( mSortByRank );
newColumn->setSortOrder( mSortOrder );
Q_NOWARN_DEPRECATED_POP
newColumn->setWidth( mWidth );
return newColumn.release();
}

QgsLayoutTableSortColumn::QgsLayoutTableSortColumn()
{}

bool QgsLayoutTableSortColumn::writeXml( QDomElement &columnElem, QDomDocument &doc ) const
{
//background color
QDomElement bgColorElem = doc.createElement( QStringLiteral( "backgroundColor" ) );
columnElem.setAttribute( QStringLiteral( "attribute" ), mAttribute );
columnElem.setAttribute( QStringLiteral( "sortOrder" ), QString::number( mSortOrder ) );
return true;
}

bool QgsLayoutTableSortColumn::readXml( const QDomElement &columnElem )
{
mAttribute = columnElem.attribute( QStringLiteral( "attribute" ), QString() );
mSortOrder = static_cast< Qt::SortOrder >( columnElem.attribute( QStringLiteral( "sortOrder" ), QString::number( Qt::AscendingOrder ) ).toInt() );
return true;
}

QgsLayoutTableSortColumn *QgsLayoutTableSortColumn::clone()
{
std::unique_ptr< QgsLayoutTableSortColumn > newColumn = qgis::make_unique< QgsLayoutTableSortColumn >();
newColumn->setAttribute( mAttribute );
newColumn->setSortOrder( mSortOrder );
newColumn->setWidth( mWidth );
return newColumn.release();
}
89 changes: 4 additions & 85 deletions src/core/layout/qgslayouttablecolumn.h
Expand Up @@ -142,19 +142,17 @@ class CORE_EXPORT QgsLayoutTableColumn : public QObject
* \note only applicable when used in a QgsLayoutItemAttributeTable
* \see setSortOrder()
* \see sortByRank()
* \deprecated since QGIS 3.14 the order is now hold in a distinct model
*/
Q_DECL_DEPRECATED Qt::SortOrder sortOrder() const SIP_DEPRECATED { return mSortOrder; }
Qt::SortOrder sortOrder() const { return mSortOrder; }

/**
* Sets the sort \a order for the column. This property is only used when the column
* is part of a QgsLayoutItemAttributeTable and when sortByRank() is > 0.
* \note only applicable when used in a QgsLayoutItemAttributeTable
* \see sortOrder()
* \see setSortByRank()
* \deprecated since QGIS 3.14 the order is now hold in a distinct model
*/
Q_DECL_DEPRECATED void setSortOrder( Qt::SortOrder order ) SIP_DEPRECATED { mSortOrder = order; }
void setSortOrder( Qt::SortOrder order ) { mSortOrder = order; }

/**
* Returns the sort rank for the column. If the sort rank is > 0 then the column
Expand All @@ -168,7 +166,7 @@ class CORE_EXPORT QgsLayoutTableColumn : public QObject
* \note only applicable when used in a QgsLayoutItemAttributeTable
* \see setSortByRank()
* \see sortOrder()
* \deprecated since QGIS 3.14 the order is now hold in a distinct model
* \deprecated since QGIS 3.14 the order is now hold in a dedicated model
*/
Q_DECL_DEPRECATED int sortByRank() const SIP_DEPRECATED { return mSortByRank; }

Expand All @@ -183,7 +181,7 @@ class CORE_EXPORT QgsLayoutTableColumn : public QObject
* \note only applicable when used in a QgsLayoutItemAttributeTable
* \see sortByRank()
* \see setSortOrder()
* \deprecated since QGIS 3.14 the order is now hold in a distinct model
* \deprecated since QGIS 3.14 the order is now hold in a dedicated model
*/
Q_DECL_DEPRECATED void setSortByRank( int rank ) SIP_DEPRECATED { mSortByRank = rank; }

Expand All @@ -207,83 +205,4 @@ class CORE_EXPORT QgsLayoutTableColumn : public QObject
friend class QgsCompositionConverter;

};

/**
* \ingroup core
* Stores properties of a column for the sorting of a QgsLayoutTable.
* \since QGIS 3.14
*/
class CORE_EXPORT QgsLayoutTableSortColumn : public QObject
{
Q_OBJECT

public:

/**
* Constructor for QgsLayoutTableColumn.
* \param heading column heading
*/
QgsLayoutTableSortColumn();

/**
* Writes the column's properties to xml for storage.
* \param columnElem an existing QDomElement in which to store the column's properties.
* \param doc QDomDocument for the destination xml.
* \see readXml()
*/
bool writeXml( QDomElement &columnElem, QDomDocument &doc ) const;

/**
* Reads the column's properties from xml.
* \param columnElem a QDomElement holding the column's desired properties.
* \see writeXml()
*/
bool readXml( const QDomElement &columnElem );

/**
* Returns the attribute name or expression used for the column's values. This property
* is only used when the column is part of a QgsLayoutItemAttributeTable.
* \note only applicable when used in a QgsLayoutItemAttributeTable
* \see setAttribute()
*/
QString attribute() const { return mAttribute; }

/**
* Sets the \a attribute name or expression used for the column's values. This property
* is only used when the column is part of a QgsLayoutItemAttributeTable.
* \note only applicable when used in a QgsLayoutItemAttributeTable
* \see attribute()
*/
void setAttribute( const QString &attribute ) { mAttribute = attribute; }

/**
* Returns the sort order for the column. This property is only used when the column
* is part of a QgsLayoutItemAttributeTable and when sortByRank is > 0.
* \note only applicable when used in a QgsLayoutItemAttributeTable
* \see setSortOrder()
* \see sortByRank()
*/
Qt::SortOrder sortOrder() const { return mSortOrder; }

/**
* Sets the sort \a order for the column. This property is only used when the column
* is part of a QgsLayoutItemAttributeTable and when sortByRank() is > 0.
* \note only applicable when used in a QgsLayoutItemAttributeTable
* \see sortOrder()
* \see setSortByRank()
*/
void setSortOrder( Qt::SortOrder order ) { mSortOrder = order; }

/**
* Creates a duplicate column which is a deep copy of this column.
* \returns a new QgsLayoutTableSortColumn with same properties as this column.
*/
QgsLayoutTableSortColumn *clone() SIP_FACTORY;

private:

QString mAttribute;
Qt::SortOrder mSortOrder = Qt::AscendingOrder;
};

#endif //QGSLAYOUTTABLECOLUMN_H

0 comments on commit 03f4cb9

Please sign in to comment.