diff --git a/src/modules/partition/core/DeviceModel.cpp b/src/modules/partition/core/DeviceModel.cpp index ba0df2c18..260315729 100644 --- a/src/modules/partition/core/DeviceModel.cpp +++ b/src/modules/partition/core/DeviceModel.cpp @@ -139,3 +139,17 @@ DeviceModel::addDevice( Device *device ) endResetModel(); } + +void +DeviceModel::removeDevice( Device *device ) +{ + beginResetModel(); + + m_devices.removeAll( device ); + std::sort( m_devices.begin(), m_devices.end(), []( const Device* dev1, const Device* dev2 ) + { + return dev1->deviceNode() < dev2->deviceNode(); + } ); + + endResetModel(); +} diff --git a/src/modules/partition/core/DeviceModel.h b/src/modules/partition/core/DeviceModel.h index 84f1c3c9d..2e2f99342 100644 --- a/src/modules/partition/core/DeviceModel.h +++ b/src/modules/partition/core/DeviceModel.h @@ -51,6 +51,8 @@ public: void addDevice( Device* device ); + void removeDevice( Device* device ); + private: QList< Device* > m_devices; }; diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index d6be78844..fc7ce9753 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -680,8 +680,33 @@ PartitionCoreModule::revert() void PartitionCoreModule::revertAllDevices() { - foreach ( DeviceInfo* devInfo, m_deviceInfos ) - revertDevice( devInfo->device.data() ); + for ( auto it = m_deviceInfos.begin(); it != m_deviceInfos.end(); ) + { + // In new VGs device info, there will be always a CreateVolumeGroupJob as the first job in jobs list + if ( !( *it )->jobs.empty() ) + { + CreateVolumeGroupJob* vgJob = dynamic_cast( ( *it )->jobs[0].data() ); + + if ( vgJob ) + { + vgJob->undoPreview(); + + ( *it )->forgetChanges(); + + m_deviceModel->removeDevice( ( *it )->device.data() ); + + it = m_deviceInfos.erase( it ); + + scanForLVMPVs(); + } + } + else + { + revertDevice( ( *it )->device.data() ); + ++it; + } + } + refresh(); } @@ -691,6 +716,7 @@ PartitionCoreModule::revertDevice( Device* dev ) { QMutexLocker locker( &m_revertMutex ); DeviceInfo* devInfo = infoForDevice( dev ); + if ( !devInfo ) return; devInfo->forgetChanges(); diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index 503a4e2ea..550e356c0 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -222,16 +222,17 @@ PartitionPage::onNewVolumeGroupClicked() QModelIndex deviceIndex = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 ); Q_ASSERT( deviceIndex.isValid() ); - QVariant previousDeviceData = m_core->deviceModel()->data( deviceIndex, Qt::ToolTipRole ); + QVariant previousIndexDeviceData = m_core->deviceModel()->data( deviceIndex, Qt::ToolTipRole ); + // Creating new VG m_core->createVolumeGroup( vgName, selectedPVs, peSize ); // As createVolumeGroup method call resets deviceModel, // is needed to set the current index in deviceComboBox as the previous one - int previousIndex = m_ui->deviceComboBox->findData( previousDeviceData, Qt::ToolTipRole ); + int previousIndex = m_ui->deviceComboBox->findData( previousIndexDeviceData, Qt::ToolTipRole ); - if ( previousIndex != -1 ) - m_ui->deviceComboBox->setCurrentIndex( previousIndex ); + m_ui->deviceComboBox->setCurrentIndex( ( previousIndex < 0 ) ? 0 : previousIndex ); + updateFromCurrentDevice(); } delete dlg; @@ -301,7 +302,7 @@ PartitionPage::onRevertClicked() int oldIndex = m_ui->deviceComboBox->currentIndex(); m_core->revertAllDevices(); - m_ui->deviceComboBox->setCurrentIndex( oldIndex ); + m_ui->deviceComboBox->setCurrentIndex( ( oldIndex < 0 ) ? 0 : oldIndex ); updateFromCurrentDevice(); } ), [ this ]{