[partition] Refactor setting the flags UI

- Setup the lsit of flags consistently, by providing the available
   and to-be-checked flags.
 - In CreatePartitionDialog, assume that ~0 is all the flags.
This commit is contained in:
Adriaan de Groot 2018-05-16 09:04:47 -04:00
parent 4f451eece5
commit ca03dad67b
6 changed files with 25 additions and 47 deletions

View File

@ -121,7 +121,8 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par
m_ui->fsComboBox->setCurrentIndex( defaultFsIndex );
updateMountPointUi();
setupFlagsList();
setFlagList( *(m_ui->m_listFlags), static_cast< PartitionTable::Flags >( ~PartitionTable::Flags::Int(0) ), PartitionTable::Flags() );
// Checks the initial selection.
checkMountPointSelection();
}
@ -136,25 +137,6 @@ CreatePartitionDialog::newFlags() const
return flagsFromList( *(m_ui->m_listFlags) );
}
void
CreatePartitionDialog::setupFlagsList()
{
int f = 1;
QString s;
while ( !( s = PartitionTable::flagName( static_cast< PartitionTable::Flag >( f ) ) ).isEmpty() )
{
QListWidgetItem* item = new QListWidgetItem( s );
m_ui->m_listFlags->addItem( item );
item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
item->setData( Qt::UserRole, f );
item->setCheckState( Qt::Unchecked );
f <<= 1;
}
}
void
CreatePartitionDialog::initMbrPartitionTypeUi()
{

View File

@ -64,7 +64,6 @@ private Q_SLOTS:
void checkMountPointSelection();
private:
void setupFlagsList();
QScopedPointer< Ui_CreatePartitionDialog > m_ui;
PartitionSizeController* m_partitionSizeController;
Device* m_device;

View File

@ -106,7 +106,7 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit
m_ui->fileSystemLabel->setEnabled( m_ui->formatRadioButton->isChecked() );
m_ui->fileSystemComboBox->setEnabled( m_ui->formatRadioButton->isChecked() );
setupFlagsList();
setFlagList( *(m_ui->m_listFlags), m_partition->availableFlags(), PartitionInfo::flags( m_partition ) );
}
@ -120,30 +120,6 @@ EditExistingPartitionDialog::newFlags() const
return flagsFromList( *(m_ui->m_listFlags) );
}
void
EditExistingPartitionDialog::setupFlagsList()
{
int f = 1;
QString s;
while ( !( s = PartitionTable::flagName( static_cast< PartitionTable::Flag >( f ) ) ).isEmpty() )
{
if ( m_partition->availableFlags() & f )
{
QListWidgetItem* item = new QListWidgetItem( s );
m_ui->m_listFlags->addItem( item );
item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
item->setData( Qt::UserRole, f );
item->setCheckState( ( PartitionInfo::flags( m_partition ) & f ) ?
Qt::Checked :
Qt::Unchecked );
}
f <<= 1;
}
}
void
EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
{

View File

@ -56,7 +56,6 @@ private:
QStringList m_usedMountPoints;
PartitionTable::Flags newFlags() const;
void setupFlagsList();
void replacePartResizerWidget();
void updateMountPointPicker();
};

View File

@ -95,3 +95,24 @@ flagsFromList( const QListWidget& list )
return flags;
}
void
setFlagList( QListWidget& list, PartitionTable::Flags available, PartitionTable::Flags checked )
{
int f = 1;
QString s;
while ( !( s = PartitionTable::flagName( static_cast< PartitionTable::Flag >( f ) ) ).isEmpty() )
{
if ( available & f )
{
QListWidgetItem* item = new QListWidgetItem( s );
list.addItem( item );
item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
item->setData( Qt::UserRole, f );
item->setCheckState( ( checked & f ) ?
Qt::Checked :
Qt::Unchecked );
}
f <<= 1;
}
}

View File

@ -63,5 +63,6 @@ static inline void setSelectedMountPoint(QComboBox* combo, const QString& select
* Get the flags that have been checked in the list widget.
*/
PartitionTable::Flags flagsFromList( const QListWidget& list );
void setFlagList( QListWidget& list, PartitionTable::Flags available, PartitionTable::Flags checked );
#endif