Enable/disable partition buttons
This commit is contained in:
parent
2000553a10
commit
c254fe0b2a
@ -22,6 +22,7 @@
|
||||
#include <DeviceModel.h>
|
||||
#include <PartitionCoreModule.h>
|
||||
#include <PartitionModel.h>
|
||||
#include <PMUtils.h>
|
||||
#include <ui_PartitionPage.h>
|
||||
|
||||
// Qt
|
||||
@ -35,6 +36,7 @@ PartitionPage::PartitionPage( QWidget* parent )
|
||||
{
|
||||
m_ui->setupUi( this );
|
||||
m_ui->deviceListView->setModel( m_core->deviceModel() );
|
||||
updateButtons();
|
||||
|
||||
connect( m_ui->deviceListView->selectionModel(), &QItemSelectionModel::currentChanged,
|
||||
[ this ]( const QModelIndex& index, const QModelIndex& oldIndex )
|
||||
@ -42,9 +44,37 @@ PartitionPage::PartitionPage( QWidget* parent )
|
||||
Device* device = m_core->deviceModel()->deviceForIndex( index );
|
||||
PartitionModel* model = m_core->partitionModelForDevice( device );
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ public Q_SLOTS:
|
||||
private:
|
||||
QScopedPointer< Ui_PartitionPage > m_ui;
|
||||
PartitionCoreModule* m_core;
|
||||
void updateButtons();
|
||||
};
|
||||
|
||||
#endif // PARTITIONPAGE_H
|
||||
|
Loading…
Reference in New Issue
Block a user