diff options
Diffstat (limited to 'libqmenumodel/src/qmenumodel.cpp')
-rw-r--r-- | libqmenumodel/src/qmenumodel.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp index cac2f1a..0fedd62 100644 --- a/libqmenumodel/src/qmenumodel.cpp +++ b/libqmenumodel/src/qmenumodel.cpp @@ -46,31 +46,25 @@ QMenuModel::QMenuModel(GMenuModel *other, QObject *parent) rolesNames[Extra] = "extra"; } setRoleNames(rolesNames); - setMenuModel(other, true); + setMenuModel(other); } /*! \internal */ QMenuModel::~QMenuModel() { - setMenuModel(NULL, false); + clearModel(); } /*! \internal */ -void QMenuModel::setMenuModel(GMenuModel *other, bool notify) +void QMenuModel::setMenuModel(GMenuModel *other) { if (m_menuModel == other) { return; } - if (notify) { - beginResetModel(); - } + beginResetModel(); - if (m_menuModel) { - g_signal_handler_disconnect(m_menuModel, m_signalChangedId); - m_signalChangedId = 0; - g_object_unref(m_menuModel); - } + clearModel(); m_menuModel = other; @@ -83,9 +77,7 @@ void QMenuModel::setMenuModel(GMenuModel *other, bool notify) this); } - if (notify) { - endResetModel(); - } + endResetModel(); } /*! \internal */ @@ -95,6 +87,17 @@ GMenuModel *QMenuModel::menuModel() const } /*! \internal */ +void QMenuModel::clearModel() +{ + if (m_menuModel) { + g_signal_handler_disconnect(m_menuModel, m_signalChangedId); + m_signalChangedId = 0; + g_object_unref(m_menuModel); + m_menuModel = NULL; + } +} + +/*! \internal */ QVariant QMenuModel::data(const QModelIndex &index, int role) const { QVariant attribute; |