From db8802647a6daaeb2e0971aee65c3b354693cec9 Mon Sep 17 00:00:00 2001
From: Emmanuel Lepage Vallee <elv1313@gmail.com>
Date: Tue, 18 Apr 2017 01:58:22 -0400
Subject: [PATCH] useractionmodel: Make execute invokable.

Also change a proxy model property to a model interface. The
bindings have trouble exporting the proxies. This is probably a
Qt bug. This has no side effect I am aware of. They both share
the same interface.

Also remove commented out code which inits the role names.

[SS: add change missing from commit msg]

Change-Id: Ib3d2e3ed3b96d9d83a711a9005235d886840dfe5
Signed-off-by: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
Reviewed-by: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
---
 src/useractionmodel.cpp | 8 ++++----
 src/useractionmodel.h   | 6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/useractionmodel.cpp b/src/useractionmodel.cpp
index 54ebec89..73a23354 100644
--- a/src/useractionmodel.cpp
+++ b/src/useractionmodel.cpp
@@ -612,11 +612,11 @@ UserActionModel::~UserActionModel()
 QHash<int,QByteArray> UserActionModel::roleNames() const
 {
    static QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
-   /*static bool initRoles = false;
+   static bool initRoles = false;
    if (!initRoles) {
       initRoles = true;
-
-   }*/
+      roles[(int)Role::ACTION] = "action";
+   }
    return roles;
 }
 
@@ -1177,7 +1177,7 @@ bool UserActionModel::execute(const QModelIndex& idx) const
 }
 
 ///Get a model filter with only the available actions
-QSortFilterProxyModel* UserActionModel::activeActionModel() const
+QAbstractItemModel* UserActionModel::activeActionModel() const
 {
    if (!d_ptr->m_pActiveModel)
       d_ptr->m_pActiveModel = new ActiveUserActionModel(const_cast<UserActionModel*>(this));
diff --git a/src/useractionmodel.h b/src/useractionmodel.h
index 12014e25..df57b2c8 100644
--- a/src/useractionmodel.h
+++ b/src/useractionmodel.h
@@ -127,7 +127,7 @@ public:
    };
    Q_FLAGS(Context)
 
-   Q_PROPERTY(QSortFilterProxyModel* activeActionModel READ activeActionModel)
+   Q_PROPERTY(QAbstractItemModel* activeActionModel READ activeActionModel CONSTANT)
 
    //Constructor
    explicit UserActionModel(Call* parent     , const FlagPack<Context> c = FlagPack<Context>(Context::MINIMAL)| Context::RECOMMENDED);
@@ -144,13 +144,13 @@ public:
    //Getters
    Q_INVOKABLE bool isActionEnabled ( UserActionModel::Action action ) const;
    Q_INVOKABLE uint relativeIndex   ( UserActionModel::Action action ) const;
-   QSortFilterProxyModel* activeActionModel() const;
+   QAbstractItemModel* activeActionModel() const;
 
    //Setters
    void setSelectionModel(QItemSelectionModel* sm);
 
    //Mutators
-   bool execute( const Action action    ) const;
+   Q_INVOKABLE bool execute( const Action action    ) const;
    bool execute( const QModelIndex& idx ) const;
 
    //Operators
-- 
GitLab