本文整理汇总了C++中QVariant::toFloat方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::toFloat方法的具体用法?C++ QVariant::toFloat怎么用?C++ QVariant::toFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::toFloat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setData
void HumanListModel::setData(const long id, const QVariant &value, int role)
{
switch (role)
{
case Human::ProfessionRole:
{
Human * item = (Human *)find( id );
item->setProfession(value.toString());
break;
}
case Human::MoraleRole:
{
Human * item = (Human *)find( id );
item->setMorale(value.toFloat());
break;
}
case Human::FatigueRole:
{
Human * item = (Human *)find( id );
item->setFatigue(value.toFloat());
break;
}
case Human::HungerRole:
{
Human * item = (Human *)find( id );
item->setHunger(value.toFloat());
break;
}
default:
qWarning() << "HumanListModel::setData does not understand what role" << role << "is.";
break;
}
}
示例2: setValue
void RenderingItem::setValue(QVariant new_value)
{
if(value == new_value)
return;
value = new_value;
if(!GUI)
return;
if(QString(GUI->metaObject()->className()) == "QSlider")
{
QSlider *slider = (QSlider*)GUI;
if(slider->maximum() == 10) // int
slider->setValue(new_value.toInt());
else
slider->setValue(new_value.toFloat()*5.0);
}
if(QString(GUI->metaObject()->className()) == "QColorToolButton")
{
((QColorToolButton*)GUI)->setColor(new_value.toInt());
}
if(QString(GUI->metaObject()->className()) == "QDoubleSpinBox")
{
((QDoubleSpinBox*)GUI)->setValue(new_value.toFloat());
}
if(QString(GUI->metaObject()->className()) == "QSpinBox")
{
((QSpinBox*)GUI)->setValue(new_value.toInt());
}
if(QString(GUI->metaObject()->className()) == "QComboBox")
{
((QComboBox*)GUI)->setCurrentIndex(new_value.toInt());
}
}
示例3: setData
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool SGLogNormalTableModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
// qDebug() << "SGLogNormalTableModel::setData " << value.toString() << "\n";
if (!index.isValid() || role != Qt::EditRole || index.row() < 0 || index.row() >= m_BinNumbers.count() || index.column() < 0 || index.column()
>= m_ColumnCount)
{
return false;
}
bool ok;
qint32 row = index.row();
qint32 col = index.column();
switch(col)
{
case BinNumber:
m_BinNumbers[row] = value.toFloat(&ok);
break;
case Average:
m_Average[row] = value.toFloat(&ok);
break;
case StdDev:
m_StdDev[row] = value.toFloat(&ok);
break;
case LineColor:
m_Colors[row] = value.toString();
break;
default:
Q_ASSERT(false);
}
emit
dataChanged(index, index);
return true;
}
示例4: setData
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool SGBetaTableModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
// std::cout << "SGBetaTableModel::setData " << value.toString().toStdString() << std::endl;
if (!index.isValid() || role != Qt::EditRole || index.row() < 0 || index.row() >= m_BinNumbers.count() || index.column() < 0 || index.column()
>= m_ColumnCount)
{
return false;
}
bool ok;
qint32 row = index.row();
qint32 col = index.column();
switch(col)
{
case BinNumber:
m_BinNumbers[row] = value.toFloat(&ok);
break;
case Alpha:
m_Alpha[row] = value.toFloat(&ok);
break;
case Beta:
m_Beta[row] = value.toFloat(&ok);
break;
case LineColor:
m_Colors[row] = value.toString();
break;
default:
Q_ASSERT(false);
}
emit
dataChanged(index, index);
return true;
}
示例5: setData
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool SGMDFTableModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
// qDebug() << "SGMDFTableModel::setData " << value.toString() << "\n";
if (!index.isValid() || role != Qt::EditRole || index.row() < 0 || index.row() >= m_Angles.count() || index.column() < 0 || index.column()
>= m_ColumnCount)
{
return false;
}
bool ok;
qint32 row = index.row();
qint32 col = index.column();
switch(col)
{
case Angle:
m_Angles[row] = value.toFloat(&ok);
break;
case Axis:
m_Axis[row] = value.toString();
break;
case Weight:
m_Weights[row] = value.toFloat(&ok);
break;
default:
Q_ASSERT(false);
}
emit dataChanged(index, index);
return true;
}
示例6: if
bool
APETagHelper::setTags( const Meta::FieldHash &changes )
{
bool modified = TagHelper::setTags( changes );
foreach( const qint64 key, changes.keys() )
{
QVariant value = changes.value( key );
TagLib::String field = fieldName( key );
if( !field.isNull() && !field.isEmpty() )
{
if( key == Meta::valRating )
m_tag->addValue( field, Qt4QStringToTString( QString::number( value.toFloat() / 10.0 ) ) );
else if( key == Meta::valScore )
m_tag->addValue( field, Qt4QStringToTString( QString::number( value.toFloat() / 100.0 ) ) );
else
m_tag->addValue( field, Qt4QStringToTString( value.toString() ) );
modified = true;
}
else if( key == Meta::valUniqueId )
{
QPair < UIDType, QString > uidPair = splitUID( value.toString() );
if( uidPair.first == UIDInvalid )
continue;
m_tag->addValue( uidFieldName( uidPair.first ), Qt4QStringToTString( uidPair.second ) );
modified = true;
}
}
return modified;
}
示例7: extractQuatArgument
glm::quat EntityActionInterface::extractQuatArgument(QString objectName, QVariantMap arguments,
QString argumentName, bool& ok, bool required) {
if (!arguments.contains(argumentName)) {
if (required) {
qDebug() << objectName << "requires argument:" << argumentName;
}
ok = false;
return glm::quat();
}
QVariant resultV = arguments[argumentName];
if (resultV.type() != (QVariant::Type) QMetaType::QVariantMap) {
qDebug() << objectName << "argument" << argumentName << "must be a map, not" << resultV.typeName();
ok = false;
return glm::quat();
}
QVariantMap resultVM = resultV.toMap();
if (!resultVM.contains("x") || !resultVM.contains("y") || !resultVM.contains("z") || !resultVM.contains("w")) {
qDebug() << objectName << "argument" << argumentName << "must be a map with keys: x, y, z, and w";
ok = false;
return glm::quat();
}
QVariant xV = resultVM["x"];
QVariant yV = resultVM["y"];
QVariant zV = resultVM["z"];
QVariant wV = resultVM["w"];
bool xOk = true;
bool yOk = true;
bool zOk = true;
bool wOk = true;
float x = xV.toFloat(&xOk);
float y = yV.toFloat(&yOk);
float z = zV.toFloat(&zOk);
float w = wV.toFloat(&wOk);
if (!xOk || !yOk || !zOk || !wOk) {
qDebug() << objectName << "argument" << argumentName
<< "must be a map with keys: x, y, z, and w of type float.";
ok = false;
return glm::quat();
}
if (x != x || y != y || z != z || w != w) {
// at least one of the components is NaN!
ok = false;
return glm::quat();
}
return glm::normalize(glm::quat(w, x, y, z));
}
示例8: switch
/*!
* Set an argument with the given index to the given value.
*
* @param index
* @param value
*/
void Similarity::Input::set(int index, const QVariant& value)
{
EDEBUG_FUNC(this,index,&value);
switch (index)
{
case ClusteringType:
_base->_clusMethod = static_cast<ClusteringMethod>(CLUSTERING_NAMES.indexOf(value.toString()));
break;
case CorrelationType:
_base->_corrMethod = static_cast<CorrelationMethod>(CORRELATION_NAMES.indexOf(value.toString()));
_base->_corrName = value.toString();
break;
case MinExpression:
_base->_minExpression = value.toFloat();
break;
case MinSamples:
_base->_minSamples = value.toInt();
break;
case MinClusters:
_base->_minClusters = value.toInt();
break;
case MaxClusters:
_base->_maxClusters = value.toInt();
break;
case CriterionType:
_base->_criterion = static_cast<Pairwise::Criterion>(CRITERION_NAMES.indexOf(value.toString()));
break;
case RemovePreOutliers:
_base->_removePreOutliers = value.toBool();
break;
case RemovePostOutliers:
_base->_removePostOutliers = value.toBool();
break;
case MinCorrelation:
_base->_minCorrelation = value.toFloat();
break;
case MaxCorrelation:
_base->_maxCorrelation = value.toFloat();
break;
case WorkBlockSize:
_base->_workBlockSize = value.toInt();
break;
case GlobalWorkSize:
_base->_globalWorkSize = value.toInt();
break;
case LocalWorkSize:
_base->_localWorkSize = value.toInt();
break;
}
}
示例9: setField
void MRecord::setField(int field, QVariant value)
{
switch (field) {
case MFieldGlobal::BRAKE:
Brake=value.toFloat();
break;
case MFieldGlobal::FUELCONSUMTION:
FuelConsumtion=value.toFloat();
break;
case MFieldGlobal::GAS:
Gas=value.toFloat();
break;
case MFieldGlobal::LATITUDE:
Latitude=value.toDouble();
break;
case MFieldGlobal::LIMITSPEED:
LimitSpeed=value.toFloat();
break;
case MFieldGlobal::LONGITUDE:
Longitude=value.toDouble();
break;
case MFieldGlobal::MAXENCODE:
MaxEncode=value.toFloat();
break;
case MFieldGlobal::ONOFF:
ONOFF=value.toInt();
break;
case MFieldGlobal::ROTASPEED:
RotaSpeed=value.toFloat();
break;
case MFieldGlobal::SPEED:
Speed=value.toFloat();
break;
case MFieldGlobal::STEERANGLE:
SteerAngel=value.toFloat();
break;
case MFieldGlobal::VALUE1:
Value1=value.toFloat();
break;
case MFieldGlobal::VALUE2:
Value2=value.toFloat();
break;
case MFieldGlobal::VALUE3:
Value3=value.toInt();
break;
default:
qDebug()<<"Value invalid in MRecord::setField!";
break;
}
}
示例10: qDebug
glm::vec3 EntityActionInterface::extractVec3Argument(QString objectName, QVariantMap arguments,
QString argumentName, bool& ok, bool required) {
if (!arguments.contains(argumentName)) {
if (required) {
qDebug() << objectName << "requires argument:" << argumentName;
}
ok = false;
return glm::vec3(0.0f);
}
QVariant resultV = arguments[argumentName];
if (resultV.type() != (QVariant::Type) QMetaType::QVariantMap) {
qDebug() << objectName << "argument" << argumentName << "must be a map";
ok = false;
return glm::vec3(0.0f);
}
QVariantMap resultVM = resultV.toMap();
if (!resultVM.contains("x") || !resultVM.contains("y") || !resultVM.contains("z")) {
qDebug() << objectName << "argument" << argumentName << "must be a map with keys: x, y, z";
ok = false;
return glm::vec3(0.0f);
}
QVariant xV = resultVM["x"];
QVariant yV = resultVM["y"];
QVariant zV = resultVM["z"];
bool xOk = true;
bool yOk = true;
bool zOk = true;
float x = xV.toFloat(&xOk);
float y = yV.toFloat(&yOk);
float z = zV.toFloat(&zOk);
if (!xOk || !yOk || !zOk) {
qDebug() << objectName << "argument" << argumentName << "must be a map with keys: x, y, and z of type float.";
ok = false;
return glm::vec3(0.0f);
}
if (x != x || y != y || z != z) {
// at least one of the values is NaN
ok = false;
return glm::vec3(0.0f);
}
return glm::vec3(x, y, z);
}
示例11: setData
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool ComparisonSelectionTableModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
// std::cout << "ComparisonSelectionTableModel::setData " << value.toString().toStdString() << std::endl;
if (!index.isValid() || role != Qt::EditRole || index.row() < 0 || index.row() >= m_FieldNames.count() || index.column() < 0 || index.column()
>= m_ColumnCount)
{
return false;
}
bool ok;
qint32 row = index.row();
qint32 col = index.column();
switch(col)
{
case FieldName:
m_FieldNames[row] = value.toString();
break;
case FieldValue:
m_FieldValues[row] = value.toFloat(&ok);
break;
case FieldOperator:
m_FieldOperators[row] = value.toString();
break;
// case FieldPhaseValue:
// m_FieldPhaseValues[row] = value.toInt(&ok);
// break;
default:
Q_ASSERT(false);
}
emit
dataChanged(index, index);
return true;
}
示例12: set
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
{
ESXRecordT record2 = record.get();
switch (record2.mValue.getType())
{
case ESM::VT_String:
record2.mValue.setString (data.toString().toUtf8().constData());
break;
case ESM::VT_Int:
case ESM::VT_Short:
case ESM::VT_Long:
record2.mValue.setInteger (data.toInt());
break;
case ESM::VT_Float:
record2.mValue.setFloat (data.toFloat());
break;
default: break;
}
record.setModified (record2);
}
示例13: if
glm::vec4 vec4FromVariant(const QVariant& object, bool& valid) {
glm::vec4 v;
valid = false;
if (!object.isValid() || object.isNull()) {
return v;
} else if (object.canConvert<float>()) {
v = glm::vec4(object.toFloat());
valid = true;
} else if (object.canConvert<QVector4D>()) {
auto qvec4 = qvariant_cast<QVector4D>(object);
v.x = qvec4.x();
v.y = qvec4.y();
v.z = qvec4.z();
v.w = qvec4.w();
valid = true;
} else {
auto map = object.toMap();
auto x = map["x"];
auto y = map["y"];
auto z = map["z"];
auto w = map["w"];
if (x.canConvert<float>() && y.canConvert<float>() && z.canConvert<float>() && w.canConvert<float>()) {
v.x = x.toFloat();
v.y = y.toFloat();
v.z = z.toFloat();
v.w = w.toFloat();
valid = true;
}
}
return v;
}
示例14: SetElementProperties
void Transcoder::SetElementProperties(const QString& name, GObject* object) {
QSettings s;
s.beginGroup("Transcoder/" + name);
guint properties_count = 0;
GParamSpec** properties = g_object_class_list_properties(
G_OBJECT_GET_CLASS(object), &properties_count);
for (int i=0 ; i<properties_count ; ++i) {
GParamSpec* property = properties[i];
const QVariant value = s.value(property->name);
if (value.isNull())
continue;
LogLine(QString("Setting %1 property: %2 = %3").arg(name, property->name, value.toString()));
switch (property->value_type) {
case G_TYPE_DOUBLE: g_object_set(object, property->name, value.toDouble(), NULL); break;
case G_TYPE_FLOAT: g_object_set(object, property->name, value.toFloat(), NULL); break;
case G_TYPE_BOOLEAN: g_object_set(object, property->name, value.toInt(), NULL); break;
case G_TYPE_INT:
default: g_object_set(object, property->name, value.toInt(), NULL); break;
}
}
g_free(properties);
}
示例15: if
void CSMWorld::ContainerRefIdAdapter::setData (const RefIdColumn *column, RefIdData& data, int index,
const QVariant& value) const
{
Record<ESM::Container>& record = static_cast<Record<ESM::Container>&> (
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Container)));
ESM::Container container = record.get();
if (column==mWeight)
container.mWeight = value.toFloat();
else if (column==mOrganic)
{
if (value.toInt())
container.mFlags |= ESM::Container::Organic;
else
container.mFlags &= ~ESM::Container::Organic;
}
else if (column==mRespawn)
{
if (value.toInt())
container.mFlags |= ESM::Container::Respawn;
else
container.mFlags &= ~ESM::Container::Respawn;
}
else
{
NameRefIdAdapter<ESM::Container>::setData (column, data, index, value);
return;
}
record.setModified(container);
}