pin table: Add GetString() to retrieve string value for column

This is in anticipation of the introduction of icons -- retrieving all the
icons and throwing them away during sorting takes ages.
This commit is contained in:
Simon Richter 2016-01-14 21:21:26 -05:00 committed by Chris Pavlina
parent a568f35978
commit 64782736ac
1 changed files with 47 additions and 41 deletions

View File

@ -71,6 +71,9 @@ private:
mutable std::list<Pin> m_Pins; mutable std::list<Pin> m_Pins;
mutable std::map<wxString, Group> m_Groups; mutable std::map<wxString, Group> m_Groups;
// like GetValue, but always returns a string
wxString GetString( const wxDataViewItem&, unsigned int ) const;
#ifdef REASSOCIATE_HACK #ifdef REASSOCIATE_HACK
wxDataViewCtrl* m_Widget; wxDataViewCtrl* m_Widget;
#endif #endif
@ -80,6 +83,7 @@ class DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Item
{ {
public: public:
virtual void GetValue( wxVariant& aValue, unsigned int aCol ) const = 0; virtual void GetValue( wxVariant& aValue, unsigned int aCol ) const = 0;
virtual wxString GetString( unsigned int aCol ) const = 0;
virtual wxDataViewItem GetParent() const = 0; virtual wxDataViewItem GetParent() const = 0;
virtual bool IsContainer() const = 0; virtual bool IsContainer() const = 0;
virtual unsigned int GetChildren( wxDataViewItemArray& ) const = 0; virtual unsigned int GetChildren( wxDataViewItemArray& ) const = 0;
@ -92,7 +96,7 @@ public:
Group( unsigned int aGroupingColumn ) : m_GroupingColumn( aGroupingColumn ) {} Group( unsigned int aGroupingColumn ) : m_GroupingColumn( aGroupingColumn ) {}
virtual void GetValue( wxVariant& aValue, unsigned int aCol ) const; virtual void GetValue( wxVariant& aValue, unsigned int aCol ) const;
virtual wxString GetString( unsigned int aCol ) const;
virtual wxDataViewItem GetParent() const { return wxDataViewItem(); } virtual wxDataViewItem GetParent() const { return wxDataViewItem(); }
virtual bool IsContainer() const { return true; } virtual bool IsContainer() const { return true; }
virtual unsigned int GetChildren( wxDataViewItemArray& aItems ) const virtual unsigned int GetChildren( wxDataViewItemArray& aItems ) const
@ -120,7 +124,7 @@ public:
LIB_PIN* aBacking ) : m_Model( aModel ), m_Backing( aBacking ), m_Group( 0 ) {} LIB_PIN* aBacking ) : m_Model( aModel ), m_Backing( aBacking ), m_Group( 0 ) {}
virtual void GetValue( wxVariant& aValue, unsigned int aCol ) const; virtual void GetValue( wxVariant& aValue, unsigned int aCol ) const;
virtual wxString GetString( unsigned int aCol ) const;
virtual wxDataViewItem GetParent() const { return wxDataViewItem( m_Group ); } virtual wxDataViewItem GetParent() const { return wxDataViewItem( m_Group ); }
virtual bool IsContainer() const { return false; } virtual bool IsContainer() const { return false; }
virtual unsigned int GetChildren( wxDataViewItemArray& ) const { return 0; } virtual unsigned int GetChildren( wxDataViewItemArray& ) const { return 0; }
@ -301,15 +305,8 @@ int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Compare( const wxDataViewItem& aIt
unsigned int aCol, unsigned int aCol,
bool aAscending ) const bool aAscending ) const
{ {
wxVariant var1; wxString str1 = GetString( aItem1, aCol );
wxString str2 = GetString( aItem2, aCol );
GetValue( var1, aItem1, aCol );
wxString str1 = var1.GetString();
wxVariant var2;
GetValue( var2, aItem2, aCol );
wxString str2 = var2.GetString();
int res = PinNumbers::Compare( str1, str2 ); int res = PinNumbers::Compare( str1, str2 );
if( res == 0 ) if( res == 0 )
@ -342,8 +339,7 @@ void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::CalculateGrouping()
for( std::list<Pin>::iterator i = m_Pins.begin(); i != m_Pins.end(); ++i ) for( std::list<Pin>::iterator i = m_Pins.begin(); i != m_Pins.end(); ++i )
{ {
i->GetValue( value, m_GroupingColumn ); wxString str = i->GetString( m_GroupingColumn );
wxString str = value.GetString();
std::map<wxString, Group>::iterator j = m_Groups.find( str ); std::map<wxString, Group>::iterator j = m_Groups.find( str );
if( j == m_Groups.end() ) if( j == m_Groups.end() )
@ -394,37 +390,45 @@ PinNumbers DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetAllPinNumbers()
PinNumbers ret; PinNumbers ret;
for( std::list<Pin>::const_iterator i = m_Pins.begin(); i != m_Pins.end(); ++i ) for( std::list<Pin>::const_iterator i = m_Pins.begin(); i != m_Pins.end(); ++i )
{ ret.insert( i->GetString( PIN_NUMBER ) );
wxVariant var;
i->GetValue( var, PIN_NUMBER );
ret.insert( var.GetString() );
}
return ret; return ret;
} }
wxString DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetString( const wxDataViewItem& aItem, unsigned int aCol ) const
{
assert( aItem.IsOk() );
return reinterpret_cast<Item const*>( aItem.GetID() )->GetString( aCol );
}
void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Group::GetValue( wxVariant& aValue, void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Group::GetValue( wxVariant& aValue,
unsigned int aCol ) const unsigned int aCol ) const
{ {
if( aCol == m_GroupingColumn ) if( aCol == m_GroupingColumn )
{
// shortcut // shortcut
m_Members.front()->GetValue( aValue, aCol ); m_Members.front()->GetValue( aValue, aCol );
}
else else
{ aValue = GetString( aCol );
PinNumbers values; }
for( std::list<Pin*>::const_iterator i = m_Members.begin(); i != m_Members.end(); ++i )
{
wxVariant value;
(*i)->GetValue( value, aCol );
values.insert( value.GetString() );
}
aValue = boost::algorithm::join( values, "," ); wxString DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Group::GetString( unsigned int aCol ) const
} {
if( aCol == m_GroupingColumn )
return m_Members.front()->GetString( aCol );
PinNumbers values;
for( std::list<Pin*>::const_iterator i = m_Members.begin(); i != m_Members.end(); ++i )
values.insert( (*i)->GetString( aCol ) );
if( values.size() > 1 )
return boost::algorithm::join( values, "," );
else
return m_Members.front()->GetString( aCol );
} }
@ -450,15 +454,19 @@ void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Group::Add( Pin* aPin )
void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Pin::GetValue( wxVariant& aValue, void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Pin::GetValue( wxVariant& aValue,
unsigned int aCol ) const unsigned int aCol ) const
{
aValue = GetString( aCol );
}
wxString DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Pin::GetString( unsigned int aCol ) const
{ {
switch( aCol ) switch( aCol )
{ {
case PIN_NUMBER: case PIN_NUMBER:
aValue = m_Backing->GetNumberString(); return m_Backing->GetNumberString();
break;
case PIN_NAME: case PIN_NAME:
{
if( m_Model.m_UnitCount > 1 ) if( m_Model.m_UnitCount > 1 )
{ {
wxString name; wxString name;
@ -471,26 +479,24 @@ void DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Pin::GetValue( wxVariant& aValue,
name << ':'; name << ':';
name << m_Backing->GetName(); name << m_Backing->GetName();
aValue = name; return name;
} }
else else
{ {
aValue = m_Backing->GetName(); return m_Backing->GetName();
} }
}
break;
case PIN_TYPE: case PIN_TYPE:
aValue = m_Backing->GetElectricalTypeName(); return m_Backing->GetElectricalTypeName();
break;
case PIN_POSITION: case PIN_POSITION:
{ {
wxPoint position = m_Backing->GetPosition(); wxPoint position = m_Backing->GetPosition();
wxString value; wxString value;
value << "(" << position.x << "," << position.y << ")"; value << "(" << position.x << "," << position.y << ")";
aValue = value; return value;
} }
break;
} }
return wxT("");
} }