Add swapDevice to DeviceModel.
This commit is contained in:
parent
1d553407b9
commit
0bf2389b1a
@ -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 ) );
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ public:
|
||||
|
||||
Device* deviceForIndex( const QModelIndex& index ) const;
|
||||
|
||||
void swapDevice( Device* oldDevice, Device* newDevice );
|
||||
|
||||
private:
|
||||
QList< Device* > m_devices;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user