aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-11-13 17:16:59 -0300
committerRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-11-13 17:16:59 -0300
commit53dfc2a919fd03f5570cb106d71d3989a3f528d9 (patch)
tree43f75f57c482c2c75f86f10c5877683a24859412 /libqmenumodel
parent1915b094437bc94aa4ea44e4ccf489456f375e06 (diff)
downloadqmenumodel-53dfc2a919fd03f5570cb106d71d3989a3f528d9.tar.gz
qmenumodel-53dfc2a919fd03f5570cb106d71d3989a3f528d9.tar.bz2
qmenumodel-53dfc2a919fd03f5570cb106d71d3989a3f528d9.zip
Created auxiliary functions. To allows access the model data from JavaScript;
Diffstat (limited to 'libqmenumodel')
-rw-r--r--libqmenumodel/src/qmenumodel.cpp40
-rw-r--r--libqmenumodel/src/qmenumodel.h7
2 files changed, 47 insertions, 0 deletions
diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp
index f0c2274..a704d85 100644
--- a/libqmenumodel/src/qmenumodel.cpp
+++ b/libqmenumodel/src/qmenumodel.cpp
@@ -51,6 +51,10 @@ QMenuModel::QMenuModel(GMenuModel *other, QObject *parent)
}
setRoleNames(rolesNames);
setMenuModel(other);
+
+ QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
+ QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
+ QObject::connect(this, SIGNAL(modelReset()), this, SIGNAL(countChanged()));
}
/*! \internal */
@@ -59,6 +63,42 @@ QMenuModel::~QMenuModel()
clearModel();
}
+/*!
+ \qmlmethod QDBusMenuModel::get(int)
+
+ Returns the item at index in the model. This allows the item data to be accessed from JavaScript:
+
+ \b Note: methods should only be called after the Component has completed.
+*/
+
+QVariantMap QMenuModel::get(int row) const
+{
+ QVariantMap result;
+ int rowCountValue = rowCount();
+ if ((rowCountValue > 0) && (row >= 0) && (row < rowCountValue)) {
+ QModelIndex i = index(row);
+ result.insert("action", data(i, Action));
+ result.insert("label", data(i, Label));
+ result.insert("linkSection", data(i, LinkSection));
+ result.insert("linkSubMenu", data(i, LinkSubMenu));
+ result.insert("extra", data(i, Extra));
+ }
+
+ return result;
+}
+
+/*!
+ \qmlmethod QDBusMenuModel::count()
+
+ The number of data entries in the model.
+
+ \b Note: methods should only be called after the Component has completed.
+*/
+int QMenuModel::count() const
+{
+ return rowCount();
+}
+
/*! \internal */
void QMenuModel::setMenuModel(GMenuModel *other)
{
diff --git a/libqmenumodel/src/qmenumodel.h b/libqmenumodel/src/qmenumodel.h
index 22c30df..ac40db5 100644
--- a/libqmenumodel/src/qmenumodel.h
+++ b/libqmenumodel/src/qmenumodel.h
@@ -30,6 +30,7 @@ typedef struct _GMenuModel GMenuModel;
class QMenuModel : public QAbstractListModel
{
Q_OBJECT
+ Q_PROPERTY(int count READ count NOTIFY countChanged)
public:
enum MenuRoles {
@@ -42,11 +43,17 @@ public:
~QMenuModel();
+ Q_INVOKABLE QVariantMap get(int row) const;
+ int count() const;
+
/* QAbstractItemModel */
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QModelIndex parent (const QModelIndex &index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
+Q_SIGNALS:
+ void countChanged();
+
protected:
QMenuModel(GMenuModel *other=0, QObject *parent=0);
void setMenuModel(GMenuModel *model);