-//! Custom item delegate (line edit with double validator)
-class HYDROGUI_GeoreferencementDlg::Delegate : public QItemDelegate
-{
-public:
- Delegate( QObject* = 0 );
-
- QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
- const QModelIndex& ) const;
-
- void setEditorData( QWidget*, const QModelIndex& ) const;
- void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
-};
-
-HYDROGUI_GeoreferencementDlg::Delegate::Delegate( QObject* theParent )
- : QItemDelegate( theParent )
-{
-}
-
-QWidget* HYDROGUI_GeoreferencementDlg::Delegate::createEditor(
- QWidget* theParent, const QStyleOptionViewItem& theOption,
- const QModelIndex& theIndex ) const
-{
- QWidget* anEditor = 0;
-
- if ( theIndex.column() > 0 ) {
- QLineEdit* aLineEdit = new QLineEdit( theParent );
- QDoubleValidator* aDoubleValidator = new QDoubleValidator();
- aDoubleValidator->setNotation( QDoubleValidator::StandardNotation );
- aDoubleValidator->setDecimals( 2 );
- aLineEdit->setValidator( aDoubleValidator );
- anEditor = aLineEdit;
- } else {
- anEditor = QItemDelegate::createEditor( theParent, theOption, theIndex );
- }
-
- return anEditor;
-}
-
-void HYDROGUI_GeoreferencementDlg::Delegate::setEditorData(
- QWidget* theEditor, const QModelIndex& theIndex ) const
-{
- if ( QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>( theEditor ) ) {
- aLineEdit->setText( theIndex.data( Qt::EditRole ).toString() );
- } else {
- QItemDelegate::setEditorData( theEditor, theIndex );
- }
-}
-
-void HYDROGUI_GeoreferencementDlg::Delegate::setModelData(
- QWidget* theEditor, QAbstractItemModel* theModel, const QModelIndex& theIndex) const
-{
- if ( QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>( theEditor ) ) {
- theModel->setData( theIndex, aLineEdit->text() );
- } else {
- QItemDelegate::setModelData( theEditor, theModel, theIndex );
- }
-}
-