bool wxPGVariantToDouble( const wxVariant& variant, double* pResult ) { if ( variant.IsNull() ) return false; wxString variantType = variant.GetType(); if ( variantType == wxPG_VARIANT_TYPE_DOUBLE ) { *pResult = variant.GetDouble(); return true; } if ( variantType == wxPG_VARIANT_TYPE_LONG ) { *pResult = (double)variant.GetLong(); return true; } if ( variantType == wxLongLong_VariantType ) { wxLongLong ll; ll << variant; *pResult = ll.ToDouble(); return true; } if ( variantType == wxPG_VARIANT_TYPE_STRING ) if ( variant.GetString().ToDouble(pResult) ) return true; return false; }
bool wxVariant::operator== (const wxVariant& variant) const { if (IsNull() || variant.IsNull()) return (IsNull() == variant.IsNull()); return (GetData()->Eq(* variant.GetData())); }
bool CTimeBarListModel::SetValueByRow( const wxVariant &variant, unsigned int row, unsigned int col ) { if (row < m_textColValues.GetCount()) { switch ( col ) { case Col_EditableText: m_textColValues[row] = variant.GetString(); break; case Col_Visible: m_view[row] = variant.GetChar(); break; case Col_Lock: m_lock[row] = variant.GetChar(); break; case Col_Max: default: wxFAIL_MSG( _T("invalid column") ); break; } } return false; }
bool MyMusicTreeModel::SetValue( const wxVariant &variant, const wxDataViewItem &item, unsigned int col ) { wxASSERT(item.IsOk()); MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) item.GetID(); switch (col) { case 0: node->m_title = variant.GetString(); return true; case 1: node->m_artist = variant.GetString(); return true; case 2: node->m_year = variant.GetLong(); return true; case 3: node->m_quality = variant.GetString(); return true; default: wxLogError( "MyMusicTreeModel::SetValue: wrong column" ); } return false; }
std::string ScalarSelectionDialog::GetValueString(const wxVariant& variant, std::type_index type, int precision) { std::string result; if (!variant.IsNull()) { if (IsFloat(type)) { std::stringstream strstream; if (precision > 0) { strstream << std::setprecision(precision) << std::fixed << variant.GetDouble(); } else { strstream << std::fixed << variant.GetDouble(); } auto tmpStr = strstream.str(); size_t last_not_zero = tmpStr.find_last_not_of('0'); result = tmpStr.substr(0, last_not_zero == std::string::npos ? last_not_zero : last_not_zero+1); } else if (IsIntegral(type)) { result = std::to_string(variant.GetInteger()); } } return result; }
void LogVariant(const wxString& prefix, const wxVariant& v) { const wxString type = v.GetType(); wxString info; const wxString& name = v.GetName(); if (type == wxS("arrstring")) { wxArrayString as = v.GetArrayString(); info.Printf(wxS("%svariant type: \"%s\", element count: %zu, name: \"%s\"."), prefix, type, as.size(), name); wxLogTrace(wxTRACE_AutoExcel, wxS("%s"), info); for (size_t i = 0; i < as.size(); i++) { info.Printf(wxS(" string #%zu value: \"%s\""), i, as[i]); if ( i == LogVariantMaxItemsInList ) { wxLogTrace(wxTRACE_AutoExcel, wxS("And %zu more strings"), as.size() - i); break; } else wxLogTrace(wxTRACE_AutoExcel, wxS("%s"), info); } return; } if (type == wxS("list")) { info.Printf(wxS("%sVariant type: \"%s\", element count: %zu, name: \"%s\"."), prefix, type, v.GetCount(), name); wxLogTrace(wxTRACE_AutoExcel, wxS("%s"), info); for (size_t i = 0; i < v.GetCount(); i++) { if ( i == LogVariantMaxItemsInList ) { wxLogTrace(wxTRACE_AutoExcel, wxS("And %zu more variants"), v.GetCount() - i); break; } else { const wxVariant& vTmp = v[i]; info.Printf(wxS(" variant #%zu type: \"%s\", value: \"%s\", name: \"%s\"."), i, vTmp.GetType(), vTmp.MakeString(), vTmp.GetName()); wxLogTrace(wxTRACE_AutoExcel, wxS("%s"), info); } } return; } if (type == wxS("void*") && v.GetVoidPtr() != NULL) { wxString automationName; wxExcelObject object; IDispatch* dispatch = (IDispatch*)v.GetVoidPtr(); dispatch->AddRef(); object.GetAutomationObject_()->SetDispatchPtr(dispatch); info.Printf(wxS("%svariant type: \"IDispatch - %s\", value: \"%s\", name: \"%s\"."), prefix, object.GetAutomationObjectName_(false), v.MakeString(), name); } else { info.Printf(wxS("%svariant type: \"%s\", value: \"%s\", name: \"%s\"."), prefix, type, v.MakeString(), name); } wxLogTrace(wxTRACE_AutoExcel, wxS("%s"), info); }
wxVariant wxPointProperty::ChildChanged(wxVariant& thisValue, int childIndex, wxVariant& childValue) const { Point& point = PointRefFromVariant(thisValue); switch ( childIndex ) { case 0: point.X = childValue.GetInteger(); break; case 1: point.Y = childValue.GetInteger(); break; } wxVariant newVariant; newVariant << point; return newVariant; }
wxVariant wxSizeProperty::ChildChanged(wxVariant& thisValue, int childIndex, wxVariant& childValue) const { Size& size = SizeRefFromVariant(thisValue); switch ( childIndex ) { case 0: size.Width = childValue.GetInteger(); break; case 1: size.Height = childValue.GetInteger(); break; } wxVariant newVariant; newVariant << size; return newVariant; }
wxVariant luVector3Property::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const { gkVector3 v; v << thisValue; switch ( childIndex ) { case 0: v.x = childValue.GetDouble(); break; case 1: v.y = childValue.GetDouble(); break; case 2: v.z = childValue.GetDouble(); break; } return thisValue << v; }
wxVariant wxRangeProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const { Range& range = RangeRefFromVariant(thisValue); switch ( childIndex ) { case 0: range.Min = childValue.GetDouble(); break; case 1: range.Max = childValue.GetDouble(); break; } wxVariant newVariant; newVariant << range; return newVariant; }
wxVariant wxVector2Property::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const { Vector2& vec = Vector2RefFromVariant(thisValue); switch ( childIndex ) { case 0: vec.X = childValue.GetDouble(); break; case 1: vec.Y = childValue.GetDouble(); break; } wxVariant newVariant; newVariant << vec; return newVariant; }
long wxPGVariantToInt( const wxVariant& variant, long defVal ) { if ( variant.IsNull() ) return defVal; if ( variant.GetType() == wxS("long") ) return variant.GetLong(); if ( variant.GetType() == wxS("bool") ) return variant.GetBool() ? 1 : 0; if ( variant.GetType() == wxS("wxLongLong") ) { wxLongLong ll; ll << variant; if ( ll >= LONG_MAX ) return LONG_MAX; else if ( ll <= LONG_MIN ) return LONG_MIN; return ll.ToLong(); } long l = defVal; if ( variant.GetType() == wxPG_VARIANT_TYPE_STRING ) variant.GetString().ToLong(&l, 0); return l; }
// ----------------------------------------------------------------------- wxVariant WxGUISizeProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const { CGUISize& size = CGUISizeRefFromVariant(thisValue); switch ( childIndex ) { case 0: size.m_fWidth = childValue.GetDouble(); break; case 1: size.m_fHeight = childValue.GetDouble(); break; } wxVariant newVariant; newVariant << size; return newVariant; }
wxVariant nsVector3Property::ChildChanged(wxVariant& thisValue, int childIndex, wxVariant& childValue) const { Vector3 vector; vector << thisValue; switch (childIndex) { case 0: vector._x = childValue.GetDouble(); break; case 1: vector._y = childValue.GetDouble(); break; case 2: vector._z = childValue.GetDouble(); break; } wxVariant newVariant; newVariant << vector; return newVariant; }
// ----------------------------------------------------------------------- wxVariant WxGUIRotatorProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const { CGUIRotator& rotator = CGUIRotatorRefFromVariant(thisValue); switch ( childIndex ) { case 0: rotator.Pitch = childValue.GetDouble(); break; case 1: rotator.Yaw = childValue.GetDouble(); break; case 2: rotator.Roll = childValue.GetDouble(); break; } wxVariant newVariant; newVariant << rotator; return newVariant; }
// ----------------------------------------------------------------------- wxVariant WxGUIVector3Property::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const { CGUIVector3& vector = CGUIVector3RefFromVariant(thisValue); switch ( childIndex ) { case 0: vector.x = childValue.GetDouble(); break; case 1: vector.y = childValue.GetDouble(); break; case 2: vector.z = childValue.GetDouble(); break; } wxVariant newVariant; newVariant << vector; return newVariant; }
// ----------------------------------------------------------------------- wxVariant WxGUIStringInfoProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const { CGUIStringRenderInfo& string_info = CGUIStringRenderInfoRefFromVariant(thisValue); switch ( childIndex ) { case 0: string_info.m_fFontScale = childValue.GetDouble(); break; case 1: string_info.m_uFontID = childValue.GetInteger(); break; case 2: string_info.m_aColor << childValue; break; } wxVariant newVariant; newVariant << string_info; return newVariant; }
// ----------------------------------------------------------------------- wxVariant WxGUIRectProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const { CGUIRect& rect = CGUIRectRefFromVariant(thisValue); switch ( childIndex ) { case 0: rect.m_fLeft = childValue.GetDouble(); break; case 1: rect.m_fTop = childValue.GetDouble(); break; case 2: rect.m_fRight = childValue.GetDouble(); break; case 3: rect.m_fBottom = childValue.GetDouble(); break; } wxVariant newVariant; newVariant << rect; return newVariant; }
bool CommandImplementation::SetParameter(const wxString ¶mName, const wxVariant ¶mValue) { wxASSERT(!paramValue.IsType(wxT("null"))); ParamValueMap::iterator iter = mParams.find(paramName); if (iter == mParams.end()) { Error(paramName + wxT(" is not a parameter accepted by ") + GetName()); return false; } Validator &validator = mType.GetSignature().GetValidator(iter->first); if (!validator.Validate(paramValue)) { Error(wxT("Invalid value for parameter '") + paramName + wxT("': should be ") + validator.GetDescription()); return false; } mParams[paramName] = validator.GetConverted(); // (debug) // Status(wxT("Set parameter ") + paramName + wxT(" to type ") + mParams[paramName].GetType() + wxT(", value ") + mParams[paramName].MakeString()); return true; }
void vvStampsModel::GetValue( wxVariant& cValue, const wxDataViewItem& cItem, unsigned int uColumn ) const { wxASSERT(cItem.IsOk()); const DataItem* pItem = this->ConvertDataItem(cItem); switch (static_cast<Column>(uColumn)) { case COLUMN_B_CHECKED: cValue = pItem->bChecked; return; case COLUMN_BS_NAME: case COLUMN_S_NAME: cValue = pItem->sName; return; case COLUMN_U_COUNT: cValue = static_cast<long>(pItem->uCount); return; default: wxLogError("Unknown StampsModel column: %u", uColumn); cValue.MakeNull(); return; } }
wxString MOPGThingTypeProperty::ValueToString(wxVariant &value, int argFlags) const { // Get value as integer int type = value.GetInteger(); ThingType* tt = theGameConfiguration->thingType(type); return S_FMT("%d: %s", type, CHR(tt->getName())); }
//----------------------------------------------------------------------------- void wxFloat3Property::ChildChanged(wxVariant &thisValue, int childIndex, wxVariant &childValue ) const { Float3 &value = Float3FromVariant(thisValue); switch (childIndex) { case 0: value[0] = (float)childValue.GetDouble(); break; case 1: value[1] = (float)childValue.GetDouble(); break; case 2: value[2] = (float)childValue.GetDouble(); break; } }
//----------------------------------------------------------------------------- void wxAPoint3Property::ChildChanged(wxVariant &thisValue, int childIndex, wxVariant &childValue ) const { APoint &point = APointFromVariant(thisValue); switch (childIndex) { case 0: point.X() = (float)childValue.GetDouble(); break; case 1: point.Y() = (float)childValue.GetDouble(); break; case 2: point.Z() = (float)childValue.GetDouble(); break; } }
// ----------------------------------------------------------------------- wxString WxGuiColorProperty::ValueToString( wxVariant& value, int argFlags ) const { wxString test = value.GetType(); CGUIColor color = CGUIColorRefFromVariant(value); CGUIString strValue; guiex::ValueToString( color, strValue ); return Gui2wxString( strValue ); }
void PgStatement::GetFieldValue ( int nIndex, wxVariant& v ) { int nIsNull = PQgetisnull(pgr, nCurrentRecord, nIndex); if(nIsNull != 0) { v.MakeNull(); return; } char * sz = PQgetvalue(pgr, nCurrentRecord, nIndex); Oid typ = PQftype(pgr, nIndex); switch(typ) { case PG_OID_BOOLEAN: { bool b = (sz[0] == 't')? true : false; v = b; break; } case PG_OID_OID: case PG_OID_INT4: case PG_OID_TRANSACTIONID: { long n = atol(sz); v = n; break; } case PG_OID_DOUBLE: { double d = atof(sz); v = d; break; } case PG_OID_NAME: case PG_OID_TEXT: case PG_OID_VARCHAR_LENGTH: { //int nFormat = PQfformat(pgr, nIndex); // 0 => text, 1 => binary wxString s(sz, wxConvLocal); //wxString s = wxConvUTF8.cMB2WX(sz); v = s; break; } // Items we don't know how to handle case PG_OID_TEXTARRAY: case PG_OID_ACLITEMARRAY: v = wxT(""); break; default: throw wx::Exception(wxT("PgStatement::GetFieldValue() Unhandled data type %d"), typ); } }
bool wxPropertyGridManager::SetEditableStateItem( const wxString& name, wxVariant value ) { if ( name == wxS("descboxheight") ) { SetDescBoxHeight(value.GetLong(), true); return true; } return false; }
bool ArrayVariableProperty::ValidateValue(wxVariant& value, wxPGValidationInfo& validationinfo) const { wxArrayString dataset_vars = get_dataset_vars(); std::set<wxString> set = get_set(dataset_vars); wxArrayString tmp = value.GetArrayString(); for (wxArrayString::const_iterator it = tmp.begin(); it != tmp.end(); it++) if (set.find(*it) == set.end()) return false; return true; }
wxVariant luObjectProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const { luGameObjProps obj; obj << thisValue; switch ( childIndex ) { case PROP_NAME: { obj.name = childValue.GetString(); break; } //case PROP_TYPE: { obj.type = childValue.GetString(); break; } case PROP_POS: { obj.pos = gkVector3RefFromVariant(childValue); break; } case PROP_SCALE: { obj.scale = gkVector3RefFromVariant(childValue); break; } case PROP_FRONT: { obj.front = gkVector3RefFromVariant(childValue); break; } case PROP_UP: { obj.up = gkVector3RefFromVariant(childValue); break; } case PROP_DIM: { obj.dim = gkVector3RefFromVariant(childValue); break; } case PROP_FLAGS: { obj.flags = childValue.GetInteger(); break; } case PROP_STATE: { obj.state = childValue.GetInteger(); break; } } return thisValue << obj; }
// set value, call ValueChanged() afterwards! bool wxDBase::SetValueByRow(const wxVariant& var, unsigned int row, unsigned int col) { bool ok = true; if (ok) ok = SetPosition(row); if (var.IsType(wxT("datetime"))) { ok = Write(col, var.GetDateTime()); } else { ok = Write(col, var.MakeString()); } if (ok) { ok = PutRecord(row); } return ok; }
bool MyListModel::SetValueByRow( const wxVariant &variant, unsigned int row, unsigned int col ) { switch ( col ) { case Col_EditableText: case Col_IconText: if (row >= m_textColValues.GetCount()) { // the item is not in the range of the items // which we store... for simplicity, don't allow editing it wxLogError( "Cannot edit rows with an index greater than %d", m_textColValues.GetCount() ); return false; } if ( col == Col_EditableText ) { m_textColValues[row] = variant.GetString(); } else // col == Col_IconText { wxDataViewIconText iconText; iconText << variant; m_iconColValues[row] = iconText.GetText(); } return true; case Col_Date: case Col_TextWithAttr: wxLogError("Cannot edit the column %d", col); break; case Col_Custom: m_customColValues[row] = variant.GetString(); break; case Col_Max: wxFAIL_MSG( "invalid column" ); } return false; }