aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src
diff options
context:
space:
mode:
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r--libqmenumodel/src/qmenumodel.cpp39
-rw-r--r--libqmenumodel/src/qmenumodel.h7
2 files changed, 46 insertions, 0 deletions
diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp
index ec5570f..53dc966 100644
--- a/libqmenumodel/src/qmenumodel.cpp
+++ b/libqmenumodel/src/qmenumodel.cpp
@@ -42,6 +42,10 @@ QMenuModel::QMenuModel(GMenuModel *other, QObject *parent)
m_signalChangedId(0)
{
setMenuModel(other);
+
+ connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), SIGNAL(countChanged()));
+ connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), SIGNAL(countChanged()));
+ connect(this, SIGNAL(modelReset()), SIGNAL(countChanged()));
}
/*! \internal */
@@ -50,6 +54,41 @@ 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;
+
+ QModelIndex index = this->index(row);
+ if (index.isValid()) {
+ QMap<int, QVariant> data = itemData(index);
+ const QHash<int, QByteArray> roleNames = this->roleNames();
+ Q_FOREACH(int i, roleNames.keys()) {
+ result.insert(roleNames[i], data[i]);
+ }
+ }
+ 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 1ab1e7a..9371bd8 100644
--- a/libqmenumodel/src/qmenumodel.h
+++ b/libqmenumodel/src/qmenumodel.h
@@ -31,6 +31,7 @@ typedef struct _GObject GObject;
class QMenuModel : public QAbstractListModel
{
Q_OBJECT
+ Q_PROPERTY(int count READ count NOTIFY countChanged)
public:
enum MenuRoles {
@@ -43,12 +44,17 @@ public:
~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;
+Q_SIGNALS:
+ void countChanged();
+
protected:
QMenuModel(GMenuModel *other=0, QObject *parent=0);
void setMenuModel(GMenuModel *model);
@@ -63,6 +69,7 @@ private:
QVariant getExtraProperties(const QModelIndex &index) const;
QString parseExtraPropertyName(const QString &name) const;
void clearModel();
+ int count() const;
static void onItemsChanged(GMenuModel *model, gint position, gint removed, gint added, gpointer data);
};