diff options
author | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2012-11-28 20:19:14 -0300 |
---|---|---|
committer | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2012-11-28 20:19:14 -0300 |
commit | 236259bc2ae2efc5ad2bac4a0eca76ebdb8293e8 (patch) | |
tree | 2ff4bf5a686f748e507fbff323a0b277a230d8bb /libqmenumodel | |
parent | 98ed17ed5c2ebab3a396906d4219af2e99988370 (diff) | |
download | qmenumodel-236259bc2ae2efc5ad2bac4a0eca76ebdb8293e8.tar.gz qmenumodel-236259bc2ae2efc5ad2bac4a0eca76ebdb8293e8.tar.bz2 qmenumodel-236259bc2ae2efc5ad2bac4a0eca76ebdb8293e8.zip |
Optimized get function code.
Diffstat (limited to 'libqmenumodel')
-rw-r--r-- | libqmenumodel/src/qmenumodel.cpp | 17 | ||||
-rw-r--r-- | libqmenumodel/src/qmenumodel.h | 2 |
2 files changed, 9 insertions, 10 deletions
diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp index 5bf740d..7f4c383 100644 --- a/libqmenumodel/src/qmenumodel.cpp +++ b/libqmenumodel/src/qmenumodel.cpp @@ -65,16 +65,15 @@ QMenuModel::~QMenuModel() 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)); - } + 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; } diff --git a/libqmenumodel/src/qmenumodel.h b/libqmenumodel/src/qmenumodel.h index f923658..9371bd8 100644 --- a/libqmenumodel/src/qmenumodel.h +++ b/libqmenumodel/src/qmenumodel.h @@ -45,7 +45,6 @@ public: ~QMenuModel(); Q_INVOKABLE QVariantMap get(int row) const; - int count() const; /* QAbstractItemModel */ QHash<int, QByteArray> roleNames() const; @@ -70,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); }; |