oKcerG / SortFilterProxyModel

A nicely exposed QSortFilterProxyModel for QML
MIT License
303 stars 102 forks source link

Add feature to build as standalone plugin #25

Open iberiozko opened 7 years ago

iberiozko commented 7 years ago

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
Thaodan commented 5 years ago

Any feadback on this?

saidinesh5 commented 5 years ago

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.

oKcerG commented 5 years ago

Sorry for not answering earlier.

I'd be happy to examine a PR about this