Shortcut can not be used for it because there is a conflict in Qt which one should be performed.
So, OperationMgr processes it from property panel and application on the whole(qApp->installEventFilter(this)).
return false;
}
+bool ModuleBase_ModelWidget::processDelete()
+{
+ return false;
+}
+
bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
{
QWidget* aWidget = qobject_cast<QWidget*>(theObject);
/// \return Current Editing mode
bool isEditingMode() const { return myIsEditing; }
- /// Returns true if the event is processed.
+ /// Returns true if the event is processed. The default implementation is empty, returns false.
virtual bool processEnter();
+ /// Returns true if the event is processed. The default implementation is empty, returns false.
+ virtual bool processDelete();
+
/// Sends Update and Redisplay for the given object
/// \param theObj is updating object
static void updateObject(ObjectPtr theObj);
myListControl->addAction(myCopyAction);
myDeleteAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this);
- myDeleteAction->setShortcut(QKeySequence::Delete);
myDeleteAction->setEnabled(false);
connect(myDeleteAction, SIGNAL(triggered(bool)), SLOT(onDeleteItem()));
myListControl->addAction(myDeleteAction);
return aValid;
}
+//********************************************************************
+bool ModuleBase_WidgetMultiSelector::processDelete()
+{
+ // find attribute indices to delete
+ std::set<int> anAttributeIds;
+ getSelectedAttributeIndices(anAttributeIds);
+
+ // refill attribute by the items which indices are not in the list of ids
+ bool aDone = false;
+ AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
+ if (aSelectionListAttr.get()) {
+ aDone = !anAttributeIds.empty();
+ aSelectionListAttr->remove(anAttributeIds);
+ }
+ else {
+ AttributeRefListPtr aRefListAttr = myFeature->data()->reflist(attributeID());
+ if (aRefListAttr.get()) {
+ aDone = !anAttributeIds.empty();
+ aRefListAttr->remove(anAttributeIds);
+ }
+ }
+ if (aDone) {
+ // update object is necessary to flush update signal. It leads to objects references map update
+ // and the operation presentation will not contain deleted items visualized as parameters of
+ // the feature.
+ updateObject(myFeature);
+
+ restoreValue();
+ myWorkshop->setSelected(getAttributeSelection());
+ myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeAllObjects, true);
+ }
+ return true; // if the delete should be processed outsize, the method should return isDone
+}
+
//********************************************************************
QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
{
//********************************************************************
void ModuleBase_WidgetMultiSelector::onDeleteItem()
{
- // find attribute indices to delete
- std::set<int> anAttributeIds;
- getSelectedAttributeIndices(anAttributeIds);
-
- // refill attribute by the items which indices are not in the list of ids
- bool aDone = false;
- AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
- if (aSelectionListAttr.get()) {
- aDone = !anAttributeIds.empty();
- aSelectionListAttr->remove(anAttributeIds);
- }
- else {
- AttributeRefListPtr aRefListAttr = myFeature->data()->reflist(attributeID());
- if (aRefListAttr.get()) {
- aDone = !anAttributeIds.empty();
- aRefListAttr->remove(anAttributeIds);
- }
- }
- if (aDone) {
- restoreValue();
- myWorkshop->setSelected(getAttributeSelection());
-
- myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeAllObjects, true);
- }
+ processDelete();
}
//********************************************************************
/// \return a boolean value
virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
- public slots:
+ /// Returns true if the event is processed. The default implementation is empty, returns false.
+ virtual bool processDelete();
+
+public slots:
/// Slot is called on selection type changed
void onSelectionTypeChanged();
#include "ModuleBase_Tools.h"
#include "ModuleBase_IModule.h"
+#include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_ModelWidget.h>
#include <ModelAPI_Result.h>
#include <ModelAPI_Attribute.h>
return !myFeatureShapes.empty() || !myFeatureResults.empty();
}
-#include <ModuleBase_IPropertyPanel.h>
-#include <ModuleBase_ModelWidget.h>
void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer theMode)
aDesktop->addAction(aAction);
addAction("DELETE_CMD", aAction);
- aAction->setShortcut(Qt::Key_Delete);
aAction->setShortcutContext(Qt::ApplicationShortcut);
aAction = new QAction(QIcon(":pictures/rename_edit.png"), tr("Rename"), this);
if (aContext.IsNull())
return;
if (aContext->HasOpenedContext()) {
- aContext->UnhilightSelected();
- aContext->ClearSelected();
+ aContext->UnhilightSelected(false);
+ aContext->ClearSelected(false);
foreach (ModuleBase_ViewerPrs aPrs, theValues) {
const TopoDS_Shape& aShape = aPrs.shape();
if (!aShape.IsNull()) {
}
}
} else {
- aContext->UnhilightCurrents();
- aContext->ClearCurrents();
+ aContext->UnhilightCurrents(false);
+ aContext->ClearCurrents(false);
foreach (ModuleBase_ViewerPrs aPrs, theValues) {
ObjectPtr anObject = aPrs.object();
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
ModuleBase_IWorkshop* theWorkshop)
: QObject(theParent), myWorkshop(theWorkshop)
{
+ /// we need to install filter to the application in order to react to 'Delete' key button
+ /// this key can not be a short cut for a corresponded action because we need to set
+ /// the actions priority
+ qApp->installEventFilter(this);
}
XGUI_OperationMgr::~XGUI_OperationMgr()
bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent)
{
+ bool isAccepted = false;
if (theEvent->type() == QEvent::KeyRelease) {
QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
if(aKeyEvent) {
- return onKeyReleased(aKeyEvent);
+ isAccepted = onKeyReleased(aKeyEvent);
}
}
- return QObject::eventFilter(theObject, theEvent);
+ if (!isAccepted)
+ isAccepted = QObject::eventFilter(theObject, theEvent);
+
+ return isAccepted;
}
bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent)
{
- QObject* aSender = sender();
-
// Let the manager decide what to do with the given key combination.
ModuleBase_Operation* anOperation = currentOperation();
- bool isAccepted = true;
+ bool isAccepted = false;
switch (theEvent->key()) {
case Qt::Key_Return:
case Qt::Key_Enter: {
}
}
}
-
+ case Qt::Key_Delete: {
+ isAccepted = onProcessDelete();
+ }
+ break;
break;
default:
isAccepted = false;
bool XGUI_OperationMgr::onProcessEnter()
{
- bool isAccepted = true;
+ bool isAccepted = false;
ModuleBase_Operation* aOperation = currentOperation();
ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
- ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
+ ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
bool isAborted = false;
- if (!aActiveWgt) {
+ if (!anActiveWgt) {
QWidget* aFocusWidget = aPanel->focusWidget();
QToolButton* aCancelBtn = aPanel->findChild<QToolButton*>(PROP_PANEL_CANCEL);
if (aFocusWidget && aCancelBtn && aFocusWidget == aCancelBtn) {
abortOperation(aOperation);
+ isAccepted = true;
isAborted = true;
}
}
if (!isAborted) {
- if (!aActiveWgt || !aActiveWgt->processEnter()) {
- if (!myWorkshop->module()->processEnter(aActiveWgt ? aActiveWgt->attributeID() : "")) {
+ isAccepted = anActiveWgt && anActiveWgt->processEnter();
+ if (!isAccepted) {
+ isAccepted = myWorkshop->module()->processEnter(anActiveWgt ? anActiveWgt->attributeID() : "");
+ if (!isAccepted) {
+ /// functionality is similar to Apply click
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
if (!aFOperation || myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
+ // key released is emitted to apply the current value to the model if it was modified in PP
emit keyEnterReleased();
commitOperation();
+ isAccepted = true;
}
else
isAccepted = false;
return isAccepted;
}
+bool XGUI_OperationMgr::onProcessDelete()
+{
+ bool isAccepted = false;
+ ModuleBase_Operation* aOperation = currentOperation();
+ ModuleBase_ModelWidget* anActiveWgt = 0;
+ if (aOperation) {
+ ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+ if (aPanel)
+ anActiveWgt = aPanel->activeWidget();
+ }
+ if (anActiveWgt)
+ isAccepted = anActiveWgt->processDelete();
+ if (!isAccepted) {
+ workshop()->deleteObjects();
+ isAccepted = true;
+ }
+
+ return isAccepted;
+}
+
XGUI_Workshop* XGUI_OperationMgr::workshop() const
{
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
/// \param theEvent the mouse event
bool onKeyReleased(QKeyEvent* theEvent);
+ protected slots:
/// The functionaly, that should be done by enter click
- /// Fistly the active widget processes it, then module. If no one do not
+ /// Fistly the active widget processes it, then module. If no one does not
/// process it, the current operation is committed
bool onProcessEnter();
- protected slots:
+ /// The functionaly, that should be done by delete click
+ /// Fistly the active widget processes it, then workshop. If no one does not
+ /// process it, do nothing
+ bool onProcessDelete();
+
/// Slot that is called by an operation stop. Removes the stopped operation form the stack.
/// If there is a suspended operation, restart it.
void onOperationStopped();