plugin: [skip ci] add new signal textChanged() to QuantitySpinBox
This commit is contained in:
@@ -640,7 +640,7 @@ void QuantitySpinBox::updateFromCache(bool notify)
|
||||
if (d->pendingEmit) {
|
||||
double factor;
|
||||
const Base::Quantity& res = d->cached;
|
||||
getUserString(res, factor, d->unitStr);
|
||||
QString text = getUserString(res, factor, d->unitStr);
|
||||
d->unitValue = res.getValue() / factor;
|
||||
d->quantity = res;
|
||||
|
||||
@@ -649,6 +649,7 @@ void QuantitySpinBox::updateFromCache(bool notify)
|
||||
d->pendingEmit = false;
|
||||
valueChanged(res);
|
||||
valueChanged(res.getValue());
|
||||
textChanged(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -670,8 +671,12 @@ void QuantitySpinBox::setUnit(const Base::Unit &unit)
|
||||
|
||||
void QuantitySpinBox::setUnitText(const QString& str)
|
||||
{
|
||||
Base::Quantity quant = Base::Quantity::parse(str);
|
||||
setUnit(quant.getUnit());
|
||||
try {
|
||||
Base::Quantity quant = Base::Quantity::parse(str);
|
||||
setUnit(quant.getUnit());
|
||||
}
|
||||
catch (const Base::Exception&) {
|
||||
}
|
||||
}
|
||||
|
||||
QString QuantitySpinBox::unitText(void)
|
||||
|
||||
@@ -174,6 +174,10 @@ Q_SIGNALS:
|
||||
* like: minimum, maximum and/or the right Unit (if specified).
|
||||
*/
|
||||
void valueChanged(double);
|
||||
/**
|
||||
* The new value is passed in \a text with unit.
|
||||
*/
|
||||
void textChanged(const QString&);
|
||||
/** Gets emitted if formula dialog is about to be opened (true)
|
||||
* or finished (false).
|
||||
*/
|
||||
|
||||
@@ -594,8 +594,8 @@ Quantity Quantity::parse(const QString& str)
|
||||
}
|
||||
|
||||
double v = QLocale::system().toDouble(txt, &ok);
|
||||
//if (!ok)
|
||||
// throw QString("Cannot convert to double");
|
||||
//if (!ok && !txt.isEmpty())
|
||||
// throw Base::Exception();
|
||||
return Quantity(v, Unit(unit));
|
||||
}
|
||||
|
||||
@@ -801,7 +801,7 @@ public:
|
||||
value = res.getValue();
|
||||
ok = true;
|
||||
}
|
||||
catch (...) {
|
||||
catch (Base::Exception&) {
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
@@ -975,7 +975,7 @@ void QuantitySpinBox::updateFromCache(bool notify)
|
||||
if (d->pendingEmit) {
|
||||
double factor;
|
||||
const Base::Quantity& res = d->cached;
|
||||
getUserString(res, factor, d->unitStr);
|
||||
QString text = getUserString(res, factor, d->unitStr);
|
||||
d->unitValue = res.getValue() / factor;
|
||||
d->quantity = res;
|
||||
|
||||
@@ -984,6 +984,7 @@ void QuantitySpinBox::updateFromCache(bool notify)
|
||||
d->pendingEmit = false;
|
||||
valueChanged(res);
|
||||
valueChanged(res.getValue());
|
||||
textChanged(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1005,8 +1006,12 @@ void QuantitySpinBox::setUnit(const Base::Unit &unit)
|
||||
|
||||
void QuantitySpinBox::setUnitText(const QString& str)
|
||||
{
|
||||
Base::Quantity quant = Base::Quantity::parse(str);
|
||||
setUnit(quant.getUnit());
|
||||
try {
|
||||
Base::Quantity quant = Base::Quantity::parse(str);
|
||||
setUnit(quant.getUnit());
|
||||
}
|
||||
catch (const Base::Exception&) {
|
||||
}
|
||||
}
|
||||
|
||||
QString QuantitySpinBox::unitText(void)
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
#include <QWidget>
|
||||
|
||||
namespace Base {
|
||||
class Exception {
|
||||
};
|
||||
class Unit{
|
||||
public:
|
||||
Unit();
|
||||
@@ -369,7 +371,7 @@ class QuantitySpinBox : public QAbstractSpinBox
|
||||
Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
|
||||
Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
|
||||
Q_PROPERTY(double rawValue READ rawValue WRITE setValue NOTIFY valueChanged)
|
||||
Q_PROPERTY(Base::Quantity value READ value WRITE setValue NOTIFY valueChanged USER true)
|
||||
//Q_PROPERTY(Base::Quantity value READ value WRITE setValue NOTIFY valueChanged USER true)
|
||||
|
||||
public:
|
||||
explicit QuantitySpinBox(QWidget *parent = 0);
|
||||
@@ -473,6 +475,10 @@ Q_SIGNALS:
|
||||
* like: minimum, maximum and/or the right Unit (if specified).
|
||||
*/
|
||||
void valueChanged(double);
|
||||
/**
|
||||
* The new value is passed in \a text with unit.
|
||||
*/
|
||||
void textChanged(const QString&);
|
||||
/** Gets emitted if formula dialog is about to be opened (true)
|
||||
* or finished (false).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user