From bfe9d3ccf8d5347b917d4c9e5e89413cebe51cc6 Mon Sep 17 00:00:00 2001 From: rkv Date: Fri, 1 Nov 2013 11:36:00 +0000 Subject: [PATCH] - Stub for drag and drop in the Calculation Case wizard is implemented (zones moving is not implemented for the moment). --- src/HYDROGUI/CMakeLists.txt | 2 + src/HYDROGUI/HYDROGUI_CalculationDlg.cxx | 40 +++++++++++++++- src/HYDROGUI/HYDROGUI_CalculationDlg.h | 5 ++ src/HYDROGUI/HYDROGUI_DataBrowser.cxx | 32 ++++++++++--- src/HYDROGUI/HYDROGUI_DataBrowser.h | 16 ++++++- src/HYDROGUI/HYDROGUI_DataModel.cxx | 45 +++++++++++++----- src/HYDROGUI/HYDROGUI_DataModel.h | 24 ++++++++++ src/HYDROGUI/HYDROGUI_Region.cxx | 48 +++++++++++++++++++ src/HYDROGUI/HYDROGUI_Region.h | 60 ++++++++++++++++++++++++ src/HYDROGUI/HYDROGUI_Zone.h | 7 ++- 10 files changed, 255 insertions(+), 24 deletions(-) create mode 100644 src/HYDROGUI/HYDROGUI_Region.cxx create mode 100644 src/HYDROGUI/HYDROGUI_Region.h diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 32e007dd..dc39fbe2 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -41,6 +41,7 @@ set(PROJECT_HEADERS HYDROGUI_PrsPolylineDriver.h HYDROGUI_PrsZone.h HYDROGUI_PrsZoneDriver.h + HYDROGUI_Region.h HYDROGUI_Shape.h HYDROGUI_ShowHideOp.h HYDROGUI_Tool.h @@ -94,6 +95,7 @@ set(PROJECT_SOURCES HYDROGUI_PrsPolylineDriver.cxx HYDROGUI_PrsZone.cxx HYDROGUI_PrsZoneDriver.cxx + HYDROGUI_Region.cxx HYDROGUI_Shape.cxx HYDROGUI_ShowHideOp.cxx HYDROGUI_Tool.cxx diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index e395d6d6..c06ab638 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -29,10 +29,11 @@ #include "HYDROGUI_Module.h" #include "HYDROGUI_DataObject.h" #include "HYDROGUI_NameValidator.h" +#include "HYDROGUI_Region.h" +#include "HYDROGUI_Zone.h" #include #include -#include #include #include @@ -168,10 +169,46 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() { connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) ); connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) ); + connect( myBrowser, + SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ), + SLOT( onZonesDropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ) ); return aPage; } +void HYDROGUI_CalculationDlg::onZonesDropped( const QList& theList, + SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction ) +{ + QList aZonesList; + HYDROGUI_Zone* aZone; + // Get a list of dropped zones + for ( int i = 0; i < theList.length(); i++ ) + { + aZone = dynamic_cast( theList.at( i ) ); + if ( aZone ) + { + aZonesList.append( aZone ); + } + } + if ( aZonesList.length() > 0 ) + { + // Get the target region + HYDROGUI_NamedObject* aRegionsRoot = dynamic_cast(theTargetParent); + if ( aRegionsRoot ) + { + // Create a new region + } + else + { + HYDROGUI_Region* aRegion = dynamic_cast(theTargetParent); + if ( aRegion ) + { + aRegion->addZones( ); + } + } + } +} + void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex ) { int aType = myBathymetryChoice->itemData( theIndex ).toInt(); @@ -276,6 +313,7 @@ void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_Calculatio myEditedObject, "", true ); myBrowser->updateTree(); myBrowser->openLevels(); + myBrowser->adjustColumnsWidth(); } HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index 7db16048..e2791f21 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -70,6 +70,11 @@ public slots: * Process merge type selection: set the selected bathymetry merge type for the currently selected zone. */ void onMergeTypeSelected( int theIndex ); + /** + * Process zones moving. Create a new region with dropped zones or add to existing one. + */ + void onZonesDropped( const QList& theList, + SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction ); signals: void addObjects(); diff --git a/src/HYDROGUI/HYDROGUI_DataBrowser.cxx b/src/HYDROGUI/HYDROGUI_DataBrowser.cxx index b6cdedb2..f4cc73c2 100644 --- a/src/HYDROGUI/HYDROGUI_DataBrowser.cxx +++ b/src/HYDROGUI/HYDROGUI_DataBrowser.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #define VISIBILITY_COLUMN_WIDTH 25 @@ -50,22 +51,26 @@ HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_Dat setWindowTitle( tr( "OBJECT_BROWSER" ) ); connect( this, SIGNAL( requestUpdate() ), theModule->getApp(), SLOT( onRefresh() ) ); + QString EntryCol = QObject::tr( "ENTRY_COLUMN" ); QString RefObjCol = tr( "REF_OBJECT_COLUMN" ); QString BathymetryCol = tr( "BATHYMETRY_COLUMN" ); SUIT_AbstractModel* treeModel = dynamic_cast( model() ); - treeModel->setSearcher( theModule->getApp() ); + //RKV: treeModel->setSearcher( theModule->getApp() ); + treeModel->setSearcher( this ); //RKV + treeModel->registerColumn( 0, EntryCol, LightApp_DataObject::EntryId ); + treeModel->setAppropriate( EntryCol, Qtx::Toggled ); treeModel->registerColumn( 0, RefObjCol, HYDROGUI_DataObject::RefObjectId ); treeModel->setAppropriate( RefObjCol, Qtx::Toggled ); treeModel->registerColumn( 0, BathymetryCol, HYDROGUI_DataObject::BathymetryId ); treeModel->setAppropriate( BathymetryCol, Qtx::Toggled ); // Mantis issue 0020136: Drag&Drop in OB - //RKV: TODO: Uncomment for drag and drop - //RKV: SUIT_ProxyModel* proxyModel = dynamic_cast(treeModel); - //RKV: if ( proxyModel ) { - //RKV: connect( proxyModel, SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ), - //RKV: theModule->getApp(), SLOT( onDropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ) ); - //RKV: } + SUIT_ProxyModel* proxyModel = dynamic_cast(treeModel); + if ( proxyModel ) { + connect( proxyModel, + SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ), + SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ) ); + } // temporary commented /* @@ -82,9 +87,22 @@ HYDROGUI_DataBrowser::HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_Dat treeView()->header()->setResizeMode(SUIT_DataObject::VisibilityId, QHeaderView::Fixed); treeView()->header()->moveSection(SUIT_DataObject::NameId,SUIT_DataObject::VisibilityId); treeView()->setColumnWidth(SUIT_DataObject::VisibilityId, VISIBILITY_COLUMN_WIDTH); + treeView()->hideColumn( SUIT_DataObject::VisibilityId ); + treeView()->hideColumn( LightApp_DataObject::EntryId ); //RKV: connectPopupRequest( theModule->getApp(), SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); } HYDROGUI_DataBrowser::~HYDROGUI_DataBrowser() { } + +SUIT_DataObject* HYDROGUI_DataBrowser::findObject( const QString& theEntry ) const +{ + LightApp_DataObject* aCurObj; + for ( SUIT_DataObjectIterator it( root(), SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) { + aCurObj = dynamic_cast( it.current() ); + if ( aCurObj && aCurObj->entry() == theEntry ) + return aCurObj; + } + return NULL; +} diff --git a/src/HYDROGUI/HYDROGUI_DataBrowser.h b/src/HYDROGUI/HYDROGUI_DataBrowser.h index 3c3e3201..2d79a829 100644 --- a/src/HYDROGUI/HYDROGUI_DataBrowser.h +++ b/src/HYDROGUI/HYDROGUI_DataBrowser.h @@ -24,13 +24,14 @@ #define HYDROGUI_DATABROWSER_H #include +#include class HYDROGUI_Module; /**\class HYDROGUI_DataBrowser *\brief The data model browser widget implementation */ -class HYDROGUI_DataBrowser : public SUIT_DataBrowser +class HYDROGUI_DataBrowser : public SUIT_DataBrowser, public SUIT_DataSearcher { Q_OBJECT @@ -38,7 +39,18 @@ public: HYDROGUI_DataBrowser( HYDROGUI_Module* theModule, SUIT_DataObject*, QWidget* = 0 ); ~HYDROGUI_DataBrowser(); - HYDROGUI_Module* module() const; + HYDROGUI_Module* module() const; + + /*! + Find a data object by the specified entry. + \param theEntry - Entry of the object. + \return data object. + */ + virtual SUIT_DataObject* findObject( const QString& ) const override; + +signals: + void dropped( const QList& theList, + SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction ); private: HYDROGUI_Module* myModule; diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index 6ea2d54a..dbe6cead 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -26,6 +26,7 @@ #include "HYDROGUI_Module.h" #include "HYDROGUI_Tool.h" #include "HYDROGUI_Zone.h" +#include "HYDROGUI_Region.h" #include #include @@ -528,17 +529,7 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* const QString& theParentEntry, const bool theIsBuildTree ) { - HYDROGUI_DataObject* aResObj; - Handle(HYDROData_Zone) aRegionZone = - Handle(HYDROData_Zone)::DownCast( theModelObject ); - if( !aRegionZone.IsNull() ) - { - aResObj = new HYDROGUI_Zone( theParent, aRegionZone, theParentEntry ); - } - else - { - aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry ); - } + HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry ); if ( theIsBuildTree ) { @@ -548,6 +539,34 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* return aResObj; } +LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* theParent, + HYDROGUI_DataObject* theObject, + const QString& theParentEntry, + const bool theIsBuildTree ) +{ + if ( theIsBuildTree ) + { + buildObjectTree( theParent, theObject, theParentEntry ); + } + return theObject; +} + +LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theParent, + Handle(HYDROData_Zone) theModelObject, + const QString& theParentEntry, + const bool theIsBuildTree ) +{ + return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree ); +} + +LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent, + Handle(HYDROData_Region) theModelObject, + const QString& theParentEntry, + const bool theIsBuildTree ) +{ + return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry ), theParentEntry, theIsBuildTree ); +} + LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent, const QString& theName, const QString& theParentEntry ) @@ -614,7 +633,7 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, Handle(HYDROData_Region) aCaseRegion = Handle(HYDROData_Region)::DownCast( anIter.Value() ); if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() ) - createObject( aCaseRegionsSect, aCaseRegion, "", true ); + createRegion( aCaseRegionsSect, aCaseRegion, "", true ); } } else if ( anObjectKind == KIND_REGION ) @@ -629,7 +648,7 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, Handle(HYDROData_Zone) aRegionZone = Handle(HYDROData_Zone)::DownCast( anIter.Value() ); if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() ) - createObject( aGuiObj, aRegionZone, "", true ); + createZone( aGuiObj, aRegionZone, "", true ); } } } diff --git a/src/HYDROGUI/HYDROGUI_DataModel.h b/src/HYDROGUI/HYDROGUI_DataModel.h index 97379263..bfc590e7 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.h +++ b/src/HYDROGUI/HYDROGUI_DataModel.h @@ -25,6 +25,8 @@ #include #include +#include +#include #include #include @@ -249,6 +251,28 @@ protected: const QString& theName, const QString& theParentEntry = QString() ); + /** + * Build object tree if the flag theIsBuildTree is true. + * This is a conditional wrapper for buildObjectTree method. + * \param theParent a created object will be appended as a child of this object + * \param theObject the GUI object + * \param theParentEntry the entry of parent object + * \param theIsBuildTree if true then build the subtree of the GUI object + */ + LightApp_DataObject* buildObject( SUIT_DataObject* theParent, + HYDROGUI_DataObject* theObject, + const QString& theParentEntry, + const bool theIsBuildTree ); + + LightApp_DataObject* createZone( SUIT_DataObject* theParent, + Handle(HYDROData_Zone) theModelObject, + const QString& theParentEntry, + const bool theIsBuildTree ); + + LightApp_DataObject* createRegion( SUIT_DataObject* theParent, + Handle(HYDROData_Region) theModelObject, + const QString& theParentEntry, + const bool theIsBuildTree ); /** * Build tree of model object. * \param theParent a created object will be appended as a child of this object diff --git a/src/HYDROGUI/HYDROGUI_Region.cxx b/src/HYDROGUI/HYDROGUI_Region.cxx new file mode 100644 index 00000000..15722904 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Region.cxx @@ -0,0 +1,48 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_Region.h" + +#include "HYDROGUI_Zone.h" + +#include +#include +#include + +#include + +HYDROGUI_Region::HYDROGUI_Region( SUIT_DataObject* theParent, + Handle(HYDROData_Region) theData, + const QString& theParentEntry ) +: HYDROGUI_DataObject( theParent, theData, theParentEntry ), CAM_DataObject( theParent ) +{ +} + +void HYDROGUI_Region::addZones( ) +{ + Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast( modelObject() ); + if ( !aRegion.IsNull() ) + { + // TODO: Add zones + ; + } +} diff --git a/src/HYDROGUI/HYDROGUI_Region.h b/src/HYDROGUI/HYDROGUI_Region.h new file mode 100644 index 00000000..c5b3ac70 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Region.h @@ -0,0 +1,60 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_REGION_H +#define HYDROGUI_REGION_H + +#include "HYDROGUI_DataObject.h" + +#include + +#include +#include + +/** + * \class HYDROGUI_Region + * \brief Browser item presenting a zone, used for object browser tree creation. + * + * This is an Object Browser item that contains reference to a zone data structure + * element inside. + */ +class HYDROGUI_Region : public HYDROGUI_DataObject +{ +public: + /** + * 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) + */ + HYDROGUI_Region( SUIT_DataObject* theParent, + Handle(HYDROData_Region) theData, + const QString& theParentEntry ); + + bool isDropAccepted() const override { return true; } + + /** + * Add zones to the region. + */ + void addZones(); +}; +#endif diff --git a/src/HYDROGUI/HYDROGUI_Zone.h b/src/HYDROGUI/HYDROGUI_Zone.h index 2b1f08fd..4dca40d2 100644 --- a/src/HYDROGUI/HYDROGUI_Zone.h +++ b/src/HYDROGUI/HYDROGUI_Zone.h @@ -58,7 +58,12 @@ public: /** * Returns the color for the specified column. */ - QColor color( const ColorRole, const int = NameId ) const override; + QColor color( const ColorRole theColorRole, const int theColumnId = NameId ) const override; + + /** + * Return true because zones are draggable. + */ + bool isDraggable() const override { return true; } /** * Returns true if it is a zone which needs merge of bathymetries. -- 2.39.2