diff options
author | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2013-01-14 15:57:10 +0000 |
---|---|---|
committer | Tarmac <> | 2013-01-14 15:57:10 +0000 |
commit | c53b046b63eae52ab73bb2a63f3fddb36ecc3178 (patch) | |
tree | 5678eb9b299cd80606552ae339315c8416309119 /libqmenumodel/src/qmenumodel.h | |
parent | 84b4e669800748dbb1b270fbf2e73c299871ac73 (diff) | |
parent | 00bd7d43ec3b7af1e5d4534fa74e1cf6e004bd56 (diff) | |
download | qmenumodel-c53b046b63eae52ab73bb2a63f3fddb36ecc3178.tar.gz qmenumodel-c53b046b63eae52ab73bb2a63f3fddb36ecc3178.tar.bz2 qmenumodel-c53b046b63eae52ab73bb2a63f3fddb36ecc3178.zip |
Implemented QMenuModel as tree model.
Sections and SubMenus are exported as tree. Fixes: https://bugs.launchpad.net/bugs/1090305.
Approved by Gustavo Pichorim Boiko, PS Jenkins bot.
Diffstat (limited to 'libqmenumodel/src/qmenumodel.h')
-rw-r--r-- | libqmenumodel/src/qmenumodel.h | 64 |
1 files changed, 26 insertions, 38 deletions
diff --git a/libqmenumodel/src/qmenumodel.h b/libqmenumodel/src/qmenumodel.h index d83a35c..8887c81 100644 --- a/libqmenumodel/src/qmenumodel.h +++ b/libqmenumodel/src/qmenumodel.h @@ -17,73 +17,61 @@ * Renato Araujo Oliveira Filho <renato@canonical.com> */ -#ifndef QMENUMODEL_H -#define QMENUMODEL_H +#ifndef QMENUTREEMODEL_H +#define QMENUTREEMODEL_H -#include <QAbstractListModel> +#include <QAbstractItemModel> -typedef int gint; -typedef unsigned int guint; -typedef void* gpointer; +class MenuNode; typedef struct _GMenuModel GMenuModel; -typedef struct _GObject GObject; -class QMenuModel : public QAbstractListModel +class QMenuModel : public QAbstractItemModel { Q_OBJECT - Q_PROPERTY(int count READ count NOTIFY countChanged) public: enum MenuRoles { - Action = 0, + Action = Qt::DisplayRole + 1, Label, - LinkSection, - LinkSubMenu, - Extra + Extra, + Depth, + hasSection, + hasSubMenu }; ~QMenuModel(); - Q_INVOKABLE QVariantMap get(int row) const; - /* QAbstractItemModel */ - QHash<int, QByteArray> roleNames() const; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - QModelIndex parent (const QModelIndex &index) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + QHash<int, QByteArray> roleNames() const; Q_SIGNALS: void countChanged(); - void aboutToRemoveLink(QMenuModel *link, int row); + +public Q_SLOTS: + void onItemsChanged(MenuNode *node, int position, int removed, int added); protected: QMenuModel(GMenuModel *other=0, QObject *parent=0); void setMenuModel(GMenuModel *model); GMenuModel *menuModel() const; - // helper getter intended for use in tests only - QHash<int, QMenuModel*> cache() const; - private: - QHash<int, QMenuModel*>* m_cache; - GMenuModel *m_menuModel; - guint m_signalChangedId; - guint m_rowCount; + MenuNode *m_root; - //control variables - int m_currentOperationPosition; - int m_currentOperationAdded; - int m_currentOperationRemoved; + MenuNode* nodeFromIndex(const QModelIndex &index) const; + QModelIndex indexFromNode(MenuNode *node) const; - QVariant getStringAttribute(int row, const QString &attribute) const; - QVariant getLink(int row, const QString &linkName) const; - QVariant getExtraProperties(int row) const; - QString parseExtraPropertyName(const QString &name) const; - void clearModel(bool destructor=false); - int count() const; - int rowIndex(const QModelIndex &index) const; + QVariant getStringAttribute(MenuNode *node, int row, const QString &attribute) const; + QVariant getExtraProperties(MenuNode *node, int row) const; + bool hasLink(MenuNode *node, int row, const QString &linkType) const; - static void onItemsChanged(GMenuModel *model, gint position, gint removed, gint added, gpointer data); + QString parseExtraPropertyName(const QString &name) const; + void clearModel(); }; #endif |