Salome HOME
Unicode support: correct handling of unicode on GUI level
[modules/gui.git] / src / SALOME_PYQT / SALOME_PYQT_GUILight / SALOME_PYQT_Selector.cxx
index c87a62a02b9f70e2eff482c90c1894dea95396e9..c0959844994add0685a75d69cdb6a619b5c02fd5 100644 (file)
@@ -51,9 +51,13 @@ SALOME_PYQT_Selector::SALOME_PYQT_Selector(SALOME_PYQT_ModuleLight* pymod, SUIT_
     SUIT_Selector(mgr, pymod), myPyModule(pymod)
 {
   MESSAGE("constructor");
+  myLocalEntries.clear();
+  mySelectedList.clear();
+  myEntries.clear();
+  myModifiedTime = 0;
   if (myPyModule)
     {
-      connect(myPyModule, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+      connect(myPyModule, SIGNAL(localSelectionChanged()), this, SLOT(onSelectionChanged()));
     }
   setModified();
 }
@@ -66,6 +70,17 @@ SALOME_PYQT_Selector::~SALOME_PYQT_Selector()
   MESSAGE("destructor");
 }
 
+/*!
+ \brief Reset selection internally. Used on close study.
+ */
+void SALOME_PYQT_Selector::clear()
+{
+  MESSAGE("clear");
+  myLocalEntries.clear();
+  mySelectedList.clear();
+  myEntries.clear();
+}
+
 /*!
  \brief Get Python module interface instance.
  \return a pointer to the Python module interface instance.
@@ -127,15 +142,16 @@ void SALOME_PYQT_Selector::getSelection(SUIT_DataOwnerPtrList& theList) const
   MESSAGE("getSelection");
   if (mySelectedList.count() == 0)
     {
+      MESSAGE("mySelectedList.count(): " << mySelectedList.count() << " myLocalEntries.size(): "<< myLocalEntries.size());
       SALOME_PYQT_Selector* that = (SALOME_PYQT_Selector*) this; // because of const...
       for (int i = 0; i < myLocalEntries.size(); i++)
         {
           SALOME_PYQT_BorrowedDataObjectLight *obj = new SALOME_PYQT_BorrowedDataObjectLight(myLocalEntries[i]);
 #ifndef DISABLE_SALOMEOBJECT
           Handle(SALOME_InteractiveObject)aSObj = new SALOME_InteractiveObject
-          ( obj->entry().toLatin1().constData(),
+          ( obj->entry().toUtf8().constData(),
               obj->componentDataType().toLatin1().constData(),
-              obj->name().toLatin1().constData() );
+              obj->name().toUtf8().constData() );
           LightApp_DataOwner* owner = new LightApp_DataOwner(aSObj);
 #else
           LightApp_DataOwner* owner = new LightApp_DataOwner( obj->entry() );
@@ -156,18 +172,18 @@ void SALOME_PYQT_Selector::setSelection(const SUIT_DataOwnerPtrList& theList)
   if (!myPyModule)
     return;
 
-  if (myEntries.count() == 0 || myModifiedTime < myPyModule->getModifiedTime())
-    fillEntries(myEntries);
-
-  DataObjectList objList;
+  myEntries.clear();
   for (SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it)
     {
       const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>((*it).operator->());
-      if (owner && myEntries.contains(owner->entry()))
-        objList.append(myEntries[owner->entry()]);
+      if (owner)
+        {
+          QString entry = owner->entry();
+          myEntries.append(entry);
+          MESSAGE("Selected: "<< entry.toStdString());
+        }
     }
-
-  myPyModule->setSelected(objList);
+  fillEntries(myEntries);
   mySelectedList.clear();
 }
 
@@ -175,21 +191,12 @@ void SALOME_PYQT_Selector::setSelection(const SUIT_DataOwnerPtrList& theList)
  \brief Fill map of the data objects currently shown in the Object Browser.
  \param entries map to be filled
  */
-void SALOME_PYQT_Selector::fillEntries(QMap<QString, LightApp_DataObject*>& entries)
+void SALOME_PYQT_Selector::fillEntries(QStringList& entries)
 {
   MESSAGE("fillEntries");
-  entries.clear();
-
   if (!myPyModule)
     return;
-
-  for (SUIT_DataObjectIterator it(myPyModule->root(), SUIT_DataObjectIterator::DepthLeft); it.current(); ++it)
-    {
-      LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>(it.current());
-      if (obj)
-        entries.insert(obj->entry(), obj);
-    }
-
+  myPyModule->setSelected(entries);
   setModified();
 }