Skip to content
Permalink
Browse files
deprecate QgsDatabaseFilterProxyModel
  • Loading branch information
3nids committed Nov 10, 2021
1 parent a3e9d11 commit 325ab02468992fa68fa5e35e74f106776c9f60ba
Showing with 15 additions and 64 deletions.
  1. +6 −8 python/core/auto_generated/qgsdbfilterproxymodel.sip.in
  2. +6 −50 src/core/qgsdbfilterproxymodel.cpp
  3. +3 −6 src/core/qgsdbfilterproxymodel.h
@@ -10,23 +10,22 @@



class QgsDatabaseFilterProxyModel: QSortFilterProxyModel
{
%Docstring(signature="appended")
class QgsDatabaseFilterProxyModel /Deprecated/ : public QSortFilterProxyModel
%Docstring
A class that implements a custom filter and can be used
as a proxy for :py:class:`QgsDbTableModel`

.. deprecated:: QGIS 3.24

.. versionadded:: 3.0
%End
{

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

QgsDatabaseFilterProxyModel( QObject *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsDatabaseFilterProxyModel.
Constructor for :py:class:`QgsDatabaseFilterProxyModel`.
%End

void _setFilterWildcard( const QString &pattern );
@@ -42,7 +41,6 @@ Calls QSortFilterProxyModel.setFilterRegExp and triggers update
protected:
virtual bool filterAcceptsRow( int row, const QModelIndex &source_parent ) const;


};

/************************************************************************
@@ -17,68 +17,24 @@

#include "qgsdbfilterproxymodel.h"

#include <QStandardItemModel>

QgsDatabaseFilterProxyModel::QgsDatabaseFilterProxyModel( QObject *parent ): QSortFilterProxyModel( parent )
{

}

bool QgsDatabaseFilterProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
bool QgsDatabaseFilterProxyModel::filterAcceptsRow( int row, const QModelIndex &source_parent ) const
{
if ( filterAcceptsRowItself( source_row, source_parent ) )
return true;

//accept if any of the parents is accepted on it's own merits
QModelIndex parent = source_parent;
while ( parent.isValid() )
{
if ( filterAcceptsRowItself( parent.row(), parent.parent() ) )
return true;
parent = parent.parent();
}

//accept if any of the children is accepted on it's own merits
if ( hasAcceptedChildren( source_row, source_parent ) )
//if parent is valid, we have a toplevel item that should be always shown
if ( !source_parent.isValid() )
{
return true;
}

return false;
}

bool QgsDatabaseFilterProxyModel::filterAcceptsRowItself( int source_row, const QModelIndex &source_parent ) const
{
return QSortFilterProxyModel::filterAcceptsRow( source_row, source_parent );
}

bool QgsDatabaseFilterProxyModel::hasAcceptedChildren( int source_row, const QModelIndex &source_parent ) const
{
QModelIndex item = sourceModel()->index( source_row, 0, source_parent );
if ( !item.isValid() )
{
return false;
}

//check if there are children
int childCount = item.model()->rowCount( item );
if ( childCount == 0 )
return false;

for ( int i = 0; i < childCount; ++i )
{
if ( filterAcceptsRowItself( i, item ) )
return true;
if ( hasAcceptedChildren( i, item ) )
return true;
}

return false;
//else we have a row that describes a table and that
//should be tested using the given wildcard/regexp
return QSortFilterProxyModel::filterAcceptsRow( row, source_parent );
}




void QgsDatabaseFilterProxyModel::_setFilterWildcard( const QString &pattern )
{
QSortFilterProxyModel::setFilterWildcard( pattern );
@@ -28,9 +28,10 @@
* \ingroup core
* \brief A class that implements a custom filter and can be used
* as a proxy for QgsDbTableModel
* \since QGIS 3.0
* \deprecated since QGIS 3.24
* \since QGIS 3.0 QSortFilterProxyModel with native recursive filtering can be used instead
*/
class CORE_EXPORT QgsDatabaseFilterProxyModel: public QSortFilterProxyModel
class CORE_EXPORT Q_DECL_DEPRECATED QgsDatabaseFilterProxyModel SIP_DEPRECATED : public QSortFilterProxyModel
{
Q_OBJECT

@@ -49,10 +50,6 @@ class CORE_EXPORT QgsDatabaseFilterProxyModel: public QSortFilterProxyModel

protected:
bool filterAcceptsRow( int row, const QModelIndex &source_parent ) const override;

private:
bool filterAcceptsRowItself( int source_row, const QModelIndex &source_parent ) const;
bool hasAcceptedChildren( int source_row, const QModelIndex &source_parent ) const;
};

#endif

0 comments on commit 325ab02

Please sign in to comment.