#include "HYDROGUI_GeoreferencementDlg.h"
+#include "HYDROGUI_Tool.h"
+
+#include <GEOMUtils.hxx>
+
+#include <OCCViewer_ViewWindow.h>
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewPort3d.h>
+
+#include <AIS_InteractiveContext.hxx>
+
#include <QTableWidget>
+#include <QItemDelegate>
#include <QHeaderView>
#include <QRadioButton>
+#include <QPushButton>
#include <QLineEdit>
#include <QButtonGroup>
#include <QGroupBox>
#include <QLayout>
+#include <QMouseEvent>
+
+//! Profile data structre constructor
+HYDROGUI_GeoreferencementDlg::ProfileGeoData::ProfileGeoData(
+ const QString& theXg, const QString& theYg,
+ const QString& theXd, const QString& theYd)
+{
+ 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 );
+ }
+}
HYDROGUI_GeoreferencementDlg::HYDROGUI_GeoreferencementDlg( HYDROGUI_Module* theModule, const QString& theTitle )
-: HYDROGUI_InputPanel( theModule, theTitle )
+: HYDROGUI_InputPanel( theModule, theTitle ), myIsModified( false )
{
// Mode selector (all/selected)
QGroupBox* aModeGroup = new QGroupBox( tr( "PROFILES" ), this );
aModeSelectorLayout->addWidget( anAllRB );
aModeSelectorLayout->addWidget( aSelectedRB );
+ // Update selection button
+ myUpdateSelBtn = new QPushButton( mainFrame() );
+ myUpdateSelBtn->setText( tr("UPDATE_SELECTION") );
+ QBoxLayout* anUpdateSelLayout = new QHBoxLayout( mainFrame() );
+ anUpdateSelLayout->addWidget( myUpdateSelBtn );
+ anUpdateSelLayout->addStretch();
+
// Table
myTable = new QTableWidget( mainFrame() );
+ myTable->setItemDelegate( new Delegate( this ) );
myTable->verticalHeader()->setVisible( false );
myTable->setSelectionBehavior( QAbstractItemView::SelectItems );
myTable->setSelectionMode( QAbstractItemView::SingleSelection );
// Layout
addWidget( aModeGroup );
+ addLayout( anUpdateSelLayout );
addWidget( myTable );
// Connect signals and slots
connect( myModeButtons, SIGNAL( buttonClicked( int ) ), this, SLOT( onModeActivated( int ) ) );
+ connect( myUpdateSelBtn, SIGNAL( clicked() ), this, SIGNAL( updateSelection() ) );
+ connect( myTable->model(), SIGNAL( dataChanged ( const QModelIndex&, const QModelIndex& ) ),
+ this, SLOT( onDataChanged() ) );
}
HYDROGUI_GeoreferencementDlg::~HYDROGUI_GeoreferencementDlg()
void HYDROGUI_GeoreferencementDlg::onModeActivated( int theMode )
{
+ myUpdateSelBtn->setEnabled( theMode == SelectedProfiles );
emit modeActivated( theMode );
}
myTable->setRowCount( 0 );
}
-void HYDROGUI_GeoreferencementDlg::onProfilesSelectionChanged()
-{
- // MZN TODO
-}
-
void HYDROGUI_GeoreferencementDlg::setMode( const int theMode )
{
bool isBlocked = myModeButtons->blockSignals( true );
aModeButton->setChecked( true );
}
+ myUpdateSelBtn->setEnabled( theMode == SelectedProfiles );
+
myModeButtons->blockSignals( isBlocked );
}
void HYDROGUI_GeoreferencementDlg::setData( const ProfilesGeoDataMap& theMap )
{
+ disconnect( myTable->model(), SIGNAL( dataChanged ( const QModelIndex&, const QModelIndex& ) ),
+ this, SLOT( onDataChanged() ) );
+
myTable->setRowCount( 0 );
foreach ( const QString& aProfileName, theMap.keys() ) {
// Get georeferencement data for the current profile
ProfileGeoData aGeoData = theMap.value( aProfileName );
QString aXg, anYg, aXd, anYd;
- if ( aGeoData.isValid ) {
- aXg = QString::number( aGeoData.Xg );
- anYg = QString::number( aGeoData.Yg );
- aXd = QString::number( aGeoData.Xd );
- anYd = QString::number( aGeoData.Yd );
+ if ( !aGeoData.isEmpty ) {
+ aXg = HYDROGUI_Tool::GetCoordinateString( aGeoData.Xg );
+ anYg = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yg );
+ aXd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Xd );
+ anYd = HYDROGUI_Tool::GetCoordinateString( aGeoData.Yd );
}
// Insert row with the data
// "Profile" column
QTableWidgetItem* aNameItem = new QTableWidgetItem( aProfileName );
aNameItem->setFlags( Qt::ItemIsEnabled );
+ QFont aFont = aNameItem->font();
+ aFont.setBold( true );
+ aNameItem->setFont( aFont );
myTable->setItem( aRow, 0, aNameItem );
// "Xg" column
- QLineEdit* aXgEdit = new QLineEdit( aXg );
- aXgEdit->setValidator( new QDoubleValidator( aXgEdit ) );
- myTable->setCellWidget( aRow, 1, aXgEdit );
+ myTable->setItem( aRow, 1, new QTableWidgetItem( aXg ) );
// "Yg" column
- QLineEdit* anYgEdit = new QLineEdit( anYg );
- anYgEdit->setValidator( new QDoubleValidator( anYgEdit ) );
- myTable->setCellWidget( aRow, 2, anYgEdit );
+ myTable->setItem( aRow, 2, new QTableWidgetItem( anYg ) );
// "Xd" column
- QLineEdit* aXdEdit = new QLineEdit( aXd );
- aXdEdit->setValidator( new QDoubleValidator( aXdEdit ) );
- myTable->setCellWidget( aRow, 3, aXdEdit );
+ myTable->setItem( aRow, 3, new QTableWidgetItem( aXd ) );
// "Yd" column
- QLineEdit* anYdEdit = new QLineEdit( anYd );
- anYdEdit->setValidator( new QDoubleValidator( anYdEdit ) );
- myTable->setCellWidget( aRow, 4, anYdEdit );
+ myTable->setItem( aRow, 4, new QTableWidgetItem( anYd ) );
}
+
+ myTable->resizeColumnToContents( 0 );
+ myTable->resizeRowsToContents();
+
+ myIsModified = false;
+
+ connect( myTable->model(), SIGNAL( dataChanged ( const QModelIndex&, const QModelIndex& ) ),
+ this, SLOT( onDataChanged() ) );
}
void HYDROGUI_GeoreferencementDlg::getData( ProfilesGeoDataMap& theMap )
// Fill the map
bool isOk = false;
+ QString aXg, anYg, aXd, anYd;
for ( int aRow = 0; aRow < myTable->rowCount(); aRow++ ) {
QString aProfileName = myTable->item( aRow, 0 )->text();
- theMap.insert( aProfileName, ProfileGeoData() );
-
- double aXg, anYg, aXd, anYd;
-
- QLineEdit* aLineEdit = qobject_cast<QLineEdit*>( myTable->cellWidget( aRow, 1 ) );
- QString aCellText = aLineEdit ? aLineEdit->text() : "";
- aXg = aCellText.toDouble( &isOk );
- if ( !isOk ) continue;
-
- aLineEdit = qobject_cast<QLineEdit*>( myTable->cellWidget( aRow, 2 ) );
- aCellText = aLineEdit ? aLineEdit->text() : "";
- anYg = aCellText.toDouble( &isOk );
- if ( !isOk ) continue;
-
- aLineEdit = qobject_cast<QLineEdit*>( myTable->cellWidget( aRow, 3 ) );
- aCellText = aLineEdit ? aLineEdit->text() : "";
- aXd = aCellText.toDouble( &isOk );
- if ( !isOk ) continue;
-
- aLineEdit = qobject_cast<QLineEdit*>( myTable->cellWidget( aRow, 4 ) );
- aCellText = aLineEdit ? aLineEdit->text() : "";
- anYd = aCellText.toDouble( &isOk );
- if ( !isOk ) continue;
+ aXg = myTable->item( aRow, 1 )->text();
+ anYg = myTable->item( aRow, 2 )->text();
+ aXd = myTable->item( aRow, 3 )->text();
+ anYd = myTable->item( aRow, 4 )->text();
- theMap[aProfileName] = ProfileGeoData( aXg, anYg, aXd, anYd );
+ theMap.insert( aProfileName, ProfileGeoData( aXg, anYg, aXd, anYd ) );
}
}
+
+void HYDROGUI_GeoreferencementDlg::onMousePress(
+ SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
+{
+ // Check the parameters
+ OCCViewer_ViewWindow* anOCCViewWindow =
+ dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
+ if ( !anOCCViewWindow || (theEvent->button() != Qt::LeftButton) ) {
+ return;
+ }
+
+ // Check for current cell
+ int aRow = myTable->currentRow();
+ int aColumn = myTable->currentColumn();
+ if ( aRow < 0 || aColumn <= 0 ) {
+ return;
+ }
+
+ // Get the selected point coordinates
+ OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
+ gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
+ aViewPort->getView() );
+
+ // Set the coordinates to the corresponding cells of the table
+ int aColumnX = aColumn < 3 ? 1 : 3;
+ int aColumnY = aColumnX + 1;
+
+ QString aXStr = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
+ QString anYStr = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
+ myTable->item( aRow, aColumnX )->setText( aXStr );
+ myTable->item( aRow, aColumnY )->setText( anYStr );
+}
+
+void HYDROGUI_GeoreferencementDlg::onDataChanged()
+{
+ myIsModified = true;
+}
+
+bool HYDROGUI_GeoreferencementDlg::isModified() const
+{
+ return myIsModified;
+}
\ No newline at end of file