void QgsDatumTransformDialog::load( const QPair<int, int> &selectedDatumTransforms )
{
  mDatumTransformTableWidget->setRowCount( 0 );

  int row = 0;

  for ( const QgsDatumTransform::TransformPair &transform : qgis::as_const( mDatumTransforms ) )
  {
    bool itemDisabled = false;
    bool itemHidden = false;

    if ( transform.sourceTransformId == -1 && transform.destinationTransformId == -1 )
      continue;

    for ( int i = 0; i < 2; ++i )
    {
      QTableWidgetItem *item = new QTableWidgetItem();
      int nr = i == 0 ? transform.sourceTransformId : transform.destinationTransformId;
      item->setData( Qt::UserRole, nr );

      item->setText( QgsDatumTransform::datumTransformToProj( nr ) );

      //Describe datums in a tooltip
      QgsDatumTransform::TransformInfo info = QgsDatumTransform::datumTransformInfo( nr );
      if ( info.datumTransformId == -1 )
        continue;

      if ( mHideDeprecatedCheckBox->isChecked() && info.deprecated )
      {
        itemHidden = true;
      }

      QString toolTipString;
      if ( gridShiftTransformation( item->text() ) )
      {
        toolTipString.append( QStringLiteral( "<p><b>NTv2</b></p>" ) );
      }

      if ( info.epsgCode > 0 )
        toolTipString.append( QStringLiteral( "<p><b>EPSG Transformations Code:</b> %1</p>" ).arg( info.epsgCode ) );

      toolTipString.append( QStringLiteral( "<p><b>Source CRS:</b> %1</p><p><b>Destination CRS:</b> %2</p>" ).arg( info.sourceCrsDescription, info.destinationCrsDescription ) );

      if ( !info.remarks.isEmpty() )
        toolTipString.append( QStringLiteral( "<p><b>Remarks:</b> %1</p>" ).arg( info.remarks ) );
      if ( !info.scope.isEmpty() )
        toolTipString.append( QStringLiteral( "<p><b>Scope:</b> %1</p>" ).arg( info.scope ) );
      if ( info.preferred )
        toolTipString.append( "<p><b>Preferred transformation</b></p>" );
      if ( info.deprecated )
        toolTipString.append( "<p><b>Deprecated transformation</b></p>" );

      item->setToolTip( toolTipString );

      if ( gridShiftTransformation( item->text() ) && !testGridShiftFileAvailability( item ) )
      {
        itemDisabled = true;
      }

      if ( !itemHidden )
      {
        if ( itemDisabled )
        {
          item->setFlags( Qt::NoItemFlags );
        }
        mDatumTransformTableWidget->setRowCount( row + 1 );
        mDatumTransformTableWidget->setItem( row, i, item );
      }
      else
      {
        delete item;
      }
    }

    if ( transform.sourceTransformId == selectedDatumTransforms.first &&
         transform.destinationTransformId == selectedDatumTransforms.second )
    {
      mDatumTransformTableWidget->selectRow( row );
    }

    row++;
  }

  mDatumTransformTableWidget->resizeColumnsToContents();

  setOKButtonEnabled();
}
void QgsDatumTransformDialog::load()
{
  QgsDebugMsg( "Entered." );

  mDatumTransformTreeWidget->clear();

  QList< QList< int > >::const_iterator it = mDt.constBegin();
  for ( ; it != mDt.constEnd(); ++it )
  {
    QTreeWidgetItem *item = new QTreeWidgetItem();
    int score = 0;

    for ( int i = 0; i < 2 && i < it->size(); ++i )
    {
      int nr = it->at( i );
      item->setData( i, Qt::UserRole, nr );
      if ( nr == -1 )
        continue;

      item->setText( i, QgsCoordinateTransform::datumTransformString( nr ) );

      //Describe datums in a tooltip
      QString srcGeoProj, destGeoProj, remarks, scope;
      int epsgNr;
      bool preferred, deprecated;
      if ( !QgsCoordinateTransform::datumTransformCrsInfo( nr, epsgNr, srcGeoProj, destGeoProj, remarks, scope, preferred, deprecated ) )
        continue;

      QString toolTipString;
      if ( gridShiftTransformation( item->text( i ) ) )
      {
        toolTipString.append( QString( "<p><b>NTv2</b></p>" ) );
        if ( !deprecated )
          score += 2;
        if ( !testGridShiftFileAvailability( item, i ) )
        {
          score -= 10;
          item->setDisabled( true );
          continue;
        }
      }

      if ( epsgNr > 0 )
        toolTipString.append( QString( "<p><b>EPSG Transformations Code:</b> %1</p>" ).arg( epsgNr ) );

      toolTipString.append( QString( "<p><b>Source CRS:</b> %1</p><p><b>Destination CRS:</b> %2</p>" ).arg( srcGeoProj ).arg( destGeoProj ) );

      if ( !remarks.isEmpty() )
        toolTipString.append( QString( "<p><b>Remarks:</b> %1</p>" ).arg( remarks ) );
      if ( !scope.isEmpty() )
        toolTipString.append( QString( "<p><b>Scope:</b> %1</p>" ).arg( scope ) );
      if ( preferred )
      {
        toolTipString.append( "<p><b>Preferred transformation</b></p>" );
        score += 1;
      }
      if ( deprecated )
      {
        toolTipString.append( "<p><b>Deprecated transformation</b></p>" );
        score -= 2;
      }

      item->setToolTip( i, toolTipString );
    }

    item->setData( 2, Qt::UserRole, score);
    item->setText( 2, QString("%1").arg( score + 50 ) );  // Sort works on text only
    mDatumTransformTreeWidget->addTopLevelItem( item );
  }

  // Sort transformations by score
  mDatumTransformTreeWidget->sortItems( 2, Qt::DescendingOrder );
  mDatumTransformTreeWidget->setSortingEnabled( true );
  mDatumTransformTreeWidget->setSortingEnabled( false );
  mDatumTransformTreeWidget->setColumnHidden( 2, true );
  mDatumTransformTreeWidget->setCurrentItem(mDatumTransformTreeWidget->topLevelItem(0));

  updateStatus();
}
void QgsDatumTransformDialog::load()
{
  QgsDebugMsg( "Entered." );

  mDatumTransformTreeWidget->clear();

  QList< QList< int > >::const_iterator it = mDt.constBegin();
  for ( ; it != mDt.constEnd(); ++it )
  {
    QTreeWidgetItem *item = new QTreeWidgetItem();
    bool itemDisabled = false;
    bool itemHidden = false;

    for ( int i = 0; i < 2 && i < it->size(); ++i )
    {
      int nr = it->at( i );
      item->setData( i, Qt::UserRole, nr );
      if ( nr == -1 )
        continue;

      item->setText( i, QgsCoordinateTransform::datumTransformString( nr ) );

      //Describe datums in a tooltip
      QString srcGeoProj, destGeoProj, remarks, scope;
      int epsgNr;
      bool preferred, deprecated;
      if ( !QgsCoordinateTransform::datumTransformCrsInfo( nr, epsgNr, srcGeoProj, destGeoProj, remarks, scope, preferred, deprecated ) )
        continue;

      if ( mHideDeprecatedCheckBox->isChecked() && deprecated )
      {
        itemHidden = true;
      }

      QString toolTipString;
      if ( gridShiftTransformation( item->text( i ) ) )
      {
        toolTipString.append( QString( "<p><b>NTv2</b></p>" ) );
      }

      if ( epsgNr > 0 )
        toolTipString.append( QString( "<p><b>EPSG Transformations Code:</b> %1</p>" ).arg( epsgNr ) );

      toolTipString.append( QString( "<p><b>Source CRS:</b> %1</p><p><b>Destination CRS:</b> %2</p>" ).arg( srcGeoProj, destGeoProj ) );

      if ( !remarks.isEmpty() )
        toolTipString.append( QString( "<p><b>Remarks:</b> %1</p>" ).arg( remarks ) );
      if ( !scope.isEmpty() )
        toolTipString.append( QString( "<p><b>Scope:</b> %1</p>" ).arg( scope ) );
      if ( preferred )
        toolTipString.append( "<p><b>Preferred transformation</b></p>" );
      if ( deprecated )
        toolTipString.append( "<p><b>Deprecated transformation</b></p>" );

      item->setToolTip( i, toolTipString );

      if ( gridShiftTransformation( item->text( i ) ) && !testGridShiftFileAvailability( item, i ) )
      {
        itemDisabled = true;
      }
    }

    if ( !itemHidden )
    {
      item->setDisabled( itemDisabled );
      mDatumTransformTreeWidget->addTopLevelItem( item );
    }
    else
    {
      delete item;
    }
  }
}