Skip to content

Commit

Permalink
[georef] Fix coordinates truncated to 2 decimal places in table
Browse files Browse the repository at this point in the history
Now, coordinates are shown in table to 4 decimal places, and a
tooltip will show the full precision of coordinates. Editing
coordinates also shows the full precision. (fix #10480)
  • Loading branch information
nyalldawson committed Jun 19, 2015
1 parent fcc9a34 commit cecae9f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/plugins/georeferencer/qgsgcplistmodel.cpp
Expand Up @@ -40,9 +40,12 @@ class QgsStandardItem : public QStandardItem
setTextAlignment( Qt::AlignCenter );
}

QgsStandardItem( double value ) : QStandardItem( QString::number( value, 'f', 2 ) )
QgsStandardItem( double value ) : QStandardItem( QString::number( value, 'f', 4 ) )
{
setData( QVariant( value ), Qt::UserRole );
//show the full precision when editing points
setData( QVariant( value ), Qt::EditRole );
setData( QVariant( value ), Qt::ToolTipRole );
setTextAlignment( Qt::AlignRight );
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/georeferencer/qgsgcplistwidget.cpp
Expand Up @@ -31,7 +31,7 @@ QgsGCPListWidget::QgsGCPListWidget( QWidget *parent )
, mGCPListModel( new QgsGCPListModel( this ) )
, mNonEditableDelegate( new QgsNonEditableDelegate( this ) )
, mDmsAndDdDelegate( new QgsDmsAndDdDelegate( this ) )
, mCoordDelegate( new QgsCoordDelegate )
, mCoordDelegate( new QgsCoordDelegate( this ) )
, mPrevRow( 0 )
, mPrevColumn( 0 )
{
Expand Down Expand Up @@ -97,7 +97,7 @@ void QgsGCPListWidget::updateGCPList()

void QgsGCPListWidget::closeEditors()
{
Q_FOREACH( QModelIndex index, selectedIndexes() )
Q_FOREACH ( QModelIndex index, selectedIndexes() )
{
closePersistentEditor( index );
}
Expand Down
42 changes: 34 additions & 8 deletions src/plugins/georeferencer/qgsgeorefdelegates.cpp
Expand Up @@ -54,11 +54,16 @@ void QgsDmsAndDdDelegate::setModelData( QWidget *editor, QAbstractItemModel *mod
const QModelIndex &index ) const
{
QLineEdit *lineEdit = static_cast<QLineEdit *>( editor );
QString value = lineEdit->text();
if ( value.contains( ' ' ) )
value = dmsToDD( value );
QString stringValue = lineEdit->text();
double value = 0;
if ( stringValue.contains( ' ' ) )
value = dmsToDD( stringValue );
else
value = stringValue.toDouble();

model->setData( index, value, Qt::EditRole );
model->setData( index, value, Qt::DisplayRole );
model->setData( index, value, Qt::ToolTipRole );
}

void QgsDmsAndDdDelegate::updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option,
Expand All @@ -67,7 +72,7 @@ void QgsDmsAndDdDelegate::updateEditorGeometry( QWidget *editor, const QStyleOpt
editor->setGeometry( option.rect );
}

QString QgsDmsAndDdDelegate::dmsToDD( QString dms ) const
double QgsDmsAndDdDelegate::dmsToDD( QString dms ) const
{
QStringList list = dms.split( ' ' );
QString tmpStr = list.at( 0 );
Expand All @@ -81,10 +86,7 @@ QString QgsDmsAndDdDelegate::dmsToDD( QString dms ) const
if ( !tmpStr.isEmpty() )
res += tmpStr.toDouble() / 3600;

if ( dms.startsWith( '-' ) )
return QString::number( -res, 'f', 7 );
else
return QString::number( res, 'f', 7 );
return dms.startsWith( '-' ) ? -res : res;
}

// ---------------------------- QgsCoordDelegate --------------------------- //
Expand All @@ -103,3 +105,27 @@ QWidget *QgsCoordDelegate::createEditor( QWidget *parent, const QStyleOptionView

return editor;
}

void QgsCoordDelegate::setEditorData( QWidget* editor, const QModelIndex& index ) const
{
QString value = index.model()->data( index, Qt::EditRole ).toString();

QLineEdit *lineEdit = static_cast<QLineEdit *>( editor );
lineEdit->setText( value );
}

void QgsCoordDelegate::setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const
{
QLineEdit *lineEdit = static_cast<QLineEdit *>( editor );
QString stringValue = lineEdit->text();
double value = stringValue.toDouble();
model->setData( index, value, Qt::EditRole );
model->setData( index, value, Qt::DisplayRole );
model->setData( index, value, Qt::ToolTipRole );
}

void QgsCoordDelegate::updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
Q_UNUSED( index );
editor->setGeometry( option.rect );
}
14 changes: 7 additions & 7 deletions src/plugins/georeferencer/qgsgeorefdelegates.h
Expand Up @@ -52,7 +52,7 @@ class QgsDmsAndDdDelegate : public QStyledItemDelegate
const QModelIndex &index ) const override;

private:
QString dmsToDD( QString dms ) const;
double dmsToDD( QString dms ) const;
};

class QgsCoordDelegate : public QStyledItemDelegate
Expand All @@ -65,12 +65,12 @@ class QgsCoordDelegate : public QStyledItemDelegate
QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index ) const override;

// void setEditorData(QWidget *editor, const QModelIndex &index);
// void setModelData(QWidget *editor, QAbstractItemModel *model,
// const QModelIndex &index);
//
// void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
// const QModelIndex &index);
void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
void setModelData( QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index ) const override;

void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option,
const QModelIndex &index ) const override;
};

#endif // QGSDELEGATES_H

0 comments on commit cecae9f

Please sign in to comment.