implementing InputField UseCase in Sketcher EditDatumDialog
This commit is contained in:
parent
5233aa7e50
commit
2fb6e75899
|
@ -98,10 +98,10 @@ FeatureTest::FeatureTest()
|
||||||
|
|
||||||
ADD_PROPERTY(QuantityLength,(1.0));
|
ADD_PROPERTY(QuantityLength,(1.0));
|
||||||
QuantityLength.setUnit(Base::Unit::Length);
|
QuantityLength.setUnit(Base::Unit::Length);
|
||||||
ADD_PROPERTY(QuantityMass,(1.0));
|
//ADD_PROPERTY(QuantityMass,(1.0));
|
||||||
QuantityMass.setUnit(Base::Unit::Mass);
|
//QuantityMass.setUnit(Base::Unit::Mass);
|
||||||
ADD_PROPERTY(QuantityAngle,(1.0));
|
//ADD_PROPERTY(QuantityAngle,(1.0));
|
||||||
QuantityAngle.setUnit(Base::Unit::Angle);
|
//QuantityAngle.setUnit(Base::Unit::Angle);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,8 +94,8 @@ public:
|
||||||
App::PropertyInteger TypeTransient;
|
App::PropertyInteger TypeTransient;
|
||||||
|
|
||||||
App::PropertyQuantity QuantityLength;
|
App::PropertyQuantity QuantityLength;
|
||||||
App::PropertyQuantity QuantityMass;
|
//App::PropertyQuantity QuantityMass;
|
||||||
App::PropertyQuantity QuantityAngle;
|
//App::PropertyQuantity QuantityAngle;
|
||||||
|
|
||||||
/** @name methods overide Feature */
|
/** @name methods overide Feature */
|
||||||
//@{
|
//@{
|
||||||
|
|
|
@ -38,6 +38,13 @@
|
||||||
# pragma warning(disable : 4335) // disable MAC file format warning on VC
|
# pragma warning(disable : 4335) // disable MAC file format warning on VC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef DOUBLE_MAX
|
||||||
|
# define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/
|
||||||
|
#endif
|
||||||
|
#ifndef DOUBLE_MIN
|
||||||
|
# define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace Base;
|
using namespace Base;
|
||||||
|
|
||||||
Quantity::Quantity()
|
Quantity::Quantity()
|
||||||
|
@ -119,12 +126,6 @@ double Quantity::getUserPrefered(QString &unitString)const
|
||||||
|
|
||||||
Quantity QuantResult;
|
Quantity QuantResult;
|
||||||
|
|
||||||
#ifndef DOUBLE_MAX
|
|
||||||
# define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/
|
|
||||||
#endif
|
|
||||||
#ifndef DOUBLE_MIN
|
|
||||||
# define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// error func
|
// error func
|
||||||
|
|
|
@ -24,49 +24,101 @@
|
||||||
#include "PreCompiled.h"
|
#include "PreCompiled.h"
|
||||||
|
|
||||||
#include <Base/Console.h>
|
#include <Base/Console.h>
|
||||||
|
#include <Base/Quantity.h>
|
||||||
|
#include <Base/Exception.h>
|
||||||
|
#include <App/Application.h>
|
||||||
|
|
||||||
#include "InputField.h"
|
#include "InputField.h"
|
||||||
using namespace Gui;
|
using namespace Gui;
|
||||||
|
using namespace Base;
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
InputField::InputField ( QWidget * parent )
|
InputField::InputField ( QWidget * parent )
|
||||||
: QLineEdit(parent)
|
: QLineEdit(parent)
|
||||||
{
|
{
|
||||||
|
this->setContextMenuPolicy(Qt::DefaultContextMenu);
|
||||||
|
|
||||||
|
QObject::connect(this, SIGNAL(textEdited (QString)),
|
||||||
|
this, SLOT(newInput(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
InputField::~InputField()
|
InputField::~InputField()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputField::contextMenuEvent(QContextMenuEvent *event)
|
||||||
|
{
|
||||||
|
QMenu *menu = createStandardContextMenu();
|
||||||
|
QAction *saveAction = menu->addAction(tr("My Menu Item"));
|
||||||
|
//...
|
||||||
|
QAction *saveAction2 = menu->exec(event->globalPos());
|
||||||
|
delete menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputField::newInput(const QString & text)
|
||||||
|
{
|
||||||
|
Quantity res;
|
||||||
|
try{
|
||||||
|
res = Quantity::parse(text.toAscii());
|
||||||
|
}catch(Base::Exception &e){
|
||||||
|
ErrorText = e.what();
|
||||||
|
this->setToolTip(QString::fromAscii(ErrorText.c_str()));
|
||||||
|
QPalette *palette = new QPalette();
|
||||||
|
palette->setColor(QPalette::Base,QColor(255,200,200));
|
||||||
|
setPalette(*palette);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QPalette *palette = new QPalette();
|
||||||
|
palette->setColor(QPalette::Base,QColor(200,255,200));
|
||||||
|
setPalette(*palette);
|
||||||
|
ErrorText = "";
|
||||||
|
this->setToolTip(QString::fromAscii(ErrorText.c_str()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputField::pushToHistory(std::string value)
|
||||||
|
{
|
||||||
|
if(_handle.isValid()){
|
||||||
|
_handle->SetASCII("Hist1",_handle->GetASCII("Hist0","").c_str());
|
||||||
|
_handle->SetASCII("Hist0",value.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> InputField::getHistory(void)
|
||||||
|
{
|
||||||
|
std::vector<std::string> res;
|
||||||
|
|
||||||
|
if(_handle.isValid()){
|
||||||
|
std::string tmp;
|
||||||
|
tmp = _handle->GetASCII("Hist0","");
|
||||||
|
if( tmp != ""){
|
||||||
|
res.push_back(tmp);
|
||||||
|
tmp = _handle->GetASCII("Hist1","");
|
||||||
|
if( tmp != ""){
|
||||||
|
res.push_back(tmp);
|
||||||
|
//tmp = _handle->GetASCII("Hist2","");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/** Sets the preference path to \a path. */
|
/** Sets the preference path to \a path. */
|
||||||
void InputField::setParamGrpPath( const QByteArray& path )
|
void InputField::setParamGrpPath( const QByteArray& path )
|
||||||
{
|
{
|
||||||
//#ifdef FC_DEBUG
|
|
||||||
// if (getWindowParameter().isValid())
|
_handle = App::GetApplication().GetParameterGroupByPath( path);
|
||||||
// {
|
if(_handle.isValid())
|
||||||
// if ( paramGrpPath() != path )
|
sGroupString = path;
|
||||||
// Base::Console().Warning("Widget already attached\n");
|
|
||||||
// }
|
|
||||||
//#endif
|
|
||||||
//
|
|
||||||
// if ( paramGrpPath() != path )
|
|
||||||
// {
|
|
||||||
// if ( setGroupName( path ) )
|
|
||||||
// {
|
|
||||||
// m_sPrefGrp = path;
|
|
||||||
// assert(getWindowParameter().isValid());
|
|
||||||
// getWindowParameter()->Attach(this);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the widget's preferences path. */
|
/** Returns the widget's preferences path. */
|
||||||
QByteArray InputField::paramGrpPath() const
|
QByteArray InputField::paramGrpPath() const
|
||||||
{
|
{
|
||||||
return m_sPrefGrp;
|
if(_handle.isValid())
|
||||||
|
return sGroupString.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,10 @@ namespace Gui {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The InputField class.
|
* The InputField class
|
||||||
|
* The input field widget handles all around user input of Quantities. Thats
|
||||||
|
* include parsing and checking input. Providing a context menu for common operations
|
||||||
|
* and managing default and history values.
|
||||||
* \author Jürgen Riegel
|
* \author Jürgen Riegel
|
||||||
*/
|
*/
|
||||||
class GuiExport InputField : public QLineEdit
|
class GuiExport InputField : public QLineEdit
|
||||||
|
@ -47,15 +50,31 @@ public:
|
||||||
InputField ( QWidget * parent = 0 );
|
InputField ( QWidget * parent = 0 );
|
||||||
virtual ~InputField();
|
virtual ~InputField();
|
||||||
|
|
||||||
// PROPERTIES
|
/** @name history and default management */
|
||||||
// getters
|
//@{
|
||||||
|
/// the param group path where the widget write and read the dafault values
|
||||||
QByteArray paramGrpPath () const;
|
QByteArray paramGrpPath () const;
|
||||||
// setters
|
/// set the param group path where the widget write and read the dafault values
|
||||||
void setParamGrpPath ( const QByteArray& name );
|
void setParamGrpPath ( const QByteArray& name );
|
||||||
|
/// push a new value to the history
|
||||||
|
void pushToHistory(std::string value);
|
||||||
|
/// get the history of the field, newest first
|
||||||
|
std::vector<std::string> getHistory(void);
|
||||||
|
//@}
|
||||||
|
|
||||||
|
protected Q_SLOTS:
|
||||||
|
void newInput(const QString & text);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void contextMenuEvent ( QContextMenuEvent * event );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QByteArray m_sPrefGrp;
|
QByteArray m_sPrefGrp;
|
||||||
|
std::string ErrorText;
|
||||||
|
|
||||||
|
/// handle to the parameter group for defaults and history
|
||||||
|
ParameterGrp::handle _handle;
|
||||||
|
std::string sGroupString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,8 @@ void EditDatumDialog::exec(bool atCursor)
|
||||||
Ui::InsertDatum ui_ins_datum;
|
Ui::InsertDatum ui_ins_datum;
|
||||||
ui_ins_datum.setupUi(&dlg);
|
ui_ins_datum.setupUi(&dlg);
|
||||||
|
|
||||||
|
ui_ins_datum.lineEdit->setParamGrpPath("User parameter:History/Sketcher/SetDatum");
|
||||||
|
|
||||||
double init_val;
|
double init_val;
|
||||||
if (Constr->Type == Sketcher::Angle ||
|
if (Constr->Type == Sketcher::Angle ||
|
||||||
((Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY) &&
|
((Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY) &&
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="lineEdit"/>
|
<widget class="Gui::InputField" name="lineEdit"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
@ -44,7 +44,15 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>Gui::InputField</class>
|
||||||
|
<extends>QLineEdit</extends>
|
||||||
|
<header>Gui/InputField.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
|
||||||
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
<sender>buttonBox</sender>
|
<sender>buttonBox</sender>
|
||||||
<signal>accepted()</signal>
|
<signal>accepted()</signal>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user