Skip to content
Permalink
Browse files

create a sort filter proxy model

  • Loading branch information
3nids committed Mar 19, 2021
1 parent 4c403a1 commit aa23d009a43be01a90f89cb4f2e930b8c7f8efac
@@ -13,6 +13,32 @@



class QgsSvgSelectorFilterModel : QSortFilterProxyModel
{
%Docstring
A model for displaying SVG files with a preview icon which can be filtered by file name.
Population of the model is performed in a background thread to ensure that
initial creation of the model is responsive and does not block the GUI.

.. versionadded:: 3.20
%End

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

QgsSvgSelectorFilterModel( QObject *parent /TransferThis/, const QString &path = QString(), int iconSize = 30 );
%Docstring
Constructor for creating a model for SVG files in a specific path.

:param parent: parent object
:param path: initial path, which is recursively searched
:param iconSize: desired size of SVG icons to create
%End

};

class QgsSvgSelectorListModel : QAbstractListModel
{
%Docstring
@@ -29,6 +29,7 @@
#include "qgsvectorlayer.h"

#include <QAbstractListModel>
#include <QSortFilterProxyModel>
#include <QCheckBox>
#include <QDir>
#include <QFileDialog>
@@ -216,6 +217,18 @@ void QgsSvgGroupLoader::loadGroup( const QString &parentPath )

///@endcond




QgsSvgSelectorFilterModel::QgsSvgSelectorFilterModel( QObject *parent, const QString &path, int iconSize )
: QSortFilterProxyModel( parent )
{
mModel = new QgsSvgSelectorListModel( parent, path, iconSize );
setFilterCaseSensitivity( Qt::CaseInsensitive );
setSourceModel( mModel );
setFilterRole( Qt::UserRole );
}

//,
// QgsSvgSelectorListModel
//
@@ -731,3 +744,5 @@ void QgsSvgParameterValueDelegate::updateEditorGeometry( QWidget *editor, const
}

///@endcond


@@ -23,6 +23,7 @@
#include "qgsguiutils.h"
#include "qgsproperty.h"

#include <QSortFilterProxyModel>
#include <QAbstractListModel>
#include <QDialog>
#include <QDialogButtonBox>
@@ -42,6 +43,7 @@ class QPushButton;
class QTreeView;

class QgsExpressionContextGenerator;
class QgsSvgSelectorListModel;


#ifndef SIP_RUN
@@ -267,6 +269,32 @@ class GUI_EXPORT QgsSvgGroupLoader : public QThread
///@endcond
#endif

/**
* \ingroup gui
* \class QgsSvgSelectorListModel
* \brief A model for displaying SVG files with a preview icon which can be filtered by file name.
* Population of the model is performed in a background thread to ensure that
* initial creation of the model is responsive and does not block the GUI.
* \since QGIS 3.20
*/
class GUI_EXPORT QgsSvgSelectorFilterModel : public QSortFilterProxyModel
{
Q_OBJECT

public:

/**
* Constructor for creating a model for SVG files in a specific path.
* \param parent parent object
* \param path initial path, which is recursively searched
* \param iconSize desired size of SVG icons to create
*/
QgsSvgSelectorFilterModel( QObject *parent SIP_TRANSFERTHIS, const QString &path = QString(), int iconSize = 30 );

private:
QgsSvgSelectorListModel *mModel = nullptr;
};

/**
* \ingroup gui
* \class QgsSvgSelectorListModel

0 comments on commit aa23d00

Please sign in to comment.