diff --git a/src/modules/partition/core/DeviceModel.cpp b/src/modules/partition/core/DeviceModel.cpp index 29bcbfc38..4c8589033 100644 --- a/src/modules/partition/core/DeviceModel.cpp +++ b/src/modules/partition/core/DeviceModel.cpp @@ -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 ) ); +} diff --git a/src/modules/partition/core/DeviceModel.h b/src/modules/partition/core/DeviceModel.h index 77b86b1bf..21c6bd939 100644 --- a/src/modules/partition/core/DeviceModel.h +++ b/src/modules/partition/core/DeviceModel.h @@ -46,6 +46,8 @@ public: Device* deviceForIndex( const QModelIndex& index ) const; + void swapDevice( Device* oldDevice, Device* newDevice ); + private: QList< Device* > m_devices; };