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

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

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

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

Loading…
Cancel
Save