Code correction to set the focus widget for all ModelWidget children.
ModuleBase_IOperation.cpp
ModuleBase_Operation.cpp
ModuleBase_OperationDescription.cpp
+ ModuleBase_ModelWidget.cpp
ModuleBase_WidgetBoolValue.cpp
ModuleBase_WidgetDoubleValue.cpp
ModuleBase_WidgetFactory.cpp
--- /dev/null
+// File: ModuleBase_ModelWidget.h
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include "ModuleBase_ModelWidget.h"
+
+#include "Config_WidgetAPI.h"
+
+#include <QWidget>
+
+ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData)
+ : QObject(theParent)
+{
+ myAttributeID = theData ? theData->widgetId() : "";
+}
+
+bool ModuleBase_ModelWidget::canFocusTo(const std::string& theAttributeName) const
+{
+ return theAttributeName == attributeID();
+}
+
+void ModuleBase_ModelWidget::focusTo()
+{
+ QList<QWidget*> aControls = getControls();
+ QList<QWidget*>::const_iterator anIt = aControls.begin(), aLast = aControls.end();
+ for (; anIt != aLast; anIt++) {
+ QWidget* aWidget = *anIt;
+ if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) {
+ aWidget->setFocus();
+ break;
+ }
+ }
+}
+
+std::string ModuleBase_ModelWidget::attributeID() const
+{
+ return myAttributeID;
+}
#include <boost/shared_ptr.hpp>
+class Config_WidgetAPI;
class ModelAPI_Feature;
class QKeyEvent;
public:
/// Constructor
/// \theParent the parent object
- ModuleBase_ModelWidget(QObject* theParent) :QObject(theParent) {};
+ /// \theData the widget configuation. The attribute of the model widget is obtained from
+ ModuleBase_ModelWidget(QObject* theParent, const Config_WidgetAPI* theData);
/// Destructor
virtual ~ModuleBase_ModelWidget() {};
/// Returns whether the widget can accept focus, or if it corresponds to the given attribute
/// \param theAttribute name
- virtual bool canFocusTo(const std::string& theAttributeName) const { return false; }
+ bool canFocusTo(const std::string& theAttributeName) const;
- /// Set focus to the current widget if it corresponds to the given attribute
- virtual void focusTo() {}
+ /// Set focus to the first control of the current widget. The focus policy of the control is checked.
+ /// If the widget has the NonFocus focus policy, it is skipped.
+ virtual void focusTo();
/// Returns list of widget controls
/// \return a control list
/// \param theAttributeName a name of the attribute
/// \param theEvent key release event
void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent);
+
+protected:
+ /// Returns the attribute name
+ /// \returns the string value
+ std::string attributeID() const;
+
+private:
+ std::string myAttributeID; /// the attribute name of the model feature
};
#endif
ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData)
-: ModuleBase_ModelWidget(theParent), myWorkshop(theWorkshop), myActivateOnStart(false)
+: ModuleBase_ModelWidget(theParent, theData), myWorkshop(theWorkshop), myActivateOnStart(false)
{
- myFeatureAttributeID = theData->widgetId();
-
myContainer = new QWidget(theParent);
QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
{
DataPtr aData = theFeature->data();
boost::shared_ptr<ModelAPI_AttributeReference> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(myFeatureAttributeID));
+ boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(attributeID()));
FeaturePtr aFeature = aRef->value();
if (!(aFeature && aFeature->isSame(mySelectedFeature))) {
bool ModuleBase_SelectorWidget::restoreValue(FeaturePtr theFeature)
{
DataPtr aData = theFeature->data();
- boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(myFeatureAttributeID);
+ boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
bool isBlocked = this->blockSignals(true);
mySelectedFeature = aRef->value();
void updateSelectionName();
void raisePanel() const;
- std::string myFeatureAttributeID;
-
QWidget* myContainer;
QLabel* myLabel;
QLineEdit* myTextLine;
#include <ModuleBase_WidgetBoolValue.h>
-#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_Data.h>
#include <QWidget>
#include <QLayout>
-#include <QLabel>
-#include <QDoubleSpinBox>
#include <QCheckBox>
ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData)
- : ModuleBase_ModelWidget(theParent)
+ : ModuleBase_ModelWidget(theParent, theData)
{
- myAttributeID = theData->widgetId();
QString aText = QString::fromStdString(theData->widgetLabel());
QString aToolTip = QString::fromStdString(theData->widgetTooltip());
QString aDefault = QString::fromStdString(theData->getProperty("default"));
bool ModuleBase_WidgetBoolValue::storeValue(FeaturePtr theFeature) const
{
DataPtr aData = theFeature->data();
- boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(myAttributeID);
+ boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
if (aBool->value() != myCheckBox->isChecked()) {
aBool->setValue(myCheckBox->isChecked());
bool ModuleBase_WidgetBoolValue::restoreValue(FeaturePtr theFeature)
{
DataPtr aData = theFeature->data();
- boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(myAttributeID);
+ boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
bool isBlocked = myCheckBox->blockSignals(true);
myCheckBox->setChecked(aRef->value());
class Config_WidgetAPI;
class QWidget;
-class QLabel;
-class QDoubleSpinBox;
class QCheckBox;
class MODULEBASE_EXPORT ModuleBase_WidgetBoolValue: public ModuleBase_ModelWidget
{
Q_OBJECT
public:
+ /// Constructor
+ /// \theParent the parent object
+ /// \theData the widget configuation. The attribute of the model widget is obtained from
ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData);
virtual ~ModuleBase_WidgetBoolValue();
QWidget* getControl() const;
private:
- std::string myAttributeID;
-
QCheckBox* myCheckBox;
};
#include <ModuleBase_WidgetDoubleValue.h>
#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_Data.h>
#include <Config_Keywords.h>
#include <QLayout>
#include <QLabel>
#include <QDoubleSpinBox>
-#include <QCheckBox>
ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, const Config_WidgetAPI* theData)
- : ModuleBase_ModelWidget(theParent)
+ : ModuleBase_ModelWidget(theParent, theData)
{
myContainer = new QWidget(theParent);
QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
myLabel->setPixmap(QPixmap(aLabelIcon));
aControlLay->addWidget(myLabel);
- myAttributeID = theData->widgetId();
mySpinBox = new QDoubleSpinBox(myContainer);
- QString anObjName = QString::fromStdString(myAttributeID);
+ QString anObjName = QString::fromStdString(attributeID());
mySpinBox->setObjectName(anObjName);
bool isOk = false;
bool ModuleBase_WidgetDoubleValue::storeValue(FeaturePtr theFeature) const
{
DataPtr aData = theFeature->data();
- boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(myAttributeID);
+ boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(attributeID());
if (aReal->value() != mySpinBox->value()) {
aReal->setValue(mySpinBox->value());
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
bool ModuleBase_WidgetDoubleValue::restoreValue(FeaturePtr theFeature)
{
DataPtr aData = theFeature->data();
- boost::shared_ptr<ModelAPI_AttributeDouble> aRef = aData->real(myAttributeID);
+ boost::shared_ptr<ModelAPI_AttributeDouble> aRef = aData->real(attributeID());
bool isBlocked = mySpinBox->blockSignals(true);
mySpinBox->setValue(aRef->value());
class QWidget;
class QLabel;
class QDoubleSpinBox;
-class QCheckBox;
class MODULEBASE_EXPORT ModuleBase_WidgetDoubleValue: public ModuleBase_ModelWidget
{
Q_OBJECT
public:
+ /// Constructor
+ /// \theParent the parent object
+ /// \theData the widget configuation. The attribute of the model widget is obtained from
ModuleBase_WidgetDoubleValue(QWidget* theParent, const Config_WidgetAPI* theData);
virtual ~ModuleBase_WidgetDoubleValue();
QWidget* getControl() const { return myContainer; }
private:
- std::string myAttributeID;
-
QWidget* myContainer;
QLabel* myLabel;
QDoubleSpinBox* mySpinBox;
QWidget* ModuleBase_WidgetFactory::pointSelectorControl(QWidget* theParent)
{
- ModuleBase_WidgetPoint2D* aWidget = new ModuleBase_WidgetPoint2D(theParent,
- qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)),
- myWidgetApi->widgetId());
+ ModuleBase_WidgetPoint2D* aWidget = new ModuleBase_WidgetPoint2D(theParent, myWidgetApi);
connectWidget(aWidget, WDG_POINT_SELECTOR);
myModelWidgets.append(aWidget);
return aWidget->getControl();
#include <ModuleBase_WidgetPoint2D.h>
#include <Config_Keywords.h>
+#include <Config_WidgetAPI.h>
#include <Events_Loop.h>
#include <Model_Events.h>
#include <cfloat>
#include <climits>
-ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle,
- const std::string& theFeatureAttributeID)
-: ModuleBase_ModelWidget(theParent), myFeatureAttributeID(theFeatureAttributeID)
+ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent,
+ const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData)
{
- myGroupBox = new QGroupBox(theTitle, theParent);
+ myGroupBox = new QGroupBox(QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)),
+ theParent);
QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
aGroupLay->setContentsMargins(0, 0, 0, 0);
aGroupLay->setColumnStretch(1, 1);
{
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(attributeID()));
ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
bool isBlocked = that->blockSignals(true);
{
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(attributeID()));
bool isBlocked = this->blockSignals(true);
myXSpin->setValue(aPoint->x());
return true;
}
-bool ModuleBase_WidgetPoint2D::canFocusTo(const std::string& theAttributeName)
-{
- return theAttributeName == myFeatureAttributeID;
-}
-
-void ModuleBase_WidgetPoint2D::focusTo()
-{
- if (!myXSpin->hasFocus() && !myYSpin->hasFocus())
- myXSpin->setFocus();
-}
-
QWidget* ModuleBase_WidgetPoint2D::getControl() const
{
return myGroupBox;
{
if (theObject == myXSpin || theObject == myYSpin) {
if (theEvent->type() == QEvent::KeyRelease) {
- emit keyReleased(myFeatureAttributeID, (QKeyEvent*) theEvent);
+ emit keyReleased(attributeID(), (QKeyEvent*) theEvent);
return true;
}
}
public:
/// Constructor
/// \theParent the parent object
- /// \theTitle the group box title
- /// \theFeatureAttributeID the identifier of the feature attribute
- ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle,
- const std::string& theFeatureAttributeID);
+ /// \theParent the parent object
+ /// \theData the widget configuation. The attribute of the model widget is obtained from
+ ModuleBase_WidgetPoint2D(QWidget* theParent, const Config_WidgetAPI* theData);
/// Destructor
virtual ~ModuleBase_WidgetPoint2D();
virtual bool restoreValue(FeaturePtr theFeature);
- /// Returns whether the widget can accept focus, or if it corresponds to the given attribute
- /// \param theAttribute name
- virtual bool canFocusTo(const std::string& theAttributeName);
-
- /// Set focus to the current widget if it corresponds to the given attribute
- virtual void focusTo();
-
/// Returns the internal parent wiget control, that can be shown anywhere
/// \returns the widget
QWidget* getControl() const;
virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
private:
- std::string myFeatureAttributeID; ///< the identifier of the feature attribute
QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets
QDoubleSpinBox* myXSpin; ///< the spin box for the X coordinate
QDoubleSpinBox* myYSpin; ///< the spin box for the Y coordinate