26 #include <QPushButton> 30 QPair<int, int> selectedDatumTransforms,
33 : QDialog( parent, f )
37 mDatumTransformTableWidget->setColumnCount( 2 );
39 headers << tr(
"Source transform" ) << tr(
"Destination transform" ) ;
40 mDatumTransformTableWidget->setHorizontalHeaderLabels( headers );
42 mSourceProjectionSelectionWidget->setCrs( sourceCrs );
43 mDestinationProjectionSelectionWidget->setCrs( destinationCrs );
45 connect( mHideDeprecatedCheckBox, &QCheckBox::stateChanged,
this, &QgsDatumTransformDialog::mHideDeprecatedCheckBox_stateChanged );
46 connect( mDatumTransformTableWidget, &QTableWidget::currentItemChanged,
this, &QgsDatumTransformDialog::tableCurrentItemChanged );
52 mSourceCrs = sourceCrs;
53 mDestinationCrs = destinationCrs;
56 QApplication::setOverrideCursor( Qt::ArrowCursor );
61 restoreGeometry( settings.
value( QStringLiteral(
"Windows/DatumTransformDialog/geometry" ) ).toByteArray() );
62 mHideDeprecatedCheckBox->setChecked( settings.
value( QStringLiteral(
"Windows/DatumTransformDialog/hideDeprecated" ),
false ).toBool() );
64 mLabelSrcDescription->clear();
65 mLabelDstDescription->clear();
67 load( selectedDatumTransforms );
72 mDatumTransformTableWidget->setRowCount( 0 );
78 bool itemDisabled =
false;
79 bool itemHidden =
false;
81 if ( transform.sourceTransformId == -1 && transform.destinationTransformId == -1 )
84 for (
int i = 0; i < 2; ++i )
86 QTableWidgetItem *item =
new QTableWidgetItem();
87 int nr = i == 0 ? transform.sourceTransformId : transform.destinationTransformId;
88 item->setData( Qt::UserRole, nr );
97 if ( mHideDeprecatedCheckBox->isChecked() && info.
deprecated )
102 QString toolTipString;
103 if ( gridShiftTransformation( item->text() ) )
105 toolTipString.append( QStringLiteral(
"<p><b>NTv2</b></p>" ) );
109 toolTipString.append( QStringLiteral(
"<p><b>EPSG Transformations Code:</b> %1</p>" ).arg( info.
epsgCode ) );
114 toolTipString.append( QStringLiteral(
"<p><b>Remarks:</b> %1</p>" ).arg( info.
remarks ) );
115 if ( !info.
scope.isEmpty() )
116 toolTipString.append( QStringLiteral(
"<p><b>Scope:</b> %1</p>" ).arg( info.
scope ) );
118 toolTipString.append(
"<p><b>Preferred transformation</b></p>" );
120 toolTipString.append(
"<p><b>Deprecated transformation</b></p>" );
122 item->setToolTip( toolTipString );
124 if ( gridShiftTransformation( item->text() ) && !testGridShiftFileAvailability( item ) )
133 item->setFlags( Qt::NoItemFlags );
135 mDatumTransformTableWidget->setRowCount( row + 1 );
136 mDatumTransformTableWidget->setItem( row, i, item );
144 if ( transform.sourceTransformId == selectedDatumTransforms.first &&
145 transform.destinationTransformId == selectedDatumTransforms.second )
147 mDatumTransformTableWidget->selectRow( row );
153 mDatumTransformTableWidget->resizeColumnsToContents();
155 setOKButtonEnabled();
158 void QgsDatumTransformDialog::setOKButtonEnabled()
160 int row = mDatumTransformTableWidget->currentRow();
161 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( mSourceCrs.
isValid() && mDestinationCrs.
isValid() && row >= 0 );
168 settings.
setValue( QStringLiteral(
"Windows/DatumTransformDialog/hideDeprecated" ), mHideDeprecatedCheckBox->isChecked() );
170 for (
int i = 0; i < 2; i++ )
172 settings.
setValue( QStringLiteral(
"Windows/DatumTransformDialog/columnWidths/%1" ).arg( i ), mDatumTransformTableWidget->columnWidth( i ) );
175 QApplication::restoreOverrideCursor();
180 return mDatumTransforms.count();
186 int row = mDatumTransformTableWidget->currentRow();
187 QPair< QPair<QgsCoordinateReferenceSystem, int>, QPair<QgsCoordinateReferenceSystem, int > > sdt;
188 sdt.first.first = mSourceCrs;
189 sdt.second.first = mDestinationCrs;
193 QTableWidgetItem *srcItem = mDatumTransformTableWidget->item( row, 0 );
194 sdt.first.second = srcItem ? srcItem->data( Qt::UserRole ).toInt() : -1;
195 QTableWidgetItem *destItem = mDatumTransformTableWidget->item( row, 1 );
196 sdt.second.second = destItem ? destItem->data( Qt::UserRole ).toInt() : -1;
200 sdt.first.second = -1;
201 sdt.second.second = -1;
206 bool QgsDatumTransformDialog::gridShiftTransformation(
const QString &itemText )
const 208 return !itemText.isEmpty() && !itemText.contains( QLatin1String(
"towgs84" ), Qt::CaseInsensitive );
211 bool QgsDatumTransformDialog::testGridShiftFileAvailability( QTableWidgetItem *item )
const 218 QString itemText = item->text();
219 if ( itemText.isEmpty() )
224 char *projLib = getenv(
"PROJ_LIB" );
230 QStringList itemEqualSplit = itemText.split(
'=' );
232 for (
int i = 1; i < itemEqualSplit.size(); ++i )
236 filename.append(
'=' );
238 filename.append( itemEqualSplit.at( i ) );
241 QDir projDir( projLib );
242 if ( projDir.exists() )
245 QStringList fileList = projDir.entryList();
246 QStringList::const_iterator fileIt = fileList.constBegin();
247 for ( ; fileIt != fileList.constEnd(); ++fileIt )
249 #if defined(Q_OS_WIN) 250 if ( fileIt->compare( filename, Qt::CaseInsensitive ) == 0 )
252 if ( fileIt->compare( filename ) == 0 )
258 item->setToolTip( tr(
"File '%1' not found in directory '%2'" ).arg( filename, projDir.absolutePath() ) );
264 void QgsDatumTransformDialog::mHideDeprecatedCheckBox_stateChanged(
int )
269 void QgsDatumTransformDialog::tableCurrentItemChanged( QTableWidgetItem *, QTableWidgetItem * )
271 int row = mDatumTransformTableWidget->currentRow();
275 QTableWidgetItem *srcItem = mDatumTransformTableWidget->item( row, 0 );
276 mLabelSrcDescription->setText( srcItem ? srcItem->toolTip() : QString() );
277 QTableWidgetItem *destItem = mDatumTransformTableWidget->item( row, 1 );
278 mLabelDstDescription->setText( destItem ? destItem->toolTip() : QString() );
280 setOKButtonEnabled();
285 mSourceCrs = sourceCrs;
288 setOKButtonEnabled();
293 mDestinationCrs = destinationCrs;
296 setOKButtonEnabled();
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void saveGeometry(QWidget *widget, const QString &keyName)
Save the wigget geometry into settings.
bool restoreGeometry(QWidget *widget, const QString &keyName)
Restore the wigget geometry from settings.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
This class represents a coordinate reference system (CRS).