Refactor: move sector math from PartitionPage to CreatePartitionDialog
This commit is contained in:
parent
7c1ecabd68
commit
a70ab4ad60
@ -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 );
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -135,7 +135,7 @@ PartitionPage::onCreateClicked()
|
||||
Q_ASSERT( partition );
|
||||
|
||||
QPointer<CreatePartitionDialog> 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<CreatePartitionDialog> 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 )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user