Show partition elements in separate column
This commit is contained in:
parent
0446bb1079
commit
3a58e2640f
@ -18,6 +18,7 @@
|
|||||||
#include <PartitionModel.h>
|
#include <PartitionModel.h>
|
||||||
|
|
||||||
#include <PMUtils.h>
|
#include <PMUtils.h>
|
||||||
|
#include <utils/Logger.h>
|
||||||
|
|
||||||
// CalaPM
|
// CalaPM
|
||||||
#include <core/device.h>
|
#include <core/device.h>
|
||||||
@ -52,6 +53,12 @@ PartitionModel::reload()
|
|||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
PartitionModel::columnCount( const QModelIndex& parent ) const
|
||||||
|
{
|
||||||
|
return LastColumn;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
PartitionModel::rowCount( const QModelIndex& parent ) const
|
PartitionModel::rowCount( const QModelIndex& parent ) const
|
||||||
{
|
{
|
||||||
@ -73,19 +80,47 @@ PartitionModel::data( const QModelIndex& index, int role ) const
|
|||||||
{
|
{
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
{
|
{
|
||||||
QString text = partition->roles().has( PartitionRole::Logical )
|
int col = index.column();
|
||||||
? QStringLiteral( " " ) : QStringLiteral();
|
if ( col == NameColumn )
|
||||||
if ( PMUtils::isPartitionFreeSpace( partition ) )
|
|
||||||
{
|
{
|
||||||
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();
|
if ( col == MountPointColumn )
|
||||||
text += tr( " (%1)" ).arg( KFormat().formatByteSize( size ) );
|
{
|
||||||
return text;
|
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:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -27,11 +27,21 @@ class PartitionNode;
|
|||||||
class PartitionModel : public QAbstractListModel
|
class PartitionModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum Column
|
||||||
|
{
|
||||||
|
NameColumn,
|
||||||
|
FileSystemColumn,
|
||||||
|
MountPointColumn,
|
||||||
|
SizeColumn,
|
||||||
|
LastColumn = SizeColumn + 1
|
||||||
|
};
|
||||||
|
|
||||||
PartitionModel( QObject* parent = 0 );
|
PartitionModel( QObject* parent = 0 );
|
||||||
void init( Device* device );
|
void init( Device* device );
|
||||||
|
|
||||||
int rowCount( const QModelIndex& parent = QModelIndex() ) const Q_DECL_OVERRIDE;
|
int columnCount( const QModelIndex& parent = QModelIndex() ) const override;
|
||||||
QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const Q_DECL_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;
|
Partition* partitionForIndex( const QModelIndex& index ) const;
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
// Qt
|
// Qt
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QHeaderView>
|
||||||
#include <QItemSelectionModel>
|
#include <QItemSelectionModel>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
@ -45,11 +46,18 @@ PartitionPage::PartitionPage( PartitionCoreModule* core, 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->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();
|
updateButtons();
|
||||||
// Establish connection here because selection model is destroyed when
|
// Establish connection here because selection model is destroyed when
|
||||||
// model changes
|
// model changes
|
||||||
connect( m_ui->partitionListView->selectionModel(), &QItemSelectionModel::currentChanged,
|
connect( m_ui->partitionTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
|
||||||
[ this ]( const QModelIndex& index, const QModelIndex& oldIndex )
|
[ this ]( const QModelIndex& index, const QModelIndex& oldIndex )
|
||||||
{
|
{
|
||||||
updateButtons();
|
updateButtons();
|
||||||
@ -70,7 +78,7 @@ PartitionPage::updateButtons()
|
|||||||
{
|
{
|
||||||
bool create = false, edit = false, del = false;
|
bool create = false, edit = false, del = false;
|
||||||
|
|
||||||
QModelIndex index = m_ui->partitionListView->currentIndex();
|
QModelIndex index = m_ui->partitionTreeView->currentIndex();
|
||||||
if ( index.isValid() )
|
if ( index.isValid() )
|
||||||
{
|
{
|
||||||
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
|
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
|
||||||
@ -89,7 +97,7 @@ PartitionPage::updateButtons()
|
|||||||
void
|
void
|
||||||
PartitionPage::onCreateClicked()
|
PartitionPage::onCreateClicked()
|
||||||
{
|
{
|
||||||
QModelIndex index = m_ui->partitionListView->currentIndex();
|
QModelIndex index = m_ui->partitionTreeView->currentIndex();
|
||||||
Q_ASSERT( index.isValid() );
|
Q_ASSERT( index.isValid() );
|
||||||
|
|
||||||
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
|
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
|
||||||
@ -107,7 +115,7 @@ PartitionPage::onCreateClicked()
|
|||||||
void
|
void
|
||||||
PartitionPage::onDeleteClicked()
|
PartitionPage::onDeleteClicked()
|
||||||
{
|
{
|
||||||
QModelIndex index = m_ui->partitionListView->currentIndex();
|
QModelIndex index = m_ui->partitionTreeView->currentIndex();
|
||||||
Q_ASSERT( index.isValid() );
|
Q_ASSERT( index.isValid() );
|
||||||
|
|
||||||
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
|
const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
|
||||||
|
@ -21,9 +21,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QListView" name="partitionListView"/>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
@ -72,6 +69,22 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
Loading…
Reference in New Issue
Block a user