From d54dfcfb781cd84ccdc1e02344871eca6ad24594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Fri, 4 Jul 2014 17:40:55 +0200 Subject: [PATCH] Get rid of DeviceInfo --- src/modules/partition/PartitionCoreModule.cpp | 58 +++++-------------- src/modules/partition/PartitionCoreModule.h | 15 ++--- 2 files changed, 17 insertions(+), 56 deletions(-) diff --git a/src/modules/partition/PartitionCoreModule.cpp b/src/modules/partition/PartitionCoreModule.cpp index 71d464a62..b3a787a8c 100644 --- a/src/modules/partition/PartitionCoreModule.cpp +++ b/src/modules/partition/PartitionCoreModule.cpp @@ -33,19 +33,6 @@ #include -//- DeviceInfo -------------------------------------------- -PartitionCoreModule::DeviceInfo::DeviceInfo( Device* dev ) - : device( dev ) - , partitionModel( new PartitionModel ) -{ -} - -PartitionCoreModule::DeviceInfo::~DeviceInfo() -{ - delete partitionModel; -} - -//- PartitionCoreModule ----------------------------------- PartitionCoreModule::PartitionCoreModule( QObject* parent ) : QObject( parent ) , m_deviceModel( new DeviceModel( this ) ) @@ -57,14 +44,14 @@ PartitionCoreModule::PartitionCoreModule( QObject* parent ) } CoreBackend* backend = CoreBackendManager::self()->backend(); - QList< Device* > lst = backend->scanDevices(); - m_deviceModel->init( lst ); - for ( auto device : lst ) + m_devices = backend->scanDevices(); + for ( auto device : m_devices ) { - DeviceInfo* info = new DeviceInfo( device ); - info->partitionModel->init( device, &m_infoForPartitionHash ); - m_devices << info; + PartitionModel* model = new PartitionModel; + model->init( device, &m_infoForPartitionHash ); + m_partitionModelForDeviceHash[ device ] = model; } + m_deviceModel->init( m_devices ); } @@ -83,45 +70,25 @@ PartitionCoreModule::deviceModel() const PartitionModel* PartitionCoreModule::partitionModelForDevice( Device* device ) const { - for ( auto it : m_devices ) - { - if ( it->device == device ) - { - return it->partitionModel; - } - } - return nullptr; + return m_partitionModelForDeviceHash[ device ]; } void PartitionCoreModule::createPartition( CreatePartitionJob* job ) { - DeviceInfo* info = deviceInfoForDevice( job->device() ); - Q_ASSERT( info ); Q_ASSERT( !m_infoForPartitionHash.contains( job->partition() ) ); PartitionInfo* partitionInfo = new PartitionInfo( job->partition() ); partitionInfo->mountPoint = job->mountPoint(); m_infoForPartitionHash[ job->partition() ] = partitionInfo; job->updatePreview(); - info->partitionModel->reload(); + auto partitionModel = m_partitionModelForDeviceHash.value( job->device() ); + Q_ASSERT( partitionModel ); + partitionModel->reload(); m_jobs << Calamares::job_ptr( job ); dumpQueue(); } -PartitionCoreModule::DeviceInfo* -PartitionCoreModule::deviceInfoForDevice( Device* device ) const -{ - for ( auto info : m_devices ) - { - if ( info->device == device ) - { - return info; - } - } - return nullptr; -} - void PartitionCoreModule::deletePartition( Device* device, Partition* partition ) { @@ -157,8 +124,9 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition ) m_jobs << Calamares::job_ptr( job ); } - DeviceInfo* info = deviceInfoForDevice( device ); - info->partitionModel->reload(); + auto partitionModel = m_partitionModelForDeviceHash.value( device ); + Q_ASSERT( partitionModel ); + partitionModel->reload(); dumpQueue(); } diff --git a/src/modules/partition/PartitionCoreModule.h b/src/modules/partition/PartitionCoreModule.h index b72fcf56a..a9255d48b 100644 --- a/src/modules/partition/PartitionCoreModule.h +++ b/src/modules/partition/PartitionCoreModule.h @@ -59,23 +59,16 @@ public: } private: - struct DeviceInfo - { - DeviceInfo( Device* dev ); - ~DeviceInfo(); - Device* device; - PartitionModel* partitionModel; - }; - QList< DeviceInfo* > m_devices; - InfoForPartitionHash m_infoForPartitionHash; + QList< Device* > m_devices; + QHash< Device*, PartitionModel* > m_partitionModelForDeviceHash; DeviceModel* m_deviceModel; + InfoForPartitionHash m_infoForPartitionHash; + QList< Calamares::job_ptr > m_jobs; void listDevices(); - DeviceInfo* deviceInfoForDevice( Device* device ) const; - void dumpQueue() const; };