本文整理汇总了C++中Quantity::getValue方法的典型用法代码示例。如果您正苦于以下问题:C++ Quantity::getValue方法的具体用法?C++ Quantity::getValue怎么用?C++ Quantity::getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Quantity
的用法示例。
在下文中一共展示了Quantity::getValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: newInput
void InputField::newInput(const QString & text)
{
Quantity res;
try{
res = Quantity::parse(text);
}catch(Base::Exception &e){
ErrorText = e.what();
this->setToolTip(QString::fromAscii(ErrorText.c_str()));
QPixmap pixmap = BitmapFactory().pixmapFromSvg(":/icons/button_invalid.svg", QSize(sizeHint().height(),sizeHint().height()));
iconLabel->setPixmap(pixmap);
parseError(QString::fromAscii(ErrorText.c_str()));
return;
}
QPixmap pixmap = BitmapFactory().pixmapFromSvg(":/icons/button_valid.svg", QSize(sizeHint().height(),sizeHint().height()));
iconLabel->setPixmap(pixmap);
ErrorText = "";
this->setToolTip(QString::fromAscii(ErrorText.c_str()));
actQuantity = res;
double dFactor;
res.getUserString(dFactor,actUnitStr);
// calculate the number shown
actUnitValue = res.getValue()/dFactor;
// signaling
valueChanged(res);
}
示例2: newInput
void InputField::newInput(const QString & text)
{
Quantity res;
try{
res = Quantity::parse(text);
}catch(Base::Exception &e){
ErrorText = e.what();
this->setToolTip(QString::fromAscii(ErrorText.c_str()));
QPalette palette;
palette.setColor(QPalette::Base,QColor(255,200,200));
setPalette(palette);
parseError(QString::fromAscii(ErrorText.c_str()));
return;
}
QPalette palette;
palette.setColor(QPalette::Base,QColor(200,255,200));
setPalette(palette);
ErrorText = "";
this->setToolTip(QString::fromAscii(ErrorText.c_str()));
actQuantity = res;
double dFactor;
res.getUserString(dFactor,actUnitStr);
// calculate the number shown
actUnitValue = res.getValue()/dFactor;
// signaling
valueChanged(res);
}
示例3: updateText
void QuantitySpinBox::updateText(const Quantity &quant)
{
Q_D(QuantitySpinBox);
double dFactor;
QString txt = quant.getUserString(dFactor,d->unitStr);
d->unitValue = quant.getValue()/dFactor;
lineEdit()->setText(txt);
}
示例4: toDbl
double UnitsApi::toDbl(PyObject *ArgObj, const Base::Unit &u)
{
if (PyString_Check(ArgObj)) {
// Parse the string
QString str = QString::fromLatin1(PyString_AsString(ArgObj));
Quantity q = Quantity::parse(str);
if (q.getUnit() == u)
return q.getValue();
throw Base::Exception("Wrong unit type!");
}
else if (PyFloat_Check(ArgObj)) {
return PyFloat_AsDouble(ArgObj);
}
else if (PyInt_Check(ArgObj)) {
return static_cast<double>(PyInt_AsLong(ArgObj));
}
else {
throw Base::Exception("Wrong parameter type!");
}
}
示例5: toQuantity
Quantity UnitsApi::toQuantity(PyObject *ArgObj, const Base::Unit &u)
{
double d;
if (PyString_Check(ArgObj)) {
// Parse the string
QString str = QString::fromLatin1(PyString_AsString(ArgObj));
Quantity q = Quantity::parse(str);
d = q.getValue();
}
else if (PyFloat_Check(ArgObj)) {
d = PyFloat_AsDouble(ArgObj);
}
else if (PyInt_Check(ArgObj)) {
d = static_cast<double>(PyInt_AsLong(ArgObj));
}
else {
throw Base::Exception("Wrong parameter type!");
}
return Quantity(d,u);
}
示例6: toDbl
double UnitsApi::toDbl(PyObject *ArgObj, const Base::Unit &u)
{
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check(ArgObj)) {
QString str = QString::fromUtf8(PyUnicode_AsUTF8(ArgObj));
#else
if (PyString_Check(ArgObj)) {
QString str = QString::fromLatin1(PyString_AsString(ArgObj));
#endif
// Parse the string
Quantity q = Quantity::parse(str);
if (q.getUnit() == u)
return q.getValue();
throw Base::UnitsMismatchError("Wrong unit type!");
}
else if (PyFloat_Check(ArgObj)) {
return PyFloat_AsDouble(ArgObj);
}
#if PY_MAJOR_VERSION < 3
else if (PyInt_Check(ArgObj)) {
return static_cast<double>(PyInt_AsLong(ArgObj));
#else
else if (PyLong_Check(ArgObj)) {
return static_cast<double>(PyLong_AsLong(ArgObj));
#endif
}
else {
throw Base::UnitsMismatchError("Wrong parameter type!");
}
}
Quantity UnitsApi::toQuantity(PyObject *ArgObj, const Base::Unit &u)
{
double d;
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check(ArgObj)) {
QString str = QString::fromUtf8(PyUnicode_AsUTF8(ArgObj));
#else
if (PyString_Check(ArgObj)) {
QString str = QString::fromLatin1(PyString_AsString(ArgObj));
#endif
// Parse the string
Quantity q = Quantity::parse(str);
d = q.getValue();
}
else if (PyFloat_Check(ArgObj)) {
d = PyFloat_AsDouble(ArgObj);
}
#if PY_MAJOR_VERSION < 3
else if (PyInt_Check(ArgObj)) {
d = static_cast<double>(PyInt_AsLong(ArgObj));
#else
else if (PyLong_Check(ArgObj)) {
d = static_cast<double>(PyLong_AsLong(ArgObj));
#endif
}
else {
throw Base::UnitsMismatchError("Wrong parameter type!");
}
return Quantity(d,u);
}
void UnitsApi::setDecimals(int prec)
{
UserPrefDecimals = prec;
}
int UnitsApi::getDecimals()
{
return UserPrefDecimals;
}
示例7: getValueAs
double Quantity::getValueAs(const Quantity &q)const
{
return _Value/q.getValue();
}
示例8: config
//.........这里部分代码省略.........
Double_t delta_t=epevent.t_gamma[j]-epevent.t_e;
getBapd3DeltaT(index)->Fill(delta_t);
if(delta_t>windows[1][1] && delta_t<=windows[1][2]){
getBapd3OnPeak(index)->Fill(epevent.E_gamma[j]);
epg_ep_bapd3[index]+=Quantity(1,1);
}else if(delta_t>windows[1][0] && delta_t<=windows[1][3]){
getBapd3OffPeak(index)->Fill(epevent.E_gamma[j]);
epg_ep_bapd3[index]-=Quantity(bapd_scale,bapd_scale);
}
}
}else if(modes[j]==BAPD_PERP){
//Int_t index=bapdIndex(modes[j],j);
//ep_bapd4[index]+=Quantity(1,1);
//if(epevent.E_gamma[j]>min[1] && epevent.E_gamma[j]<max[1]){
// Double_t delta_t=epevent.t_gamma[j]-epevent.t_e;
// getBapd4DeltaT(index)->Fill(delta_t);
// if(delta_t>windows[1][1] && delta_t<=windows[1][2]){
// getBapd4OnPeak(index)->Fill(epevent.E_gamma[j]);
// epg_ep_bapd4[index]+=Quantity(1,1);
// }else if(delta_t>windows[1][0] && delta_t<=windows[1][3]){
// getBapd4OffPeak(index)->Fill(epevent.E_gamma[j]);
// epg_ep_bapd4[index]-=Quantity(bapd_scale,bapd_scale);
// }
//}
}
}
}
}
if(multi_missmatch>0){
avg_missmatch/=multi_missmatch;
cout<<"Multiplicity missmatches: "<<multi_missmatch<<endl;
cout<<"Average missmatch: "<<avg_missmatch<<endl;
}
Quantity ep_total=0;
for(Int_t i=0;i<12;i++){
ep_total+=ep_bgo[i];
if(ep_bgo[i].getValue()>0){
Double_t scale=EPSCALE?1/ep_bgo[i].getValue():1;
getBgoOnPeak(i)->Scale(scale);
getBgoOffPeak(i)->Scale(scale);
getBgoDeltaT(i)->Scale(scale);
getBgoFinal(i)->Add(getBgoOnPeak(i),getBgoOffPeak(i),1,bgo_scale);
}
}
for(Int_t i=0;i<12;i++){
getBgoOnPeak(12)->Add(getBgoOnPeak(i),(ep_bgo[i]/ep_total).getValue());
getBgoOffPeak(12)->Add(getBgoOffPeak(i),(ep_bgo[i]/ep_total).getValue());
getBgoDeltaT(12)->Add(getBgoDeltaT(i),(ep_bgo[i]/ep_total).getValue());
epg_ep_bgo[12]+=epg_ep_bgo[i];
epg_ep_bgo[i]/=ep_bgo[i];
}
epg_ep_bgo[12]/=ep_total;
getBgoFinal(12)->Add(getBgoOnPeak(12),getBgoOffPeak(12),1,bgo_scale);
getBgoFinal(12)->Scale(12);
ep_total=0;
for(Int_t i=0;i<3;i++){
ep_total+=ep_bapd3[i];
Double_t scale=EPSCALE?1/ep_bapd3[i].getValue():1;
getBapd3OnPeak(i)->Scale(scale);
getBapd3OffPeak(i)->Scale(scale);
getBapd3DeltaT(i)->Scale(scale);
getBapd3Final(i)->Add(getBapd3OnPeak(i),getBapd3OffPeak(i),1,bapd_scale);
}
for(Int_t i=0;i<3;i++){
Double_t scale=(ep_bapd3[i]/ep_total).getValue(); //Weighted sum
//Double_t scale=1; //Non weighted sum
getBapd3OnPeak(3)->Add(getBapd3OnPeak(i),scale);
getBapd3OffPeak(3)->Add(getBapd3OffPeak(i),scale);
getBapd3DeltaT(3)->Add(getBapd3DeltaT(i),scale);
epg_ep_bapd3[3]+=epg_ep_bapd3[i];
epg_ep_bapd3[i]/=ep_bapd3[i];
}
epg_ep_bapd3[3]/=ep_total;
getBapd3Final(3)->Add(getBapd3OnPeak(3),getBapd3OffPeak(3),1,bapd_scale);
getBapd3Final(3)->Scale(3);
ep_total=0;
for(Int_t i=0;i<4;i++){
ep_total+=ep_bapd4[i];
Double_t scale=EPSCALE?1/ep_bapd4[i].getValue():1;
getBapd4OnPeak(i)->Scale(scale);
getBapd4OffPeak(i)->Scale(scale);
getBapd4Final(i)->Add(getBapd4OnPeak(i),getBapd4OffPeak(i),1,bapd_scale);
}
for(Int_t i=0;i<4;i++){
getBapd4OnPeak(4)->Add(getBapd4OnPeak(i),(ep_bapd4[i]/ep_total).getValue());
getBapd4OffPeak(4)->Add(getBapd4OffPeak(i),(ep_bapd4[i]/ep_total).getValue());
getBapd4DeltaT(4)->Add(getBapd4DeltaT(i),(ep_bapd4[i]/ep_total).getValue());
epg_ep_bapd4[4]+=epg_ep_bapd4[i];
epg_ep_bapd4[i]/=ep_bapd4[i];
}
epg_ep_bapd4[4]/=ep_total;
getBapd4Final(4)->Add(getBapd4OnPeak(4),getBapd4OffPeak(4),1,bapd_scale);
getBapd4Final(4)->Scale(4);
Double_t scale=EPSCALE?1/ep.getValue():1;
sbd_E_e->Scale(scale);
sbd_E_p->Scale(scale);
sbd_tof->Scale(scale);
sbd_E_q->Scale(scale);
sbd_q_tof->Scale(scale);
}
示例9: if
QString UnitsSchemaImperial1::schemaTranslate(const Quantity &quant, double &factor, QString &unitString)
{
double UnitValue = std::abs(quant.getValue());
Unit unit = quant.getUnit();
// for imperial user/programmer mind; UnitValue is in internal system, that means
// mm/kg/s. And all combined units have to be calculated from there!
// now do special treatment on all cases seems necessary:
if (unit == Unit::Length) { // Length handling ============================
if (UnitValue < 0.00000254) {// smaller then 0.001 thou -> inch and scientific notation
unitString = QString::fromLatin1("in");
factor = 25.4;
}
else if(UnitValue < 2.54) { // smaller then 0.1 inch -> Thou (mil)
unitString = QString::fromLatin1("thou");
factor = 0.0254;
}
else if(UnitValue < 304.8) {
unitString = QString::fromLatin1("\"");
factor = 25.4;
}
else if(UnitValue < 914.4) {
unitString = QString::fromLatin1("\'");
factor = 304.8;
}
else if(UnitValue < 1609344.0) {
unitString = QString::fromLatin1("yd");
factor = 914.4;
}
else if(UnitValue < 1609344000.0) {
unitString = QString::fromLatin1("mi");
factor = 1609344.0;
}
else { // bigger then 1000 mi -> scientific notation
unitString = QString::fromLatin1("in");
factor = 25.4;
}
}
else if (unit == Unit::Area) {
// TODO Cascade for the Areas
// default action for all cases without special treatment:
unitString = QString::fromLatin1("in^2");
factor = 645.16;
}
else if (unit == Unit::Volume) {
// TODO Cascade for the Volume
// default action for all cases without special treatment:
unitString = QString::fromLatin1("in^3");
factor = 16387.064;
}
else if (unit == Unit::Mass) {
// TODO Cascade for the weights
// default action for all cases without special treatment:
unitString = QString::fromLatin1("lb");
factor = 0.45359237;
}
else if (unit == Unit::Pressure) {
if (UnitValue < 6894.744) {// psi is the smallest
unitString = QString::fromLatin1("psi");
factor = 6.894744825494;
}
else if (UnitValue < 6894744.825) {
unitString = QString::fromLatin1("ksi");
factor = 6894.744825494;
}
else { // bigger then 1000 ksi -> psi + scientific notation
unitString = QString::fromLatin1("psi");
factor = 6.894744825494;
}
}
else if (unit == Unit::Velocity) {
unitString = QString::fromLatin1("in/min");
factor = 25.4/60;
}
else {
// default action for all cases without special treatment:
unitString = quant.getUnit().getString();
factor = 1.0;
}
return toLocale(quant, factor, unitString);
}
示例10: schemaTranslate
QString UnitsSchemaImperialBuilding::schemaTranslate(const Quantity &quant, double &factor, QString &unitString)
{
// this schema expresses distances in feet + inches + fractions
// ex: 3'- 4 1/4" with proper rounding
Unit unit = quant.getUnit();
if (unit == Unit::Length) {
unitString = QString::fromLatin1("in");
factor = 25.4;
// Total number of inches to format
double totalInches = std::abs(quant.getValue())/factor;
// minimum denominator (8 for 1/8, 16 for 1/16, etc)
int minden;
// Outputs
int feet; // whole feet
int inches; // whole inches
int num,den; // numerator and denominator of fractional val
std::stringstream output; // output stream
// Intermediate values
int ntot; // total fractional units
int a,b,d; // used to compute greatest common denominator
int tmp; // temporary variable for GCD
// Get the current user specified minimum denominator
minden = quant.getFormat().getDenominator();
// Compute and round the total number of fractional units
ntot = (int)std::round(totalInches * (double)minden);
// If this is zero, nothing to do but return
if( ntot==0 )
return QString::fromLatin1("0");
// Compute the whole number of feet and remaining units
feet = (int)std::floor(ntot / (12*minden));
ntot = ntot - 12*minden*feet;
// Compute the remaining number of whole inches
inches = (int)std::floor(ntot/minden);
// Lastly the fractional quantities
num = ntot - inches*minden;
den = minden;
// If numerator is not zero, compute greatest common divisor and reduce
// fraction
if( num!=0 )
{
// initialize
a = num;
b = den;
while (b != 0)
{
tmp = a % b;
a = b;
b = tmp;
}
d = a;
num /= d;
den /= d;
}
// Process into string. Start with negative sign if quantity is less
// than zero
if( quant.getValue() < 0 )
output << "-";
// Print feet if we have any
if( feet!=0 )
{
output << feet << "'";
// if there is to be trailing numbers, add space
if( inches!=0 || num!=0 )
{
output << " ";
}
}
// Three cases:
// 1. Whole inches, no fraction
// 2. Whole inches, fraction
// 3. Fraction only
if( inches>0 && num==0 ) // case 1.
{
output << inches << "\"";
}
else if( inches>0 && num!=0 ) // case 2
{
output << inches << "+" << num << "/" << den << "\"";
}
else if( inches==0 && num!=0 ) // case 3
{
output << num << "/" << den << "\"";
}
//.........这里部分代码省略.........