From aaa8dc80407f2b29ae7aee8079be8e84a86ba139 Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Sun, 26 Feb 2017 11:36:59 +0100 Subject: [PATCH] PyQt Selection in and out OK --- .../SALOME_PYQT_ModuleLight.cxx | 6 --- .../SALOME_PYQT_PyModule.cxx | 13 ++++--- .../SALOME_PYQT_Selector.cxx | 38 ++++++++----------- .../SALOME_PYQT_Selector.h | 4 +- 4 files changed, 24 insertions(+), 37 deletions(-) diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx index 4cebc3a46..6b17d8d09 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx @@ -630,12 +630,6 @@ void SALOME_PYQT_ModuleLight::setSelected( const QStringList& entries, const boo return myHelper->selectionUpdated(entries); } - -//void SALOME_PYQT_ModuleLight::selectionChanged() -//{ -// MESSAGE("signal selectionChanged"); -//} - void SALOME_PYQT_ModuleLight::setLocalSelected(const QStringList & entries) { MESSAGE("setLocalSelected"); diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx index a344757d4..e6ba25f84 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx @@ -1170,6 +1170,7 @@ void PyModuleHelper::actionActivated() void PyModuleHelper::selectionUpdated(const QStringList& entries) { FuncMsg fmsg( "PyModuleHelper::selectionUpdated()" ); + MESSAGE("selectionUpdated"); // perform synchronous request to Python event dispatcher class SelectionReq : public PyInterp_LockRequest @@ -1181,10 +1182,13 @@ void PyModuleHelper::selectionUpdated(const QStringList& entries) : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true) myHelper( _helper ), myEntries( _entries ) - {} + { + MESSAGE("SelectionReq"); + } protected: virtual void execute() { + MESSAGE("execute"); myHelper->internalSelectionUpdated( myEntries ); } private: @@ -1192,11 +1196,6 @@ void PyModuleHelper::selectionUpdated(const QStringList& entries) const QStringList& myEntries; }; - // get sender action - QAction* action = qobject_cast( sender() ); - if ( !action ) - return; - // post request PyInterp_Dispatcher::Get()->Exec( new SelectionReq( myInterp, this, entries ) ); } @@ -2271,6 +2270,7 @@ void PyModuleHelper::internalActionActivated( int id ) void PyModuleHelper::internalSelectionUpdated(const QStringList& entries) { FuncMsg fmsg("--- PyModuleHelper::internalSelectionUpdated()"); + MESSAGE("internalSelectionUpdated"); // Python interpreter should be initialized and Python module should be imported first if (!myInterp || !myPyModule) @@ -2285,6 +2285,7 @@ void PyModuleHelper::internalSelectionUpdated(const QStringList& entries) #endif if (PyObject_HasAttrString(myPyModule, (char*) "onSelectionUpdated")) { + MESSAGE("call onSelectionUpdated"); PyObjWrapper res(PyObject_CallMethod(myPyModule, (char*) "onSelectionUpdated", (char*) "O", sipList.get())); if (!res) diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.cxx index 6d115dc73..0a2d61f8f 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.cxx @@ -127,6 +127,7 @@ 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++) { @@ -156,18 +157,18 @@ void SALOME_PYQT_Selector::setSelection(const SUIT_DataOwnerPtrList& theList) if (!myPyModule) return; - if (myEntries.count() == 0 || myModifiedTime < myPyModule->getModifiedTime()) - fillEntries(myEntries); - -// DataObjectList objList; -// for (SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it) -// { -// const LightApp_DataOwner* owner = dynamic_cast((*it).operator->()); -// if (owner && myEntries.contains(owner->entry())) -// objList.append(myEntries[owner->entry()]); -// } -// -// myPyModule->setSelected(objList); + myEntries.clear(); + for (SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it) + { + const LightApp_DataOwner* owner = dynamic_cast((*it).operator->()); + if (owner) + { + QString entry = owner->entry(); + myEntries.append(entry); + MESSAGE("Selected: "<< entry.toStdString()); + } + } + fillEntries(myEntries); mySelectedList.clear(); } @@ -175,21 +176,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& 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(it.current()); -// if (obj) -// entries.insert(obj->entry(), obj); -// } - + myPyModule->setSelected(entries); setModified(); } diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.h index a6ffc6aa1..36ef872b5 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.h @@ -63,13 +63,13 @@ protected: virtual void setSelection( const SUIT_DataOwnerPtrList& ); private: - void fillEntries( QMap& ); + void fillEntries( QStringList& ); private: QStringList myLocalEntries; SALOME_PYQT_ModuleLight* myPyModule; SUIT_DataOwnerPtrList mySelectedList; - QMap myEntries; + QStringList myEntries; unsigned long myModifiedTime; }; -- 2.39.2