Apply SelectionFilter in Partition{Labels,Bars}View.
This commit is contained in:
parent
f7f19eb617
commit
ddf4878ec7
@ -53,6 +53,7 @@ static const int SELECTION_MARGIN = qMin( ( EXTENDED_PARTITION_MARGIN - 2 ) / 2,
|
||||
PartitionBarsView::PartitionBarsView( QWidget* parent )
|
||||
: QAbstractItemView( parent )
|
||||
, m_hoveredIndex( QModelIndex() )
|
||||
, canBeSelected( []( const QModelIndex& ) { return true; } )
|
||||
{
|
||||
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
|
||||
setFrameStyle( QFrame::NoFrame );
|
||||
@ -397,6 +398,13 @@ PartitionBarsView::setSelectionModel( QItemSelectionModel* selectionModel )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PartitionBarsView::setSelectionFilter( std::function< bool ( const QModelIndex& ) > canBeSelected )
|
||||
{
|
||||
this->canBeSelected = canBeSelected;
|
||||
}
|
||||
|
||||
|
||||
QModelIndex
|
||||
PartitionBarsView::moveCursor( CursorAction cursorAction, Qt::KeyboardModifiers modifiers )
|
||||
{
|
||||
@ -430,7 +438,11 @@ PartitionBarsView::setSelection( const QRect& rect, QItemSelectionModel::Selecti
|
||||
// TL;DR: this sucks, look away. -- Teo 12/2015
|
||||
int x1, y1, x2, y2;
|
||||
rect.getCoords( &x1, &y1, &x2, &y2 );
|
||||
selectionModel()->select( indexAt( QPoint( x2, y2 ) ), flags );
|
||||
|
||||
QModelIndex eventIndex = indexAt( QPoint( x2, y2 ) );
|
||||
if ( canBeSelected( eventIndex ) )
|
||||
selectionModel()->select( eventIndex, flags );
|
||||
|
||||
viewport()->repaint();
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,11 @@
|
||||
#ifndef PARTITIONPREVIEW_H
|
||||
#define PARTITIONPREVIEW_H
|
||||
|
||||
#include "PartitionViewSelectionFilter.h"
|
||||
|
||||
#include <QAbstractItemView>
|
||||
|
||||
|
||||
/**
|
||||
* A Qt model view which displays the partitions inside a device as a colored bar.
|
||||
*
|
||||
@ -48,6 +51,8 @@ public:
|
||||
|
||||
void setSelectionModel( QItemSelectionModel* selectionModel ) override;
|
||||
|
||||
void setSelectionFilter( SelectionFilter canBeSelected );
|
||||
|
||||
protected:
|
||||
// QAbstractItemView API
|
||||
QRegion visualRegionForSelection( const QItemSelection& selection ) const override;
|
||||
@ -69,6 +74,8 @@ private:
|
||||
QModelIndex indexAt( const QPoint& point, const QRect& rect, const QModelIndex& parent ) const;
|
||||
QRect visualRect( const QModelIndex& index, const QRect& rect, const QModelIndex& parent ) const;
|
||||
|
||||
SelectionFilter canBeSelected;
|
||||
|
||||
struct Item
|
||||
{
|
||||
qreal size;
|
||||
|
@ -53,6 +53,7 @@ buildUnknownDisklabelTexts( Device* dev )
|
||||
|
||||
PartitionLabelsView::PartitionLabelsView( QWidget* parent )
|
||||
: QAbstractItemView( parent )
|
||||
, canBeSelected( []( const QModelIndex& ) { return true; } )
|
||||
{
|
||||
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
|
||||
setFrameStyle( QFrame::NoFrame );
|
||||
@ -523,7 +524,9 @@ PartitionLabelsView::isIndexHidden( const QModelIndex& index ) const
|
||||
void
|
||||
PartitionLabelsView::setSelection( const QRect& rect, QItemSelectionModel::SelectionFlags flags )
|
||||
{
|
||||
selectionModel()->select( indexAt( rect.topLeft() ), flags );
|
||||
QModelIndex eventIndex = indexAt( rect.topLeft() );
|
||||
if ( canBeSelected( eventIndex ) )
|
||||
selectionModel()->select( eventIndex, flags );
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,6 +20,8 @@
|
||||
#ifndef PARTITIONLABELSVIEW_H
|
||||
#define PARTITIONLABELSVIEW_H
|
||||
|
||||
#include "PartitionViewSelectionFilter.h"
|
||||
|
||||
#include <QAbstractItemView>
|
||||
|
||||
/**
|
||||
@ -51,6 +53,8 @@ public:
|
||||
|
||||
void setSelectionModel( QItemSelectionModel* selectionModel ) override;
|
||||
|
||||
void setSelectionFilter( SelectionFilter canBeSelected );
|
||||
|
||||
protected:
|
||||
// QAbstractItemView API
|
||||
QRegion visualRegionForSelection( const QItemSelection& selection ) const override;
|
||||
@ -75,6 +79,9 @@ private:
|
||||
const QPoint& pos , bool selected );
|
||||
QModelIndexList getIndexesToDraw( const QModelIndex& parent ) const;
|
||||
QStringList buildTexts( const QModelIndex& index ) const;
|
||||
|
||||
SelectionFilter canBeSelected;
|
||||
|
||||
QString m_customNewRootLabel;
|
||||
QPersistentModelIndex m_hoveredIndex;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user