From 58dcd27e75266f5734ce96619682d2a41fb520ad Mon Sep 17 00:00:00 2001 From: rkv Date: Thu, 5 Dec 2013 13:49:23 +0000 Subject: [PATCH] Fix for the bug #45: check and warning when the same image is used in 2 arguments. --- src/HYDROGUI/HYDROGUI_ObjSelector.cxx | 17 +++++++++++++++++ src/HYDROGUI/HYDROGUI_ObjSelector.h | 7 +++++++ src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx | 4 ++++ src/HYDROGUI/HYDROGUI_TwoImagesDlg.h | 7 +++++++ src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx | 12 ++++++++++++ src/HYDROGUI/HYDROGUI_TwoImagesOp.h | 7 +++++++ src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 4 ++++ 7 files changed, 58 insertions(+) diff --git a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx index 19ddb76e..f3b0ae69 100644 --- a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx +++ b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx @@ -102,8 +102,25 @@ void HYDROGUI_ObjSelector::OnSelectionChanged() Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::GetSelectedObject( myModule ); if( !anObject.IsNull() ) if( myObjectKind == KIND_UNKNOWN || myObjectKind == anObject->GetKind() ) + { anObjName = anObject->GetName(); + // Check if the same object has not been selected in other selectors of the same parent widget. + if ( !anObjName.isEmpty() ) + { + QList aSelectors = parentWidget()->findChildren(); + foreach( HYDROGUI_ObjSelector* aSelector, aSelectors ) + { + if( aSelector != this && ( aSelector->GetName() == anObjName ) ) + { + // Forbid selection of the same object + emit alreadySelected( anObjName ); + return; + } + } + } + } + SetName( anObjName ); } diff --git a/src/HYDROGUI/HYDROGUI_ObjSelector.h b/src/HYDROGUI/HYDROGUI_ObjSelector.h index 717d7001..e44ba07a 100644 --- a/src/HYDROGUI/HYDROGUI_ObjSelector.h +++ b/src/HYDROGUI/HYDROGUI_ObjSelector.h @@ -47,6 +47,13 @@ public: void SetName( const QString& ); QString GetName() const; +signals: + /** Signal is emitted if the name has already been selected + * in other selector of the same parent widget. + * @param theName the selected object name + */ + void alreadySelected( const QString& theName ); + protected: virtual void paintEvent( QPaintEvent* ); virtual bool hitButton( const QPoint& thePnt ) const; diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx index 44b0283e..d8edd596 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx @@ -99,6 +99,10 @@ HYDROGUI_TwoImagesDlg::HYDROGUI_TwoImagesDlg( HYDROGUI_Module* theModule, const this, SLOT( onModifySelectedImage( bool ) ) ); connect( myTransparent, SIGNAL( toggled( bool ) ), myColorBox, SLOT( setDisabled( bool ) ) ); + connect( myImage1, SIGNAL( alreadySelected( const QString& ) ), + this, SIGNAL( alreadySelected( const QString& ) ) ); + connect( myImage2, SIGNAL( alreadySelected( const QString& ) ), + this, SIGNAL( alreadySelected( const QString& ) ) ); setMode( myMode, myIsEdit ); } diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h index 5f952266..76dbe97c 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h +++ b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h @@ -63,6 +63,13 @@ public: void setColor( const QColor& theColor ); QColor getColor() const; +signals: + /** Signal is emitted if the name has already been selected + * in other selector of the same parent widget. + * @param theName the selected object name + */ + void alreadySelected( const QString& theName ); + protected slots: void onModifySelectedImage( bool theState ); diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx index def6f125..885fff83 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx @@ -36,6 +36,10 @@ #include #include +#include +#include +#include + HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType, const bool theIsEdit ) @@ -132,6 +136,14 @@ void HYDROGUI_TwoImagesOp::startOperation() aPanel->setPreselectedObject( aSelectedName ); } } + connect( aPanel, SIGNAL( alreadySelected( const QString& ) ), SLOT( onAlreadySelected( const QString& ) ) ); +} + +void HYDROGUI_TwoImagesOp::onAlreadySelected( const QString& theName ) +{ + QString aTitle = tr( "INSUFFICIENT_INPUT_DATA" ); + QString aMessage = tr( "OBJECT_ALREADY_SELECTED" ).arg( theName ); + SUIT_MessageBox::critical( module()->getApp()->desktop(), aTitle, aMessage ); } bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags, diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.h b/src/HYDROGUI/HYDROGUI_TwoImagesOp.h index 83ef1de9..095d47f1 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.h +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.h @@ -45,6 +45,13 @@ protected: virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); +protected slots: + /** Show warning if the name has already been selected + * in other selector of the same parent widget. + * @param theName the selected object name + */ + void onAlreadySelected( const QString& theName ); + private: int myType; bool myIsEdit; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 51e68873..5c4fc3de 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -1308,6 +1308,10 @@ file cannot be correctly imported for a Bathymetry definition. SPLIT_IMAGE Split image + + OBJECT_ALREADY_SELECTED + The object "%1" has been already selected. Please select another one to perform the operation. + -- 2.39.2