Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to build as standalone plugin #25

Open
iberiozko opened this issue Jan 26, 2017 · 3 comments
Open

Add feature to build as standalone plugin #25

iberiozko opened this issue Jan 26, 2017 · 3 comments

Comments

@iberiozko
Copy link

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
Copy link

Thaodan commented May 28, 2019

Any feadback on this?

@saidinesh5
Copy link

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
Copy link
Owner

oKcerG commented Jun 20, 2019

Sorry for not answering earlier.

I'd be happy to examine a PR about this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants