Use conditional operators to simplify statements

This commit is contained in:
Artur Wieczorek 2022-10-26 11:06:59 +02:00
parent 5845312825
commit f1cefb8be3
3 changed files with 11 additions and 40 deletions

View file

@ -1841,40 +1841,28 @@ wxVariant wxPGProperty::DoGetAttribute( const wxString& WXUNUSED(name) ) const
wxVariant wxPGProperty::GetAttribute( const wxString& name ) const
{
wxVariant value = DoGetAttribute(name);
if ( !value.IsNull() )
return value;
return m_attributes.FindValue(name);
return !value.IsNull() ? value : m_attributes.FindValue(name);
}
wxString wxPGProperty::GetAttribute( const wxString& name, const wxString& defVal ) const
{
wxVariant variant = m_attributes.FindValue(name);
if ( !variant.IsNull() )
return variant.GetString();
return defVal;
return variant.IsNull() ? defVal : variant.GetString();
}
long wxPGProperty::GetAttributeAsLong( const wxString& name, long defVal ) const
{
wxVariant variant = m_attributes.FindValue(name);
if ( variant.IsNull() )
return defVal;
return variant.GetLong();
return variant.IsNull() ? defVal : variant.GetLong();
}
double wxPGProperty::GetAttributeAsDouble( const wxString& name, double defVal ) const
{
wxVariant variant = m_attributes.FindValue(name);
if ( variant.IsNull() )
return defVal;
return variant.GetDouble();
return variant.IsNull() ? defVal : variant.GetDouble();
}
wxVariant wxPGProperty::GetAttributesAsList() const
@ -2213,12 +2201,9 @@ wxPropertyGrid* wxPGProperty::GetGridIfDisplayed() const
if ( !state )
return nullptr;
wxPropertyGrid* propGrid = state->GetGrid();
if ( state == propGrid->GetState() )
return propGrid;
return nullptr;
return state == propGrid->GetState() ? propGrid : nullptr;
}
int wxPGProperty::GetY2( int lh ) const
{
const wxPGProperty* parent;
@ -2728,10 +2713,7 @@ wxString wxPGProperty::GetHintText() const
{
wxVariant vHintText = GetAttribute(wxPG_ATTR_HINT);
if ( !vHintText.IsNull() )
return vHintText.GetString();
return wxEmptyString;
return vHintText.IsNull() ? wxString() : vHintText.GetString();
}
int wxPGProperty::GetDisplayedCommonValueCount() const
@ -2837,18 +2819,13 @@ wxPropertyCategory::~wxPropertyCategory()
wxString wxPropertyCategory::ValueToString( wxVariant& WXUNUSED(value),
int WXUNUSED(argFlags) ) const
{
if ( m_value.IsType(wxPG_VARIANT_TYPE_STRING) )
return m_value.GetString();
return wxEmptyString;
return m_value.IsType(wxPG_VARIANT_TYPE_STRING) ? m_value.GetString() : wxEmptyString;
}
wxString wxPropertyCategory::GetValueAsString( int argFlags ) const
{
// Unspecified value is always empty string
if ( IsValueUnspecified() )
return wxEmptyString;
return wxPGProperty::GetValueAsString(argFlags);
return IsValueUnspecified() ? wxEmptyString : wxPGProperty::GetValueAsString(argFlags);
}
static int DoGetTextExtent(const wxWindow* wnd, const wxString& label, const wxFont& font)
@ -2860,9 +2837,7 @@ static int DoGetTextExtent(const wxWindow* wnd, const wxString& label, const wxF
int wxPropertyCategory::GetTextExtent( const wxWindow* wnd, const wxFont& font ) const
{
if ( m_textExtent > 0 )
return m_textExtent;
return DoGetTextExtent(wnd, m_label, font);
return (m_textExtent > 0) ? m_textExtent : DoGetTextExtent(wnd, m_label, font);
}
void wxPropertyCategory::CalculateTextExtent(const wxWindow* wnd, const wxFont& font)

View file

@ -6084,9 +6084,7 @@ wxPGEditor* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor* editorClass,
if ( !noDefCheck && wxPGGlobalVars->m_mapEditorClasses.empty() )
RegisterDefaultEditors();
wxString name = editorName;
if ( name.empty() )
name = editorClass->GetName();
wxString name = editorName.empty() ? editorClass->GetName() : editorName;
// Existing editor under this name?
wxPGHashMapS2P::iterator vt_it = wxPGGlobalVars->m_mapEditorClasses.find(name);

View file

@ -1703,9 +1703,7 @@ bool wxPropertyGridPageState::PrepareToAddItem( wxPGProperty* property,
wxPGProperty* wxPropertyGridPageState::DoAppend( wxPGProperty* property )
{
wxPropertyCategory* cur_cat = m_currentCategory;
if ( property->IsCategory() )
cur_cat = nullptr;
wxPropertyCategory* cur_cat = property->IsCategory() ? nullptr : m_currentCategory;
return DoInsert( cur_cat, -1, property );
}