Add swapDevice to DeviceModel.

This commit is contained in:
Teo Mrnjavac 2015-12-17 17:58:13 +01:00
parent 1d553407b9
commit 0bf2389b1a
2 changed files with 20 additions and 0 deletions

View File

@ -90,6 +90,7 @@ DeviceModel::data( const QModelIndex& index, int role ) const
}
}
Device*
DeviceModel::deviceForIndex( const QModelIndex& index ) const
{
@ -98,3 +99,20 @@ DeviceModel::deviceForIndex( const QModelIndex& index ) const
return nullptr;
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 ) );
}

View File

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