Example #1
2
//written to get yaw data
void Communication::getAngle(int sensor, int dir){
    // dir: 0=x, 1=y, 2=z
    cout << "in getAngle" << endl;
    stringstream ss;
    if(q.size() != 0)
    q.pop();
    cout<<"before while"<<endl;
    while(q.front() != 'z'){ // 'z' is the end packet footer
        if(q.size() == 0)
            return;
        ss<<q.front();
        if(q.size()!=0)
        q.pop();
        cout<<q.size()<<endl;
        if(q.size() == 0)
            return;
    }
    cout<<"after while"<<endl;

    if(q.size()!=0)
        q.pop();

    // stringstream to float conversion - convoluded but actually easiest to go ss->QStr->float
    float in = 0.0;
    QString QStr = QString::fromStdString(ss.str());
    in = QStr.toFloat();
    if(sensor==1)
    {
        cout << "dir:" <<endl;
        cout << dir << endl;
        if(dir==1)
        {
            k1.setX(in);
            cout << "set x" << endl;
            cout << k1.getX() << endl;
        }
        else if(dir==2)
        {
            cout<<"set y"<<endl;
            k1.setY(in);
        }
        else
        {
            cout<<"set z"<<endl;
            k1.setZ(in);
        }
    }
    else if(sensor==2)
    {
        if(dir==1)
            k2.setX(in);
        else if(dir==2)
            k2.setY(in);
        else
            k2.setZ(in);
    }
    cout<<"out angleOut"<<endl;
}
Example #2
2
void MainWindow::readIperfOutput(){
    qDebug()<<"reading tp output:";
    QString tpOutput = iperf->readAllStandardOutput();
    qDebug()<<tpOutput;
    float tp=0;
    if(ui->protocolField->currentIndex()==0){ //tcp test
        if(tpOutput.indexOf("Bandwidth")!=-1){
            QStringList tokens = tpOutput.split(" ");
            for(int i=0;i<tokens.size();i++){
                if(tokens.at(i).contains("/sec")){
                    ui->tpLine->setText(tokens.at(i-1)+" "+tokens.at(i));
                    tp = tokens.at(i-1).toFloat();
                }
            }

            tpVector.append(tp);
        }
    }else{ //udp test
        if(tpOutput.indexOf("Server Report:")!=-1){
            QStringList tokens = tpOutput.split(" ");
            //14 is TP
            //15 is TP unit
            //18 is Jitter
            //19 is Jitter unit
            //lost/send DG 21,22
            for(int i=0;i<tokens.size();i++){
                if(tokens.at(i).contains("/sec")){
                    tp = tokens.at(i-1).toFloat();
                    tpVector.append(tp);
                    ui->tpLine->setText(tokens.at(i-1)+" "+tokens.at(i));
                }if(tokens.at(i).contains("ms")&&(!tokens.at(i).contains("datagrams"))){
                    ui->jitterLine->setText(tokens.at(i-1)+" "+tokens.at(i));
                }
                if(tokens.at(i).contains("%")){
                    QString aux;
                    aux =tokens.at(i-2);
                    aux.chop(1);
                    float lost = aux.toFloat();
                    std::cout<<aux.toStdString()<<"lost"<<std::endl;
                    float sent = tokens.at(i-1).toFloat();
                    float percentage;
                    if(sent=!0){
                        percentage = lost/sent;
                    }else{
                        percentage = 100.0;
                    }
                    std::cout<<tokens.at(i-1).toStdString()<<"sent"<<std::endl;
                    ui->datagramLossLine->setText(tokens.at(i-2)+tokens.at(i-1)+"  ("+QString::number(percentage,'f',2)+"%)");
                }
            }

        }
    }
    if(tp>maxTp){
        maxTp=tp;
    }
}
Example #3
1
void adjustparameter::ReadConfigSetting()//读出ini里参数
{
    QSettings settings(IniAddr,QSettings::IniFormat);
    QString AlarmValue = settings.value("AlarmPar/AlarmValue").toString();
    QString ControlValue = settings.value("AlarmPar/ControlValue").toString();
    QString ControlDelay = settings.value("AlarmPar/ControlDelay").toString();
    QString InstantValue = settings.value("AlarmPar/InstantValue").toString();
    QString InstantDelay = settings.value("AlarmPar/InstantDelay").toString();
    QString SlowValue = settings.value("AlarmPar/SlowValue").toString();
    QString SlowDelay = settings.value("AlarmPar/SlowDelay").toString();

    mAllInputPar.AlarmValue = AlarmValue.toFloat();
    mAllInputPar.ControlValue = ControlValue.toFloat();
    mAllInputPar.ControlDelay = ControlDelay.toFloat();
    mAllInputPar.InstantValue = InstantValue.toFloat();
    mAllInputPar.InstantDelay = InstantDelay.toFloat();
    mAllInputPar.SlowValue = SlowValue.toFloat();
    mAllInputPar.SlowDelay = SlowDelay.toFloat();

    ui->AlarmValue->setText(AlarmValue);
    ui->ControlValue->setText(ControlValue);
    ui->ControlDelay->setText(ControlDelay);
    ui->InstantValue->setText(InstantValue);
    ui->InstantDelay->setText(InstantDelay);
    ui->SlowValue->setText(SlowValue);
    ui->SlowDelay->setText(SlowDelay);

}
bool MDSParameterExplorerTabWidget::isCastable(QString parameter,
                                               QString property)
{
    QString parameterValue = queryDatabase(parameter,property);

    bool ok;
    parameterValue.toFloat(&ok);
    return ok;
}
void SeExprEdNumberControl::editChanged(int id,const QString& text)
{
    Q_UNUSED(id);
    if (_updating) return;
    bool ok = 0;
    float val = text.toFloat(&ok);
    if (!ok) return;
    setValue(val);
}
Example #6
0
void FloatParameter::setValue(const QString& value)
{
    bool isOk = true;
    float floatValue = value.toFloat(&isOk);
    if (isOk)
    {
        m_value = floatValue;
    }
}
void MainWindow::changeItemRadius(QString rad)
{
    if(activeLevelObject == NULL)
        return;
    bool worked;
    rad.toFloat(&worked);
    if(worked)
        /* */;
}
void VideoConverter::getCurrentTimeConversion(QString strFrame)
{
	// get the current progress
	float time = strFrame.toFloat();

	videoItem->setProgress(calculePercent(time, videoLength), this);

	emit videoItemUpdated(videoItem);
}
Example #9
0
bool QtnPropertyFloatBase::fromStrImpl(const QString& str)
{
    bool ok = false;
    ValueType value = str.toFloat(&ok);
    if (!ok)
        return false;

    return setValue(value);
}
Example #10
0
// adds the converted version of the scale value if it is a valid, non-negative float
static void maybeAddPeak( const TagLib::String &scaleVal, Meta::ReplayGainTag key, Meta::ReplayGainTagMap *map )
{
    // scale value is >= 0, and typically not much bigger than 1
    QString value = TStringToQString( scaleVal );
    bool ok = false;
    qreal peak = value.toFloat( &ok );
    if ( ok && peak >= 0 )
        (*map)[key] = peakToDecibels( peak );
}
Example #11
0
void FloatDataRef::setValue(QString &newValue) {
    bool ok = false;
    float value = newValue.toFloat(&ok);
    if(ok) {
        setValue(value);
    } else {
        INFO << "Cannot set value " << newValue;
    }
}
Example #12
0
void OsmAnd::RoutingProfile::addAttribute( const QString& key, const QString& value )
{
    _attributes.insert(key, value);

    if(key == "restrictionsAware")
    {
        _restrictionsAware = Utilities::parseArbitraryBool(value, _restrictionsAware);
    }
    else if(key == "leftTurn")
    {
        bool ok;
        auto parsed = value.toFloat(&ok);
        if(ok)
            _leftTurn = parsed;
    }
    else if(key == "rightTurn")
    {
        bool ok;
        auto parsed = value.toFloat(&ok);
        if(ok)
            _rightTurn = parsed;
    }
    else if(key == "roundaboutTurn")
    {
        bool ok;
        auto parsed = value.toFloat(&ok);
        if(ok)
            _roundaboutTurn = parsed;
    }
    else if(key == "minDefaultSpeed")
    {
        bool ok;
        auto parsed = value.toFloat(&ok);
        if(ok)
            _minDefaultSpeed = parsed / 3.6f;
    }
    else if(key == "maxDefaultSpeed")
    {
        bool ok;
        auto parsed = value.toFloat(&ok);
        if(ok)
            _maxDefaultSpeed = parsed / 3.6f;
    }
}
/**
  /brief Extract the oembed infos from the XML
  @param xmlUrl as the url of the XML file
  */
