src/hbcore/gui/hbactionmanager.cpp
changeset 2 06ff229162e9
parent 0 16d8024aca5e
--- a/src/hbcore/gui/hbactionmanager.cpp	Mon May 03 12:48:33 2010 +0300
+++ b/src/hbcore/gui/hbactionmanager.cpp	Fri May 14 16:09:54 2010 +0300
@@ -79,26 +79,32 @@
     Calculates and returns the position of the action 
     based on the container template.
 */
-int HbActionManager::position(QAction *aAction, QList<QAction *> actions) const
+int HbActionManager::position(QAction *aAction, QList<QAction *> actions, int maxPos) const
 {
-   if (actions.count() == 0) {
+    if (actions.count() == 0) {
         return 0;
     }
 
+    if (maxPos < 0) {
+        maxPos = actions.count();
+    }
     // try to downcast aAction. If that fails, return a fallback value
     HbAction* action = qobject_cast<HbAction *>(aAction);
     if (!action){
-        return actions.count();
+        return maxPos;
     }
 
     int index = templateIndex(action);
     if (index == -1) {
-        return actions.count();
+        return maxPos;
     }
 
     int pos(0);
     foreach (QAction *qaction, actions) {
         HbAction *containerAction = qobject_cast<HbAction *>(qaction);
+        if (!containerAction) {
+            break;
+        }
         int containerIndex = templateIndex(containerAction);
         if (index < containerIndex) {
             break;
@@ -107,6 +113,9 @@
             pos++;
         }
     }
+    if (pos > maxPos) {
+        pos = maxPos;
+    }
     return pos;
 }