diff options
author | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2012-09-06 16:43:27 -0300 |
---|---|---|
committer | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2012-09-06 16:43:27 -0300 |
commit | 31f8103187d2e27b1bb76eaed10dc9c9be226c90 (patch) | |
tree | 5b0d6a0a6bf07aaf213c482c61860a2784cd678f /src/QMenuModel | |
parent | 0dfd3d4cd4214a732e4a5cda59fd4dfc082b8425 (diff) | |
download | qmenumodel-31f8103187d2e27b1bb76eaed10dc9c9be226c90.tar.gz qmenumodel-31f8103187d2e27b1bb76eaed10dc9c9be226c90.tar.bz2 qmenumodel-31f8103187d2e27b1bb76eaed10dc9c9be226c90.zip |
Implemented QDBusActionGroup.
Diffstat (limited to 'src/QMenuModel')
-rw-r--r-- | src/QMenuModel/CMakeLists.txt | 10 | ||||
-rw-r--r-- | src/QMenuModel/plugin.cpp | 6 | ||||
-rw-r--r-- | src/QMenuModel/qdbusactiongroup.cpp | 193 | ||||
-rw-r--r-- | src/QMenuModel/qdbusactiongroup.h | 63 | ||||
-rw-r--r-- | src/QMenuModel/qdbusmenumodel.cpp | 105 | ||||
-rw-r--r-- | src/QMenuModel/qdbusmenumodel.h | 58 | ||||
-rw-r--r-- | src/QMenuModel/qdbusobject.cpp | 121 | ||||
-rw-r--r-- | src/QMenuModel/qdbusobject.h | 65 | ||||
-rw-r--r-- | src/QMenuModel/qmenumodel.cpp | 13 | ||||
-rw-r--r-- | src/QMenuModel/qmenumodel.h | 2 |
10 files changed, 499 insertions, 137 deletions
diff --git a/src/QMenuModel/CMakeLists.txt b/src/QMenuModel/CMakeLists.txt index dae9ff4..ee3f28c 100644 --- a/src/QMenuModel/CMakeLists.txt +++ b/src/QMenuModel/CMakeLists.txt @@ -1,12 +1,16 @@ set(QMENUMODEL_SRC qmenumodel.cpp + qdbusobject.cpp qdbusmenumodel.cpp + qdbusactiongroup.cpp plugin.cpp ) set(QMENUMODEL_HEADERS qmenumodel.h + qdbusobject.h qdbusmenumodel.h + qdbusactiongroup.h plugin.h ) @@ -19,8 +23,6 @@ add_library(qmenumodel MODULE ${QMENUMODEL_MOC} ) -#set_target_properties(dbusmenuqmlcommon PROPERTIES COMPILE_FLAGS -fPIC) - include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${QT_INCLUDE_DIR} @@ -41,3 +43,7 @@ target_link_libraries(qmenumodel execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/qmldir" "${CMAKE_CURRENT_BINARY_DIR}/qmldir") + +set(QMENUMODEL_INSTALL_PREFIX "${QT_IMPORTS_DIR}/Ubuntu/QMenuModel/") +install(TARGETS qmenumodel DESTINATION ${QMENUMODEL_INSTALL_PREFIX}) +install(FILES qmldir DESTINATION ${QMENUMODEL_INSTALL_PREFIX}) diff --git a/src/QMenuModel/plugin.cpp b/src/QMenuModel/plugin.cpp index e6a828b..4b5b18e 100644 --- a/src/QMenuModel/plugin.cpp +++ b/src/QMenuModel/plugin.cpp @@ -1,15 +1,17 @@ #include "plugin.h" #include "qmenumodel.h" #include "qdbusmenumodel.h" +#include "qdbusactiongroup.h" #include <QtDeclarative> void QMenuModelQmlPlugin::registerTypes(const char *uri) { - qmlRegisterUncreatableType<QMenuModel>(uri, 1, 0, "QMenuModel", + qmlRegisterUncreatableType<QMenuModel>(uri, 0, 1, "QMenuModel", "QMenuModel is a interface"); - qmlRegisterType<QDBusMenuModel>(uri, 1, 0, "QDBusMenuModel"); + qmlRegisterType<QDBusMenuModel>(uri, 0, 1, "QDBusMenuModel"); + qmlRegisterType<QDBusActionGroup>(uri, 0, 1, "QDBusActionGroup"); } Q_EXPORT_PLUGIN2(qmenumodel, QMenuModelQmlPlugin) diff --git a/src/QMenuModel/qdbusactiongroup.cpp b/src/QMenuModel/qdbusactiongroup.cpp new file mode 100644 index 0000000..ca430fb --- /dev/null +++ b/src/QMenuModel/qdbusactiongroup.cpp @@ -0,0 +1,193 @@ +#include "qdbusactiongroup.h" + +#include <QDebug> + +#include <gio/gio.h> + +QDBusActionGroup::QDBusActionGroup(QObject *parent) + :QObject(parent), + m_actionGroup(NULL) +{ +} + +QDBusActionGroup::~QDBusActionGroup() +{ + clear(); +} + +QAction *QDBusActionGroup::getAction(const QString &actionName) +{ + Q_FOREACH(QAction *act, m_actions) { + if (act->text() == actionName) { + return act; + } + } + + return NULL; +} + +void QDBusActionGroup::serviceVanish(GDBusConnection *) +{ + clear(); +} + +void QDBusActionGroup::serviceAppear(GDBusConnection *connection) +{ + GDBusActionGroup *ag = g_dbus_action_group_get(connection, + busName().toLatin1(), + objectPath().toLatin1()); + setActionGroup(ag); + if (ag == NULL) { + stop(); + } +} + +void QDBusActionGroup::start() +{ + QDbusObject::connect(); +} + +void QDBusActionGroup::stop() +{ + QDbusObject::disconnect(); +} + +void QDBusActionGroup::busTypeChanged(BusType) +{ + busTypeChanged(); +} + +void QDBusActionGroup::busNameChanged(const QString &) +{ + busNameChanged(); +} + +void QDBusActionGroup::objectPathChanged(const QString &objectPath) +{ + objectPathChanged(); +} + +void QDBusActionGroup::statusChanged(ConnectionStatus status) +{ + statusChanged(); +} + +void QDBusActionGroup::setIntBusType(int busType) +{ + if ((busType > None) && (busType < LastBusType)) { + setBusType(static_cast<BusType>(busType)); + } +} + +void QDBusActionGroup::setActionGroup(GDBusActionGroup *ag) +{ + if (m_actionGroup == reinterpret_cast<GActionGroup*>(ag)) { + return; + } + + if (m_actionGroup) { + g_signal_handler_disconnect(m_actionGroup, m_signalActionAddId); + g_signal_handler_disconnect(m_actionGroup, m_signalActionRemovedId); + m_signalActionAddId = m_signalActionRemovedId = 0; + g_object_unref(m_actionGroup); + } + + m_actionGroup = reinterpret_cast<GActionGroup*>(ag); + + if (m_actionGroup) { + + m_signalActionAddId = g_signal_connect(m_actionGroup, + "action-add", + G_CALLBACK(QDBusActionGroup::onActionAdded), + this); + + m_signalActionRemovedId = g_signal_connect(m_actionGroup, + "action-removed", + G_CALLBACK(QDBusActionGroup::onActionRemoved), + this); + + gchar **actionNames = g_action_group_list_actions(m_actionGroup); + for(int i=0; actionNames[i] != NULL; i++) { + addAction(actionNames[i]); + } + g_strfreev(actionNames); + } +} + +void QDBusActionGroup::addAction(const char *actionName) +{ + QAction *act = new QAction(actionName, this); + + act->setEnabled(g_action_group_get_action_enabled(m_actionGroup, actionName)); + + const GVariantType *stateType = g_action_group_get_action_state_type(m_actionGroup, actionName); + if (stateType == G_VARIANT_TYPE_BOOLEAN) { + act->setCheckable(true); + + GVariant *actState = g_action_group_get_action_state(m_actionGroup, actionName); + if (actState != NULL) { + act->setChecked(g_variant_get_boolean(actState)); + g_variant_unref(actState); + } + } + + // remove any older action with the same name + removeAction(actionName); + + m_actions.insert(act); +} + +void QDBusActionGroup::removeAction(const char *actionName) +{ + Q_FOREACH(QAction *act, m_actions) { + if (act->text() == actionName) { + m_actions.remove(act); + delete act; + break; + } + } +} + +void QDBusActionGroup::updateAction(const char *actionName, GVariant *state) +{ + QAction *action = getAction(actionName); + if ((action != NULL) && (state != NULL)) { + + const GVariantType *stateType = g_variant_get_type(state); + if (stateType == G_VARIANT_TYPE_BOOLEAN) { + action->setChecked(g_variant_get_boolean(state)); + } + } +} + +void QDBusActionGroup::clear() +{ + Q_FOREACH(QAction *act, m_actions) { + delete act; + } + m_actions.clear(); + + if (m_actionGroup != NULL) { + g_object_unref(m_actionGroup); + m_actionGroup = NULL; + } +} + +void QDBusActionGroup::onActionAdded(GDBusActionGroup *, gchar *actionName, gpointer data) +{ + QDBusActionGroup *self = reinterpret_cast<QDBusActionGroup*>(data); + self->addAction(actionName); +} + +void QDBusActionGroup::onActionRemoved(GDBusActionGroup *, gchar *actionName, gpointer data) +{ + QDBusActionGroup *self = reinterpret_cast<QDBusActionGroup*>(data); + self->removeAction(actionName); + +} + +void QDBusActionGroup::onActionStateChanged(GDBusActionGroup *ag, gchar *actionName, GVariant *value, gpointer data) +{ + QDBusActionGroup *self = reinterpret_cast<QDBusActionGroup*>(data); + self->updateAction(actionName, value); +} diff --git a/src/QMenuModel/qdbusactiongroup.h b/src/QMenuModel/qdbusactiongroup.h new file mode 100644 index 0000000..a32b03e --- /dev/null +++ b/src/QMenuModel/qdbusactiongroup.h @@ -0,0 +1,63 @@ +#ifndef QDBUSACTIONGROUP_H +#define QDBUSACTIONGROUP_H + +#include "qdbusobject.h" + +#include <QObject> +#include <QAction> +#include <QSet> + +class QDBusActionGroup : public QObject, public QDbusObject +{ + Q_OBJECT + Q_PROPERTY(int busType READ busType WRITE setIntBusType NOTIFY busTypeChanged) + Q_PROPERTY(QString busName READ busName WRITE setBusName NOTIFY busNameChanged) + Q_PROPERTY(QString objectPath READ objectPath WRITE setObjectPath NOTIFY objectPathChanged) + Q_PROPERTY(int status READ status NOTIFY statusChanged) + +public: + QDBusActionGroup(QObject *parent=0); + ~QDBusActionGroup(); + +Q_SIGNALS: + void busTypeChanged(); + void busNameChanged(); + void objectPathChanged(); + void statusChanged(); + +public Q_SLOTS: + void start(); + void stop(); + QAction *getAction(const QString &actionName); + +protected: + virtual void serviceAppear(GDBusConnection *connection); + virtual void serviceVanish(GDBusConnection *connection); + + virtual void busTypeChanged(BusType type); + virtual void busNameChanged(const QString &busNameChanged); + virtual void objectPathChanged(const QString &objectPath); + virtual void statusChanged(ConnectionStatus status); + +private: + GActionGroup *m_actionGroup; + QSet<QAction*> m_actions; + int m_signalActionAddId; + int m_signalActionRemovedId; + + // workaround to support int as bustType + void setIntBusType(int busType); + + void setActionGroup(GDBusActionGroup *ag); + void addAction(const char *actionName); + void removeAction(const char *actionName); + void updateAction(const char *actionName, GVariant *state); + void clear(); + + // glib slots + static void onActionAdded(GDBusActionGroup *ag, gchar *actionName, gpointer data); + static void onActionRemoved(GDBusActionGroup *ag, gchar *actionName, gpointer data); + static void onActionStateChanged(GDBusActionGroup *ag, gchar *actionName, GVariant *value, gpointer data); +}; + +#endif diff --git a/src/QMenuModel/qdbusmenumodel.cpp b/src/QMenuModel/qdbusmenumodel.cpp index 96f936c..c551464 100644 --- a/src/QMenuModel/qdbusmenumodel.cpp +++ b/src/QMenuModel/qdbusmenumodel.cpp @@ -2,95 +2,58 @@ #include <QDebug> QDBusMenuModel::QDBusMenuModel(QObject *parent) - :QMenuModel(parent), - m_watchId(0), - m_busType(None) + :QMenuModel(0, parent) { } QDBusMenuModel::~QDBusMenuModel() { - disconnect(); } -QDBusMenuModel::BusType QDBusMenuModel::busType() const +void QDBusMenuModel::start() { - return m_busType; + QDbusObject::connect(); } -void QDBusMenuModel::setBusType(QDBusMenuModel::BusType type) +void QDBusMenuModel::stop() { - if (m_busType != type) { - if (isConnected()) - disconnect(); - m_busType = type; - Q_EMIT busTypeChanged(m_busType); - } + QDbusObject::disconnect(); } -QString QDBusMenuModel::busName() const +void QDBusMenuModel::serviceVanish(GDBusConnection *) { - return m_busName; + setMenuModel(NULL); } -void QDBusMenuModel::setBusName(const QString &busName) +void QDBusMenuModel::serviceAppear(GDBusConnection *connection) { - if (m_busName != busName) { - if (isConnected()) - disconnect(); - m_busName = busName; - Q_EMIT busNameChanged(m_busName); + GMenuModel *model = reinterpret_cast<GMenuModel*>(g_dbus_menu_model_get(connection, + busName().toLatin1(), + objectPath().toLatin1())); + setMenuModel(model); + if (model == NULL) { + stop(); } } -QString QDBusMenuModel::objectPath() const +void QDBusMenuModel::busTypeChanged(BusType) { - return m_objectPath; + busTypeChanged(); } -void QDBusMenuModel::setObjectPath(const QString &objectPath) +void QDBusMenuModel::busNameChanged(const QString &) { - if (m_objectPath != objectPath) { - if (isConnected()) - disconnect(); - m_objectPath = objectPath; - Q_EMIT objectPathChanged(m_objectPath); - } + busNameChanged(); } -void QDBusMenuModel::connect() +void QDBusMenuModel::objectPathChanged(const QString &objectPath) { - if (isConnected() || (m_watchId > 0)) { - return; - } else if ((m_busType > None) && !m_objectPath.isEmpty() && !m_busName.isEmpty()) { - qDebug() << "Wait for service"; - GBusType type = m_busType == SessionBus ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM; - m_watchId = g_bus_watch_name (type, - m_busName.toLatin1(), - G_BUS_NAME_WATCHER_FLAGS_NONE, - QDBusMenuModel::onServiceAppeared, - QDBusMenuModel::onServiceFanished, - this, - NULL); - } else { - Q_EMIT connectionError("Invalid menu model connection args"); - } -} - -void QDBusMenuModel::disconnect() -{ - if (isConnected()) { - g_bus_unwatch_name (m_watchId); - m_watchId = 0; - - setMenuModel(NULL); - Q_EMIT disconnected(); - } + objectPathChanged(); } -bool QDBusMenuModel::isConnected() const +void QDBusMenuModel::statusChanged(ConnectionStatus status) { - return (m_watchId != 0); + statusChanged(); } void QDBusMenuModel::setIntBusType(int busType) @@ -99,27 +62,3 @@ void QDBusMenuModel::setIntBusType(int busType) setBusType(static_cast<BusType>(busType)); } } - -void QDBusMenuModel::onServiceAppeared(GDBusConnection *connection, const gchar *, const gchar *, gpointer data) -{ - qDebug() << "Service appears"; - QDBusMenuModel *self = reinterpret_cast<QDBusMenuModel*>(data); - GMenuModel *model = reinterpret_cast<GMenuModel*>(g_dbus_menu_model_get(connection, - self->m_busName.toLatin1(), - self->m_objectPath.toLatin1())); - self->setMenuModel(model); - if (model) { - Q_EMIT self->connected(); - } else { - Q_EMIT self->connectionError("Fail to retrieve menu model"); - self->disconnect(); - } -} - -void QDBusMenuModel::onServiceFanished(GDBusConnection *, const gchar *, gpointer data) -{ - qDebug() << "Service fanished"; - QDBusMenuModel *self = reinterpret_cast<QDBusMenuModel*>(data); - Q_EMIT self->connectionError("Menu model disapear"); - self->disconnect(); -} diff --git a/src/QMenuModel/qdbusmenumodel.h b/src/QMenuModel/qdbusmenumodel.h index e9d2461..975e72d 100644 --- a/src/QMenuModel/qdbusmenumodel.h +++ b/src/QMenuModel/qdbusmenumodel.h @@ -1,65 +1,45 @@ #ifndef QDBUSMENUMODEL_H #define QDBUSMENUMODEL_H +#include "qdbusobject.h" #include "qmenumodel.h" #include <gio/gio.h> -class QDBusMenuModel : public QMenuModel +class QDBusMenuModel : public QMenuModel, public QDbusObject { Q_OBJECT Q_PROPERTY(int busType READ busType WRITE setIntBusType NOTIFY busTypeChanged) Q_PROPERTY(QString busName READ busName WRITE setBusName NOTIFY busNameChanged) Q_PROPERTY(QString objectPath READ objectPath WRITE setObjectPath NOTIFY objectPathChanged) + Q_PROPERTY(int status READ status NOTIFY statusChanged) public: - enum BusType { - None = 0, - SessionBus, - SystemBus, - LastBusType - }; - QDBusMenuModel(QObject *parent=0); - ~QDBusMenuModel(); - - BusType busType() const; - void setBusType(BusType type); - - QString busName() const; - void setBusName(const QString &busName); + ~QDBusMenuModel(); - QString objectPath() const; - void setObjectPath(const QString &busName); - - bool isConnected() const; +Q_SIGNALS: + void busTypeChanged(); + void busNameChanged(); + void objectPathChanged(); + void statusChanged(); public Q_SLOTS: - void connect(); - void disconnect(); + void start(); + void stop(); +protected: + virtual void serviceAppear(GDBusConnection *connection); + virtual void serviceVanish(GDBusConnection *connection); -Q_SIGNALS: - void busTypeChanged(BusType type); - void busNameChanged(const QString &busNameChanged); - void objectPathChanged(const QString &objectPath); - - void connected(); - void disconnected(); - void connectionError(const QString &errorMessage); + virtual void busTypeChanged(BusType type); + virtual void busNameChanged(const QString &busNameChanged); + virtual void objectPathChanged(const QString &objectPath); + virtual void statusChanged(ConnectionStatus status); private: - guint m_watchId; - BusType m_busType; - QString m_busName; - QString m_objectPath; - - // workaround to support busType as int + // workaround to support int as bustType void setIntBusType(int busType); - - // glib slots - static void onServiceAppeared(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer data); - static void onServiceFanished(GDBusConnection *connection, const gchar *name, gpointer data); }; #endif diff --git a/src/QMenuModel/qdbusobject.cpp b/src/QMenuModel/qdbusobject.cpp new file mode 100644 index 0000000..9f11813 --- /dev/null +++ b/src/QMenuModel/qdbusobject.cpp @@ -0,0 +1,121 @@ +#include "qdbusobject.h" + +#include <QDebug> + +QDbusObject::QDbusObject() + :m_watchId(0), + m_busType(None), + m_status(QDbusObject::Disconnected) +{ +} + +QDbusObject::~QDbusObject() +{ + if (m_watchId != 0) { + g_bus_unwatch_name (m_watchId); + m_watchId = 0; + } +} + +QDbusObject::BusType QDbusObject::busType() const +{ + return m_busType; +} + +void QDbusObject::setBusType(QDbusObject::BusType type) +{ + if (m_busType != type) { + if (m_status != QDbusObject::Disconnected) + disconnect(); + m_busType = type; + busTypeChanged(m_busType); + } +} + +QString QDbusObject::busName() const +{ + return m_busName; +} + +void QDbusObject::setBusName(const QString &busName) +{ + if (m_busName != busName) { + if (m_status != QDbusObject::Disconnected) + disconnect(); + m_busName = busName; + busNameChanged(m_busName); + } +} + +QString QDbusObject::objectPath() const +{ + return m_objectPath; +} + +void QDbusObject::setObjectPath(const QString &objectPath) +{ + if (m_objectPath != objectPath) { + if (m_status != QDbusObject::Disconnected) + disconnect(); + m_objectPath = objectPath; + objectPathChanged(m_objectPath); + } +} + +void QDbusObject::setStatus(QDbusObject::ConnectionStatus status) +{ + if (m_status != status) { + m_status = status; + statusChanged(m_status); + } +} + +QDbusObject::ConnectionStatus QDbusObject::status() const +{ + return m_status; +} + +void QDbusObject::connect() +{ + if (m_status != QDbusObject::Disconnected) { + return; + } else if ((m_busType > None) && !m_objectPath.isEmpty() && !m_busName.isEmpty()) { + GBusType type = m_busType == SessionBus ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM; + m_watchId = g_bus_watch_name (type, + m_busName.toLatin1(), + G_BUS_NAME_WATCHER_FLAGS_NONE, + QDbusObject::onServiceAppeared, + QDbusObject::onServiceFanished, + this, + NULL); + + setStatus(QDbusObject::Connecting); + } else { + qWarning() << "Invalid dbus connection args"; + } +} + +void QDbusObject::disconnect() +{ + if (m_status != QDbusObject::Disconnected) { + g_bus_unwatch_name (m_watchId); + m_watchId = 0; + setStatus(QDbusObject::Disconnected); + } +} + +void QDbusObject::onServiceAppeared(GDBusConnection *connection, const gchar *, const gchar *, gpointer data) +{ + QDbusObject *self = reinterpret_cast<QDbusObject*>(data); + + self->setStatus(QDbusObject::Connected); + self->serviceAppear(connection); +} + +void QDbusObject::onServiceFanished(GDBusConnection *connection, const gchar *, gpointer data) +{ + QDbusObject *self = reinterpret_cast<QDbusObject*>(data); + + self->setStatus(QDbusObject::Connecting); + self->serviceVanish(connection); +} diff --git a/src/QMenuModel/qdbusobject.h b/src/QMenuModel/qdbusobject.h new file mode 100644 index 0000000..0b17ae1 --- /dev/null +++ b/src/QMenuModel/qdbusobject.h @@ -0,0 +1,65 @@ +#ifndef QDBUSOBJECT_H +#define QDBUSOBJECT_H + +#include <QObject> + +#include <gio/gio.h> + +class QDbusObject +{ +public: + enum BusType { + None = 0, + SessionBus, + SystemBus, + LastBusType + }; + + enum ConnectionStatus { + Disconnected = 0, + Connecting, + Connected + }; + + QDbusObject(); + ~QDbusObject(); + + BusType busType() const; + void setBusType(BusType type); + + QString busName() const; + void setBusName(const QString &busName); + + QString objectPath() const; + void setObjectPath(const QString &busName); + + ConnectionStatus status() const; + + void connect(); + void disconnect(); + +protected: + virtual void serviceAppear(GDBusConnection *connection) = 0; + virtual void serviceVanish(GDBusConnection *connection) = 0; + + // notify functions + virtual void busTypeChanged(BusType type) = 0; + virtual void busNameChanged(const QString &busNameChanged) = 0; + virtual void objectPathChanged(const QString &objectPath) = 0; + virtual void statusChanged(ConnectionStatus status) = 0; + +private: + guint m_watchId; + BusType m_busType; + QString m_busName; + QString m_objectPath; + ConnectionStatus m_status; + + void setStatus(ConnectionStatus status); + + // glib slots + static void onServiceAppeared(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer data); + static void onServiceFanished(GDBusConnection *connection, const gchar *name, gpointer data); +}; + +#endif diff --git a/src/QMenuModel/qmenumodel.cpp b/src/QMenuModel/qmenumodel.cpp index 173dbbe..c7ccf56 100644 --- a/src/QMenuModel/qmenumodel.cpp +++ b/src/QMenuModel/qmenumodel.cpp @@ -1,7 +1,7 @@ #include "qmenumodel.h" #include <QDebug> -QMenuModel::QMenuModel(QObject *parent, GMenuModel *other) +QMenuModel::QMenuModel(GMenuModel *other, QObject *parent) : QAbstractListModel(parent), m_menuModel(0), m_signalChangedId(0) @@ -66,7 +66,6 @@ QVariant QMenuModel::data(const QModelIndex &index, int role) const int rowCountValue = rowCount(); if ((rowCountValue > 0) && (index.row() >= 0) && (index.row() < rowCountValue)) { - qDebug() << "GetData: " << index.row() << role; if (m_menuModel) { switch (role) { @@ -87,7 +86,6 @@ QVariant QMenuModel::data(const QModelIndex &index, int role) const } } } - qDebug() << "GetData done" << attribute; return attribute; } @@ -129,10 +127,8 @@ QVariant QMenuModel::getLink(const QModelIndex &index, index.row(), linkName.toLatin1()); - if (link) { - qDebug() << "link: " << (void*)link; - QMenuModel *other = new QMenuModel(const_cast<QMenuModel*>(this), link); - qDebug() << "link created: " << (void*)link; + if (link) { + QMenuModel *other = new QMenuModel(link, const_cast<QMenuModel*>(this)); return QVariant::fromValue<QObject*>(other); } @@ -147,8 +143,6 @@ void QMenuModel::onItemsChanged(GMenuModel *, { QMenuModel *self = reinterpret_cast<QMenuModel*>(data); - qDebug() << "model changed" << position << removed << added; - if (removed > 0) { self->beginRemoveRows(QModelIndex(), position, position + removed - 1); self->endRemoveRows(); @@ -158,6 +152,5 @@ void QMenuModel::onItemsChanged(GMenuModel *, self->beginInsertRows(QModelIndex(), position, position + added - 1); self->endInsertRows(); } - qDebug() << "model size: " << self->rowCount(); } diff --git a/src/QMenuModel/qmenumodel.h b/src/QMenuModel/qmenumodel.h index 91b0eb9..18ad21c 100644 --- a/src/QMenuModel/qmenumodel.h +++ b/src/QMenuModel/qmenumodel.h @@ -26,7 +26,7 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const; protected: - QMenuModel(QObject *parent=0, GMenuModel *other=0); + QMenuModel(GMenuModel *other=0, QObject *parent=0); void setMenuModel(GMenuModel *model); GMenuModel *menuModel() const; |