Skip to content
Permalink
Browse files
use native recursive filtering of QSortFilterProxyModel, avoid usage …
…of re-implementation
  • Loading branch information
3nids committed Nov 10, 2021
1 parent 440f572 commit a3e9d113b297720a7cb94656a344e5a39a04a416
Showing with 12 additions and 8 deletions.
  1. +9 −5 src/gui/providers/qgsdbsourceselectbase.cpp
  2. +3 −3 src/gui/providers/qgsdbsourceselectbase.h
@@ -15,20 +15,20 @@

#include "qgsabstractdbtablemodel.h"
#include "qgsdbsourceselectbase.h"
#include "qgsdbfilterproxymodel.h"

#include <QMenu>

#include <QSortFilterProxyModel>

QgsDbSourceSelectBase::QgsDbSourceSelectBase( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QgsAbstractDataSourceWidget( parent, fl, widgetMode )
{
setupUi( this );

mProxyModel = new QgsDatabaseFilterProxyModel( this );
mProxyModel = new QSortFilterProxyModel( this );
mProxyModel->setParent( this );
mProxyModel->setFilterKeyColumn( -1 );
mProxyModel->setFilterCaseSensitivity( Qt::CaseInsensitive );
mProxyModel->setRecursiveFilteringEnabled( true );

// Do not do dynamic sorting - otherwise whenever user selects geometry type / srid / pk columns,
// that item suddenly jumps to the end of the list (because the item gets changed) which is very annoying.
@@ -115,11 +115,15 @@ void QgsDbSourceSelectBase::filterResults()

if ( regex )
{
mProxyModel->_setFilterRegExp( searchText );
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
mProxyModel->setFilterRegExp( searchText );
#else
mProxyModel->setFilterRegularExpression( searchText );
#endif
}
else
{
mProxyModel->_setFilterWildcard( searchText );
mProxyModel->setFilterWildcard( searchText );
}
}

@@ -21,7 +21,7 @@
#include "ui_qgsdbsourceselectbase.h"
#include "qgsabstractdatasourcewidget.h"

class QgsDatabaseFilterProxyModel;
class QSortFilterProxyModel;
class QgsAbstractDbTableModel;

/**
@@ -41,12 +41,12 @@ class GUI_EXPORT QgsDbSourceSelectBase : public QgsAbstractDataSourceWidget, pro
void setSourceModel( QgsAbstractDbTableModel *model );

//! Returns the proxy model used to filter the results
QgsDatabaseFilterProxyModel *proxyModel() {return mProxyModel;}
QSortFilterProxyModel *proxyModel() {return mProxyModel;}

private:
void filterResults();

QgsDatabaseFilterProxyModel *mProxyModel = nullptr;
QSortFilterProxyModel *mProxyModel = nullptr;
QMenu *mSearchSettingsMenu = nullptr;

QAction *mSearchColumnAllAction = nullptr;

0 comments on commit a3e9d11

Please sign in to comment.