Skip to content
Permalink
Browse files

[georef] Fix coordinates truncated to 2 decimal places in table

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 cecae9f107351404f202166237b3397735d4d9c2
@@ -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 );
}
};
@@ -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 )
{
@@ -97,7 +97,7 @@ void QgsGCPListWidget::updateGCPList()

void QgsGCPListWidget::closeEditors()
{
Q_FOREACH( QModelIndex index, selectedIndexes() )
Q_FOREACH ( QModelIndex index, selectedIndexes() )
{
closePersistentEditor( index );
}
@@ -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,
@@ -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 );
@@ -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 --------------------------- //
@@ -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 );
}
@@ -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
@@ -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.
You can’t perform that action at this time.