sOEmbedContent UBOEmbedParser::getXMLInfos(const QString &xml)
{
    sOEmbedContent content;

    QDomDocument domDoc;
    domDoc.setContent(xml);
    QDomNode oembed = domDoc.documentElement();

    QDomNodeList children = oembed.toElement().childNodes();

    for(int i=0; i<children.size(); i++) {
        QDomNode node = children.at(i);
        QString tag = node.nodeName();
        QString value = node.toElement().text();
        if("provider_url" == tag) {
            content.providerUrl = value;
        } else if("title" == tag) {
            content.title = value;
        } else if("html" == tag) {
            content.html = value;
        } else if("author_name" == tag) {
            content.author = value;
        } else if("height" == tag) {
            content.height = value.toInt();
        } else if("thumbnail_width" == tag) {
            content.thumbWidth = value.toInt();
        } else if("width" == tag) {
            content.width = value.toInt();
        } else if("version" == tag) {
            content.version = value.toFloat();
        } else if("author_url" == tag) {
            content.authorUrl = value;
        } else if("provider_name" == tag) {
            content.providerName = value;
        } else if("thumbnail_url" == tag) {
            content.thumbUrl = value;
        } else if("type" == tag) {
            content.type = value;
        } else if("thumbnail_height" == tag) {
            content.thumbHeight = value.toInt();
        } else if("url" == tag) {
            content.url = value; // This case appears only for type = photo
        }
    }

    if("video" == content.type) {
        QStringList strl = content.html.split('\"');
        for(int i=0; i<strl.size(); i++) {
            if(strl.at(i).endsWith("src=") && strl.size() > (i+1)) {
                content.url = strl.at(i+1);
            }
        }
    }

    return content;
}
Example #14
0
void THERM::setIndicatorSettings (Setting &dict)
{
  setDefaults();
  
  if (! dict.count())
    return;
  
  QString s;
  dict.getData(upColorLabel, s);
  if (s.length())
    upColor.setNamedColor(s);
    
  dict.getData(downColorLabel, s);
  if (s.length())
    downColor.setNamedColor(s);
  
  dict.getData(threshColorLabel, s);
  if (s.length())
    threshColor.setNamedColor(s);
  
  dict.getData(maColorLabel, s);
  if (s.length())
    maColor.setNamedColor(s);
    
  dict.getData(labelLabel, s);
  if (s.length())
    label = s;
    
  dict.getData(thresholdLabel, s);
  if (s.length())
    threshold = s.toFloat();
  
  dict.getData(smoothingLabel, s);
  if (s.length())
    smoothing = s.toInt();
  
  dict.getData(smoothTypeLabel, s);
  if (s.length())
    smoothType = s.toInt();
  
  dict.getData(maLineTypeLabel, s);
  if (s.length())
    maLineType = (PlotLine::LineType) s.toInt();

  dict.getData(maLabelLabel, s);
  if (s.length())
    maLabel = s;
    
  dict.getData(maPeriodLabel, s);
  if (s.length())
    maPeriod = s.toInt();

  dict.getData(maTypeLabel, s);
  if (s.length())
    maType = s.toInt();
}
/*!
 * \brief AbstractAnimationWindow::setSpeedUpSlotFunction
 * slot function to set the user input speed up
 */
