aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-11-28 20:19:14 -0300
committerRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-11-28 20:19:14 -0300
commit236259bc2ae2efc5ad2bac4a0eca76ebdb8293e8 (patch)
tree2ff4bf5a686f748e507fbff323a0b277a230d8bb
parent98ed17ed5c2ebab3a396906d4219af2e99988370 (diff)
downloadqmenumodel-236259bc2ae2efc5ad2bac4a0eca76ebdb8293e8.tar.gz
qmenumodel-236259bc2ae2efc5ad2bac4a0eca76ebdb8293e8.tar.bz2
qmenumodel-236259bc2ae2efc5ad2bac4a0eca76ebdb8293e8.zip
Optimized get function code.
-rw-r--r--libqmenumodel/src/qmenumodel.cpp17
-rw-r--r--libqmenumodel/src/qmenumodel.h2
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);
};