Skip to content
Permalink
Browse files
Show item counts in annotation layer metadata
  • Loading branch information
nyalldawson committed Sep 10, 2021
1 parent fbce5ad commit 7d1077837960f2c60b32328f23ae78238a41cf02
Showing with 25 additions and 0 deletions.
  1. +25 −0 src/core/annotations/qgsannotationlayer.cpp
@@ -483,6 +483,31 @@ QString QgsAnnotationLayer::htmlMetadata() const
// CRS
metadata += crsHtmlMetadata();

// items section
metadata += QStringLiteral( "<h1>" ) + tr( "Items" ) + QStringLiteral( "</h1>\n<hr>\n" );

metadata += QLatin1String( "<table width=\"100%\" class=\"tabular-view\">\n" );
metadata += QLatin1String( "<tr><th>" ) + tr( "Type" ) + QLatin1String( "</th><th>" ) + tr( "Count" ) + QLatin1String( "</th></tr>\n" );

QMap< QString, int > itemCounts;
for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
{
itemCounts[ it.value()->type() ]++;
}

const QMap<QString, QString> itemTypes = QgsApplication::annotationItemRegistry()->itemTypes();
int i = 0;
for ( auto it = itemTypes.begin(); it != itemTypes.end(); ++it )
{
QString rowClass;
if ( i % 2 )
rowClass = QStringLiteral( "class=\"odd-row\"" );
metadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td>" ) + it.value() + QLatin1String( "</td><td>" ) + locale.toString( static_cast<qlonglong>( itemCounts.value( it.key() ) ) ) + QLatin1String( "</td></tr>\n" );
i++;
}

metadata += QLatin1String( "</table>\n<br><br>" );

metadata += QLatin1String( "\n</body>\n</html>\n" );
return metadata;
}

0 comments on commit 7d10778

Please sign in to comment.