aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-10-10 09:47:23 -0300
committerRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-10-10 09:47:23 -0300
commit1e659aed9b6882dbe05d812363715c8e0583fc9a (patch)
treea81a067507184e479634f93c78d1256216070a6a /libqmenumodel
parentc07f87e35062e39e9d4b3b978362dbf94dd36fbb (diff)
downloadqmenumodel-1e659aed9b6882dbe05d812363715c8e0583fc9a.tar.gz
qmenumodel-1e659aed9b6882dbe05d812363715c8e0583fc9a.tar.bz2
qmenumodel-1e659aed9b6882dbe05d812363715c8e0583fc9a.zip
Created a new private function "clearModel" instead of change signature of "setModel" function.
Diffstat (limited to 'libqmenumodel')
-rw-r--r--libqmenumodel/src/qdbusmenumodel.cpp4
-rw-r--r--libqmenumodel/src/qmenumodel.cpp31
-rw-r--r--libqmenumodel/src/qmenumodel.h3
3 files changed, 21 insertions, 17 deletions
diff --git a/libqmenumodel/src/qdbusmenumodel.cpp b/libqmenumodel/src/qdbusmenumodel.cpp
index 6d4746c..ae88c35 100644
--- a/libqmenumodel/src/qdbusmenumodel.cpp
+++ b/libqmenumodel/src/qdbusmenumodel.cpp
@@ -85,7 +85,7 @@ void QDBusMenuModel::stop()
/*! \internal */
void QDBusMenuModel::serviceVanish(GDBusConnection *)
{
- setMenuModel(NULL, true);
+ setMenuModel(NULL);
}
/*! \internal */
@@ -94,7 +94,7 @@ void QDBusMenuModel::serviceAppear(GDBusConnection *connection)
GMenuModel *model = reinterpret_cast<GMenuModel*>(g_dbus_menu_model_get(connection,
busName().toLatin1(),
objectPath().toLatin1()));
- setMenuModel(model, true);
+ setMenuModel(model);
if (model == NULL) {
stop();
}
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;
diff --git a/libqmenumodel/src/qmenumodel.h b/libqmenumodel/src/qmenumodel.h
index e482e9b..5f17dd6 100644
--- a/libqmenumodel/src/qmenumodel.h
+++ b/libqmenumodel/src/qmenumodel.h
@@ -48,7 +48,7 @@ public:
protected:
QMenuModel(GMenuModel *other=0, QObject *parent=0);
- void setMenuModel(GMenuModel *model, bool notify);
+ void setMenuModel(GMenuModel *model);
GMenuModel *menuModel() const;
private:
@@ -59,6 +59,7 @@ private:
QVariant getLink(const QModelIndex &index, const QString &linkName) const;
QVariant getExtraProperties(const QModelIndex &index) const;
QString parseExtraPropertyName(const QString &name) const;
+ void clearModel();
static void onItemsChanged(GMenuModel *model, gint position, gint removed, gint added, gpointer data);
};