Double editor for the constraint value.
//Specific widget containers
const static char* WDG_POINT_SELECTOR = "point_selector";
-
const static char* WDG_FEATURE_SELECTOR = "feature_selector";
+const static char* WDG_DOUBLEVALUE_EDITOR = "doublevalue_editor";
const static char* _ID = "id";
//const static char* WORKBENCH_ID = "id";
ModuleBase_ModelWidget.h
ModuleBase_WidgetBoolValue.h
ModuleBase_WidgetDoubleValue.h
+ ModuleBase_WidgetEditor.h
ModuleBase_WidgetFactory.h
ModuleBase_WidgetFeature.h
ModuleBase_WidgetPoint2D.h
ModuleBase_ModelWidget.cpp
ModuleBase_WidgetBoolValue.cpp
ModuleBase_WidgetDoubleValue.cpp
+ ModuleBase_WidgetEditor.cpp
ModuleBase_WidgetFactory.cpp
ModuleBase_WidgetFeature.cpp
ModuleBase_WidgetPoint2D.cpp
/// \param theAttributeName a name of the attribute
/// \param theEvent key release event
void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent);
+ /// The signal about the widget is lost focus
+ /// \param theWidget the model base widget
+ void focusOutWidget(ModuleBase_ModelWidget* theWidget);
protected:
bool myHasDefaultValue; /// the boolean state whether the control has a default value
--- /dev/null
+// File: ModuleBase_WidgetEditor.cpp
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetEditor.h>
+
+#include <Config_Keywords.h>
+#include <Config_WidgetAPI.h>
+
+#include <Events_Loop.h>
+#include <Model_Events.h>
+
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeDouble.h>
+
+#include <GeomDataAPI_Point2D.h>
+
+#include <QWidget>
+#include <QLineEdit>
+
+ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
+ const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData)
+{
+ myEditor = new QLineEdit(0);
+ myEditor->setWindowFlags(Qt::ToolTip);
+ myEditor->setFocusPolicy(Qt::StrongFocus);
+
+ connect(myEditor, SIGNAL(returnPressed()), this, SLOT(onStopEditing()));
+ connect(myEditor, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesChanged()));
+}
+
+ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
+{
+ delete myEditor;
+}
+
+bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const
+{
+ DataPtr aData = theFeature->data();
+ AttributeDoublePtr aReal = aData->real(attributeID());
+ bool isOk;
+ double aValue = myEditor->text().toDouble(&isOk);
+ if (isOk && aReal->value() != aValue) {
+ //ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
+ //bool isBlocked = that->blockSignals(true);
+ aReal->setValue(aValue);
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ //that->blockSignals(isBlocked);
+ }
+ return true;
+}
+
+bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ AttributeDoublePtr aRef = aData->real(attributeID());
+
+ //bool isBlocked = this->blockSignals(true);
+ myEditor->setText(QString::number(aRef->value()));
+ //this->blockSignals(isBlocked);
+ return true;
+}
+
+void ModuleBase_WidgetEditor::focusTo()
+{
+ QPoint aPoint = QCursor::pos();
+
+ myEditor->move(aPoint);
+ myEditor->show();
+
+ myEditor->selectAll();
+ myEditor->setFocus();
+}
+
+QWidget* ModuleBase_WidgetEditor::getControl() const
+{
+ return 0;
+}
+
+QList<QWidget*> ModuleBase_WidgetEditor::getControls() const
+{
+ QList<QWidget*> aControls;
+ return aControls;
+}
+
+void ModuleBase_WidgetEditor::onStopEditing()
+{
+ myEditor->hide();
+ emit focusOutWidget(this);
+}
--- /dev/null
+// File: ModuleBase_WidgetEditor.h
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModuleBase_WidgetEditor_H
+#define ModuleBase_WidgetEditor_H
+
+#include <ModuleBase.h>
+#include "ModuleBase_ModelWidget.h"
+
+#include <QObject>
+#include <QStringList>
+
+class ModelAPI_Feature;
+class QLineEdit;
+
+/**\class ModuleBase_WidgetEditor
+ * \ingroup GUI
+ * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls
+ */
+class MODULEBASE_EXPORT ModuleBase_WidgetEditor : public ModuleBase_ModelWidget
+{
+ Q_OBJECT
+public:
+ /// Constructor
+ /// \theParent the parent object
+ /// \theParent the parent object
+ /// \theData the widget configuation. The attribute of the model widget is obtained from
+ ModuleBase_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData);
+ /// Destructor
+ virtual ~ModuleBase_WidgetEditor();
+
+ /// Saves the internal parameters to the given feature
+ /// \param theFeature a model feature to be changed
+ virtual bool storeValue(FeaturePtr theFeature) const;
+
+ virtual bool restoreValue(FeaturePtr theFeature);
+
+ /// 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 the internal parent wiget control, that can be shown anywhere
+ /// \returns the widget
+ QWidget* getControl() const;
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+protected slots:
+ /// Slot to check the editing stop
+ void onStopEditing();
+
+private:
+ QLineEdit* myEditor;
+ FeaturePtr myFeature; ///< the current widget feature
+ QStringList myFeatureKinds; ///< the kinds of possible features
+};
+
+#endif
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_WidgetPoint2D.h>
#include <ModuleBase_WidgetFeature.h>
+#include <ModuleBase_WidgetEditor.h>
#include <ModuleBase_WidgetSwitch.h>
#include <ModuleBase_WidgetSelector.h>
#include <ModuleBase_WidgetDoubleValue.h>
} else if (theType == WDG_FEATURE_SELECTOR) {
result = featureSelectorControl(theParent);
+ } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
+ result = doubleValueEditor(theParent);
+
}
else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
result = createContainer(theType, theParent);
return aWidget->getControl();
}
+QWidget* ModuleBase_WidgetFactory::doubleValueEditor(QWidget* theParent)
+{
+ ModuleBase_WidgetEditor* aWidget = new ModuleBase_WidgetEditor(theParent, myWidgetApi);
+ myModelWidgets.append(aWidget);
+ return 0;
+}
+
QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const
{
return QString::fromStdString(theStdString);
QWidget* doubleSpinBoxControl(QWidget* theParent);
QWidget* pointSelectorControl(QWidget* theParent);
QWidget* featureSelectorControl(QWidget* theParent);
+ QWidget* doubleValueEditor(QWidget* theParent);
QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
QWidget* selectorControl(QWidget* theParent);
QWidget* booleanControl(QWidget* theParent);
bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId)
{
- return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND /*||
+ return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND ||
theId == SKETCH_CONSTRAINT_DISTANCE_KIND/*|| theId == SKETCH_CIRCLE_KIND ||
theId == SKETCH_ARC_KIND*/;
}
<feature_selector id="ConstraintEntityA" keysequence="SketchPoint"/>
<feature_selector id="ConstraintEntityB" keysequence="SketchPoint"/>
<point_selector id="ConstraintFlyoutValuePnt" title="Flyout point" tooltip="Flyout"/>
- <doublevalue id="ConstraintValue" label="Value:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Constraint value"/>
+ <doublevalue_editor id="ConstraintValue" min="0" step="1.0" tooltip="Constraint value"/>
</feature>
<feature id="SketchConstraintLength" title="Length of a line" tooltip="Create constraint for the given length of a line segment">
<label title="Select a line entity on which to calculate lenght" tooltip="Select a line entity on which to calculate lenght"/>
for (; anIt != aLast; anIt++) {
connect(*anIt, SIGNAL(keyReleased(const std::string&, QKeyEvent*)),
this, SIGNAL(keyReleased(const std::string&, QKeyEvent*)));
+
+ connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
+ this, SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
}
ModuleBase_ModelWidget* aLastWidget = theWidgets.last();
if (aLastWidget) {