Salome HOME
Improved implementaion of internal data structure of Accelerator manager. Now it...
authorasv <asv@opencascade.com>
Wed, 24 Aug 2005 07:52:12 +0000 (07:52 +0000)
committerasv <asv@opencascade.com>
Wed, 24 Aug 2005 07:52:12 +0000 (07:52 +0000)
src/SUIT/SUIT_Accel.cxx
src/SUIT/SUIT_Accel.h

index 0b8534404dbeeb8f30104dcd200d186467062935..5e94b549726ce952b5308dd0831203e7e7646401 100644 (file)
@@ -31,30 +31,29 @@ SUIT_Accel::~SUIT_Accel()
 /*! setActionKey  assign a ceratain action for a key accelerator */
 void SUIT_Accel::setActionKey( const int action, const int key, const QString& type )
 {    
-  if ( myKeyActionMap.contains( key ) )
-    myAccel->removeItem( action );
-
-  myKeyActionMap[key] = action;
-  QStringList vTypes;
-  if ( myActionViewerTypesMap.contains( action ) )
-    vTypes = myActionViewerTypesMap[action];
-  if ( !vTypes.contains( type ) )
-    vTypes.append( type );
-  myActionViewerTypesMap[action] = vTypes;
-
-  myAccel->insertItem( key, action );
+  // 1. get or generate interal "id" of action
+  int id = myAccel->findKey( key );
+  if ( id == -1 )
+    id = myAccel->insertItem( key );
+
+  IdActionMap idActionMap;
+  if ( myMap.contains( type ) )
+    idActionMap = myMap[type];
+
+  idActionMap[id] = action;
+  myMap[type] = idActionMap;
 }
 
 /*! onActivated  slot called when a registered key accelerator was activated */
-void SUIT_Accel::onActivated( int action )
+void SUIT_Accel::onActivated( int id )
 {
   if ( myDesktop ) {
     if ( SUIT_ViewWindow* vw = myDesktop->activeWindow() ) {
       QString type = vw->getViewManager()->getViewModel()->getType();
-      if (  myActionViewerTypesMap.contains( action ) ) {
-       QStringList vTypes = myActionViewerTypesMap[action];
-       if ( vTypes.contains( type ) ) {
-         vw->onAccelAction( action );
+      if (  myMap.contains( type ) ) {
+       IdActionMap idActionMap = myMap[type];
+       if ( idActionMap.contains( id ) ) {
+         vw->onAccelAction( idActionMap[id] );
        }
       }
     }
index 0c72053da913f40f105a395c88f1b38da0e96bb1..1821ce22469efae462e94833f7ed630521c0bce8 100644 (file)
@@ -8,7 +8,7 @@
 #include "SUIT.h"
 
 #include <qobject.h>
-#include <qstringlist.h>
+#include <qstring.h>
 #include <qmap.h>
 
 class QAccel;
@@ -18,11 +18,26 @@ class SUIT_EXPORT SUIT_Accel: public QObject
 {
   Q_OBJECT
 
+public:
+  enum Actions { 
+    PanLeft = 1, 
+    PanRight, 
+    PanUp, 
+    PanDown, 
+    ZoomIn, 
+    ZoomOut, 
+    ZoomFit, 
+    RotateLeft, 
+    RotateRight, 
+    RotateUp, 
+    RotateDown, 
+    LastAction 
+  };
+
 public:
   SUIT_Accel( SUIT_Desktop* theDesktop );
   virtual ~SUIT_Accel();
 
-  enum Actions { PanLeft = 1, PanRight, PanUp, PanDown, ZoomIn, ZoomOut, ZoomFit, RotateLeft, RotateRight, RotateUp, RotateDown, UserAction };
   void setActionKey( const int action, const int key, const QString& type );
 
 protected slots:
@@ -32,10 +47,9 @@ private:
   QAccel* myAccel; 
   SUIT_Desktop* myDesktop;
 
-  typedef QMap<int, int> KeyActionMap; // key-to-action map
-  typedef QMap<int, QStringList> ActionViewerTypesMap; // key=action id
-  KeyActionMap myKeyActionMap;
-  ActionViewerTypesMap myActionViewerTypesMap;
+  typedef QMap<int, int> IdActionMap; // internal_id - to - action map
+  typedef QMap<QString, IdActionMap> ViewerTypeIdActionMap; // viewer_type - to - IdActionMap
+  ViewerTypeIdActionMap myMap;
 };
 
 #endif