Fix header data for combined model

This commit is contained in:
Nyall Dawson 2022-05-13 14:55:17 +10:00
parent d005c6bbc2
commit 6529309f48
6 changed files with 22 additions and 1 deletions

View File

@ -40,6 +40,9 @@ A model which contains entities from multiple :py:class:`QgsStyle` databases.
Constructor for QgsCombinedStyleModel with the specified ``parent`` object.
%End
virtual QVariant headerData( int section, Qt::Orientation orientation,
int role = Qt::DisplayRole ) const;
void addStyle( QgsStyle *style );
%Docstring
Adds a style to the model.

View File

@ -28,6 +28,11 @@ QgsCombinedStyleModel::QgsCombinedStyleModel( QObject *parent )
}
QVariant QgsCombinedStyleModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
return QgsStyleModel::headerDataStatic( section, orientation, role );
}
void QgsCombinedStyleModel::addStyle( QgsStyle *style )
{
connect( style, &QgsStyle::destroyed, this, [this, style]()

View File

@ -61,6 +61,9 @@ class CORE_EXPORT QgsCombinedStyleModel: public QConcatenateTablesProxyModel
*/
explicit QgsCombinedStyleModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
QVariant headerData( int section, Qt::Orientation orientation,
int role = Qt::DisplayRole ) const override;
/**
* Adds a style to the model.
*

View File

@ -511,6 +511,11 @@ Qt::ItemFlags QgsStyleModel::flags( const QModelIndex &index ) const
}
QVariant QgsStyleModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
return headerDataStatic( section, orientation, role );
}
QVariant QgsStyleModel::headerDataStatic( int section, Qt::Orientation orientation, int role )
{
if ( role == Qt::DisplayRole )
{

View File

@ -199,7 +199,10 @@ class CORE_EXPORT QgsStyleModel: public QAbstractItemModel
QgsStyle::StyleEntity entityTypeFromRow( int row ) const;
int offsetForEntity( QgsStyle::StyleEntity entity ) const;
static QVariant headerDataStatic( int section, Qt::Orientation orientation,
int role = Qt::DisplayRole );
friend class QgsCombinedStyleModel;
};
/**

View File

@ -14,7 +14,7 @@ import os
import qgis # NOQA
from qgis.PyQt.QtCore import QCoreApplication, QEvent
from qgis.PyQt.QtCore import QCoreApplication, QEvent, Qt
from qgis.core import (
QgsStyle,
@ -47,6 +47,8 @@ class TestQgsCombinedStyleModel(unittest.TestCase):
model.addStyle(style1)
self.assertEqual(model.styles(), [style1])
self.assertEqual(model.headerData(0, Qt.Horizontal), 'Name')
self.assertEqual(model.headerData(1, Qt.Horizontal), 'Tags')
self.assertEqual(model.columnCount(), 2)
self.assertEqual(model.rowCount(), 1)