diff --git a/src/modules/partition/PartitionModel.cpp b/src/modules/partition/PartitionModel.cpp index 248bdfc5c..fe6923473 100644 --- a/src/modules/partition/PartitionModel.cpp +++ b/src/modules/partition/PartitionModel.cpp @@ -18,6 +18,7 @@ #include #include +#include // CalaPM #include @@ -52,6 +53,12 @@ PartitionModel::reload() endResetModel(); } +int +PartitionModel::columnCount( const QModelIndex& parent ) const +{ + return LastColumn; +} + int PartitionModel::rowCount( const QModelIndex& parent ) const { @@ -73,19 +80,47 @@ PartitionModel::data( const QModelIndex& index, int role ) const { case Qt::DisplayRole: { - QString text = partition->roles().has( PartitionRole::Logical ) - ? QStringLiteral( " " ) : QStringLiteral(); - if ( PMUtils::isPartitionFreeSpace( partition ) ) + int col = index.column(); + if ( col == NameColumn ) { - text += tr( "Free Space" ); + // FIXME: Turn model into a tree model, will make implementing the + // preview easier + QString prefix = partition->roles().has( PartitionRole::Logical ) + ? QStringLiteral( " " ) : QStringLiteral(); + if ( PMUtils::isPartitionFreeSpace( partition ) ) + { + return prefix + tr( "Free Space" ); + } + else + { + return prefix + ( partition->partitionPath().isEmpty() + ? tr( "New partition" ) + : partition->partitionPath() ); + } } - else + if ( col == FileSystemColumn ) { - text += partition->partitionPath() + " " + partition->fileSystem().name() + " " + partition->mountPoint(); + return partition->fileSystem().name(); } - qint64 size = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize(); - text += tr( " (%1)" ).arg( KFormat().formatByteSize( size ) ); - return text; + if ( col == MountPointColumn ) + { + QString mountPoint = partition->mountPoint(); + if ( mountPoint.isEmpty() || mountPoint == "none" ) + { + return QString(); + } + else + { + return mountPoint; + } + } + if ( col == SizeColumn ) + { + qint64 size = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize(); + return KFormat().formatByteSize( size ); + } + cDebug() << "Unknown column" << col; + return QVariant(); } default: return QVariant(); diff --git a/src/modules/partition/PartitionModel.h b/src/modules/partition/PartitionModel.h index 64fb018f8..494efe733 100644 --- a/src/modules/partition/PartitionModel.h +++ b/src/modules/partition/PartitionModel.h @@ -27,11 +27,21 @@ class PartitionNode; class PartitionModel : public QAbstractListModel { public: + enum Column + { + NameColumn, + FileSystemColumn, + MountPointColumn, + SizeColumn, + LastColumn = SizeColumn + 1 + }; + PartitionModel( QObject* parent = 0 ); void init( Device* device ); - int rowCount( const QModelIndex& parent = QModelIndex() ) const Q_DECL_OVERRIDE; - QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const Q_DECL_OVERRIDE; + int columnCount( const QModelIndex& parent = QModelIndex() ) const override; + int rowCount( const QModelIndex& parent = QModelIndex() ) const override; + QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override; Partition* partitionForIndex( const QModelIndex& index ) const; diff --git a/src/modules/partition/PartitionPage.cpp b/src/modules/partition/PartitionPage.cpp index 25bf75415..96ba77c31 100644 --- a/src/modules/partition/PartitionPage.cpp +++ b/src/modules/partition/PartitionPage.cpp @@ -28,6 +28,7 @@ // Qt #include +#include #include #include @@ -45,11 +46,18 @@ PartitionPage::PartitionPage( PartitionCoreModule* core, QWidget* parent ) { Device* device = m_core->deviceModel()->deviceForIndex( index ); PartitionModel* model = m_core->partitionModelForDevice( device ); - m_ui->partitionListView->setModel( model ); + m_ui->partitionTreeView->setModel( model ); + + // Must be done here because we need to have a model set to define + // individual column resize mode + QHeaderView* header = m_ui->partitionTreeView->header(); + header->setSectionResizeMode( QHeaderView::ResizeToContents ); + header->setSectionResizeMode( 0, QHeaderView::Stretch ); + updateButtons(); // Establish connection here because selection model is destroyed when // model changes - connect( m_ui->partitionListView->selectionModel(), &QItemSelectionModel::currentChanged, + connect( m_ui->partitionTreeView->selectionModel(), &QItemSelectionModel::currentChanged, [ this ]( const QModelIndex& index, const QModelIndex& oldIndex ) { updateButtons(); @@ -70,7 +78,7 @@ PartitionPage::updateButtons() { bool create = false, edit = false, del = false; - QModelIndex index = m_ui->partitionListView->currentIndex(); + QModelIndex index = m_ui->partitionTreeView->currentIndex(); if ( index.isValid() ) { const PartitionModel* model = static_cast< const PartitionModel* >( index.model() ); @@ -89,7 +97,7 @@ PartitionPage::updateButtons() void PartitionPage::onCreateClicked() { - QModelIndex index = m_ui->partitionListView->currentIndex(); + QModelIndex index = m_ui->partitionTreeView->currentIndex(); Q_ASSERT( index.isValid() ); const PartitionModel* model = static_cast< const PartitionModel* >( index.model() ); @@ -107,7 +115,7 @@ PartitionPage::onCreateClicked() void PartitionPage::onDeleteClicked() { - QModelIndex index = m_ui->partitionListView->currentIndex(); + QModelIndex index = m_ui->partitionTreeView->currentIndex(); Q_ASSERT( index.isValid() ); const PartitionModel* model = static_cast< const PartitionModel* >( index.model() ); diff --git a/src/modules/partition/PartitionPage.ui b/src/modules/partition/PartitionPage.ui index cc5b34fea..2e6f0de41 100644 --- a/src/modules/partition/PartitionPage.ui +++ b/src/modules/partition/PartitionPage.ui @@ -21,9 +21,6 @@ - - - @@ -72,6 +69,22 @@ + + + + false + + + true + + + false + + + false + + +