Refactor: move sector math from PartitionPage to CreatePartitionDialog

This commit is contained in:
Aurélien Gâteau 2014-07-16 10:15:57 +02:00
parent 7c1ecabd68
commit a70ab4ad60
3 changed files with 26 additions and 17 deletions

View File

@ -81,19 +81,6 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par
CreatePartitionDialog::~CreatePartitionDialog() 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* PartitionInfo*
CreatePartitionDialog::createPartitionInfo() CreatePartitionDialog::createPartitionInfo()
{ {
@ -148,11 +135,33 @@ CreatePartitionDialog::updateMountPointUi()
m_ui->mountPointComboBox->setEnabled( enabled ); 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 void
CreatePartitionDialog::initFromPartitionInfo( PartitionInfo* partitionInfo ) CreatePartitionDialog::initFromPartitionInfo( PartitionInfo* partitionInfo )
{ {
Q_ASSERT( partitionInfo ); Q_ASSERT( partitionInfo );
Partition* partition = partitionInfo->partition; Partition* partition = partitionInfo->partition;
initSectorRange( partition );
qint64 maxSize = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize(); qint64 maxSize = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize();
m_ui->sizeSpinBox->setValue( maxSize / 1024 / 1024 ); m_ui->sizeSpinBox->setValue( maxSize / 1024 / 1024 );

View File

@ -38,7 +38,7 @@ public:
CreatePartitionDialog( Device* device, PartitionNode* parentPartition, QWidget* parentWidget = nullptr ); CreatePartitionDialog( Device* device, PartitionNode* parentPartition, QWidget* parentWidget = nullptr );
~CreatePartitionDialog(); ~CreatePartitionDialog();
void setSectorRange( qint64 minSector, qint64 maxSector ); void initFromFreeSpace( Partition* partition );
void initFromPartitionInfo( PartitionInfo* partitionInfo ); void initFromPartitionInfo( PartitionInfo* partitionInfo );
PartitionInfo* createPartitionInfo(); PartitionInfo* createPartitionInfo();
@ -52,6 +52,8 @@ private:
qint64 m_maxSector = 0; qint64 m_maxSector = 0;
PartitionNode* m_parent; PartitionNode* m_parent;
PartitionRole m_role = PartitionRole( PartitionRole::None ); PartitionRole m_role = PartitionRole( PartitionRole::None );
void initSectorRange( Partition* );
}; };
#endif /* CREATEPARTITIONDIALOG_H */ #endif /* CREATEPARTITIONDIALOG_H */

View File

@ -135,7 +135,7 @@ PartitionPage::onCreateClicked()
Q_ASSERT( partition ); Q_ASSERT( partition );
QPointer<CreatePartitionDialog> dlg = new CreatePartitionDialog( model->device(), partition->parent(), this ); QPointer<CreatePartitionDialog> dlg = new CreatePartitionDialog( model->device(), partition->parent(), this );
dlg->setSectorRange( partition->firstSector(), partition->lastSector() ); dlg->initFromFreeSpace( partition );
if ( dlg->exec() == QDialog::Accepted ) if ( dlg->exec() == QDialog::Accepted )
m_core->createPartition( model->device(), dlg->createPartitionInfo() ); m_core->createPartition( model->device(), dlg->createPartitionInfo() );
delete dlg; delete dlg;
@ -176,8 +176,6 @@ PartitionPage::updatePartitionToCreate( Device* device, PartitionInfo* partition
{ {
Partition* partition = partitionInfo->partition; Partition* partition = partitionInfo->partition;
QPointer<CreatePartitionDialog> dlg = new CreatePartitionDialog( device, partition->parent(), this ); 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 ); dlg->initFromPartitionInfo( partitionInfo );
if ( dlg->exec() == QDialog::Accepted ) if ( dlg->exec() == QDialog::Accepted )
{ {