Skip to content

Commit e718f92

Browse files
committed
Better headers in guide view
1 parent 048a5b7 commit e718f92

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

python/core/layout/qgslayoutguidecollection.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ class QgsLayoutGuideCollection : QAbstractTableModel
164164

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

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

168170
void addGuide( QgsLayoutGuide *guide /Transfer/ );
169171
%Docstring

src/core/layout/qgslayoutguidecollection.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ QgsLayoutGuideCollection::QgsLayoutGuideCollection( QgsLayout *layout )
152152
: QAbstractTableModel( layout )
153153
, mLayout( layout )
154154
{
155-
155+
QFont f;
156+
mHeaderSize = QFontMetrics( f ).width( "XX" );
156157
}
157158

158159
QgsLayoutGuideCollection::~QgsLayoutGuideCollection()
@@ -276,6 +277,17 @@ Qt::ItemFlags QgsLayoutGuideCollection::flags( const QModelIndex &index ) const
276277
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
277278
}
278279

280+
QVariant QgsLayoutGuideCollection::headerData( int section, Qt::Orientation orientation, int role ) const
281+
{
282+
if ( role == Qt::DisplayRole )
283+
return QVariant();
284+
else if ( role == Qt::SizeHintRole )
285+
{
286+
return QSize( mHeaderSize, mHeaderSize );
287+
}
288+
return QAbstractTableModel::headerData( section, orientation, role );
289+
}
290+
279291
void QgsLayoutGuideCollection::addGuide( QgsLayoutGuide *guide )
280292
{
281293
guide->setLayout( mLayout );

src/core/layout/qgslayoutguidecollection.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractTableModel
189189
QVariant data( const QModelIndex &index, int role ) const override;
190190
bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
191191
Qt::ItemFlags flags( const QModelIndex &index ) const override;
192+
QVariant headerData( int section, Qt::Orientation orientation,
193+
int role = Qt::DisplayRole ) const override;
192194

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

215217
QList< QgsLayoutGuide * > mGuides;
218+
int mHeaderSize = 0;
216219

217220
};
218221

0 commit comments

Comments
 (0)