Skip to content

Commit

Permalink
[georeferencer] Fix recenter on points fails when some points in list
Browse files Browse the repository at this point in the history
are disabled
  • Loading branch information
nyalldawson committed Feb 9, 2022
1 parent 6255e7a commit fa424a4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 31 deletions.
2 changes: 2 additions & 0 deletions src/app/georeferencer/qgsgcplistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ void QgsGCPListModel::updateModel()
else
si->setCheckState( Qt::Unchecked );

si->setData( p->sourcePoint(), SourcePointRole );
setItem( i, j++, si );

setItem( i, j++, new QgsStandardItem( i ) );
setItem( i, j++, new QgsStandardItem( p->sourcePoint().x() ) );
setItem( i, j++, new QgsStandardItem( p->sourcePoint().y() ) );
Expand Down
5 changes: 5 additions & 0 deletions src/app/georeferencer/qgsgcplistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class QgsGCPListModel : public QStandardItemModel
Q_OBJECT

public:
enum Role
{
SourcePointRole = Qt::UserRole + 1,
};

explicit QgsGCPListModel( QObject *parent = nullptr );

void setGCPList( QgsGCPList *theGCPList );
Expand Down
26 changes: 17 additions & 9 deletions src/app/georeferencer/qgsgcplistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ void QgsGCPListWidget::closeEditors()
}
}

void QgsGCPListWidget::itemDoubleClicked( QModelIndex index )
void QgsGCPListWidget::itemDoubleClicked( const QModelIndex &index )
{
index = static_cast<const QSortFilterProxyModel *>( model() )->mapToSource( index );
QStandardItem *item = mGCPListModel->item( index.row(), 1 );
bool ok;
const int id = item->text().toInt( &ok );

if ( ok )
const QModelIndex sourceIndex = static_cast<const QSortFilterProxyModel *>( model() )->mapToSource( index );
if ( QStandardItem *item = mGCPListModel->item( sourceIndex.row(), 0 ) )
{
emit jumpToGCP( id );
const QgsPointXY sourcePoint = item->data( QgsGCPListModel::Role::SourcePointRole ).value< QgsPointXY >();
if ( !sourcePoint.isEmpty() )
{
emit jumpToGCP( sourcePoint );
}
}
}

Expand Down Expand Up @@ -285,7 +285,15 @@ void QgsGCPListWidget::jumpToPoint()
const QModelIndex index = static_cast<const QSortFilterProxyModel *>( model() )->mapToSource( currentIndex() );
mPrevRow = index.row();
mPrevColumn = index.column();
emit jumpToGCP( index.row() );

if ( QStandardItem *item = mGCPListModel->item( index.row(), 0 ) )
{
const QgsPointXY sourcePoint = item->data( QgsGCPListModel::Role::SourcePointRole ).value< QgsPointXY >();
if ( !sourcePoint.isEmpty() )
{
emit jumpToGCP( sourcePoint );
}
}
}

void QgsGCPListWidget::adjustTableContent()
Expand Down
4 changes: 2 additions & 2 deletions src/app/georeferencer/qgsgcplistwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class QgsGCPListWidget : public QTableView

public slots:
// This slot is called by the list view if an item is double-clicked
void itemDoubleClicked( QModelIndex index );
void itemDoubleClicked( const QModelIndex &index );
void itemClicked( QModelIndex index );

signals:
void jumpToGCP( uint theGCPIndex );
void jumpToGCP( const QgsPointXY &point );
void pointEnabled( QgsGeorefDataPoint *pnt, int i );
void deleteDataPoint( int index );

Expand Down
22 changes: 3 additions & 19 deletions src/app/georeferencer/qgsgeorefmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,25 +751,9 @@ void QgsGeoreferencerMainWindow::localHistogramStretch()
mCanvas->refresh();
}

// Comfort slots
void QgsGeoreferencerMainWindow::jumpToGCP( uint theGCPIndex )
void QgsGeoreferencerMainWindow::recenterOnPoint( const QgsPointXY &point )
{
// TODO -- probably a bug here!!!! re enabled/not enabled points
if ( static_cast<int>( theGCPIndex ) >= mPoints.countEnabledPoints() )
{
return;
}

// qgsmapcanvas doesn't seem to have a method for recentering the map
QgsRectangle ext = mCanvas->extent();

QgsPointXY center = ext.center();
QgsPointXY new_center = mPoints[theGCPIndex]->sourcePoint();

QgsPointXY diff( new_center.x() - center.x(), new_center.y() - center.y() );
QgsRectangle new_extent( ext.xMinimum() + diff.x(), ext.yMinimum() + diff.y(),
ext.xMaximum() + diff.x(), ext.yMaximum() + diff.y() );
mCanvas->setExtent( new_extent );
mCanvas->setCenter( point );
mCanvas->refresh();
}

Expand Down Expand Up @@ -1094,7 +1078,7 @@ void QgsGeoreferencerMainWindow::createDockWidgets()
mGCPListWidget->setGeorefTransform( &mGeorefTransform );
dockWidgetGCPpoints->setWidget( mGCPListWidget );

connect( mGCPListWidget, &QgsGCPListWidget::jumpToGCP, this, &QgsGeoreferencerMainWindow::jumpToGCP );
connect( mGCPListWidget, &QgsGCPListWidget::jumpToGCP, this, &QgsGeoreferencerMainWindow::recenterOnPoint );
#if 0
connect( mGCPListWidget, SIGNAL( replaceDataPoint( QgsGeorefDataPoint *, int ) ),
this, SLOT( replaceDataPoint( QgsGeorefDataPoint *, int ) ) );
Expand Down
2 changes: 1 addition & 1 deletion src/app/georeferencer/qgsgeorefmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class QgsGeoreferencerMainWindow : public QMainWindow, private Ui::QgsGeorefPlug
void showGeorefConfigDialog();

// comfort
void jumpToGCP( uint theGCPIndex );
void recenterOnPoint( const QgsPointXY &point );
void extentsChangedGeorefCanvas();
void extentsChangedQGisCanvas();
void updateCanvasRotation();
Expand Down

0 comments on commit fa424a4

Please sign in to comment.