Skip to content

Commit

Permalink
Fix misleading override of QList::size
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 9, 2022
1 parent b8b79f6 commit 56fccbd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
55 changes: 25 additions & 30 deletions src/app/georeferencer/qgsgcplist.cpp
Expand Up @@ -35,40 +35,40 @@ QgsGCPList::QgsGCPList( const QgsGCPList &list )

void QgsGCPList::createGCPVectors( QVector<QgsPointXY> &sourceCoordinates, QVector<QgsPointXY> &destinationCoordinates, const QgsCoordinateReferenceSystem &targetCrs )
{
sourceCoordinates = QVector<QgsPointXY>( size() );
destinationCoordinates = QVector<QgsPointXY>( size() );
QgsPointXY transCoords;
for ( int i = 0, j = 0; i < sizeAll(); i++ )
const int targetSize = countEnabledPoints();
sourceCoordinates.clear();
sourceCoordinates.reserve( targetSize );
destinationCoordinates.clear();
destinationCoordinates.reserve( targetSize );

for ( QgsGeorefDataPoint *pt : std::as_const( *this ) )
{
QgsGeorefDataPoint *pt = at( i );
if ( pt->isEnabled() )
if ( !pt->isEnabled() )
continue;

sourceCoordinates.push_back( pt->sourceCoords() );
if ( targetCrs.isValid() )
{
if ( targetCrs.isValid() )
try
{
try
{
transCoords = QgsCoordinateTransform( pt->destinationCrs(), targetCrs,
QgsProject::instance() ).transform( pt->destinationMapCoords() );
destinationCoordinates[j] = transCoords;
pt->setTransCoords( transCoords );
}
catch ( const QgsException & )
{
destinationCoordinates[j] = pt->destinationMapCoords();
}
QgsPointXY transCoords = QgsCoordinateTransform( pt->destinationCrs(), targetCrs,
QgsProject::instance() ).transform( pt->destinationMapCoords() );
destinationCoordinates.push_back( transCoords );
pt->setTransCoords( transCoords );
}
catch ( const QgsException & )
{
destinationCoordinates.push_back( pt->destinationMapCoords() );
}
else
destinationCoordinates[j] = pt->destinationMapCoords();

sourceCoordinates[j] = pt->sourceCoords();
j++;
}
else
destinationCoordinates.push_back( pt->destinationMapCoords() );
}
}

int QgsGCPList::size() const
int QgsGCPList::countEnabledPoints() const
{
if ( QList<QgsGeorefDataPoint *>::isEmpty() )
if ( isEmpty() )
return 0;

int s = 0;
Expand All @@ -82,11 +82,6 @@ int QgsGCPList::size() const
return s;
}

int QgsGCPList::sizeAll() const
{
return QList<QgsGeorefDataPoint *>::size();
}

QgsGCPList &QgsGCPList::operator =( const QgsGCPList &list )
{
clear();
Expand Down
13 changes: 10 additions & 3 deletions src/app/georeferencer/qgsgcplist.h
Expand Up @@ -23,16 +23,23 @@ class QgsGeorefDataPoint;
class QgsPointXY;
class QgsCoordinateReferenceSystem;

// what is better use inherid or agrigate QList?
/**
* A container for GCP data points.
*
* The container does NOT own the points!
*/
class QgsGCPList : public QList<QgsGeorefDataPoint *>
{
public:
QgsGCPList() = default;
QgsGCPList( const QgsGCPList &list );

void createGCPVectors( QVector<QgsPointXY> &sourceCoordinates, QVector<QgsPointXY> &destinationCoordinates, const QgsCoordinateReferenceSystem &targetCrs );
int size() const;
int sizeAll() const;

/**
* Returns the count of currently enabled data points.
*/
int countEnabledPoints() const;

QgsGCPList &operator =( const QgsGCPList &list );
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/georeferencer/qgsgcplistmodel.cpp
Expand Up @@ -116,7 +116,7 @@ void QgsGCPListModel::updateModel()
setHorizontalHeaderLabels( itemLabels );
setRowCount( mGCPList->size() );

for ( int i = 0; i < mGCPList->sizeAll(); ++i )
for ( int i = 0; i < mGCPList->size(); ++i )
{
int j = 0;
QgsGeorefDataPoint *p = mGCPList->at( i );
Expand Down
2 changes: 1 addition & 1 deletion src/app/georeferencer/qgsgeorefmainwindow.cpp
Expand Up @@ -754,7 +754,7 @@ void QgsGeoreferencerMainWindow::localHistogramStretch()
// Comfort slots
void QgsGeoreferencerMainWindow::jumpToGCP( uint theGCPIndex )
{
if ( static_cast<int>( theGCPIndex ) >= mPoints.size() )
if ( static_cast<int>( theGCPIndex ) >= mPoints.numberEnabledPoints() )
{
return;
}
Expand Down

0 comments on commit 56fccbd

Please sign in to comment.