void AbstractAnimationWindow::setSpeedSlotFunction()
{
  QString str = mpSpeedComboBox->lineEdit()->text();
  bool isFloat = true;
  double value = str.toFloat(&isFloat);
  if (isFloat && value > 0.0) {
    mpVisualizer->getTimeManager()->setSpeedUp(value);
    mpViewerWidget->update();
  }
}
QVariant FloatTransformer::read(QString _value)
{
	bool ok = false;
	float number = _value.toFloat(&ok);
	if(!ok)
	{
		throw QString("Can not convert value %1 to float").arg(_value);
	}
	return number;
}
Example #17
0
void TestPage::Estimate()
{
    QString bidtotal = ui->labelTotal_2->text(); 
    float bidz = bidtotal.toFloat();
    float mybid = ui->lineEditBid->text().toFloat();
    float newtotal = bidz + mybid;
    float mybcr = (mybid / newtotal) * 30000;
    QString mybcrz = QString::number(mybcr);
    ui->labelBCR->setText("<b>" + mybcrz + "</b> BCR");   
}
Example #18
0
NativeEventList::NativeEventList(int defaultWaitMs)
    : playbackMultiplier(1.0)
    , currIndex(-1)
    , wait(false)
    , defaultWaitMs(defaultWaitMs)
{
    QString multiplier = qgetenv("NATIVEDEBUG");
    if (!multiplier.isEmpty())
        setTimeMultiplier(multiplier.toFloat());
}
Example #19
0
QPoint *SdfRenderer::getpoints(QDomElement &element, int n)
{
	QPoint *array = new QPoint[n];
	float x = 0;
	float y = 0;
	for (int i = 0; i < n; i++)
	{
		QString str;
		str.setNum(i + 1);
		QDomElement elem = element;
		QString xnum = elem.attribute(QString("x").append(str));
		if (xnum.endsWith("%"))
		{
			xnum.chop(1);
			x = current_size_x * xnum.toFloat() / 100 + mStartX;
		}
		else if (xnum.endsWith("a") && mNeedScale)
		{
			xnum.chop(1);
			x = xnum.toFloat() + mStartX;
		}
		else if (xnum.endsWith("a") && !mNeedScale)
		{
			xnum.chop(1);
			x = xnum.toFloat() * current_size_x / first_size_x + mStartX;
		}
		else
			x = xnum.toFloat() * current_size_x / first_size_x + mStartX;

		QString ynum = elem.attribute(QString("y").append(str));
		if (ynum.endsWith("%"))
		{
			ynum.chop(1);
			y = current_size_y * ynum.toFloat() / 100 + mStartY;
		}
		else if (ynum.endsWith("a") && mNeedScale)
		{
			ynum.chop(1);
			y = ynum.toFloat() + mStartY;
		}
		else if (ynum.endsWith("a") && !mNeedScale)
		{
			ynum.chop(1);
			y = ynum.toFloat() * current_size_y / first_size_y + mStartY;
		}
		else
			y = ynum.toFloat() * current_size_y / first_size_y + mStartY;

		array[i].setX(static_cast<int>(x));
		array[i].setY(static_cast<int>(y));
	}
	return array;
}
Example #20
0
void SoundSource::parseReplayGainString (QString sReplayGain) {
    QString ReplayGainstring = sReplayGain.remove( " dB" );
    float fReplayGain = pow(10,(ReplayGainstring.toFloat())/20);
    //I found some mp3s of mine with replaygain tag set to 0dB even if not normalized.
    //This is because of Rapid Evolution 3, I suppose. I prefer to rescan them by setting value to 0 (i.e. rescan via analyserrg)
    if(fReplayGain==1.0f){
        fReplayGain= 0.0f;
    }
    setReplayGain(fReplayGain);
}
Example #21
0
void Param::set(QString value)
{
	if (this->type == ParamInt) {
		return setInt(value.toInt());
	} else if (this->type == ParamFloat) {
		return setFloat(value.toFloat());
	} else {
		strValue = value;
	}
}
Example #22
0
void points_loader::create_point( QStringList obsrv_tokens, QStringList points_tokens ){


    //  Create the point.
    //
    model_point point;

    //  Get the point's class.
    //
    //  The database won't accept '-'.
    //
    {
        QString s = obsrv_tokens.back();
        s.replace( "-", "_" );
        point._attribute_class = s;
    }

    //  Get the point's class values.
    //
    //  The database won't accept '-'.
    //
    for( int ii=0; ii<obsrv_tokens.size() - 1; ii++ )
    {
        QString s = obsrv_tokens.at(ii);
        s.replace( "-", "_" );
        point._attribute_values.push_back( s );
    }

    //  Get the point's x,y coordinates.
    //
    QString x = points_tokens.front();
    QString y = points_tokens.back();
    point._position.setX( x.toFloat() );
    point._position.setY( y.toFloat() );

    //  Get the point's probability values.
    //

    //  Save.
    //
    _temp_points.push_back( point );
}
void tst_QAndroidJniObject::callStaticFloatMethodClassName()
{
    QString number = QString::number(123.45);
    QAndroidJniObject parameter = QAndroidJniObject::fromString(number);

    jfloat returnValue = QAndroidJniObject::callStaticMethod<jfloat>("java/lang/Float",
                                                          "parseFloat",
                                                          "(Ljava/lang/String;)F",
                                                          parameter.object<jstring>());
    QCOMPARE(returnValue, number.toFloat());
}
Example #24
0
QVariant File::parse(const QString &value)
{
    bool ok = false;
    const QPointF point = QtUtils::toPoint(value, &ok);
    if (ok) return point;
    const QRectF rect = QtUtils::toRect(value, &ok);
    if (ok) return rect;
    const float f = value.toFloat(&ok);
    if (ok) return f;
    return value;
}
Example #25
0
float QtCommonString::FromString(const QString& s, const float& fDefault, bool *ok){
    if (s.length()<=0)
        return fDefault;
    bool b;
    float v = s.toFloat(&b);
    if ( ok ) *ok = b;
    if (b)
        return v;
    else
        return fDefault;
}
void toResultViewCheck::setText(int col, const QString &txt)
{
    if (txt != text(col))
    {
        if (col >= ColumnCount || !ColumnData)
        {
            int ns = (col + ALLOC_SIZE) / ALLOC_SIZE * ALLOC_SIZE;
            keyData *nd = new keyData[ns];
            int i;
            for (i = 0; i < ColumnCount; i++)
                nd[i] = ColumnData[i];
            while (i < ns)
            {
                nd[i].Width = 0;
                nd[i].Type = keyData::String;
                i++;
            }
            delete[] ColumnData;
            ColumnData = nd;
            ColumnCount = ns;
        }

        static QRegExp number(QString::fromLatin1("^\\d*\\.?\\d+E?-?\\d*.?.?$"));

        ColumnData[col].Data = txt;

        if (txt == "N/A")
        {
            ColumnData[col].Type = keyData::String;
            ColumnData[col].KeyAsc = "\xff";
            ColumnData[col].KeyDesc = "\x00";
        }
// qt4        else if (number.match(txt) >= 0)
        else if (number.indexIn(txt) >= 0)
        {
            ColumnData[col].Type = keyData::Number;

            static char buf[100];
            double val = txt.toFloat();
            if (val < 0)
                sprintf(buf, "\x01%015.5f", val);
            else
                sprintf(buf, "%015.5f", val);
            ColumnData[col].KeyAsc = ColumnData[col].KeyDesc = QString::fromLatin1(buf);
        }
        else
        {
            ColumnData[col].Type = keyData::String;
            ColumnData[col].KeyAsc = ColumnData[col].KeyDesc = ColumnData[col].Data;
        }
        ColumnData[col].Width = realWidth(listView()->fontMetrics(), listView(), col, txt);
    }
    toTreeWidgetCheck::setText(col, firstText(col));
}
Example #27
0
QString AttrTypeInductance::printableValueTr(const QString& value, const AttributeUnit* unit) const noexcept
{
    bool ok = false;
    float v = value.toFloat(&ok);
    if (ok && unit)
        return QString(tr("%1%2")).arg(QLocale().toString(v), unit->getSymbolTr());
    else if (ok)
        return QLocale().toString(v);
    else
        return QString();
}
Example #28
0
void BookmarkManager::slotShowMarked(void)
{
    if (GetMarkedCount() == 0)
        return;

    MythUIButtonListItem *item = m_bookmarkList->GetItemCurrent();
    if (item && item->GetData().isValid())
    {
       Bookmark *site = qVariantValue<Bookmark*>(item->GetData());
       m_savedBookmark = *site;
    }

    QString cmd = gCoreContext->GetSetting("WebBrowserCommand", "Internal");
    QString zoom = gCoreContext->GetSetting("WebBrowserZoomLevel", "1.4");
    QStringList urls;

    for (int x = 0; x < m_siteList.size(); x++)
    {
        Bookmark *site = m_siteList.at(x);
        if (site && site->selected)
            urls.append(site->url);
    }

    if (cmd.toLower() == "internal")
    {
        MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();

        MythBrowser *mythbrowser = new MythBrowser(mainStack, urls, zoom.toFloat());

        if (mythbrowser->Create())
        {
            connect(mythbrowser, SIGNAL(Exiting()), SLOT(slotBrowserClosed()));
            mainStack->AddScreen(mythbrowser);
        }
        else
            delete mythbrowser;
    }
    else
    {
        cmd.replace("%ZOOM%", zoom);
        cmd.replace("%URL%", urls.join(" "));

        cmd.replace("&","\\&");
        cmd.replace(";","\\;");

        GetMythMainWindow()->AllowInput(false);
        myth_system(cmd, kMSDontDisableDrawing);
        GetMythMainWindow()->AllowInput(true);

        // we need to reload the bookmarks incase the user added/deleted
        // any while in MythBrowser
        ReloadBookmarks();
    }
}
Example #29
0
//-----------------------------------------------------------------------------
//! This method returns a calibrated (or at least nominally adjusted to make sense) voltage
//-----------------------------------------------------------------------------
bool tIMX51Common::ReadInternalVoltage(float &value)
{
    int adcVoltVal;
    int adcStatus = ReadAdc( GEN_PURPOSE_AD6, adcVoltVal );

    // Stingray2 (and Atlantis 8", 10"):
    //  BATTERY_AD is divided 8.66k/(8.66k+3*33k)
    //  Vbat = Adc_Ch11 * 2.4/1024/8.66*107.66
    //  Vbat ~= Adc_Ch11 * 0.029137
    // Atlantis (5", 7"):
    //  BATTERY_AD is divided 8.66k/(8.66k+100k)
    //  Vbat = Adc_Ch11 * 2.4/1024/8.66*108.66
    //  Vbat ~= Adc_Ch11 * 0.028867
    // Cougar:
    //  BATTERY_AD is divided 9.1k/(9.1k+100k)
    //  Vbat = Adc_Ch11 * 2.4/1024/9.1*109.1
    //  Vbat ~= Adc_Ch11 * 0.028099

    // There may be a stored calibrated multiplier which, if present and
    // within accepted limits, we use it in place of the calculated one
    if ( adcStatus == EXIT_SUCCESS )
    {
        static bool firstTime = true;

        if( firstTime )
        {
            const char *batt_cal_file = "/etc/NOS/battery_cal";
            QFile f( batt_cal_file );
            if ( f.open( QIODevice::ReadOnly ) )
            {
                QTextStream stream(&f);
                QString s;
                s = stream.readLine();
                f.close();

                float minGoodCalValue = m_adcMultiplier * 0.94f;
                float maxGoodCalValue = m_adcMultiplier * 1.06f;
                bool isNumeric = false;
                float calVal = s.toFloat( &isNumeric );
                calVal /= 1000.0f; // Cal val stored relative to mV
                if ( isNumeric && ( minGoodCalValue <= calVal && calVal <= maxGoodCalValue ) )
                {
                    m_adcMultiplier = calVal;
                }
            }
            firstTime = false;
        }

        value = static_cast<float>( adcVoltVal ) * m_adcMultiplier;
        return true;
    }

    return false;
}
Example #30
0
void BidPage::Estimate()
{
    QString bidtotal = ui->labelTotal_2->text();
    float bidz = bidtotal.toFloat();
    float mybid = ui->lineEditBid->text().toFloat();
    float newtotal = bidz + mybid;
    float mybcr = (mybid / newtotal) * 31500;
    QString mybcrz = QString::number(mybcr);
    float cost = mybid / mybcr;
    QString coststr = QString::number(cost, 'f', 8);
    ui->labelBCR->setText("<b>" + mybcrz + "</b> BCR @ " + "<b>" + coststr + "</b>");
}