+#include <QMouseEvent>
+
+//! Profile data structre constructor
+HYDROGUI_GeoreferencementDlg::ProfileGeoData::ProfileGeoData(
+ const QString& theName,
+ const QString& theXg, const QString& theYg,
+ const QString& theXd, const QString& theYd)
+{
+ this->Name = theName;
+ this->isEmpty = theXg.isEmpty() && theYg.isEmpty() &&
+ theXd.isEmpty() && theYd.isEmpty();
+ this->isIncomplete = !isEmpty;
+
+ if ( isIncomplete ) {
+ bool isOk = false;
+
+ this->Xg= theXg.toDouble( &isOk );
+ if ( isOk ) {
+ this->Yg = theYg.toDouble( &isOk );
+ if ( isOk ) {
+ this->Xd = theXd.toDouble( &isOk );
+ if ( isOk ) {
+ this->Yd = theYd.toDouble( &isOk );
+ this->isIncomplete = !isOk;
+ }
+ }
+ }
+ }
+}
+
+//! 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 );
+ }
+}