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