Skip to content

Commit

Permalink
Gui: offer possibility to editing view provider to handle "Select All…
Browse files Browse the repository at this point in the history
…" command
  • Loading branch information
0penBrain committed May 9, 2024
1 parent 0095e52 commit 849a81d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Gui/View3DInventorViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,12 @@ class Gui::ViewerEventFilter : public QObject
else if (event->type() == QEvent::KeyPress) {
auto ke = static_cast<QKeyEvent*>(event); // NOLINT
if (ke->matches(QKeySequence::SelectAll)) {
static_cast<View3DInventorViewer*>(obj)->selectAll();
auto* viewer3d = static_cast<View3DInventorViewer*>(obj);

Check warning on line 230 in src/Gui/View3DInventorViewer.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
auto* editingVP = viewer3d->getEditingViewProvider();
if(!editingVP || !editingVP->selectAll())
{
viewer3d->selectAll();
}
return true;
}
}
Expand Down Expand Up @@ -1088,6 +1093,12 @@ bool View3DInventorViewer::isEditingViewProvider() const
return this->editViewProvider != nullptr;
}

/// return currently editing view provider
ViewProvider* View3DInventorViewer::getEditingViewProvider() const
{
return this->editViewProvider;
}

/// display override mode
void View3DInventorViewer::setOverrideMode(const std::string& mode)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/View3DInventorViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ class GuiExport View3DInventorViewer : public Quarter::SoQTQuarterAdaptor, publi
void setEditingViewProvider(Gui::ViewProvider* vp, int ModNum);
/// return whether a view provider is edited
bool isEditingViewProvider() const;
/// return currently editing view provider
ViewProvider* getEditingViewProvider() const;
/// reset from edit mode
void resetEditingViewProvider();
void setupEditingRoot(SoNode *node=nullptr, const Base::Matrix4D *mat=nullptr);
Expand Down
3 changes: 3 additions & 0 deletions src/Gui/ViewProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ class GuiExport ViewProvider : public App::TransactionalObject
virtual void getTaskViewContent(std::vector<Gui::TaskView::TaskContent*>&) const {}
//@}

/// is called when the provider is in edit and a "Select All" command was issued
/// Provider shall return 'false' is it ignores the command, 'true' otherwise
virtual bool selectAll() { return false; }
/// is called when the provider is in edit and a key event occurs. Only ESC ends edit.
virtual bool keyPressed(bool pressed, int key);
/// Is called by the tree if the user double clicks on the object. It returns the string
Expand Down
6 changes: 6 additions & 0 deletions src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2588,6 +2588,12 @@ void ViewProviderSketch::updateColor()
editCoinManager->updateColor();
}

bool ViewProviderSketch::selectAll()
{
// TODO: eventually implement "select all" logic
return true;
}

bool ViewProviderSketch::doubleClicked()
{
Gui::Application::Instance->activeDocument()->setEdit(this);
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Sketcher/Gui/ViewProviderSketch.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ class SketcherGuiExport ViewProviderSketch: public PartGui::ViewProvider2DObject
{
return nullptr;
}
/// is called when the provider is in edit and a "Select All" command was issued
/// Provider shall return 'false' is it ignores the command, 'true' otherwise
virtual bool selectAll() override;

Check warning on line 661 in src/Mod/Sketcher/Gui/ViewProviderSketch.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

"virtual" is redundant since function is already declared as "override" [readability/inheritance] [4]
/// is called by the tree if the user double clicks on the object
bool doubleClicked() override;
/// is called when the Provider is in edit and the mouse is moved
Expand Down

0 comments on commit 849a81d

Please sign in to comment.