Sketcher: ToolSettings Widget - Tool Management

===============================================

Sets the full interface between the DrawSketchHandler and a tool widget available somewhere in the UI.

Signalling is as follows:
1. On activation of the tool, DrawSketchHandler notifies the tool widget.
2. The tool widget retrieves tool information necessary for representation (type of widget, visibility, ...)
3. When the tool widget has created an appropriate widget, it notifies back a widget change.
4. The tool receives the widget handler and can now configure and interact with the widget.
This commit is contained in:
Abdullah Tahiri
2023-10-15 06:43:34 +02:00
committed by abdullahtahiriyo
parent 9538aafc9a
commit 71a9eca750
7 changed files with 163 additions and 20 deletions

View File

@@ -286,6 +286,27 @@ QString DrawSketchHandler::getCrosshairCursorSVGName() const
return QString::fromLatin1("None");
}
std::unique_ptr<QWidget> DrawSketchHandler::createWidget() const
{
return nullptr;
}
bool DrawSketchHandler::isWidgetVisible() const
{
return false;
};
QPixmap DrawSketchHandler::getToolIcon() const
{
return QPixmap();
}
QString DrawSketchHandler::getToolWidgetText() const
{
return QString();
}
void DrawSketchHandler::activate(ViewProviderSketch* vp)
{
sketchgui = vp;
@@ -1105,6 +1126,26 @@ void DrawSketchHandler::drawDirectionAtCursor(const Base::Vector2d& position,
}
}
std::unique_ptr<QWidget> DrawSketchHandler::createToolWidget() const
{
return createWidget(); // NVI
}
bool DrawSketchHandler::isToolWidgetVisible() const
{
return isWidgetVisible(); // NVI
}
QPixmap DrawSketchHandler::getToolWidgetHeaderIcon() const
{
return getToolIcon();
}
QString DrawSketchHandler::getToolWidgetHeaderText() const
{
return getToolWidgetText();
}
void DrawSketchHandler::drawEditMarkers(const std::vector<Base::Vector2d>& EditMarkers,
unsigned int augmentationlevel)
{

View File

@@ -178,8 +178,38 @@ public:
void resetPositionText();
void renderSuggestConstraintsCursor(std::vector<AutoConstraint>& suggestedConstraints);
/** @name Interfacing with tool dialogs */
//@{
/** @brief Slot to receive signaling that a widget intended for the tool has changed and is
* available ant the provided pointer.
*/
void toolWidgetChanged(QWidget* newwidget);
/** @brief Factory function returning a tool widget of the type necessary for the specific tool.
* This is a NVI interface and specific handlers must overload the corresponding virtual
* function.
*/
std::unique_ptr<QWidget> createToolWidget() const;
/** @brief Returns whether this tool expects/supports a visible tool widget. Emphasis is in
* visibility, so to allow to adapt the interface accordingly.
* This is an NVI interface and specific handlers must overload the corresponding virtual
* function.
*/
bool isToolWidgetVisible() const;
/** @brief Returns a pixmap icon intended for a visible tool widget.
* This is an NVI interface and specific handlers must overload the corresponding virtual
* function.
*/
QPixmap getToolWidgetHeaderIcon() const;
/** @brief Returns a header text intended for a visible tool widget.
* This is an NVI interface and specific handlers must overload the corresponding virtual
* function.
*/
QString getToolWidgetHeaderText() const;
//@}
private: // NVI
virtual void preActivated();
virtual void activated()
@@ -195,6 +225,11 @@ protected: // NVI requiring base implementation
virtual std::string getToolName() const;
virtual QString getCrosshairCursorSVGName() const;
virtual std::unique_ptr<QWidget> createWidget() const;
virtual bool isWidgetVisible() const;
virtual QPixmap getToolIcon() const;
virtual QString getToolWidgetText() const;
protected:
// helpers
/**

View File

@@ -95,12 +95,15 @@ TaskDlgEditSketch::~TaskDlgEditSketch()
void TaskDlgEditSketch::slotToolChanged(const std::string& toolname)
{
bool hidden = toolname == "DSH_None" || toolname == "DSH_Point";
ToolSettings->setHidden(hidden);
bool widgetvisible = false;
if (toolname != "DSH_None") {
widgetvisible = sketchView->toolManager.isWidgetVisible();
ToolSettings->toolChanged(toolname);
}
ToolSettings->setHidden(!widgetvisible);
}
//==== calls from the TaskView ===============================================================

View File

@@ -74,6 +74,7 @@ public:
return QDialogButtonBox::Close;
}
/** @brief Function used to register a slot to be triggered when the tool widget is changed. */
template<typename F>
boost::signals2::connection registerToolWidgetChanged(F&& f)
{

View File

@@ -47,34 +47,22 @@ using namespace Gui::TaskView;
TaskSketcherTool::TaskSketcherTool(ViewProviderSketch* sketchView)
: TaskBox(Gui::BitmapFactory().pixmap("document-new"), tr("Tool parameters"), true, nullptr)
, sketchView(sketchView)
{
widget = std::make_unique<SketcherToolDefaultWidget>(this, sketchView);
this->groupLayout()->addWidget(widget.get());
}
{}
TaskSketcherTool::~TaskSketcherTool()
{}
void TaskSketcherTool::toolChanged(const std::string& toolname)
{
// TODO: Implement a factory here to get an appropriate widget from the toolname
Q_UNUSED(toolname)
// At this stage, we add a Default tool widget for all tools with a defined name, but this needs
// to change
if (toolname != "DSH_None") {
widget = std::make_unique<SketcherToolDefaultWidget>(this, sketchView);
widget = sketchView->toolManager.createToolWidget();
if (widget) {
this->groupLayout()->addWidget(widget.get());
if (toolname == "DSH_Line") {
setHeaderText(tr("Line parameters"));
setHeaderIcon(Gui::BitmapFactory().pixmap("Sketcher_CreateLine"));
}
else if (toolname == "DSH_Circle") {
setHeaderText(tr("Circle parameters"));
setHeaderIcon(Gui::BitmapFactory().pixmap("Sketcher_CreateCircle"));
}
setHeaderText(sketchView->toolManager.getToolWidgetText());
setHeaderIcon(sketchView->toolManager.getToolIcon());
signalToolWidgetChanged(this->widget.get());
}

View File

@@ -377,6 +377,53 @@ void ViewProviderSketch::ParameterObserver::OnChange(Base::Subject<const char*>&
}
}
/************** ViewProviderSketch::ToolManager *********************/
ViewProviderSketch::ToolManager::ToolManager(ViewProviderSketch * vp): vp(vp)
{}
std::unique_ptr<QWidget> ViewProviderSketch::ToolManager::createToolWidget() const
{
if(vp && vp->sketchHandler) {
return vp->sketchHandler->createToolWidget();
}
else {
return nullptr;
}
}
bool ViewProviderSketch::ToolManager::isWidgetVisible() const
{
if(vp && vp->sketchHandler) {
return vp->sketchHandler->isWidgetVisible();
}
else {
return false;
}
}
QPixmap ViewProviderSketch::ToolManager::getToolIcon() const
{
if(vp && vp->sketchHandler) {
return vp->sketchHandler->getToolIcon();
}
else {
return QPixmap();
}
}
QString ViewProviderSketch::ToolManager::getToolWidgetText() const
{
if(vp && vp->sketchHandler) {
return vp->sketchHandler->getToolWidgetText();
}
else {
return QString();
}
}
/*************************** ViewProviderSketch **************************/
// Struct for holding previous click information
@@ -395,6 +442,7 @@ PROPERTY_SOURCE_WITH_EXTENSIONS(SketcherGui::ViewProviderSketch, PartGui::ViewPr
ViewProviderSketch::ViewProviderSketch()
: SelectionObserver(false)
, toolManager(this)
, Mode(STATUS_NONE)
, listener(nullptr)
, editCoinManager(nullptr)

View File

@@ -472,6 +472,31 @@ private:
SoRenderManager* renderMgr;
};
public:
/* API to retrieve information about the active DrawSketchHandler. In particular related to how
* tool widgets should be handled.
*/
class ToolManager
{
public:
ToolManager(ViewProviderSketch* vp);
/** @brief Factory function returning a tool widget of the type appropriate for the current
* active tool. If no tool is active, expect a nullptr.
*/
std::unique_ptr<QWidget> createToolWidget() const;
/** @brief Returns whether the current tool's widget is intended to be visible for the user
*/
bool isWidgetVisible() const;
/** @brief Returns the intended icon for a visible tool widget (e.g. for header/title).*/
QPixmap getToolIcon() const;
/** @brief Returns the intended text for a visible tool widget (e.g. for header/title).*/
QString getToolWidgetText() const;
private:
ViewProviderSketch* vp;
};
public:
/// constructor
ViewProviderSketch();
@@ -493,6 +518,8 @@ public:
SketcherGui::PropertyVisualLayerList VisualLayerList;
//@}
const ToolManager toolManager;
// TODO: It is difficult to imagine that these functions are necessary in the public interface.
// This requires review at a second stage and possibly refactor it.
/** @name handler control */