diff --git a/src/modules/partition/CreatePartitionDialog.cpp b/src/modules/partition/CreatePartitionDialog.cpp index e093aadd7..17ec65765 100644 --- a/src/modules/partition/CreatePartitionDialog.cpp +++ b/src/modules/partition/CreatePartitionDialog.cpp @@ -81,19 +81,6 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par CreatePartitionDialog::~CreatePartitionDialog() {} -void -CreatePartitionDialog::setSectorRange( qint64 minSector, qint64 maxSector ) -{ - Q_ASSERT( minSector <= maxSector ); - m_minSector = minSector; - m_maxSector = maxSector; - - qint64 maxSize = ( m_maxSector - m_minSector + 1 ) * m_device->logicalSectorSize(); - - m_ui->sizeSpinBox->setMaximum( maxSize / 1024 / 1024 ); - m_ui->sizeSpinBox->setValue( m_ui->sizeSpinBox->maximum() ); -} - PartitionInfo* CreatePartitionDialog::createPartitionInfo() { @@ -148,11 +135,33 @@ CreatePartitionDialog::updateMountPointUi() m_ui->mountPointComboBox->setEnabled( enabled ); } +void +CreatePartitionDialog::initSectorRange( Partition* partition ) +{ + PartitionTable* table = m_device->partitionTable(); + m_minSector = partition->firstSector() - table->freeSectorsBefore( *partition ); + m_maxSector = partition->lastSector() + table->freeSectorsAfter( *partition ); + + qint64 maxSize = ( m_maxSector - m_minSector + 1 ) * m_device->logicalSectorSize(); + + m_ui->sizeSpinBox->setMaximum( maxSize / 1024 / 1024 ); + m_ui->sizeSpinBox->setValue( m_ui->sizeSpinBox->maximum() ); +} + +void +CreatePartitionDialog::initFromFreeSpace( Partition* freeSpacePartition ) +{ + initSectorRange( freeSpacePartition ); +} + void CreatePartitionDialog::initFromPartitionInfo( PartitionInfo* partitionInfo ) { Q_ASSERT( partitionInfo ); Partition* partition = partitionInfo->partition; + + initSectorRange( partition ); + qint64 maxSize = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize(); m_ui->sizeSpinBox->setValue( maxSize / 1024 / 1024 ); diff --git a/src/modules/partition/CreatePartitionDialog.h b/src/modules/partition/CreatePartitionDialog.h index f97f81d31..1f8e0c88a 100644 --- a/src/modules/partition/CreatePartitionDialog.h +++ b/src/modules/partition/CreatePartitionDialog.h @@ -38,7 +38,7 @@ public: CreatePartitionDialog( Device* device, PartitionNode* parentPartition, QWidget* parentWidget = nullptr ); ~CreatePartitionDialog(); - void setSectorRange( qint64 minSector, qint64 maxSector ); + void initFromFreeSpace( Partition* partition ); void initFromPartitionInfo( PartitionInfo* partitionInfo ); PartitionInfo* createPartitionInfo(); @@ -52,6 +52,8 @@ private: qint64 m_maxSector = 0; PartitionNode* m_parent; PartitionRole m_role = PartitionRole( PartitionRole::None ); + + void initSectorRange( Partition* ); }; #endif /* CREATEPARTITIONDIALOG_H */ diff --git a/src/modules/partition/PartitionPage.cpp b/src/modules/partition/PartitionPage.cpp index 44d75bcce..eba971b60 100644 --- a/src/modules/partition/PartitionPage.cpp +++ b/src/modules/partition/PartitionPage.cpp @@ -135,7 +135,7 @@ PartitionPage::onCreateClicked() Q_ASSERT( partition ); QPointer dlg = new CreatePartitionDialog( model->device(), partition->parent(), this ); - dlg->setSectorRange( partition->firstSector(), partition->lastSector() ); + dlg->initFromFreeSpace( partition ); if ( dlg->exec() == QDialog::Accepted ) m_core->createPartition( model->device(), dlg->createPartitionInfo() ); delete dlg; @@ -176,8 +176,6 @@ PartitionPage::updatePartitionToCreate( Device* device, PartitionInfo* partition { Partition* partition = partitionInfo->partition; QPointer dlg = new CreatePartitionDialog( device, partition->parent(), this ); - qint64 extraSectors = device->partitionTable()->freeSectorsAfter( *partition ); - dlg->setSectorRange( partition->firstSector(), partition->lastSector() + extraSectors ); dlg->initFromPartitionInfo( partitionInfo ); if ( dlg->exec() == QDialog::Accepted ) {