diff options
author | Nick Dedekind <nicholas.dedekind@gmail.com> | 2013-08-08 16:12:57 +0100 |
---|---|---|
committer | Nick Dedekind <nicholas.dedekind@gmail.com> | 2013-08-08 16:12:57 +0100 |
commit | c6cb726c5694f8a35711a48a7bf5e2a6723aeba8 (patch) | |
tree | 509f5b5c2cf1223274034721a611c55c5039b0ab /libqmenumodel/src/qmenumodel.cpp | |
parent | 52b17007596bcd29ec0fe01468d28fddfcc18785 (diff) | |
download | qmenumodel-c6cb726c5694f8a35711a48a7bf5e2a6723aeba8.tar.gz qmenumodel-c6cb726c5694f8a35711a48a7bf5e2a6723aeba8.tar.bz2 qmenumodel-c6cb726c5694f8a35711a48a7bf5e2a6723aeba8.zip |
Glib callbacks send events through qt.
Diffstat (limited to 'libqmenumodel/src/qmenumodel.cpp')
-rw-r--r-- | libqmenumodel/src/qmenumodel.cpp | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp index 9bc9e02..2b1397a 100644 --- a/libqmenumodel/src/qmenumodel.cpp +++ b/libqmenumodel/src/qmenumodel.cpp @@ -28,6 +28,8 @@ extern "C" { #include <QCoreApplication> #include <QThread> +const QEvent::Type MenuModelEvent::eventType = static_cast<QEvent::Type>(QEvent::registerEventType()); + /*! \qmltype QMenuModel \brief The QMenuModel class implements the base list model for menus @@ -225,28 +227,37 @@ QVariant QMenuModel::getExtraProperties(MenuNode *node, int row) const return extra; } -/*! \internal */ -void QMenuModel::onItemsChanged(MenuNode *node, - int position, - int removed, - int added) +bool QMenuModel::event(QEvent* e) { - QModelIndex index = indexFromNode(node); - if (removed > 0) { - beginRemoveRows(index, position, position + removed - 1); + if (e->type() == MenuNodeItemChangeEvent::eventType) { + MenuNodeItemChangeEvent *mnice = static_cast<MenuNodeItemChangeEvent*>(e); - node->commitOperation(); + QModelIndex index = indexFromNode(mnice->node); + if (mnice->removed > 0) { + beginRemoveRows(index, mnice->position, mnice->position + mnice->removed - 1); - endRemoveRows(); - } + mnice->node->commitOperation(); + + endRemoveRows(); + } + + if (mnice->added > 0) { + beginInsertRows(index, mnice->position, mnice->position + mnice->added - 1); + + mnice->node->commitOperation(); + + endInsertRows(); + } + return true; - if (added > 0) { - beginInsertRows(index, position, position + added - 1); + } else if (e->type() == MenuModelEvent::eventType) { - node->commitOperation(); + MenuModelEvent *mme = static_cast<MenuModelEvent*>(e); - endInsertRows(); + setMenuModel(mme->model); + return true; } + return QAbstractItemModel::event(e); } /*! \internal */ @@ -292,3 +303,19 @@ bool QMenuModel::hasLink(MenuNode *node, int row, const QString &linkType) const MenuNode *child = node->child(row); return (child && (child->linkType() == linkType)); } + +MenuModelEvent::MenuModelEvent(GMenuModel* _model) + : QEvent(MenuModelEvent::eventType), + model(_model) +{ + if (model) { + g_object_ref(model); + } +} + +MenuModelEvent::~MenuModelEvent() +{ + if (model) { + g_object_unref(model); + } +} |