Skip to content

Commit

Permalink
Make layer col spanned and show feature count inline if more than 1 f…
Browse files Browse the repository at this point in the history
…eature identified
  • Loading branch information
suricactus authored and nyalldawson committed Mar 25, 2020
1 parent d40ab03 commit 8de8103
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 30 deletions.
35 changes: 6 additions & 29 deletions src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -481,19 +481,6 @@ QTreeWidgetItem *QgsIdentifyResultsDialog::layerItem( QObject *object )
return nullptr;
}

QTreeWidgetItem *QgsIdentifyResultsDialog::findResultFeaturesItem( QTreeWidgetItem *layerItem )
{
for ( int i = 0; i < layerItem->childCount(); i++ )
{
QTreeWidgetItem *item = layerItem->child( i );

if ( item->data( 0, Qt::UserRole ).toString() == QLatin1String( "count" ) )
return item;
}

return nullptr;
}

void QgsIdentifyResultsDialog::addFeature( const QgsMapToolIdentify::IdentifyResult &result )
{
switch ( result.mLayer->type() )
Expand Down Expand Up @@ -539,19 +526,12 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
featItem->setData( 0, Qt::UserRole + 1, mFeatures.size() );
mFeatures << f;
layItem->addChild( featItem );

QTreeWidgetItem *resultFeaturesCountItem = findResultFeaturesItem( layItem );
if ( ! resultFeaturesCountItem )
{
resultFeaturesCountItem = new QTreeWidgetItem( QStringList() << tr( "(Count Results)" ) );
resultFeaturesCountItem->setData( 0, Qt::UserRole, QLatin1String( "count" ) );
layItem->insertChild( 0, resultFeaturesCountItem );
}

if ( resultFeaturesCountItem )
{
resultFeaturesCountItem->setText( 1, QString::number( layItem->childCount() - 1 ) );
}
layItem->setFirstColumnSpanned( true );
QString countSuffix = lstResults->topLevelItemCount() > 1 || layItem->childCount() > 1
? QStringLiteral( " [%1]" ).arg( layItem->childCount() )
: QString();
QgsLogger::warning( countSuffix + QStringLiteral( __FILE__ ) + ": " + QString::number( __LINE__ ) );
layItem->setText( 0, QStringLiteral( "%1 %2" ).arg( vlayer->name(), countSuffix ) );

if ( derivedAttributes.size() >= 0 )
{
Expand Down Expand Up @@ -1132,9 +1112,6 @@ void QgsIdentifyResultsDialog::editingToggled()
{
QTreeWidgetItem *featItem = layItem->child( i );

if ( featItem->data( 0, Qt::UserRole ).toString() == QLatin1String( "result features" ) )
continue;

int j;
for ( j = 0; j < featItem->childCount() && featItem->child( j )->data( 0, Qt::UserRole ).toString() != QLatin1String( "actions" ); j++ )
{
Expand Down
1 change: 0 additions & 1 deletion src/app/qgsidentifyresultsdialog.h
Expand Up @@ -278,7 +278,6 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
QTreeWidgetItem *featureItem( QTreeWidgetItem *item );
QTreeWidgetItem *layerItem( QTreeWidgetItem *item );
QTreeWidgetItem *layerItem( QObject *layer );
QTreeWidgetItem *findResultFeaturesItem( QTreeWidgetItem *layerItem );


void highlightLayer( QTreeWidgetItem *object );
Expand Down

0 comments on commit 8de8103

Please sign in to comment.