Enable/disable partition buttons

This commit is contained in:
Aurélien Gâteau 2014-06-30 15:04:10 +02:00
parent 2000553a10
commit c254fe0b2a
2 changed files with 31 additions and 0 deletions

View File

@ -22,6 +22,7 @@
#include <DeviceModel.h> #include <DeviceModel.h>
#include <PartitionCoreModule.h> #include <PartitionCoreModule.h>
#include <PartitionModel.h> #include <PartitionModel.h>
#include <PMUtils.h>
#include <ui_PartitionPage.h> #include <ui_PartitionPage.h>
// Qt // Qt
@ -35,6 +36,7 @@ PartitionPage::PartitionPage( QWidget* parent )
{ {
m_ui->setupUi( this ); m_ui->setupUi( this );
m_ui->deviceListView->setModel( m_core->deviceModel() ); m_ui->deviceListView->setModel( m_core->deviceModel() );
updateButtons();
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 )
@ -42,9 +44,37 @@ PartitionPage::PartitionPage( QWidget* parent )
Device* device = m_core->deviceModel()->deviceForIndex( index ); Device* device = m_core->deviceModel()->deviceForIndex( index );
PartitionModel* model = m_core->partitionModelForDevice( device ); PartitionModel* model = m_core->partitionModelForDevice( device );
m_ui->partitionListView->setModel( model ); m_ui->partitionListView->setModel( model );
updateButtons();
// Establish connection here because selection model is destroyed when
// model changes
connect( m_ui->partitionListView->selectionModel(), &QItemSelectionModel::currentChanged,
[ this ]( const QModelIndex& index, const QModelIndex& oldIndex )
{
updateButtons();
} );
} ); } );
} }
PartitionPage::~PartitionPage() PartitionPage::~PartitionPage()
{ {
} }
void PartitionPage::updateButtons()
{
bool create = false, edit = false, del = false;
QModelIndex index = m_ui->partitionListView->currentIndex();
if ( index.isValid() )
{
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
Q_ASSERT( model );
Partition* partition = model->partitionForIndex( index );
Q_ASSERT( partition );
bool isFree = PMUtils::isPartitionFreeSpace( partition );
create = isFree;
edit = del = !isFree;
}
m_ui->createButton->setEnabled( create );
m_ui->editButton->setEnabled( edit );
m_ui->deleteButton->setEnabled( del );
}

View File

@ -42,6 +42,7 @@ public Q_SLOTS:
private: private:
QScopedPointer< Ui_PartitionPage > m_ui; QScopedPointer< Ui_PartitionPage > m_ui;
PartitionCoreModule* m_core; PartitionCoreModule* m_core;
void updateButtons();
}; };
#endif // PARTITIONPAGE_H #endif // PARTITIONPAGE_H