SortFilterProxyModel icon indicating copy to clipboard operation
SortFilterProxyModel copied to clipboard

Add feature to build as standalone plugin

Open iberiozko opened this issue 9 years ago • 3 comments

That will be nice if the model is availiable as a standalone QML plugin, for example when running QML application from PyQT.

Code of plugin.cpp:

#include <qqmlsortfilterproxymodel.h>
#include <sorter.h>
#include <filter.h>

#include <QtQml/QQmlExtensionPlugin>
#include <QtQml/qqml.h>

using namespace qqsfpm;

class QExampleQmlPlugin : public QQmlExtensionPlugin {
        Q_OBJECT
        Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)

public:
        void registerTypes(const char *uri) {
                Q_ASSERT(uri == QLatin1String("QQSFPM"));

                qmlRegisterType<QQmlSortFilterProxyModel>(uri, 0, 2, "SortFilterProxyModel");

                qmlRegisterUncreatableType<Sorter>(uri, 0, 2, "Sorter", "Sorter is an abstract class");
                qmlRegisterType<RoleSorter>(uri, 0, 2, "RoleSorter");
                qmlRegisterType<ExpressionSorter>(uri, 0, 2, "ExpressionSorter");

                qmlRegisterUncreatableType<Filter>(uri, 0, 2, "Filter", "Filter is an abstract class");
                qmlRegisterType<ValueFilter>(uri, 0, 2, "ValueFilter");
                qmlRegisterType<IndexFilter>(uri, 0, 2, "IndexFilter");
                qmlRegisterType<RegExpFilter>(uri, 0, 2, "RegExpFilter");
                qmlRegisterType<RangeFilter>(uri, 0, 2, "RangeFilter");
                qmlRegisterType<ExpressionFilter>(uri, 0, 2, "ExpressionFilter");
                qmlRegisterType<AnyOfFilter>(uri, 0, 2, "AnyOf");
                qmlRegisterType<AllOfFilter>(uri, 0, 2, "AllOf");
        }
};

#include "plugin.moc"

Code of SortFilterProxyModel.pro to build a standalone plugin library using qmake:

!c++11: warning("SortFilterProxyModel needs c++11, add CONFIG += c++11 to your .pro")

TEMPLATE = lib
CONFIG += plugin
QT += qml
INCLUDEPATH += $$PWD

TARGET  = qmlqsortfilterproxymodelplugin

SOURCES += $$PWD/qqmlsortfilterproxymodel.cpp \
    $$PWD/filter.cpp \
    $$PWD/sorter.cpp \
    $$PWD/plugin.cpp

HEADERS += $$PWD/qqmlsortfilterproxymodel.h \
    $$PWD/filter.h \
    $$PWD/sorter.h

iberiozko avatar Jan 26 '17 12:01 iberiozko

Any feadback on this?

Thaodan avatar May 28 '19 06:05 Thaodan

We have been using this as a plugin for quite a while now: https://github.com/Proemion/SortFilterProxyModel/ . Would be happy to send a pull request (with updated .pro file, cmakelists) if anyone here is interested.

saidinesh5 avatar Jun 20 '19 13:06 saidinesh5

Sorry for not answering earlier.

I'd be happy to examine a PR about this

oKcerG avatar Jun 20 '19 14:06 oKcerG