Add swapDevice to DeviceModel.

main
Teo Mrnjavac 9 years ago
parent 1d553407b9
commit 0bf2389b1a

@ -90,6 +90,7 @@ DeviceModel::data( const QModelIndex& index, int role ) const
} }
} }
Device* Device*
DeviceModel::deviceForIndex( const QModelIndex& index ) const DeviceModel::deviceForIndex( const QModelIndex& index ) const
{ {
@ -98,3 +99,20 @@ DeviceModel::deviceForIndex( const QModelIndex& index ) const
return nullptr; return nullptr;
return m_devices.at( row ); return m_devices.at( row );
} }
void
DeviceModel::swapDevice( Device* oldDevice, Device* newDevice )
{
Q_ASSERT( oldDevice );
Q_ASSERT( newDevice );
Q_ASSERT( oldDevice->deviceNode() == newDevice->deviceNode() );
int indexOfOldDevice = m_devices.indexOf( oldDevice );
if ( indexOfOldDevice < 0 )
return;
m_devices[ indexOfOldDevice ] = newDevice;
emit dataChanged( index( indexOfOldDevice ), index( indexOfOldDevice ) );
}

@ -46,6 +46,8 @@ public:
Device* deviceForIndex( const QModelIndex& index ) const; Device* deviceForIndex( const QModelIndex& index ) const;
void swapDevice( Device* oldDevice, Device* newDevice );
private: private:
QList< Device* > m_devices; QList< Device* > m_devices;
}; };

Loading…
Cancel
Save