LCOV - code coverage report
Current view: top level - core/metadata - qgslayermetadataformatter.cpp (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 185 0.0 %
Date: 2021-04-10 08:29:14 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :     qgslayermetadataformatter.cpp
       3                 :            :     ---------------------
       4                 :            :     begin                : September 2017
       5                 :            :     copyright            : (C) 2017 by Etienne Trimaille
       6                 :            :     email                : etienne.trimaille at gmail dot com
       7                 :            :  ***************************************************************************
       8                 :            :  *                                                                         *
       9                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      10                 :            :  *   it under the terms of the GNU General Public License as published by  *
      11                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      12                 :            :  *   (at your option) any later version.                                   *
      13                 :            :  *                                                                         *
      14                 :            :  ***************************************************************************/
      15                 :            : #include <QStringBuilder>
      16                 :            : #include <QDateTime>
      17                 :            : 
      18                 :            : #include "qgslayermetadataformatter.h"
      19                 :            : #include "qgslayermetadata.h"
      20                 :            : 
      21                 :            : 
      22                 :          0 : QgsLayerMetadataFormatter::QgsLayerMetadataFormatter( const QgsLayerMetadata &metadata )
      23                 :          0 :   : mMetadata( metadata )
      24                 :            : {
      25                 :          0 : }
      26                 :            : 
      27                 :          0 : QString QgsLayerMetadataFormatter::accessSectionHtml() const
      28                 :            : {
      29                 :          0 :   QString myMetadata = QStringLiteral( "<table class=\"list-view\">\n" );
      30                 :          0 :   myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Fees" ) + QStringLiteral( "</td><td>" ) + mMetadata.fees() + QStringLiteral( "</td></tr>\n" );
      31                 :          0 :   myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Licenses" ) + QStringLiteral( "</td><td>" ) + mMetadata.licenses().join( QLatin1String( "<br />" ) ) + QStringLiteral( "</td></tr>\n" );
      32                 :          0 :   myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Rights" ) + QStringLiteral( "</td><td>" ) + mMetadata.rights().join( QLatin1String( "<br />" ) ) + QStringLiteral( "</td></tr>\n" );
      33                 :          0 :   myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Constraints" ) + QStringLiteral( "</td><td>" );
      34                 :          0 :   const QList<QgsLayerMetadata::Constraint> &constraints = mMetadata.constraints();
      35                 :          0 :   bool notFirstRow = false;
      36                 :          0 :   for ( const QgsLayerMetadata::Constraint &constraint : constraints )
      37                 :            :   {
      38                 :          0 :     if ( notFirstRow )
      39                 :            :     {
      40                 :          0 :       myMetadata += QLatin1String( "<br />" );
      41                 :          0 :     }
      42                 :          0 :     myMetadata += QStringLiteral( "<strong>" ) + constraint.type + QStringLiteral( ": </strong>" ) + constraint.constraint;
      43                 :          0 :     notFirstRow = true;
      44                 :            :   }
      45                 :          0 :   mMetadata.rights().join( QLatin1String( "<br />" ) );
      46                 :          0 :   myMetadata += QLatin1String( "</td></tr>\n" );
      47                 :          0 :   myMetadata += QLatin1String( "</table>\n" );
      48                 :          0 :   return myMetadata;
      49                 :          0 : }
      50                 :            : 
      51                 :          0 : QString QgsLayerMetadataFormatter::contactsSectionHtml() const
      52                 :            : {
      53                 :          0 :   const QList<QgsAbstractMetadataBase::Contact> &contacts = mMetadata.contacts();
      54                 :          0 :   QString myMetadata;
      55                 :          0 :   if ( contacts.isEmpty() )
      56                 :            :   {
      57                 :          0 :     myMetadata += QStringLiteral( "<p>" ) + tr( "No contact yet." ) + QStringLiteral( "</p>" );
      58                 :          0 :   }
      59                 :            :   else
      60                 :            :   {
      61                 :          0 :     myMetadata += QLatin1String( "<table width=\"100%\" class=\"tabular-view\">\n" );
      62                 :          0 :     myMetadata += QLatin1String( "<tr><th>" ) + tr( "ID" ) + QLatin1String( "</th><th>" ) + tr( "Name" ) + QLatin1String( "</th><th>" ) + tr( "Position" ) + QLatin1String( "</th><th>" ) + tr( "Organization" ) + QLatin1String( "</th><th>" ) + tr( "Role" ) + QLatin1String( "</th><th>" ) + tr( "Email" ) + QLatin1String( "</th><th>" ) + tr( "Voice" ) + QLatin1String( "</th><th>" ) + tr( "Fax" ) + QLatin1String( "</th><th>" ) + tr( "Addresses" ) + QLatin1String( "</th></tr>\n" );
      63                 :          0 :     int i = 1;
      64                 :          0 :     for ( const QgsAbstractMetadataBase::Contact &contact : contacts )
      65                 :            :     {
      66                 :          0 :       QString rowClass;
      67                 :          0 :       if ( i % 2 )
      68                 :          0 :         rowClass = QStringLiteral( "class=\"odd-row\"" );
      69                 :          0 :       myMetadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td>" ) + QString::number( i ) + QLatin1String( "</td><td>" ) + contact.name + QLatin1String( "</td><td>" ) + contact.position + QLatin1String( "</td><td>" ) + contact.organization + QLatin1String( "</td><td>" ) + contact.role + QLatin1String( "</td><td>" ) + contact.email + QLatin1String( "</td><td>" ) + contact.voice + QLatin1String( "</td><td>" ) + contact.fax + QLatin1String( "</td><td>" );
      70                 :          0 :       bool notFirstRow = false;
      71                 :          0 :       for ( const QgsAbstractMetadataBase::Address &oneAddress : contact.addresses )
      72                 :            :       {
      73                 :          0 :         if ( notFirstRow )
      74                 :            :         {
      75                 :          0 :           myMetadata += QLatin1String( "<br />\n" );
      76                 :          0 :         }
      77                 :          0 :         if ( ! oneAddress.type.isEmpty() )
      78                 :            :         {
      79                 :          0 :           myMetadata += oneAddress.type + QStringLiteral( "<br />" );
      80                 :          0 :         }
      81                 :          0 :         if ( ! oneAddress.address.isEmpty() )
      82                 :            :         {
      83                 :          0 :           myMetadata += oneAddress.address + QStringLiteral( "<br />" );
      84                 :          0 :         }
      85                 :          0 :         if ( ! oneAddress.postalCode.isEmpty() )
      86                 :            :         {
      87                 :          0 :           myMetadata += oneAddress.postalCode + QStringLiteral( "<br />" );
      88                 :          0 :         }
      89                 :          0 :         if ( ! oneAddress.city.isEmpty() )
      90                 :            :         {
      91                 :          0 :           myMetadata += oneAddress.city + QStringLiteral( "<br />" );
      92                 :          0 :         }
      93                 :          0 :         if ( ! oneAddress.administrativeArea.isEmpty() )
      94                 :            :         {
      95                 :          0 :           myMetadata += oneAddress.administrativeArea + QStringLiteral( "<br />" );
      96                 :          0 :         }
      97                 :          0 :         if ( ! oneAddress.country.isEmpty() )
      98                 :            :         {
      99                 :          0 :           myMetadata += oneAddress.country;
     100                 :          0 :         }
     101                 :          0 :         notFirstRow = true;
     102                 :            :       }
     103                 :          0 :       myMetadata += QLatin1String( "</td></tr>\n" );
     104                 :          0 :       i++;
     105                 :          0 :     }
     106                 :          0 :     myMetadata += QLatin1String( "</table>\n" );
     107                 :            :   }
     108                 :          0 :   return myMetadata;
     109                 :          0 : }
     110                 :            : 
     111                 :          0 : QString QgsLayerMetadataFormatter::extentSectionHtml( const bool showSpatialExtent ) const
     112                 :            : {
     113                 :          0 :   const QgsLayerMetadata::Extent extent = mMetadata.extent();
     114                 :          0 :   bool notFirstRow = false;
     115                 :          0 :   QString myMetadata = QStringLiteral( "<table class=\"list-view\">\n" );
     116                 :          0 :   if ( showSpatialExtent )
     117                 :            :   {
     118                 :          0 :     myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "CRS" ) + QStringLiteral( "</td><td>" );
     119                 :          0 :     if ( mMetadata.crs().isValid() )
     120                 :            :     {
     121                 :          0 :       myMetadata += mMetadata.crs().userFriendlyIdentifier() + QStringLiteral( " - " );
     122                 :          0 :       if ( mMetadata.crs().isGeographic() )
     123                 :          0 :         myMetadata += tr( "Geographic" );
     124                 :            :       else
     125                 :          0 :         myMetadata += tr( "Projected" );
     126                 :          0 :     }
     127                 :          0 :     myMetadata += QLatin1String( "</td></tr>\n" );
     128                 :            : 
     129                 :          0 :     myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Spatial Extent" ) + QStringLiteral( "</td><td>" );
     130                 :          0 :     const QList< QgsLayerMetadata::SpatialExtent > spatialExtents = extent.spatialExtents();
     131                 :          0 :     for ( const QgsLayerMetadata::SpatialExtent &spatialExtent : spatialExtents )
     132                 :            :     {
     133                 :          0 :       if ( notFirstRow )
     134                 :            :       {
     135                 :          0 :         myMetadata += QLatin1String( "<br />\n" );
     136                 :          0 :       }
     137                 :          0 :       myMetadata += QStringLiteral( "<strong>" ) + tr( "CRS" ) + QStringLiteral( ": </strong>" ) + spatialExtent.extentCrs.userFriendlyIdentifier() + QStringLiteral( " - " );
     138                 :          0 :       if ( spatialExtent.extentCrs.isGeographic() )
     139                 :          0 :         myMetadata += tr( "Geographic" );
     140                 :            :       else
     141                 :          0 :         myMetadata += tr( "Projected" );
     142                 :          0 :       myMetadata += QLatin1String( "<br />" );
     143                 :          0 :       myMetadata += QStringLiteral( "<strong>" ) + tr( "X Minimum:" ) + QStringLiteral( " </strong>" ) +  qgsDoubleToString( spatialExtent.bounds.xMinimum() ) + QStringLiteral( "<br />" );
     144                 :          0 :       myMetadata += QStringLiteral( "<strong>" ) + tr( "Y Minimum:" ) + QStringLiteral( " </strong>" ) +  qgsDoubleToString( spatialExtent.bounds.yMinimum() ) + QStringLiteral( "<br />" );
     145                 :          0 :       myMetadata += QStringLiteral( "<strong>" ) + tr( "X Maximum:" ) + QStringLiteral( " </strong>" ) +  qgsDoubleToString( spatialExtent.bounds.xMaximum() ) + QStringLiteral( "<br />" );
     146                 :          0 :       myMetadata += QStringLiteral( "<strong>" ) + tr( "Y Maximum:" ) + QStringLiteral( " </strong>" ) +  qgsDoubleToString( spatialExtent.bounds.yMaximum() ) + QStringLiteral( "<br />" );
     147                 :          0 :       if ( spatialExtent.bounds.zMinimum() || spatialExtent.bounds.zMaximum() )
     148                 :            :       {
     149                 :          0 :         myMetadata += QStringLiteral( "<strong>" ) + tr( "Z Minimum:" ) + QStringLiteral( " </strong>" ) +  qgsDoubleToString( spatialExtent.bounds.zMinimum() ) + QStringLiteral( "<br />" );
     150                 :          0 :         myMetadata += QStringLiteral( "<strong>" ) + tr( "Z Maximum:" ) + QStringLiteral( " </strong>" ) +  qgsDoubleToString( spatialExtent.bounds.zMaximum() );
     151                 :          0 :       }
     152                 :          0 :       notFirstRow = true;
     153                 :            :     }
     154                 :          0 :     myMetadata += QLatin1String( "</td></tr>\n" );
     155                 :          0 :   }
     156                 :          0 :   myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Temporal Extent" ) + QStringLiteral( "</td><td>" );
     157                 :          0 :   const QList< QgsDateTimeRange > temporalExtents = extent.temporalExtents();
     158                 :          0 :   notFirstRow = false;
     159                 :          0 :   for ( const QgsDateTimeRange &temporalExtent : temporalExtents )
     160                 :            :   {
     161                 :          0 :     if ( notFirstRow )
     162                 :            :     {
     163                 :          0 :       myMetadata += QLatin1String( "<br />\n" );
     164                 :          0 :     }
     165                 :          0 :     if ( temporalExtent.isInstant() )
     166                 :            :     {
     167                 :          0 :       myMetadata += QStringLiteral( "<strong>" ) + tr( "Instant:" ) + QStringLiteral( " </strong>" ) + temporalExtent.begin().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate );
     168                 :          0 :     }
     169                 :            :     else
     170                 :            :     {
     171                 :          0 :       myMetadata += QStringLiteral( "<strong>" ) + tr( "Start:" ) + QStringLiteral( " </strong>" ) + temporalExtent.begin().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) + QStringLiteral( "<br />\n" );
     172                 :          0 :       myMetadata += QStringLiteral( "<strong>" ) + tr( "End:" ) + QStringLiteral( " </strong>" ) + temporalExtent.end().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate );
     173                 :            :     }
     174                 :          0 :     notFirstRow = true;
     175                 :            :   }
     176                 :          0 :   myMetadata += QLatin1String( "</td></tr>\n" );
     177                 :          0 :   myMetadata += QLatin1String( "</table>\n" );
     178                 :          0 :   return myMetadata;
     179                 :          0 : }
     180                 :            : 
     181                 :          0 : QString QgsLayerMetadataFormatter::identificationSectionHtml() const
     182                 :            : {
     183                 :          0 :   QString myMetadata = QStringLiteral( "<table class=\"list-view\">\n" );
     184                 :            : 
     185                 :            :   // Identifier
     186                 :          0 :   myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Identifier" ) + QStringLiteral( "</td><td>" ) + mMetadata.identifier() + QStringLiteral( "</td></tr>\n" );
     187                 :            : 
     188                 :            :   // Parent Identifier
     189                 :          0 :   myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Parent Identifier" ) + QStringLiteral( "</td><td>" ) + mMetadata.parentIdentifier() + QStringLiteral( "</td></tr>\n" );
     190                 :            : 
     191                 :            :   // Title
     192                 :          0 :   myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Title" ) + QStringLiteral( "</td><td>" ) + mMetadata.title() + QStringLiteral( "</td></tr>\n" );
     193                 :            : 
     194                 :            :   // Type
     195                 :          0 :   myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Type" ) + QStringLiteral( "</td><td>" ) + mMetadata.type() + QStringLiteral( "</td></tr>\n" );
     196                 :            : 
     197                 :            :   // Language
     198                 :          0 :   myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Language" ) + QStringLiteral( "</td><td>" ) + mMetadata.language() + QStringLiteral( "</td></tr>\n" );
     199                 :            : 
     200                 :            :   // Abstract
     201                 :          0 :   myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Abstract" ) + QStringLiteral( "</td><td>" ) + mMetadata.abstract() + QStringLiteral( "</td></tr>\n" );
     202                 :            : 
     203                 :            :   // Categories
     204                 :          0 :   myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Categories" ) + QStringLiteral( "</td><td>" ) + mMetadata.categories().join( QLatin1String( ", " ) ) + QStringLiteral( "</td></tr>\n" );
     205                 :            : 
     206                 :            :   // Keywords
     207                 :          0 :   myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Keywords" ) + QStringLiteral( "</td><td>\n" );
     208                 :          0 :   QMapIterator<QString, QStringList> i( mMetadata.keywords() );
     209                 :          0 :   if ( i.hasNext() )
     210                 :            :   {
     211                 :          0 :     myMetadata += QLatin1String( "<table width=\"100%\" class=\"tabular-view\">\n" );
     212                 :          0 :     myMetadata += QLatin1String( "<tr><th>" ) + tr( "Vocabulary" ) + QLatin1String( "</th><th>" ) + tr( "Items" ) + QLatin1String( "</th></tr>\n" );
     213                 :          0 :     int j = 1;
     214                 :          0 :     while ( i.hasNext() )
     215                 :            :     {
     216                 :          0 :       i.next();
     217                 :          0 :       QString rowClass;
     218                 :          0 :       if ( j % 2 )
     219                 :          0 :         rowClass = QStringLiteral( "class=\"odd-row\"" );
     220                 :          0 :       myMetadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td>" ) + i.key() + QLatin1String( "</td><td>" ) + i.value().join( QLatin1String( ", " ) ) + QLatin1String( "</td></tr>\n" );
     221                 :          0 :       j++;
     222                 :          0 :     }
     223                 :          0 :     myMetadata += QLatin1String( "</table>\n" ); // End keywords table
     224                 :          0 :   }
     225                 :          0 :   myMetadata += QLatin1String( "</td></tr>\n" ); // End of keywords row
     226                 :          0 :   myMetadata += QLatin1String( "</table>\n" ); // End identification table
     227                 :          0 :   return myMetadata;
     228                 :          0 : }
     229                 :            : 
     230                 :          0 : QString QgsLayerMetadataFormatter::historySectionHtml() const
     231                 :            : {
     232                 :          0 :   QString myMetadata;
     233                 :          0 :   const QStringList historyItems = mMetadata.history();
     234                 :          0 :   if ( historyItems.isEmpty() )
     235                 :            :   {
     236                 :          0 :     myMetadata += QStringLiteral( "<p>" ) + tr( "No history yet." ) + QStringLiteral( "</p>\n" );
     237                 :          0 :   }
     238                 :            :   else
     239                 :            :   {
     240                 :          0 :     myMetadata += QLatin1String( "<table width=\"100%\" class=\"tabular-view\">\n" );
     241                 :          0 :     myMetadata += QLatin1String( "<tr><th>" ) + tr( "ID" ) + QLatin1String( "</th><th>" ) + tr( "Action" ) + QLatin1String( "</th></tr>\n" );
     242                 :          0 :     int i = 1;
     243                 :          0 :     for ( const QString &history : historyItems )
     244                 :            :     {
     245                 :          0 :       QString rowClass;
     246                 :          0 :       if ( i % 2 )
     247                 :          0 :         rowClass = QStringLiteral( "class=\"odd-row\"" );
     248                 :          0 :       myMetadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td width=\"5%\">" ) + QString::number( i ) + QLatin1String( "</td><td>" ) + history + QLatin1String( "</td></tr>\n" );
     249                 :          0 :       i++;
     250                 :          0 :     }
     251                 :          0 :     myMetadata += QLatin1String( "</table>\n" );
     252                 :            :   }
     253                 :          0 :   return myMetadata;
     254                 :          0 : }
     255                 :            : 
     256                 :          0 : QString QgsLayerMetadataFormatter::linksSectionHtml() const
     257                 :            : {
     258                 :          0 :   QString myMetadata;
     259                 :          0 :   const QList<QgsAbstractMetadataBase::Link> &links = mMetadata.links();
     260                 :          0 :   if ( links.isEmpty() )
     261                 :            :   {
     262                 :          0 :     myMetadata += QStringLiteral( "<p>" ) + tr( "No links yet." ) + QStringLiteral( "</p>\n" );
     263                 :          0 :   }
     264                 :            :   else
     265                 :            :   {
     266                 :          0 :     myMetadata += QLatin1String( "<table width=\"100%\" class=\"tabular-view\">\n" );
     267                 :          0 :     myMetadata += QLatin1String( "<tr><th>" ) + tr( "ID" ) + QLatin1String( "</th><th>" ) + tr( "Name" ) + QLatin1String( "</th><th>" ) + tr( "Type" ) + QLatin1String( "</th><th>" ) + tr( "URL" ) + QLatin1String( "</th><th>" ) + tr( "Description" ) + QLatin1String( "</th><th>" ) + tr( "Format" ) + QLatin1String( "</th><th>" ) + tr( "MIME Type" ) + QLatin1String( "</th><th>" ) + tr( "Size" ) + QLatin1String( "</th></tr>\n" );
     268                 :          0 :     int i = 1;
     269                 :          0 :     for ( const QgsAbstractMetadataBase::Link &link : links )
     270                 :            :     {
     271                 :          0 :       QString rowClass;
     272                 :          0 :       if ( i % 2 )
     273                 :          0 :         rowClass = QStringLiteral( "class=\"odd-row\"" );
     274                 :          0 :       myMetadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td>" ) + QString::number( i ) + QLatin1String( "</td><td>" ) + link.name + QLatin1String( "</td><td>" ) + link.type + QLatin1String( "</td><td>" ) + link.url + QLatin1String( "</td><td>" ) + link.description + QLatin1String( "</td><td>" ) + link.format + QLatin1String( "</td><td>" ) + link.mimeType + QLatin1String( "</td><td>" ) + link.size + QLatin1String( "</td></tr>\n" );
     275                 :          0 :       i++;
     276                 :          0 :     }
     277                 :          0 :     myMetadata += QLatin1String( "</table>\n" );
     278                 :            :   }
     279                 :          0 :   return myMetadata;
     280                 :          0 : }

Generated by: LCOV version 1.14