Use wxVariant::IsType() function to check the type of variant values in wxPG.

Since there is a dedicated function to check the type of variant then there is not necessary to call wxVariant::GetType() function and perform explicit comparisons of returned strings.
This commit is contained in:
Artur Wieczorek
2015-03-29 21:36:12 +02:00
parent e4ea660dfd
commit 5353a00180
7 changed files with 27 additions and 27 deletions

View File

@@ -537,7 +537,7 @@ public:
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
wxString typeName(wxS(TYPENAME)); \
wxVariant value = p->GetValue(); \
if ( value.GetType() != typeName ) \
if ( !value.IsType(typeName) ) \
{ \
wxPGGetFailed(p, typeName); \
return DEFVAL; \
@@ -546,7 +546,7 @@ public:
#define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(TYPENAME, DEFVAL) \
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
wxVariant value = p->GetValue(); \
if ( value.GetType() != wxS(TYPENAME) ) \
if ( !value.IsType(wxS(TYPENAME)) ) \
return DEFVAL; \
wxArrayString GetPropertyValueAsArrayString( wxPGPropArg id ) const

View File

@@ -483,7 +483,7 @@ wxPGWindowList wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid* propgri
wxDateTime dateValue(wxInvalidDateTime);
wxVariant value = prop->GetValue();
if ( value.GetType() == wxT("datetime") )
if ( value.IsType(wxT("datetime")) )
dateValue = value.GetDateTime();
ctrl->Create(propgrid->GetPanel(),
@@ -509,7 +509,7 @@ void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty* property,
wxDateTime dateValue(wxInvalidDateTime);
wxVariant v(property->GetValue());
if ( v.GetType() == wxT("datetime") )
if ( v.IsType(wxT("datetime")) )
dateValue = v.GetDateTime();
ctrl->SetValue( dateValue );
@@ -697,7 +697,7 @@ bool wxFontProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(prima
wxFontData data;
wxFont font;
if ( useValue.GetType() == wxS("wxFont") )
if ( useValue.IsType(wxS("wxFont")) )
font << useValue;
data.SetInitialFont( font );
@@ -1069,7 +1069,7 @@ int wxSystemColourProperty::ColToInd( const wxColour& colour ) const
void wxSystemColourProperty::OnSetValue()
{
// Convert from generic wxobject ptr to wxPGVariantDataColour
if ( m_value.GetType() == wxS("wxColour*") )
if ( m_value.IsType(wxS("wxColour*")) )
{
wxColour* pCol = wxStaticCast(m_value.GetWxObjectPtr(), wxColour);
m_value << *pCol;
@@ -1093,7 +1093,7 @@ void wxSystemColourProperty::OnSetValue()
int ind = wxNOT_FOUND;
if ( m_value.GetType() == wxS("wxColourPropertyValue") )
if ( m_value.IsType(wxS("wxColourPropertyValue")) )
{
wxColourPropertyValue cpv;
cpv << m_value;
@@ -1218,7 +1218,7 @@ int wxSystemColourProperty::GetCustomColourIndex() const
bool wxSystemColourProperty::QueryColourFromUser( wxVariant& variant ) const
{
wxASSERT( m_value.GetType() != wxPG_VARIANT_TYPE_STRING );
wxASSERT( !m_value.IsType(wxPG_VARIANT_TYPE_STRING) );
bool res = false;
wxPropertyGrid* propgrid = GetGrid();
@@ -2018,7 +2018,7 @@ void wxMultiChoiceProperty::GenerateValueAsString( wxVariant& value,
{
wxArrayString strings;
if ( value.GetType() == wxPG_VARIANT_TYPE_ARRSTRING )
if ( value.IsType(wxPG_VARIANT_TYPE_ARRSTRING) )
strings = value.GetArrayString();
wxString& tempStr = *target;
@@ -2204,7 +2204,7 @@ void wxDateProperty::OnSetValue()
{
//
// Convert invalid dates to unspecified value
if ( m_value.GetType() == wxT("datetime") )
if ( m_value.IsType(wxT("datetime")) )
{
if ( !m_value.GetDateTime().IsValid() )
m_value.MakeNull();

View File

@@ -1984,7 +1984,7 @@ wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos,
wxVariant attrVal = prop->GetAttribute(wxPG_ATTR_AUTOCOMPLETE);
if ( !attrVal.IsNull() )
{
wxASSERT(attrVal.GetType() == wxS("arrstring"));
wxASSERT(attrVal.IsType(wxS("arrstring")));
tc->AutoComplete(attrVal.GetArrayString());
}

View File

@@ -936,7 +936,7 @@ void wxPGProperty::DoGenerateComposedValue( wxString& text,
{
if ( overridesLeft &&
curChild->HasFlag(wxPG_PROP_COMPOSED_VALUE) &&
childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
childValue.IsType(wxPG_VARIANT_TYPE_LIST) )
{
wxVariantList& childList = childValue.GetList();
DoGenerateComposedValue(s, argFlags|wxPG_COMPOSITE_FRAGMENT,
@@ -1368,7 +1368,7 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
// List variants are reserved a special purpose
// as intermediate containers for child values
// of properties with children.
if ( value.GetType() == wxPG_VARIANT_TYPE_LIST )
if ( value.IsType(wxPG_VARIANT_TYPE_LIST) )
{
//
// However, situation is different for composed string properties
@@ -1389,7 +1389,7 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
if ( pList && !pList->IsNull() )
{
wxASSERT( pList->GetType() == wxPG_VARIANT_TYPE_LIST );
wxASSERT( pList->IsType(wxPG_VARIANT_TYPE_LIST) );
wxASSERT( GetChildCount() );
wxASSERT( !IsCategory() );
@@ -1408,7 +1408,7 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
if ( child )
{
//wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
if ( childValue.IsType(wxPG_VARIANT_TYPE_LIST) )
{
if ( child->HasFlag(wxPG_PROP_AGGREGATE) && !(flags & wxPG_SETVAL_AGGREGATED) )
{
@@ -2409,7 +2409,7 @@ void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const
{
//wxLogDebug(wxT(" %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
if ( childValue.IsType(wxPG_VARIANT_TYPE_LIST) )
{
wxVariant cv2(child->GetValue());
child->AdaptListToValue(childValue, &cv2);
@@ -2712,7 +2712,7 @@ bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const
{
const wxVariant* childList = NULL;
if ( listValue && listValue->GetType() == wxPG_VARIANT_TYPE_LIST )
if ( listValue && listValue->IsType(wxPG_VARIANT_TYPE_LIST) )
childList = listValue;
if ( !child->AreAllChildrenSpecified((wxVariant*)childList) )
@@ -2843,7 +2843,7 @@ wxPropertyCategory::~wxPropertyCategory()
wxString wxPropertyCategory::ValueToString( wxVariant& WXUNUSED(value),
int WXUNUSED(argFlags) ) const
{
if ( m_value.GetType() == wxPG_VARIANT_TYPE_STRING )
if ( m_value.IsType(wxPG_VARIANT_TYPE_STRING) )
return m_value.GetString();
return wxEmptyString;
}

View File

@@ -2999,7 +2999,7 @@ bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue
//
// Variant list a special value that cannot be validated
// by normal means.
if ( pendingValue.GetType() != wxPG_VARIANT_TYPE_LIST )
if ( !pendingValue.IsType(wxPG_VARIANT_TYPE_LIST) )
{
if ( !p->ValidateValue(pendingValue, m_validationInfo) )
return false;
@@ -3045,7 +3045,7 @@ bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue
wxVariant value;
wxPGProperty* evtChangingProperty = changedProperty;
if ( pPendingValue->GetType() != wxPG_VARIANT_TYPE_LIST )
if ( !pPendingValue->IsType(wxPG_VARIANT_TYPE_LIST) )
{
value = *pPendingValue;
}
@@ -3104,7 +3104,7 @@ bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue
// If changedProperty is not property which value was edited,
// then call wxPGProperty::ValidateValue() for that as well.
if ( p != changedProperty && value.GetType() != wxPG_VARIANT_TYPE_LIST )
if ( p != changedProperty && !value.IsType(wxPG_VARIANT_TYPE_LIST) )
{
if ( !changedProperty->ValidateValue(value, m_validationInfo) )
return false;

View File

@@ -1595,7 +1595,7 @@ void wxPropertyGridPageState::DoSetPropertyValues( const wxVariantList& list, wx
else
{
// Is it list?
if ( current->GetType() != wxS("list") )
if ( !current->IsType(wxS("list")) )
{
// Not.
}
@@ -1638,7 +1638,7 @@ void wxPropertyGridPageState::DoSetPropertyValues( const wxVariantList& list, wx
wxPGProperty* foundProp = BaseGetPropertyByName(propName);
if ( foundProp )
{
wxASSERT( current->GetType() == wxPG_VARIANT_TYPE_LIST );
wxASSERT( current->IsType(wxPG_VARIANT_TYPE_LIST) );
wxVariantList& list2 = current->GetList();
wxVariantList::const_iterator node2;

View File

@@ -327,7 +327,7 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int
bool wxIntProperty::IntToValue( wxVariant& variant, int value, int WXUNUSED(argFlags) ) const
{
if ( variant.GetType() != wxPG_VARIANT_TYPE_LONG || variant != (long)value )
if ( !variant.IsType(wxPG_VARIANT_TYPE_LONG) || variant != (long)value )
{
variant = (long)value;
return true;
@@ -640,7 +640,7 @@ wxString wxUIntProperty::ValueToString( wxVariant& value,
if ( index >= wxPG_UINT_TEMPLATE_MAX )
index = wxPG_UINT_DEC;
if ( value.GetType() == wxPG_VARIANT_TYPE_LONG )
if (value.IsType(wxPG_VARIANT_TYPE_LONG))
{
return wxString::Format(gs_uintTemplates32[index],
(unsigned long)value.GetLong());
@@ -1223,7 +1223,7 @@ bool wxEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WXUNUS
// Make sure string value is in the list,
// unless property has string as preferred value type
// To reduce code size, use conversion here as well
if ( value.GetType() == wxPG_VARIANT_TYPE_STRING )
if ( value.IsType(wxPG_VARIANT_TYPE_STRING) )
return ValueFromString_(value, NULL, value.GetString(), wxPG_PROPERTY_SPECIFIC);
return true;
@@ -1232,7 +1232,7 @@ bool wxEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WXUNUS
wxString wxEnumProperty::ValueToString( wxVariant& value,
int WXUNUSED(argFlags) ) const
{
if ( value.GetType() == wxPG_VARIANT_TYPE_STRING )
if ( value.IsType(wxPG_VARIANT_TYPE_STRING) )
return value.GetString();
int index = m_choices.Index(value.GetLong());