From cf463f65c127715829e65a8da84fb1619588b576 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 18 Feb 2016 10:06:10 +0300 Subject: [PATCH] Ctrl+space show list of possible parameters in widget expr editor. --- src/ModuleBase/ModuleBase_Tools.cpp | 25 +++++++++++++++++++ src/ModuleBase/ModuleBase_Tools.h | 8 ++++-- .../ModuleBase_WidgetExprEditor.cpp | 9 +++++++ src/ModuleBase/ModuleBase_WidgetExprEditor.h | 3 +++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 6cbbe1c80..5d921bdc8 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -382,6 +383,30 @@ TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape) return aShapeType; } +void getParameters(QStringList& theParameters) +{ + theParameters.clear(); + + SessionPtr aSession = ModelAPI_Session::get(); + std::list aDocList; + DocumentPtr anActiveDocument = aSession->activeDocument(); + DocumentPtr aRootDocument = aSession->moduleDocument(); + aDocList.push_back(anActiveDocument); + if (anActiveDocument != aRootDocument) { + aDocList.push_back(aRootDocument); + } + std::string aGroupId = ModelAPI_ResultParameter::group(); + for(std::list::const_iterator it = aDocList.begin(); it != aDocList.end(); ++it) { + DocumentPtr aDocument = *it; + int aSize = aDocument->size(aGroupId); + for (int i = 0; i < aSize; i++) { + ObjectPtr anObject = aDocument->object(aGroupId, i); + std::string aParameterName = anObject->data()->name(); + theParameters.append(aParameterName.c_str()); + } + } +} + } // namespace ModuleBase_Tools diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 31556d8d8..9346e28ff 100755 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -159,14 +159,18 @@ MODULEBASE_EXPORT Quantity_Color color(const std::string& theSection, const std::string& theDefault); -// Returns the object from the attribute +/// Returns the object from the attribute /// \param theObj an object MODULEBASE_EXPORT ObjectPtr getObject(const AttributePtr& theAttribute); -// Returns the object from the attribute +/// Returns the object from the attribute /// \param theObj an object MODULEBASE_EXPORT TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape); +/// Returns list of parameters accessible in the active part and partset +/// \theParameters a list of parameter names +MODULEBASE_EXPORT void getParameters(QStringList& theParameters); + } #endif diff --git a/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp b/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp index 2900b1eb9..1df376b2b 100644 --- a/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp @@ -236,6 +236,15 @@ ModuleBase_WidgetExprEditor::~ModuleBase_WidgetExprEditor() { } +void ModuleBase_WidgetExprEditor::activateCustom() +{ + ModuleBase_ModelWidget::activateCustom(); + + QStringList aParameters; + ModuleBase_Tools::getParameters(aParameters); + myEditor->setCompletionList(aParameters); +} + void ModuleBase_WidgetExprEditor::initializeValueByActivate() { } diff --git a/src/ModuleBase/ModuleBase_WidgetExprEditor.h b/src/ModuleBase/ModuleBase_WidgetExprEditor.h index 6e9941cf0..bbd84a89f 100644 --- a/src/ModuleBase/ModuleBase_WidgetExprEditor.h +++ b/src/ModuleBase/ModuleBase_WidgetExprEditor.h @@ -108,6 +108,9 @@ class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWid const std::string& thePlaceHolder ); virtual ~ModuleBase_WidgetExprEditor(); + /// The methiod called when widget is activated + virtual void activateCustom(); + /// Redefinition of virtual method virtual QList getControls() const; -- 2.39.2