From 5c212d40c54726dafdbc0c396802b65bce8c4d38 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 7 Dec 2015 14:19:22 +0300 Subject: [PATCH] Debug information for setFocus/activateWindow methods. --- src/ModuleBase/ModuleBase_ModelWidget.cpp | 3 ++- src/ModuleBase/ModuleBase_Tools.cpp | 20 +++++++++++++++++++ src/ModuleBase/ModuleBase_Tools.h | 17 ++++++++++++++++ src/ModuleBase/ModuleBase_WidgetChoice.cpp | 2 +- src/ModuleBase/ModuleBase_WidgetEditor.cpp | 2 +- .../ModuleBase_WidgetMultiSelector.cpp | 3 ++- src/PartSet/PartSet_WidgetSketchLabel.cpp | 2 +- src/XGUI/XGUI_Displayer.cpp | 10 ---------- src/XGUI/XGUI_ErrorDialog.cpp | 4 +++- src/XGUI/XGUI_PropertyPanel.cpp | 10 +++++----- src/XGUI/XGUI_Workshop.cpp | 8 ++++---- 11 files changed, 56 insertions(+), 25 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 11a884722..ff7554f1d 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -5,6 +5,7 @@ // Author: Natalia ERMOLAEVA #include "ModuleBase_ModelWidget.h" +#include "ModuleBase_Tools.h" #include #include @@ -136,7 +137,7 @@ bool ModuleBase_ModelWidget::focusTo() for (; anIt != aLast && !isFocusAccepted; anIt++) { QWidget* aWidget = *anIt; if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) { - aWidget->setFocus(); + ModuleBase_Tools::setFocus(aWidget, "ModuleBase_ModelWidget::focusTo()"); isFocusAccepted = true; } } diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 7c9fced2b..d33467c7e 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -34,6 +34,8 @@ const double tolerance = 1e-7; +//#define DEBUG_ACTIVATE_WINDOW +//#define DEBUG_SET_FOCUS namespace ModuleBase_Tools { @@ -71,6 +73,24 @@ void zeroMargins(QLayout* theLayout) theLayout->setSpacing(5); } +void activateWindow(QWidget* theWidget, const QString& theInfo) +{ + theWidget->activateWindow(); + +#ifdef DEBUG_ACTIVATE_WINDOW + qDebug(QString("activateWindow: %1").arg(theInfo).toStdString().c_str()); +#endif +} + +void setFocus(QWidget* theWidget, const QString& theInfo) +{ + theWidget->setFocus(); + +#ifdef DEBUG_SET_FOCUS + qDebug(QString("setFocus: %1").arg(theInfo).toStdString().c_str()); +#endif +} + QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon) { QImage anIcon(theIcon); diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 8c2a00db1..7aa9f9d64 100755 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -37,6 +37,23 @@ MODULEBASE_EXPORT void adjustMargins(QLayout* theLayout); MODULEBASE_EXPORT void zeroMargins(QWidget* theWidget); MODULEBASE_EXPORT void zeroMargins(QLayout* theLayout); +/* + * Calls the same-named Qt method for the given widget. + * It sets the top-level widget containing this widget to be the active window. + * An active window is a visible top-level window that has the keyboard input focus. + * \param theWidget a widget to be activated + * \param theIndo a debug information + */ +MODULEBASE_EXPORT void activateWindow(QWidget* theWidget, const QString& theInfo = QString()); + +/* + * Calls the same-named Qt method for the given widget. + * Gives the keyboard input focus to this widget (or its focus proxy) if this widget or + * one of its parents is the active window. + * \param theWidget a widget to be activated + * \param theIndo a debug information + */ +MODULEBASE_EXPORT void setFocus(QWidget* theWidget, const QString& theInfo = QString()); /** * \ingroup GUI diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.cpp b/src/ModuleBase/ModuleBase_WidgetChoice.cpp index ea35a3f82..024b73678 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.cpp +++ b/src/ModuleBase/ModuleBase_WidgetChoice.cpp @@ -139,7 +139,7 @@ bool ModuleBase_WidgetChoice::restoreValueCustom() bool ModuleBase_WidgetChoice::focusTo() { if (myCombo) - myCombo->setFocus(); + ModuleBase_Tools::setFocus(myCombo, "ModuleBase_WidgetChoice::focusTo()"); else return false; return true; diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index 20e836072..6ef0847ab 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -65,7 +65,7 @@ void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText) aLay->addWidget(anEditor); - anEditor->setFocus(); + ModuleBase_Tools::setFocus(anEditor, "ModuleBase_WidgetEditor::editedValue"); anEditor->selectAll(); QObject::connect(anEditor, SIGNAL(editingFinished()), &aDlg, SLOT(accept())); diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 0d8d976fa..95dfd185f 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -329,7 +329,8 @@ void ModuleBase_WidgetMultiSelector::updateFocus() // Set focus to List control in order to make possible // to use Tab key for transfer the focus to next widgets myListControl->setCurrentRow(myListControl->model()->rowCount() - 1); - myListControl->setFocus(); + ModuleBase_Tools::setFocus(myListControl, + "ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()"); } //******************************************************************** diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index b167f5a47..846ea9999 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -235,7 +235,7 @@ std::shared_ptr PartSet_WidgetSketchLabel::plane() const bool PartSet_WidgetSketchLabel::focusTo() { - myStackWidget->setFocus(); + ModuleBase_Tools::setFocus(myStackWidget, "PartSet_WidgetSketchLabel::focusTo()"); return true; } diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 9aba5dfdd..4fb6a729b 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -57,8 +57,6 @@ const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity -//#define WORKAROUND_691 - //#define DEBUG_ACTIVATE_OBJECTS //#define DEBUG_DEACTIVATE //#define DEBUG_ACTIVATE_AIS @@ -318,15 +316,7 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) arg(!isEqualShapes || isCustomized).arg(isEqualShapes).arg(isCustomized).toStdString().c_str()); #endif if (!isEqualShapes || isCustomized) { -#ifdef WORKAROUND_691 - // this is a workaround for OCCT 6.9.1, selection area is wrong - // on sketch and 3D features - aContext->RecomputePrsOnly (aAISIO, false); - aContext->SelectionManager()->RecomputeSelection (aAISIO, true); - aContext->LocalContext()->ClearOutdatedSelection (aAISIO, false); -#else aContext->Redisplay(aAISIO, false); -#endif aRedisplayed = true; #ifdef DEBUG_FEATURE_REDISPLAY qDebug(" Redisplay happens"); diff --git a/src/XGUI/XGUI_ErrorDialog.cpp b/src/XGUI/XGUI_ErrorDialog.cpp index ee076f1c4..d389e3b3f 100644 --- a/src/XGUI/XGUI_ErrorDialog.cpp +++ b/src/XGUI/XGUI_ErrorDialog.cpp @@ -8,6 +8,8 @@ */ #include +#include + #include #include #include @@ -61,7 +63,7 @@ void XGUI_ErrorDialog::addError(const QString& theError) if (!isVisible()) { show(); raise(); - activateWindow(); + ModuleBase_Tools::activateWindow(this, "XGUI_ErrorDialog::addError"); } } diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index c91596ec1..762bde305 100755 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -164,7 +164,7 @@ void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget) QList::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end(); bool isFoundWidget = false; - activateWindow(); + ModuleBase_Tools::activateWindow(this, "XGUI_PropertyPanel::activateNextWidget()"); for (; anIt != aLast; anIt++) { ModuleBase_ModelWidget* aCurrentWidget = *anIt; if (isFoundWidget || !theWidget) { @@ -195,7 +195,7 @@ bool XGUI_PropertyPanel::focusNextPrevChild(bool theIsNext) for (int i = 0, aSize = myWidgets.size(); i < aSize && !aFirstControl; i++) aFirstControl = myWidgets[i]->getControlAcceptingFocus(true); if (aFirstControl) - aFirstControl->setFocus(); + ModuleBase_Tools::setFocus(aFirstControl, "XGUI_PropertyPanel::focusNextPrevChild()"); isChangedFocus = true; } else { @@ -217,7 +217,7 @@ bool XGUI_PropertyPanel::focusNextPrevChild(bool theIsNext) for (int i = myWidgets.size()-1; i >= 0 && !aLastControl; i--) aLastControl = myWidgets[i]->getControlAcceptingFocus(false); if (aLastControl) - aLastControl->setFocus(); + ModuleBase_Tools::setFocus(aLastControl, "XGUI_PropertyPanel::focusNextPrevChild()"); isChangedFocus = true; } else { @@ -227,7 +227,7 @@ bool XGUI_PropertyPanel::focusNextPrevChild(bool theIsNext) aFirstControl = myWidgets[i]->getControlAcceptingFocus(true); if (aFirstControl && aFirstControl->hasFocus()) { QToolButton* aCancelBtn = findChild(PROP_PANEL_CANCEL); - aCancelBtn->setFocus(); + ModuleBase_Tools::setFocus(aCancelBtn, "XGUI_PropertyPanel::focusNextPrevChild()"); isChangedFocus = true; } } @@ -283,7 +283,7 @@ bool XGUI_PropertyPanel::setActiveWidget(ModuleBase_ModelWidget* theWidget) void XGUI_PropertyPanel::setFocusOnOkButton() { QToolButton* anOkBtn = findChild(PROP_PANEL_OK); - anOkBtn->setFocus(); + ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::setFocusOnOkButton()"); } void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled) diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index f8a81b03f..145ddd367 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1079,8 +1079,8 @@ void XGUI_Workshop::showPropertyPanel() // in order to operation manager could process key events of the panel. // otherwise they are ignored. It happens only if the same(activateWindow) is // not happened by property panel activation(e.g. resume operation of Sketch) - myPropertyPanel->activateWindow(); - myPropertyPanel->setFocus(); + ModuleBase_Tools::activateWindow(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()"); + ModuleBase_Tools::setFocus(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()"); } //****************************************************** @@ -1099,8 +1099,8 @@ void XGUI_Workshop::hidePropertyPanel() // are processed by this console. For example Undo actions. // It is possible that this code is to be moved to NewGeom package QMainWindow* aDesktop = desktop(); - aDesktop->activateWindow(); - aDesktop->setFocus(); + ModuleBase_Tools::activateWindow(aDesktop, "XGUI_Workshop::hidePropertyPanel()"); + ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::showPropertyPanel()"); } //****************************************************** -- 2.39.2