From 2258c806aef77283b5b3eff2d7573cbf31764681 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 17 Dec 2015 15:39:52 +0100 Subject: [PATCH] Make the bars/labels views members in ChoicePage. --- src/modules/partition/gui/ChoicePage.cpp | 40 +++++++++++++++--------- src/modules/partition/gui/ChoicePage.h | 6 ++++ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 81cc774a7..f66165148 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -67,6 +67,8 @@ ChoicePage::ChoicePage( QWidget* parent ) , m_deviceInfoWidget( nullptr ) , m_lastSelectedDeviceIndex( -1 ) , m_isEfi( false ) + , m_beforePartitionBarsView( nullptr ) + , m_beforePartitionLabelsView( nullptr ) { setupUi( this ); @@ -430,6 +432,16 @@ ChoicePage::applyActionChoice( Device* currentDevice, ChoicePage::Choice choice PartitionActions::doAutopartition( m_core, selectedDevice() ); break; case Replace: + connect( m_beforePartitionBarsView->selectionModel(), &QItemSelectionModel::currentRowChanged, + this, [ this ]( const QModelIndex& current, const QModelIndex& previous ) + { + if ( m_core->isDirty() ) + m_core->clearJobs(); + + PartitionActions::doReplacePartition( m_core, + selectedDevice(), + ( Partition* )( current.data( PartitionModel::PartitionPtrRole ).value< void* >() ) ); + } ); case NoChoice: case Manual: @@ -461,41 +473,41 @@ ChoicePage::updateDeviceStatePreview( Device* currentDevice ) CalamaresUtils::unmarginLayout( layout ); layout->setSpacing( 6 ); - PartitionBarsView* preview = new PartitionBarsView( m_previewBeforeFrame ); - PartitionLabelsView* previewLabels = new PartitionLabelsView( m_previewBeforeFrame ); + m_beforePartitionBarsView = new PartitionBarsView( m_previewBeforeFrame ); + m_beforePartitionLabelsView = new PartitionLabelsView( m_previewBeforeFrame ); Device* deviceBefore = m_core->createImmutableDeviceCopy( currentDevice ); - PartitionModel* model = new PartitionModel( preview ); + PartitionModel* model = new PartitionModel( m_beforePartitionBarsView ); model->init( deviceBefore, m_core->osproberEntries() ); // The QObject parents tree is meaningful for memory management here, // see qDeleteAll above. deviceBefore->setParent( model ); - model->setParent( preview ); + model->setParent( m_beforePartitionBarsView ); - preview->setModel( model ); - previewLabels->setModel( model ); + m_beforePartitionBarsView->setModel( model ); + m_beforePartitionLabelsView->setModel( model ); // Make the bars and labels view use the same selectionModel. - auto sm = previewLabels->selectionModel(); - previewLabels->setSelectionModel( preview->selectionModel() ); + auto sm = m_beforePartitionLabelsView->selectionModel(); + m_beforePartitionLabelsView->setSelectionModel( m_beforePartitionBarsView->selectionModel() ); sm->deleteLater(); switch ( m_choice ) { case Replace: case Alongside: - preview->setSelectionMode( QAbstractItemView::SingleSelection ); - previewLabels->setSelectionMode( QAbstractItemView::SingleSelection ); + m_beforePartitionBarsView->setSelectionMode( QAbstractItemView::SingleSelection ); + m_beforePartitionLabelsView->setSelectionMode( QAbstractItemView::SingleSelection ); break; default: - preview->setSelectionMode( QAbstractItemView::NoSelection ); - previewLabels->setSelectionMode( QAbstractItemView::NoSelection ); + m_beforePartitionBarsView->setSelectionMode( QAbstractItemView::NoSelection ); + m_beforePartitionLabelsView->setSelectionMode( QAbstractItemView::NoSelection ); } - layout->addWidget( preview ); - layout->addWidget( previewLabels ); + layout->addWidget( m_beforePartitionBarsView ); + layout->addWidget( m_beforePartitionLabelsView ); } diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index e52bf941c..615c48f2a 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -26,6 +26,7 @@ #include "core/OsproberEntry.h" #include +#include class QBoxLayout; class QComboBox; @@ -33,6 +34,8 @@ class QLabel; class QListView; class ExpandableRadioButton; +class PartitionBarsView; +class PartitionLabelsView; class PartitionCoreModule; class PrettyRadioButton; class DeviceInfoWidget; @@ -97,6 +100,9 @@ private: DeviceInfoWidget* m_deviceInfoWidget; + QPointer< PartitionBarsView > m_beforePartitionBarsView; + QPointer< PartitionLabelsView > m_beforePartitionLabelsView; + int m_lastSelectedDeviceIndex; };