From 92169828596d539dd5cdeb37faed43327f1c25cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Wed, 16 Jul 2014 10:02:41 +0200 Subject: [PATCH] Allow editing of partition mount points --- src/modules/partition/CreatePartitionDialog.cpp | 7 ++++--- src/modules/partition/CreatePartitionDialog.h | 2 +- src/modules/partition/PartitionModel.cpp | 9 +++++++++ src/modules/partition/PartitionModel.h | 2 ++ src/modules/partition/PartitionPage.cpp | 10 ++++++---- src/modules/partition/PartitionPage.h | 3 ++- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/modules/partition/CreatePartitionDialog.cpp b/src/modules/partition/CreatePartitionDialog.cpp index bac85df1c..e093aadd7 100644 --- a/src/modules/partition/CreatePartitionDialog.cpp +++ b/src/modules/partition/CreatePartitionDialog.cpp @@ -149,11 +149,12 @@ CreatePartitionDialog::updateMountPointUi() } void -CreatePartitionDialog::initFromPartition( Partition* partition ) +CreatePartitionDialog::initFromPartitionInfo( PartitionInfo* partitionInfo ) { - Q_ASSERT( partition ); + Q_ASSERT( partitionInfo ); + Partition* partition = partitionInfo->partition; qint64 maxSize = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize(); m_ui->sizeSpinBox->setValue( maxSize / 1024 / 1024 ); - // FIXME: Update other fields + m_ui->mountPointComboBox->setCurrentText( partitionInfo->mountPoint ); } diff --git a/src/modules/partition/CreatePartitionDialog.h b/src/modules/partition/CreatePartitionDialog.h index cd83364c1..f97f81d31 100644 --- a/src/modules/partition/CreatePartitionDialog.h +++ b/src/modules/partition/CreatePartitionDialog.h @@ -39,7 +39,7 @@ public: ~CreatePartitionDialog(); void setSectorRange( qint64 minSector, qint64 maxSector ); - void initFromPartition( Partition* partition ); + void initFromPartitionInfo( PartitionInfo* partitionInfo ); PartitionInfo* createPartitionInfo(); private Q_SLOTS: diff --git a/src/modules/partition/PartitionModel.cpp b/src/modules/partition/PartitionModel.cpp index 3348f670b..2af265647 100644 --- a/src/modules/partition/PartitionModel.cpp +++ b/src/modules/partition/PartitionModel.cpp @@ -139,3 +139,12 @@ PartitionModel::partitionForIndex( const QModelIndex& index ) const return nullptr; return m_partitionList.at( row ); } + +PartitionInfo* +PartitionModel::partitionInfoForIndex( const QModelIndex& index ) const +{ + Partition* partition = partitionForIndex( index ); + if (!partition ) + return nullptr; + return m_infoProvider->infoForPartition( partition ); +} diff --git a/src/modules/partition/PartitionModel.h b/src/modules/partition/PartitionModel.h index edbe3a645..c864a124f 100644 --- a/src/modules/partition/PartitionModel.h +++ b/src/modules/partition/PartitionModel.h @@ -25,6 +25,7 @@ class Device; class Partition; +class PartitionInfo; class PartitionNode; class PartitionInfoProvider @@ -63,6 +64,7 @@ public: QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override; Partition* partitionForIndex( const QModelIndex& index ) const; + PartitionInfo* partitionInfoForIndex( const QModelIndex& index ) const; Device* device() const { diff --git a/src/modules/partition/PartitionPage.cpp b/src/modules/partition/PartitionPage.cpp index 17f27b4c2..44d75bcce 100644 --- a/src/modules/partition/PartitionPage.cpp +++ b/src/modules/partition/PartitionPage.cpp @@ -149,10 +149,11 @@ PartitionPage::onEditClicked() const PartitionModel* model = static_cast< const PartitionModel* >( index.model() ); Partition* partition = model->partitionForIndex( index ); + PartitionInfo* partitionInfo = model->partitionInfoForIndex( index ); Q_ASSERT( partition ); - if ( index.data( PartitionModel::IsNewPartitionRole ).toBool() ) - updatePartitionToCreate( model->device(), partition ); + if ( PMUtils::isPartitionNew( partitionInfo->partition ) ) + updatePartitionToCreate( model->device(), partitionInfo ); else editExistingPartition( partition ); } @@ -171,12 +172,13 @@ PartitionPage::onDeleteClicked() } void -PartitionPage::updatePartitionToCreate( Device* device, Partition* partition ) +PartitionPage::updatePartitionToCreate( Device* device, PartitionInfo* partitionInfo ) { + 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->initFromPartition( partition ); + dlg->initFromPartitionInfo( partitionInfo ); if ( dlg->exec() == QDialog::Accepted ) { m_core->deletePartition( device, partition ); diff --git a/src/modules/partition/PartitionPage.h b/src/modules/partition/PartitionPage.h index d4741a5ea..ac9634694 100644 --- a/src/modules/partition/PartitionPage.h +++ b/src/modules/partition/PartitionPage.h @@ -28,6 +28,7 @@ class Ui_PartitionPage; class Device; class DeviceModel; class Partition; +class PartitionInfo; class PartitionPage : public QWidget { @@ -49,7 +50,7 @@ private: void onEditClicked(); void onDeleteClicked(); - void updatePartitionToCreate( Device*, Partition* ); + void updatePartitionToCreate( Device*, PartitionInfo* ); void editExistingPartition( Partition* ); };