Skip to content
Permalink
Browse files

Fix missing Report top level item in organizer widget

  • Loading branch information
nyalldawson committed Dec 31, 2017
1 parent 57cac01 commit 69a225ade373dd42eaf325580b6c8ad30aa1e637
Showing with 35 additions and 23 deletions.
  1. +34 −23 src/app/layout/qgsreportsectionmodel.cpp
  2. +1 −0 src/app/layout/qgsreportsectionmodel.h
@@ -96,16 +96,20 @@ QVariant QgsReportSectionModel::headerData( int section, Qt::Orientation orienta

int QgsReportSectionModel::rowCount( const QModelIndex &parent ) const
{
QgsAbstractReportSection *parentSection = nullptr;
if ( parent.column() > 0 )
return 0;
if ( !parent.isValid() )
return 1; // report

QgsAbstractReportSection *parentSection = sectionForIndex( parent );
return parentSection ? parentSection->childCount() : 0;
}

bool QgsReportSectionModel::hasChildren( const QModelIndex &parent ) const
{
if ( !parent.isValid() )
parentSection = mReport;
else
parentSection = sectionForIndex( parent );
return true; // root item: its children are top level items

return parentSection->childCount();
QgsAbstractReportSection *parentSection = sectionForIndex( parent );
return parentSection && parentSection->childCount() > 0;
}

int QgsReportSectionModel::columnCount( const QModelIndex & ) const
@@ -118,32 +122,33 @@ QModelIndex QgsReportSectionModel::index( int row, int column, const QModelIndex
if ( !hasIndex( row, column, parent ) )
return QModelIndex();

QgsAbstractReportSection *parentSection = nullptr;

if ( !parent.isValid() )
parentSection = mReport;
else
parentSection = sectionForIndex( parent );

QgsAbstractReportSection *childSection = parentSection->childSection( row );
if ( childSection )
return createIndex( row, column, childSection );
QgsAbstractReportSection *parentSection = sectionForIndex( parent );
if ( parentSection )
{
QgsAbstractReportSection *item = parentSection->childSections().value( row, nullptr );
return item ? createIndex( row, column, item ) : QModelIndex();
}
else
return QModelIndex();
{
if ( row == 0 )
return createIndex( row, column, nullptr );
else
return QModelIndex();
}
}

QModelIndex QgsReportSectionModel::parent( const QModelIndex &index ) const
{
if ( !index.isValid() )
QgsAbstractReportSection *childSection = sectionForIndex( index );
if ( !childSection )
return QModelIndex();

QgsAbstractReportSection *childSection = sectionForIndex( index );
QgsAbstractReportSection *parentSection = childSection->parentSection();

if ( parentSection == mReport )
if ( !parentSection )
return QModelIndex();

return createIndex( parentSection->row(), 0, parentSection );
else
return createIndex( parentSection->row(), 0, parentSection != mReport ? parentSection : nullptr );
}

bool QgsReportSectionModel::setData( const QModelIndex &index, const QVariant &value, int role )
@@ -173,6 +178,12 @@ bool QgsReportSectionModel::setData( const QModelIndex &index, const QVariant &v

QgsAbstractReportSection *QgsReportSectionModel::sectionForIndex( const QModelIndex &index ) const
{
if ( !index.isValid() )
return nullptr;

if ( !index.internalPointer() ) // top level item
return mReport; // IMPORTANT - QgsReport uses multiple inheritance, so cannot static cast the void*!

return static_cast<QgsAbstractReportSection *>( index.internalPointer() );
}

@@ -42,6 +42,7 @@ class QgsReportSectionModel : public QAbstractItemModel
QVariant headerData( int section, Qt::Orientation orientation,
int role = Qt::DisplayRole ) const override;
int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
int columnCount( const QModelIndex & = QModelIndex() ) const override;

QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;

0 comments on commit 69a225a

Please sign in to comment.
You can’t perform that action at this time.