Skip to content

Commit

Permalink
Better headers in guide view
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 7, 2017
1 parent 048a5b7 commit e718f92
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions python/core/layout/qgslayoutguidecollection.sip
Expand Up @@ -164,6 +164,8 @@ class QgsLayoutGuideCollection : QAbstractTableModel

virtual Qt::ItemFlags flags( const QModelIndex &index ) const;

virtual QVariant headerData( int section, Qt::Orientation orientation,
int role = Qt::DisplayRole ) const;

void addGuide( QgsLayoutGuide *guide /Transfer/ );
%Docstring
Expand Down
14 changes: 13 additions & 1 deletion src/core/layout/qgslayoutguidecollection.cpp
Expand Up @@ -152,7 +152,8 @@ QgsLayoutGuideCollection::QgsLayoutGuideCollection( QgsLayout *layout )
: QAbstractTableModel( layout )
, mLayout( layout )
{

QFont f;
mHeaderSize = QFontMetrics( f ).width( "XX" );
}

QgsLayoutGuideCollection::~QgsLayoutGuideCollection()
Expand Down Expand Up @@ -276,6 +277,17 @@ Qt::ItemFlags QgsLayoutGuideCollection::flags( const QModelIndex &index ) const
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
}

QVariant QgsLayoutGuideCollection::headerData( int section, Qt::Orientation orientation, int role ) const
{
if ( role == Qt::DisplayRole )
return QVariant();
else if ( role == Qt::SizeHintRole )
{
return QSize( mHeaderSize, mHeaderSize );
}
return QAbstractTableModel::headerData( section, orientation, role );
}

void QgsLayoutGuideCollection::addGuide( QgsLayoutGuide *guide )
{
guide->setLayout( mLayout );
Expand Down
3 changes: 3 additions & 0 deletions src/core/layout/qgslayoutguidecollection.h
Expand Up @@ -189,6 +189,8 @@ class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractTableModel
QVariant data( const QModelIndex &index, int role ) const override;
bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
Qt::ItemFlags flags( const QModelIndex &index ) const override;
QVariant headerData( int section, Qt::Orientation orientation,
int role = Qt::DisplayRole ) const override;

/**
* Adds a \a guide to the collection. Ownership of the guide is transferred to the
Expand All @@ -213,6 +215,7 @@ class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractTableModel
QgsLayout *mLayout = nullptr;

QList< QgsLayoutGuide * > mGuides;
int mHeaderSize = 0;

};

Expand Down

0 comments on commit e718f92

Please sign in to comment.