Show partition elements in separate column

main
Aurélien Gâteau 11 years ago
parent 0446bb1079
commit 3a58e2640f

@ -18,6 +18,7 @@
#include <PartitionModel.h>
#include <PMUtils.h>
#include <utils/Logger.h>
// CalaPM
#include <core/device.h>
@ -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();

@ -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;

@ -28,6 +28,7 @@
// Qt
#include <QDebug>
#include <QHeaderView>
#include <QItemSelectionModel>
#include <QPointer>
@ -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() );

@ -21,9 +21,6 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QListView" name="partitionListView"/>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@ -72,6 +69,22 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QTreeView" name="partitionTreeView">
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerStretchLastSection">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
<resources/>

Loading…
Cancel
Save