Persistent partition model

This will make it possible to update the partition list on changes,
regardless of the actual device state
main
Aurélien Gâteau 11 years ago
parent e6be09982e
commit 8f474fa08f

@ -16,20 +16,43 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include <DeviceModel.h>
#include <PartitionModel.h>
// CalaPM
#include <core/device.h>
DeviceModel::DeviceInfo::DeviceInfo( Device* dev )
: device( dev )
, partitionModel( new PartitionModel )
{
partitionModel->init( dev );
}
DeviceModel::DeviceInfo::~DeviceInfo()
{
delete device;
delete partitionModel;
}
DeviceModel::DeviceModel( QObject* parent )
: QAbstractListModel( parent )
{
}
DeviceModel::~DeviceModel()
{
qDeleteAll( m_devices );
}
void
DeviceModel::init( const QList< Device* >& devices )
{
beginResetModel();
m_devices = devices;
m_devices.clear();
for ( auto device : devices )
{
m_devices << new DeviceInfo( device );
}
endResetModel();
}
@ -48,7 +71,7 @@ DeviceModel::data( const QModelIndex& index, int role ) const
return QVariant();
}
Device* device = m_devices.at( row );
Device* device = m_devices.at( row )->device;
switch ( role )
{
@ -66,13 +89,13 @@ DeviceModel::data( const QModelIndex& index, int role ) const
}
}
Device*
DeviceModel::deviceForIndex( const QModelIndex& index ) const
PartitionModel*
DeviceModel::partitionModelForIndex( const QModelIndex& index ) const
{
int row = index.row();
if ( row < 0 || row >= m_devices.count() )
{
return nullptr;
}
return m_devices.at( row );
return m_devices.at( row )->partitionModel;
}

@ -19,23 +19,38 @@
#define DEVICEMODEL_H
#include <QAbstractListModel>
#include <QScopedPointer>
#include <QList>
class Device;
class PartitionModel;
class DeviceModel : public QAbstractListModel
{
public:
DeviceModel( QObject* parent = 0 );
~DeviceModel();
/**
* Init the model with the list of devices.
* Takes ownership of the devices.
*/
void init( const QList< Device* >& devices );
int rowCount( const QModelIndex& parent = QModelIndex() ) const Q_DECL_OVERRIDE;
QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const Q_DECL_OVERRIDE;
Device* deviceForIndex( const QModelIndex& index ) const;
PartitionModel* partitionModelForIndex( const QModelIndex& index ) const;
private:
QList< Device* > m_devices;
struct DeviceInfo
{
DeviceInfo( Device* dev );
~DeviceInfo();
Device* device;
PartitionModel* partitionModel;
};
QList< DeviceInfo* > m_devices;
};
#endif /* DEVICEMODEL_H */

@ -36,7 +36,6 @@ PartitionPage::PartitionPage( QWidget* parent )
: Calamares::AbstractPage( parent )
, m_ui( new Ui_PartitionPage )
, m_deviceModel( new DeviceModel( this ) )
, m_partitionModel( new PartitionModel( this ) )
{
// FIXME: Should be done at startup
if ( !CalaPM::init() )
@ -46,16 +45,15 @@ PartitionPage::PartitionPage( QWidget* parent )
m_backend = CoreBackendManager::self()->backend();
m_ui->setupUi( this );
m_ui->deviceListView->setModel( m_deviceModel );
m_ui->partitionListView->setModel( m_partitionModel );
m_deviceModel->init( m_backend->scanDevices() );
connect( m_ui->deviceListView->selectionModel(), &QItemSelectionModel::currentChanged,
[ this ]( const QModelIndex& index, const QModelIndex& oldIndex )
{
Device* device = m_deviceModel->deviceForIndex( index );
m_partitionModel->init( device );
} );
[ this ]( const QModelIndex& index, const QModelIndex& oldIndex )
{
PartitionModel* model = m_deviceModel->partitionModelForIndex( index );
m_ui->partitionListView->setModel( model );
} );
}
PartitionPage::~PartitionPage()

@ -27,7 +27,6 @@ class CoreBackend;
class Ui_PartitionPage;
class DeviceModel;
class PartitionModel;
class PartitionPage : public Calamares::AbstractPage
{
@ -43,7 +42,6 @@ public Q_SLOTS:
private:
QScopedPointer< Ui_PartitionPage > m_ui;
DeviceModel* m_deviceModel;
PartitionModel* m_partitionModel;
CoreBackend* m_backend;
};

Loading…
Cancel
Save