From 7ec27726afa16572a7cab1d7936c8e899674050b Mon Sep 17 00:00:00 2001 From: rkv Date: Fri, 13 Dec 2013 09:02:17 +0000 Subject: [PATCH] Feature #103: Names of Regions: - It is now possible to rename objects by F2 in Calculation dialog; - Main module's object browser is synchronyzed with calculation dialog browser. --- src/HYDROGUI/HYDROGUI_CalculationDlg.cxx | 23 ++++++-- src/HYDROGUI/HYDROGUI_CalculationDlg.h | 1 + src/HYDROGUI/HYDROGUI_CalculationOp.cxx | 41 +++++++++++-- src/HYDROGUI/HYDROGUI_CalculationOp.h | 1 + src/HYDROGUI/HYDROGUI_DataBrowser.cxx | 35 +++++++++++ src/HYDROGUI/HYDROGUI_DataBrowser.h | 1 + src/HYDROGUI/HYDROGUI_DataModel.cxx | 74 ++++++++++++++++++++---- src/HYDROGUI/HYDROGUI_DataModel.h | 45 +++++++++++--- src/HYDROGUI/HYDROGUI_DataObject.cxx | 46 +++++++++++++-- src/HYDROGUI/HYDROGUI_DataObject.h | 46 ++++++++++++--- src/HYDROGUI/HYDROGUI_Operations.cxx | 18 ++++-- src/HYDROGUI/HYDROGUI_Region.cxx | 5 +- src/HYDROGUI/HYDROGUI_Region.h | 6 +- src/HYDROGUI/HYDROGUI_Zone.cxx | 60 ++++++++++++++++++- src/HYDROGUI/HYDROGUI_Zone.h | 11 +++- 15 files changed, 357 insertions(+), 56 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index 5d39423b..322fc123 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -168,7 +168,7 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() { QGridLayout* aLayout = new QGridLayout( aPage ); - myBrowser = new HYDROGUI_DataBrowser( module(), 0, aPage ); + myBrowser = new HYDROGUI_DataBrowser( module(), NULL, aPage ); myBrowser->setAutoOpenLevel( 3 ); aLayout->setMargin( 5 ); aLayout->setSpacing( 5 ); @@ -186,6 +186,7 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() { aPage->setLayout( aLayout ); + connect( myBrowser, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ) ); connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) ); connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) ); @@ -430,13 +431,15 @@ void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_Calculatio myEditedObject = theCase; myValidator->setEditedObject( theCase ); - HYDROGUI_DataObject* anobj = new HYDROGUI_DataObject( 0, NULL, "" ); - myBrowser->setRoot(anobj); + // Build the calculation case subtree + module()->getDataModel()->buildCaseTree( myBrowser->root(), myEditedObject ); - module()->getDataModel()->buildCaseTree( anobj, myEditedObject ); myBrowser->updateTree(); myBrowser->openLevels(); myBrowser->adjustColumnsWidth(); + myBrowser->setAutoUpdate( true ); + myBrowser->setUpdateModified( true ); + } HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const @@ -446,5 +449,15 @@ HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const void HYDROGUI_CalculationDlg::refreshZonesBrowser() { - myBrowser->updateTree(); + SUIT_DataObject* aRoot = myBrowser->root(); + module()->getDataModel()->updateObjectTree( myEditedObject ); + module()->getDataModel()->buildCaseTree( aRoot, myEditedObject ); + myBrowser->updateTree( aRoot ); +} + +void HYDROGUI_CalculationDlg::onDataChanged() +{ + SUIT_DataObject* aRoot = myBrowser->root(); + module()->getDataModel()->buildCaseTree( aRoot, myEditedObject ); + myBrowser->updateTree( aRoot ); } \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index 7178207f..43770dc2 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -66,6 +66,7 @@ public slots: void onEmptyName(); void onAlreadyExists( QString theName ); void refreshZonesBrowser(); + void onDataChanged(); /** * Process items selection: hide/show bathymetry merge type selector. */ diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index ad69b40c..2dabc9fa 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -46,8 +46,11 @@ #include #include +#include #include +#include +#include HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit ) : HYDROGUI_Operation( theModule ), @@ -75,6 +78,20 @@ void HYDROGUI_CalculationOp::startOperation() if ( !aPanel ) return; + SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser(); + QList aShortcuts = aOb->findChildren(); + QShortcut* aShortcut; + foreach( aShortcut, aShortcuts ) + { + if ( aShortcut->key() == + QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey( + SUIT_DataBrowser::RenameShortcut ) ) ) + { + aShortcut->setEnabled( false ); + } + } + + aPanel->reset(); QStringList aList; QStringList anEntryList; @@ -169,6 +186,7 @@ void HYDROGUI_CalculationOp::abortOperation() // Abort transaction abortDocOperation(); HYDROGUI_Operation::abortOperation(); + module()->getApp()->updateObjectBrowser(); } void HYDROGUI_CalculationOp::commitOperation() @@ -188,7 +206,7 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) ); connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onSplitZones() ) ); connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) ); - connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) ); + //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) ); connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) ); connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList& ) ), SLOT( onMoveZones( SUIT_DataObject*, const QList& ) ) ); @@ -344,7 +362,7 @@ void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const ::qobject_cast( inputPanel() ); if ( aPanel ) { - aPanel->setEditedObject(myEditedObject); + aPanel->refreshZonesBrowser(); } createPreview(); } @@ -371,7 +389,7 @@ void HYDROGUI_CalculationOp::onCreateRegion( const QList& theZ ::qobject_cast( inputPanel() ); if ( aPanel ) { - aPanel->setEditedObject(myEditedObject); + aPanel->refreshZonesBrowser(); } createPreview(); } @@ -558,7 +576,8 @@ void HYDROGUI_CalculationOp::onSplitZones() myShowZones = true; myEditedObject->Update(); - aPanel->setEditedObject( myEditedObject ); + //aPanel->setEditedObject( myEditedObject ); + aPanel->refreshZonesBrowser(); createPreview(); } @@ -719,6 +738,20 @@ void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager void HYDROGUI_CalculationOp::closePreview() { + SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser(); + QList aShortcuts = aOb->findChildren(); + QShortcut* aShortcut; + foreach( aShortcut, aShortcuts ) + { + if ( aShortcut->key() == + QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey( + SUIT_DataBrowser::RenameShortcut ) ) ) + { + aShortcut->setEnabled( true ); + } + } + + if( myPreviewViewManager ) { disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.h b/src/HYDROGUI/HYDROGUI_CalculationOp.h index bf449bde..1ede7ff6 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.h +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.h @@ -105,6 +105,7 @@ private: void setZonesVisible( bool theIsVisible ); void getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq, QStringList& theNames, QStringList& theEntries ) const; + /** * Ask user to confirm splitting zones recalculation. * \return true if confirmed diff --git a/src/HYDROGUI/HYDROGUI_DataBrowser.cxx b/src/HYDROGUI/HYDROGUI_DataBrowser.cxx index f4cc73c2..714d2a16 100644 --- a/src/HYDROGUI/HYDROGUI_DataBrowser.cxx +++ b/src/HYDROGUI/HYDROGUI_DataBrowser.cxx @@ -42,8 +42,15 @@ HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_Dat { SUIT_ResourceMgr* resMgr = theModule->getApp()->resourceMgr(); + if ( ( !theRoot ) && theModule ) + { + // Initialize the root with the module data model + setRoot( new CAM_ModuleObject( theModule->dataModel(), NULL ) ); + } + setSortMenuEnabled( true ); setAutoUpdate( true ); + setUpdateModified( true ); if ( resMgr->hasValue( "ObjectBrowser", "auto_hide_search_tool" ) ) searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) ); @@ -54,6 +61,7 @@ HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_Dat QString EntryCol = QObject::tr( "ENTRY_COLUMN" ); QString RefObjCol = tr( "REF_OBJECT_COLUMN" ); QString BathymetryCol = tr( "BATHYMETRY_COLUMN" ); + SUIT_AbstractModel* treeModel = dynamic_cast( model() ); //RKV: treeModel->setSearcher( theModule->getApp() ); treeModel->setSearcher( this ); //RKV @@ -70,6 +78,33 @@ HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_Dat connect( proxyModel, SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ), SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ) ); + + //// Connect signal emitted after editing for updating after objects renaming + SUIT_TreeModel* aMiniModel = dynamic_cast( proxyModel->sourceModel() ); + if ( aMiniModel ) + { + connect( aMiniModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ), + SIGNAL( dataChanged() ) ); + } + + // Do updating also in the module's main object browser. + if ( theModule ) + { + SUIT_DataBrowser* aModulBrowser = theModule->getApp()->objectBrowser(); + if ( aModulBrowser ) + { + SUIT_ProxyModel* aPModel = dynamic_cast(aModulBrowser->model()); + if ( aPModel ) + { + SUIT_TreeModel* aModel = dynamic_cast(aPModel->sourceModel()); + //connect( proxyModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ), + // aPModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ) ); + //connect( proxyModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ), + // aModel, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ) ); + connect( proxyModel, SIGNAL( modelUpdated() ), aModel, SIGNAL( modelUpdated() ) ); + } + } + } } // temporary commented diff --git a/src/HYDROGUI/HYDROGUI_DataBrowser.h b/src/HYDROGUI/HYDROGUI_DataBrowser.h index 50a77534..11856cf6 100644 --- a/src/HYDROGUI/HYDROGUI_DataBrowser.h +++ b/src/HYDROGUI/HYDROGUI_DataBrowser.h @@ -51,6 +51,7 @@ public: signals: void dropped( const QList& theList, SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction ); + void dataChanged(); private: HYDROGUI_Module* myModule; diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index a436ec17..ca645914 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -663,11 +663,12 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* theParent, HYDROGUI_DataObject* theObject, const QString& theParentEntry, - const bool theIsBuildTree ) + const bool theIsBuildTree, + const bool theIsInOperation ) { if ( theIsBuildTree ) { - buildObjectTree( theParent, theObject, theParentEntry ); + buildObjectTree( theParent, theObject, theParentEntry, theIsInOperation ); } return theObject; } @@ -675,17 +676,21 @@ LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* thePa LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theParent, Handle(HYDROData_Zone) theModelObject, const QString& theParentEntry, - const bool theIsBuildTree ) + const bool theIsBuildTree, + const bool theIsInOperation ) { - return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree ); + return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation ), + theParentEntry, theIsBuildTree, theIsInOperation ); } LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent, Handle(HYDROData_Region) theModelObject, const QString& theParentEntry, - const bool theIsBuildTree ) + const bool theIsBuildTree, + const bool theIsInOperation ) { - return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree ); + return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry, theIsInOperation ), + theParentEntry, theIsBuildTree, theIsInOperation ); } LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent, @@ -697,7 +702,8 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParen void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, SUIT_DataObject* theObject, - const QString& theParentEntry ) + const QString& theParentEntry, + const bool theIsInOperation ) { HYDROGUI_DataObject* aGuiObj = dynamic_cast( theObject ); if ( !aGuiObj ) @@ -764,7 +770,7 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, Handle(HYDROData_Region) aCaseRegion = Handle(HYDROData_Region)::DownCast( anIter.Value() ); if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() ) - createRegion( aCaseRegionsSect, aCaseRegion, "", true ); + createRegion( aCaseRegionsSect, aCaseRegion, "", true, theIsInOperation ); } } else if ( anObjectKind == KIND_REGION ) @@ -779,7 +785,7 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, Handle(HYDROData_Zone) aRegionZone = Handle(HYDROData_Zone)::DownCast( anIter.Value() ); if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() ) - createZone( aGuiObj, aRegionZone, "", true ); + createZone( aGuiObj, aRegionZone, "", true, theIsInOperation ); } } else if ( anObjectKind == KIND_PROFILE ) @@ -795,7 +801,17 @@ void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDRO { if ( !theCase.IsNull() ) { - new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "" ); + if ( theParent ) + { + // Remove previous objects tree + DataObjectList aList; + theParent->children( aList ); + QListIterator anIter( aList ); + while( anIter.hasNext() ) + removeChild( theParent, anIter.next() ); + } + + new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "", true ); HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions(); HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions ); @@ -804,7 +820,43 @@ void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDRO Handle(HYDROData_Region) aCaseRegion = Handle(HYDROData_Region)::DownCast( anIter.Value() ); if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() ) - createRegion( theParent, aCaseRegion, "", true ); + createRegion( theParent, aCaseRegion, "", true, true ); + } + } +} + +void HYDROGUI_DataModel::updateObjectTree( Handle(HYDROData_Entity)& theObj ) +{ + if ( !theObj.IsNull() ) + { + HYDROGUI_DataObject* aGuiObj = dynamic_cast( + findObject( HYDROGUI_DataObject::dataObjectEntry( theObj ) ) ); + if ( aGuiObj ) + { + // Remove previous objects tree + DataObjectList aList; + aGuiObj->children( aList ); + QListIterator anIter( aList ); + while( anIter.hasNext() ) + removeChild( aGuiObj, anIter.next() ); + + // Rebuild the subtree + QString aParentEntry; + HYDROGUI_DataObject* aParent = dynamic_cast( aGuiObj->parent() ); + if ( aParent ) + { + aParentEntry = aParent->entry(); + } + buildObjectTree( aParent, aGuiObj, aParentEntry, aGuiObj->isInOperation() ); + } + else + { + // workaround for the bug in SalomeApp_Study::findObjectByEntry - it can't find LightApp_DataObjects + HYDROGUI_Module* aModule = dynamic_cast( module() ); + if( aModule ) + { + aModule->getApp()->updateObjectBrowser(); + } } } } diff --git a/src/HYDROGUI/HYDROGUI_DataModel.h b/src/HYDROGUI/HYDROGUI_DataModel.h index e4d2bcb7..077905a5 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.h +++ b/src/HYDROGUI/HYDROGUI_DataModel.h @@ -226,14 +226,19 @@ public: bool rename( Handle(HYDROData_Entity) theEntity, const QString& theName ); /** - * Creates the GUI data object according to the model object. - * \param theParent a created object will be appended as a child of this object - * \param theModelObject model object - * \param theParentEntry entry of parent object + * Creates the Calculation Case subtree for usage within an operation dialog. + * \param theParent a created object will be appended as a child of this GUI object + * \param theCase the calculation case model object */ void buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase ); + /** + * Updates the object subtree. + * \param theObj the data model entity + */ + void updateObjectTree( Handle(HYDROData_Entity)& theObj ); + /** * Update the sequence of the objects to be copied */ @@ -280,30 +285,52 @@ protected: * \param theObject the GUI object * \param theParentEntry the entry of parent object * \param theIsBuildTree if true then build the subtree of the GUI object + * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default */ LightApp_DataObject* buildObject( SUIT_DataObject* theParent, HYDROGUI_DataObject* theObject, const QString& theParentEntry, - const bool theIsBuildTree ); + const bool theIsBuildTree, + const bool theIsInOperation = false ); + /** + * Build object tree if the flag theIsBuildTree is true. + * \param theParent a created object will be appended as a child of this GUI object + * \param theModelObject the data model zone object + * \param theParentEntry the entry of parent object + * \param theIsBuildTree if true then build the subtree of the GUI object + * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default + */ LightApp_DataObject* createZone( SUIT_DataObject* theParent, Handle(HYDROData_Zone) theModelObject, const QString& theParentEntry, - const bool theIsBuildTree ); + const bool theIsBuildTree , + const bool theIsInOperation = false ); + /** + * Build object tree if the flag theIsBuildTree is true. + * \param theParent a created object will be appended as a child of this GUI object + * \param theModelObject the data model region object + * \param theParentEntry the entry of parent object + * \param theIsBuildTree if true then build the subtree of the GUI object + * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default + */ LightApp_DataObject* createRegion( SUIT_DataObject* theParent, Handle(HYDROData_Region) theModelObject, const QString& theParentEntry, - const bool theIsBuildTree ); + const bool theIsBuildTree , + const bool theIsInOperation = false ); /** - * Build tree of model object. + * Build tree of a model object. * \param theParent a created object will be appended as a child of this object * \param theObject gui object for which the tree will be build * \param theParentEntry entry of parent object + * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default */ void buildObjectTree( SUIT_DataObject* theParent, SUIT_DataObject* theObject, - const QString& theParentEntry = QString() ); + const QString& theParentEntry = QString(), + const bool theIsInOperation = false ); /** * Removes data object from the tree. diff --git a/src/HYDROGUI/HYDROGUI_DataObject.cxx b/src/HYDROGUI/HYDROGUI_DataObject.cxx index a3227a7d..cc62a54a 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.cxx +++ b/src/HYDROGUI/HYDROGUI_DataObject.cxx @@ -30,17 +30,23 @@ #include #include #include +#include +#include +#include +#include #include HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent, Handle(HYDROData_Entity) theData, - const QString& theParentEntry ) + const QString& theParentEntry, + const bool theIsInOperation ) : CAM_DataObject( theParent ), LightApp_DataObject( theParent ), myData( theData ), myParentEntry( theParentEntry ), - myIsValid( true ) + myIsValid( true ), + myIsInOperation( theIsInOperation ) { } @@ -192,13 +198,39 @@ bool HYDROGUI_DataObject::isValid() const return myIsValid; } +bool HYDROGUI_DataObject::renameAllowed( const int theColumnId ) const +{ + bool aRes = false; + if ( theColumnId == NameId && module()) + { + SUIT_Operation* anOp = module()->application()->activeStudy()->activeOperation(); + if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) ) + { + aRes = isInOperation(); + } + else + { + aRes = !anOp; + } + } + else + { + aRes = LightApp_DataObject::renameAllowed( theColumnId ); + } + return aRes; +} + + + HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent, const QString& theName, - const QString& theParentEntry ) + const QString& theParentEntry, + const bool theIsInOperation ) : CAM_DataObject( theParent ), LightApp_DataObject( theParent ), myName( theName ), - myParentEntry( theParentEntry ) + myParentEntry( theParentEntry ), + myIsInOperation( theIsInOperation ) { } @@ -227,7 +259,9 @@ QPixmap HYDROGUI_NamedObject::icon( const int theId ) const HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent, const QString& theName, - const QString& theParentEntry ) -: HYDROGUI_NamedObject( theParent, theName, theParentEntry ), CAM_DataObject( theParent ) + const QString& theParentEntry, + const bool theIsInOperation ) +: HYDROGUI_NamedObject( theParent, theName, theParentEntry, theIsInOperation ), + CAM_DataObject( theParent ) { } diff --git a/src/HYDROGUI/HYDROGUI_DataObject.h b/src/HYDROGUI/HYDROGUI_DataObject.h index ea9fb38c..d8b78a8c 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.h +++ b/src/HYDROGUI/HYDROGUI_DataObject.h @@ -50,15 +50,22 @@ public: BathymetryId //!< Bathymetry column }; + //! Role + enum { + IsInOperationRole = Qtx::AppropriateRole + 100 //!< Filter value role + }; + /** * Constructor. * \param theParent parent data object * \param theData reference to the corresponding object from data structure * \param theParentEntry entry of the parent data object (for reference objects) + * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default */ - HYDROGUI_DataObject( SUIT_DataObject* theParent, + HYDROGUI_DataObject( SUIT_DataObject* theParent, Handle(HYDROData_Entity) theData, - const QString& theParentEntry ); + const QString& theParentEntry, + const bool theIsInOperation = false ); /** * Returns the unique object identifier string. @@ -90,6 +97,11 @@ public: */ virtual QPixmap icon( const int = NameId ) const; + /** + * Returns true if renaming is allowed for the object. + */ + virtual bool renameAllowed( const int = NameId ) const; + /** * Returns the model data object. */ @@ -118,14 +130,22 @@ public: /** * Returns the validity flag: is object valid or not - * \returns false if object is not valid + * \return false if object is not valid */ bool isValid() const; + /** + * Returns the usage within active operation flag: + * is the object is used in the local tree of an active operation dialog or not. + * \return false if the object is used in the main object browser tree + */ + bool isInOperation() const { return myIsInOperation; } + protected: Handle(HYDROData_Entity) myData; ///< object from data model QString myParentEntry; bool myIsValid; ///< indicates if the object is valid + bool myIsInOperation; ///< indicates if the object is used within an active operation QPixmap myIcon; }; @@ -145,10 +165,12 @@ public: * Constructor. * \param theParent parent data object * \param theName displayed name + * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default */ HYDROGUI_NamedObject( SUIT_DataObject* theParent, - const QString& theName, - const QString& theParentEntry ); + const QString& theName, + const QString& theParentEntry, + const bool theIsInOperation = false ); /** * Returns the unique object identifier string. @@ -165,10 +187,18 @@ public: */ virtual QPixmap icon( const int = NameId ) const; + /** + * Returns the usage within active operation flag: + * is the object is used in the local tree of an active operation dialog or not. + * \return false if the object is used in the main object browser tree + */ + bool isInOperation() const { return myIsInOperation; } + private: QString myName; ///< name in the OB QString myParentEntry; QPixmap myIcon; + bool myIsInOperation; ///< indicates if the object is used within an active operation }; /** @@ -183,10 +213,12 @@ public: * Constructor. * \param theParent parent data object * \param theName displayed name + * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default */ HYDROGUI_DropTargetObject( SUIT_DataObject* theParent, - const QString& theName, - const QString& theParentEntry ); + const QString& theName, + const QString& theParentEntry, + const bool theIsInOperation = false ); bool isDropAccepted() const { return true; } }; diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index c9fca653..7d8dba61 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -544,8 +544,8 @@ bool HYDROGUI_Module::renameAllowed( const QString& theEntry ) const bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theName ) { Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry ); - bool aRes = !anEntity.IsNull(); - if ( aRes ) + bool aRes = false; + if ( !anEntity.IsNull() ) { HYDROGUI_DataModel* aModel = getDataModel(); if( aModel ) @@ -554,10 +554,18 @@ bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theN { // check that there are no other objects with the same name in the document Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( this, theName ); - aRes = anObject.IsNull(); - if ( aRes ) + if ( anObject.IsNull() ) { - aRes = aModel->rename( anEntity, theName ); + SUIT_Operation* anOp = application()->activeStudy()->activeOperation(); + if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) ) + { + anEntity->SetName( theName ); + aRes = true; + } + else + { + aRes = aModel->rename( anEntity, theName ); + } } else { diff --git a/src/HYDROGUI/HYDROGUI_Region.cxx b/src/HYDROGUI/HYDROGUI_Region.cxx index f9e1547b..a53ddc78 100644 --- a/src/HYDROGUI/HYDROGUI_Region.cxx +++ b/src/HYDROGUI/HYDROGUI_Region.cxx @@ -32,8 +32,9 @@ HYDROGUI_Region::HYDROGUI_Region( SUIT_DataObject* theParent, Handle(HYDROData_Region) theData, - const QString& theParentEntry ) -: HYDROGUI_DataObject( theParent, theData, theParentEntry ), CAM_DataObject( theParent ) + const QString& theParentEntry, + const bool theIsInOperation ) +: HYDROGUI_DataObject( theParent, theData, theParentEntry, theIsInOperation ), CAM_DataObject( theParent ) { } diff --git a/src/HYDROGUI/HYDROGUI_Region.h b/src/HYDROGUI/HYDROGUI_Region.h index b9e705d2..b6db313f 100644 --- a/src/HYDROGUI/HYDROGUI_Region.h +++ b/src/HYDROGUI/HYDROGUI_Region.h @@ -47,10 +47,12 @@ public: * \param theParent parent data object * \param theData reference to the corresponding object from data structure * \param theParentEntry entry of the parent data object (for reference objects) + * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default */ - HYDROGUI_Region( SUIT_DataObject* theParent, + HYDROGUI_Region( SUIT_DataObject* theParent, Handle(HYDROData_Region) theData, - const QString& theParentEntry ); + const QString& theParentEntry, + const bool theIsInOperation = false ); bool isDropAccepted() const { return true; } diff --git a/src/HYDROGUI/HYDROGUI_Zone.cxx b/src/HYDROGUI/HYDROGUI_Zone.cxx index 189394cf..4485ec4f 100644 --- a/src/HYDROGUI/HYDROGUI_Zone.cxx +++ b/src/HYDROGUI/HYDROGUI_Zone.cxx @@ -31,8 +31,9 @@ HYDROGUI_Zone::HYDROGUI_Zone( SUIT_DataObject* theParent, Handle(HYDROData_Zone) theData, - const QString& theParentEntry ) -: HYDROGUI_DataObject( theParent, theData, theParentEntry ), CAM_DataObject( theParent ) + const QString& theParentEntry, + const bool theIsInOperation ) +: HYDROGUI_DataObject( theParent, theData, theParentEntry, theIsInOperation ), CAM_DataObject( theParent ) { } @@ -277,3 +278,58 @@ void HYDROGUI_Zone::setMergeType( int theMergeType, QString theBathymetryName ) } } } + +/*! + \brief Check if this object is can't be renamed in place + + \param id column id + \return \c true if the item can be renamed by the user in place (e.g. in the Object browser) +*/ +bool HYDROGUI_Zone::renameAllowed( const int id ) const +{ + if ( id == NameId && isInOperation() ) + { + return true; + } + return HYDROGUI_DataObject::renameAllowed( id ); +} + +///*! +// \brief Set name of this object. +// +// \return \c true if rename operation finished successfully, \c false otherwise. +//*/ +//bool HYDROGUI_Zone::setName(const QString& theName) +//{ +// if ( isInOperation() ) +// { +// bool aRes = false; +// if ( !theName.isEmpty() ) +// { +// Handle(HYDROData_Entity) anEntity = modelObject(); +// CAM_Module* aModule = module(); +// if( anEntity->GetName() != theName && aModule ) +// { +// // check that there are no other objects with the same name in the document +// Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( aModule, theName ); +// if ( anObject.IsNull() ) +// { +// anEntity->SetName( theName ); +// aRes = true; +// } +// else +// { +// // Inform the user that the name is already used +// QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" ); +// QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ); +// SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage ); +// } +// } +// } +// } +// else +// { +// aRes = HYDROGUI_DataObject::setName( theName ); +// } +// return aRes; +//} diff --git a/src/HYDROGUI/HYDROGUI_Zone.h b/src/HYDROGUI/HYDROGUI_Zone.h index ee25b802..e960de24 100644 --- a/src/HYDROGUI/HYDROGUI_Zone.h +++ b/src/HYDROGUI/HYDROGUI_Zone.h @@ -45,10 +45,12 @@ public: * \param theParent parent data object * \param theData reference to the corresponding object from data structure * \param theParentEntry entry of the parent data object (for reference objects) + * \param theIsInOperation if true then the tree is used for a browser within an operation, it is false by default */ - HYDROGUI_Zone( SUIT_DataObject* theParent, - Handle(HYDROData_Zone) theData, - const QString& theParentEntry ); + HYDROGUI_Zone( SUIT_DataObject* theParent, + Handle(HYDROData_Zone) theData, + const QString& theParentEntry, + const bool theIsInOperation = false ); /** * Returns the text for the specified column. @@ -65,6 +67,9 @@ public: */ bool isDraggable() const { return true; } + bool renameAllowed( const int = NameId ) const; + //bool setName( const QString& ); + /** * Returns true if it is a zone which needs merge of bathymetries. */ -- 2.39.2