diff --git a/ApplicationLibCode/Commands/OsduImportCommands/RiuWellImportWizard.cpp b/ApplicationLibCode/Commands/OsduImportCommands/RiuWellImportWizard.cpp index 10e97818ba..ea4cfc8fb0 100644 --- a/ApplicationLibCode/Commands/OsduImportCommands/RiuWellImportWizard.cpp +++ b/ApplicationLibCode/Commands/OsduImportCommands/RiuWellImportWizard.cpp @@ -248,7 +248,7 @@ FieldSelectionPage::FieldSelectionPage( RiaOsduConnector* osduConnector, QWidget m_osduFieldsModel = new OsduFieldTableModel; m_tableView->setModel( m_osduFieldsModel ); m_tableView->setSortingEnabled( true ); - int nameColumn = 2; + int nameColumn = OsduFieldTableModel::Column::Name; m_tableView->sortByColumn( nameColumn, Qt::AscendingOrder ); layout->addWidget( m_tableView ); @@ -308,7 +308,7 @@ void FieldSelectionPage::selectField( const QItemSelection& newSelection, const if ( !newSelection.indexes().empty() ) { QModelIndex index = newSelection.indexes()[0]; - int column = 0; + int column = OsduFieldTableModel::Column::Id; QString fieldId = m_osduFieldsModel->data( index.siblingAtColumn( column ) ).toString(); RiuWellImportWizard* wiz = dynamic_cast( wizard() ); wiz->setSelectedFieldId( fieldId ); @@ -353,7 +353,7 @@ WellSelectionPage::WellSelectionPage( RiaOsduConnector* osduConnector, QWidget* m_tableView->setSelectionBehavior( QAbstractItemView::SelectRows ); m_tableView->setSelectionMode( QAbstractItemView::ExtendedSelection ); m_tableView->setSortingEnabled( true ); - int nameColumn = 2; + int nameColumn = OsduWellboreTableModel::Column::Name; m_tableView->sortByColumn( nameColumn, Qt::AscendingOrder ); QHeaderView* header = m_tableView->horizontalHeader(); @@ -449,8 +449,7 @@ void WellSelectionPage::selectWellbore( const QItemSelection& newSelection, cons QModelIndexList selection = m_tableView->selectionModel()->selectedRows(); for ( QModelIndex index : selection ) { - int idColumn = 0; - + int idColumn = OsduWellboreTableModel::Column::Id; if ( index.column() == idColumn ) { QString wellboreId = m_proxyModel->data( index.siblingAtColumn( idColumn ) ).toString(); diff --git a/ApplicationLibCode/Commands/OsduImportCommands/RiuWellImportWizard.h b/ApplicationLibCode/Commands/OsduImportCommands/RiuWellImportWizard.h index 7b2583167c..83914c95f2 100644 --- a/ApplicationLibCode/Commands/OsduImportCommands/RiuWellImportWizard.h +++ b/ApplicationLibCode/Commands/OsduImportCommands/RiuWellImportWizard.h @@ -34,7 +34,6 @@ class QFile; class QLabel; class QTextEdit; class QTableView; - class OsduFieldTableModel : public QAbstractTableModel { Q_OBJECT @@ -45,6 +44,14 @@ public: { } + enum Column + { + Id, + Kind, + Name, + ColumnCount + }; + int rowCount( const QModelIndex& parent = QModelIndex() ) const override { Q_UNUSED( parent ); @@ -54,8 +61,7 @@ public: int columnCount( const QModelIndex& parent = QModelIndex() ) const override { Q_UNUSED( parent ); - // Assuming you have three fields: id, kind, and name - return 3; + return ColumnCount; } QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override @@ -67,13 +73,13 @@ public: if ( role == Qt::DisplayRole ) { const OsduField& field = m_osduFields.at( index.row() ); - switch ( index.column() ) + switch ( static_cast( index.column() ) ) { - case 0: + case Id: return field.id; - case 1: + case Kind: return field.kind; - case 2: + case Name: return field.name; default: return QVariant(); @@ -89,13 +95,13 @@ public: if ( orientation == Qt::Horizontal ) { - switch ( section ) + switch ( static_cast( section ) ) { - case 0: + case Id: return tr( "ID" ); - case 1: + case Kind: return tr( "Kind" ); - case 2: + case Name: return tr( "Name" ); default: return QVariant(); @@ -117,13 +123,13 @@ public: m_osduFields.end(), [column, order]( const OsduField& a, const OsduField& b ) { - switch ( column ) + switch ( static_cast( column ) ) { - case 0: + case Id: return ( order == Qt::AscendingOrder ) ? a.id < b.id : a.id > b.id; - case 1: + case Kind: return ( order == Qt::AscendingOrder ) ? a.kind < b.kind : a.kind > b.kind; - case 2: + case Name: return ( order == Qt::AscendingOrder ) ? a.name < b.name : a.name > b.name; default: return false; @@ -147,6 +153,14 @@ public: { } + enum Column + { + Id, + Kind, + Name, + ColumnCount + }; + int rowCount( const QModelIndex& parent = QModelIndex() ) const override { Q_UNUSED( parent ); @@ -156,8 +170,7 @@ public: int columnCount( const QModelIndex& parent = QModelIndex() ) const override { Q_UNUSED( parent ); - // Assuming you have three fields: id, kind, and name - return 3; + return ColumnCount; } QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override @@ -169,13 +182,13 @@ public: if ( role == Qt::DisplayRole ) { const OsduWellbore& field = m_osduWellbores.at( index.row() ); - switch ( index.column() ) + switch ( static_cast( index.column() ) ) { - case 0: + case Id: return field.id; - case 1: + case Kind: return field.kind; - case 2: + case Name: return field.name; default: return QVariant(); @@ -191,13 +204,13 @@ public: if ( orientation == Qt::Horizontal ) { - switch ( section ) + switch ( static_cast( section ) ) { - case 0: + case Id: return tr( "ID" ); - case 1: + case Kind: return tr( "Kind" ); - case 2: + case Name: return tr( "Name" ); default: return QVariant(); @@ -216,7 +229,6 @@ public: for ( auto v : values ) m_osduWellbores.push_back( v ); } - endResetModel(); } @@ -226,13 +238,13 @@ public: m_osduWellbores.end(), [column, order]( const OsduWellbore& a, const OsduWellbore& b ) { - switch ( column ) + switch ( static_cast( column ) ) { - case 0: + case Id: return ( order == Qt::AscendingOrder ) ? a.id < b.id : a.id > b.id; - case 1: + case Kind: return ( order == Qt::AscendingOrder ) ? a.kind < b.kind : a.kind > b.kind; - case 2: + case Name: return ( order == Qt::AscendingOrder ) ? a.name < b.name : a.name > b.name; default: return false;