From d6e19029f8b41f295db878e9aecf451c2edda4af Mon Sep 17 00:00:00 2001 From: mkr Date: Mon, 15 Jun 2015 15:18:07 +0300 Subject: [PATCH] refs #568: use ordered list view with selection synchronized with object browser to define a set of polylines for constructed land cover. --- src/HYDROGUI/HYDROGUI_CalculationDlg.cxx | 2 - src/HYDROGUI/HYDROGUI_LandCoverDlg.cxx | 118 +++++++++++++--------- src/HYDROGUI/HYDROGUI_LandCoverDlg.h | 15 ++- src/HYDROGUI/HYDROGUI_LandCoverOp.cxx | 93 ++++++++++++++++- src/HYDROGUI/HYDROGUI_LandCoverOp.h | 3 + src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 16 +++ 6 files changed, 188 insertions(+), 59 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index 9e97678e..b796efb1 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -668,7 +668,6 @@ void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects ) { - HYDROGUI_ListModel::Object2VisibleList anObjectsToInclude; QList aFoundItems; foreach ( const QString& anObjName, theObjects ) { // Hide the object in the available objects list @@ -1050,7 +1049,6 @@ void HYDROGUI_CalculationDlg::includeLandCovers( const QStringList& theLandCover myLandCovers->setObjects(anObject2VisibleList); } - HYDROGUI_ListModel::Object2VisibleList anObjectsToInclude; QList aFoundItems; foreach ( const QString& anObjName, theLandCovers ) { // Hide the land cover in the available land covers list diff --git a/src/HYDROGUI/HYDROGUI_LandCoverDlg.cxx b/src/HYDROGUI/HYDROGUI_LandCoverDlg.cxx index fabcc568..39baff78 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverDlg.cxx @@ -18,33 +18,68 @@ #include "HYDROGUI_LandCoverDlg.h" +#include "HYDROGUI_Module.h" +#include "HYDROGUI_OrderedListWidget.h" +#include "HYDROGUI_ListSelector.h" + +#include +#include + #include #include #include #include +#include HYDROGUI_LandCoverDlg::HYDROGUI_LandCoverDlg( HYDROGUI_Module* theModule, const QString& theTitle ) : HYDROGUI_BasicZoneDlg( theModule, theTitle, tr( "LAND_COVER_NAME" ), tr( "NAME" ), tr( "LAND_COVER_PARAMETERS" ), tr( "LAND_COVER_STRICKLER_TYPE" ) ) { - myPolylines = new QListWidget( myPolylineFrame ); - myPolylines->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); - myPolylines->setSelectionMode( QAbstractItemView::ExtendedSelection ); - - QBoxLayout* aPolyLayout = new QVBoxLayout( myPolylineFrame ); - aPolyLayout->setMargin( 0 ); + myPolylines = new HYDROGUI_OrderedListWidget( myPolylineFrame, 16 ); + myPolylines->setHiddenObjectsShown(true); + myPolylines->setVisibilityIconShown(false); + myPolylines->setContentsMargins(QMargins()); + myPolylines->setOrderingEnabled( true ); + + // Include/Exclude buttons + QFrame* aBtnsFrame = new QFrame( myPolylineFrame ); + QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame ); + aBtnsLayout->setMargin( 5 ); + aBtnsLayout->setSpacing( 5 ); + aBtnsFrame->setLayout( aBtnsLayout ); + QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame ); + QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame ); + + // Fill the butons frame with two buttons + aBtnsLayout->addWidget( anAddBtn ); + aBtnsLayout->addWidget( aRemoveBtn ); + aBtnsLayout->addStretch( 1 ); + + QGridLayout* aPolyLayout = new QGridLayout( myPolylineFrame ); + aPolyLayout->setMargin( 5 ); aPolyLayout->setSpacing( 5 ); - aPolyLayout->addWidget( new QLabel( tr( "LAND_COVER_POLYLINES" ), myPolylineFrame ) ); - aPolyLayout->addWidget( myPolylines ); + aPolyLayout->addWidget( new QLabel( tr( "LAND_COVER_POLYLINES" ), myPolylineFrame ), 0, 0, 1, 2 ); + aPolyLayout->addWidget( aBtnsFrame, 1, 0, 1, 1 ); + aPolyLayout->addWidget( myPolylines, 1, 1, 1, 1 ); QBoxLayout* aParamLayout = new QVBoxLayout( myParamGroup ); aParamLayout->setMargin( 5 ); aParamLayout->setSpacing( 5 ); aParamLayout->addWidget( myPolylineFrame ); + // Create selector + if ( module() ) { + HYDROGUI_ListSelector* aListSelector = + new HYDROGUI_ListSelector( myPolylines, module()->getApp()->selectionMgr() ); + aListSelector->setAutoBlock( true ); + } + // Connect signals and slots connect( myPolylines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onZoneDefChanged() ) ); + connect( myPolylines, SIGNAL( orderPolylinesChanged() ), SLOT( onOrderPolylinesChanged() ) ); + connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addPolylines() ) ); + connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removePolylines() ) ); } HYDROGUI_LandCoverDlg::~HYDROGUI_LandCoverDlg() @@ -57,62 +92,42 @@ void HYDROGUI_LandCoverDlg::reset() HYDROGUI_BasicZoneDlg::reset(); - myPolylines->clear(); + HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList; + myPolylines->setObjects(anObject2VisibleList); + myPolylines->setOrderingEnabled( false ); blockSignals( isBlocked ); onZoneDefChanged(); } -void HYDROGUI_LandCoverDlg::setPolylineNames( const QStringList& thePolylines ) +void HYDROGUI_LandCoverDlg::includePolylines( const HYDROGUI_ListModel::Object2VisibleList& theSelectedPolylines ) { - bool isBlocked = blockSignals( true ); - - myPolylines->clear(); - myPolylines->addItems( thePolylines ); + QStringList anIncludedPolylinesNames = myPolylines->getAllNames(); - blockSignals( isBlocked ); + foreach ( const HYDROGUI_ListModel::Object2Visible& aSelectedPolyline, theSelectedPolylines ) + { + if ( !anIncludedPolylinesNames.contains( aSelectedPolyline.first->GetName() ) ) + myPolylines->addObject( aSelectedPolyline ); + } + myPolylines->setOrderingEnabled( myPolylines->getObjects().count() > 1 ); } -void HYDROGUI_LandCoverDlg::setSelectedPolylineNames( const QStringList& theSelectedPolylines ) +void HYDROGUI_LandCoverDlg::excludePolylines( const HYDROGUI_ListModel::Object2VisibleList& theSelectedPolylines ) { - bool anUpdateNeeded = false; - for (int i =0; i< myPolylines->count(); i++) - { - QListWidgetItem* anItem = myPolylines->item( i ); - if ( anItem ) - { - bool aIsSelected = anItem->isSelected(); - if ( theSelectedPolylines.contains( anItem->text() ) ) - { - if ( !aIsSelected ) - { - anUpdateNeeded = true; - anItem->setSelected( true ); - } - } - else if ( aIsSelected ) - { - anUpdateNeeded = true; - anItem->setSelected( false ); - } - } - } + foreach ( const HYDROGUI_ListModel::Object2Visible& aSelectedPolyline, theSelectedPolylines ) + myPolylines->removeObjectByName( aSelectedPolyline.first->GetName() ); + myPolylines->setOrderingEnabled( myPolylines->getObjects().count() > 1 ); +} - if ( anUpdateNeeded ) - onZoneDefChanged(); +QStringList HYDROGUI_LandCoverDlg::getPolylineNames() const +{ + return myPolylines->getAllNames(); } QStringList HYDROGUI_LandCoverDlg::getSelectedPolylineNames() const { - QStringList aSelectedPolylines; - - QList aSelectedItems = myPolylines->selectedItems(); - QList::const_iterator anIt = aSelectedItems.begin(), aLast = aSelectedItems.end(); - for( ; anIt!=aLast; anIt++ ) - aSelectedPolylines.append( (*anIt)->text() ); - - return aSelectedPolylines; + return myPolylines->getSelectedNames(); } void HYDROGUI_LandCoverDlg::onZoneDefChanged() @@ -120,6 +135,11 @@ void HYDROGUI_LandCoverDlg::onZoneDefChanged() if ( signalsBlocked() ) return; - QStringList aPolylineNames = getSelectedPolylineNames(); + QStringList aPolylineNames = getPolylineNames(); emit CreatePreview( aPolylineNames ); } + +void HYDROGUI_LandCoverDlg::onOrderPolylinesChanged() +{ + // TODO: implement this method +} diff --git a/src/HYDROGUI/HYDROGUI_LandCoverDlg.h b/src/HYDROGUI/HYDROGUI_LandCoverDlg.h index bb529fa0..5c5aa3d8 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverDlg.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverDlg.h @@ -21,6 +21,10 @@ #include "HYDROGUI_BasicZoneDlg.h" +#include "HYDROGUI_ListModel.h" + +class HYDROGUI_OrderedListWidget; + class QListWidget; class HYDROGUI_LandCoverDlg : public HYDROGUI_BasicZoneDlg @@ -33,18 +37,23 @@ public: virtual void reset(); - void setPolylineNames( const QStringList& thePolylines ); - void setSelectedPolylineNames( const QStringList& theSelectedPolylines ); + void includePolylines( const HYDROGUI_ListModel::Object2VisibleList& theSelectedPolylines ); + void excludePolylines( const HYDROGUI_ListModel::Object2VisibleList& theSelectedPolylines ); + QStringList getPolylineNames() const; QStringList getSelectedPolylineNames() const; signals: void CreatePreview( const QStringList& thePolylineNames ); + void orderPolylinesChanged(); + void addPolylines(); + void removePolylines(); private slots: void onZoneDefChanged(); + void onOrderPolylinesChanged(); private: - QListWidget* myPolylines; + HYDROGUI_OrderedListWidget* myPolylines; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx b/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx index 75c4ce08..5240b42d 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx @@ -35,6 +35,9 @@ #include +#include +#include + #include #include #include @@ -69,7 +72,7 @@ void HYDROGUI_LandCoverOp::startOperation() QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_LAND_COVER_NAME" ) ); - QStringList aSelectedPolylines; + HYDROGUI_ListModel::Object2VisibleList aSelectedPolylines; QString aSelectedStricklerType; if ( myIsEdit ) @@ -84,7 +87,7 @@ void HYDROGUI_LandCoverOp::startOperation() for ( int i = aRefPolylines.Lower(); i <= aRefPolylines.Upper(); i++ ) { Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aRefPolylines.Value( i ) ); if ( !aPolyline.IsNull() ) { - aSelectedPolylines.append( aPolyline->GetName() ); + aSelectedPolylines.append( HYDROGUI_ListModel::Object2Visible( aPolyline, true ) ); } } } @@ -93,7 +96,6 @@ void HYDROGUI_LandCoverOp::startOperation() } aPanel->setObjectName( anObjectName ); - aPanel->setPolylineNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) ); // Construct a list of unique names of all Strickler types defined within the data model QStringList aStricklerTypes; HYDROData_Iterator anIterator( doc(), KIND_STRICKLER_TABLE ); @@ -118,7 +120,7 @@ void HYDROGUI_LandCoverOp::startOperation() aPanel->blockSignals( false ); - aPanel->setSelectedPolylineNames( aSelectedPolylines ); + aPanel->includePolylines( aSelectedPolylines ); aPanel->setSelectedAdditionalParamName( aSelectedStricklerType ); } @@ -141,6 +143,8 @@ HYDROGUI_InputPanel* HYDROGUI_LandCoverOp::createInputPanel() const HYDROGUI_LandCoverDlg* aPanel = new HYDROGUI_LandCoverDlg( module(), getName() ); connect( aPanel, SIGNAL( CreatePreview( const QStringList& ) ), this, SLOT( onCreatePreview( const QStringList& ) ) ); + connect( aPanel, SIGNAL( addPolylines() ), SLOT( onAddPolylines() ) ); + connect( aPanel, SIGNAL( removePolylines() ), SLOT( onRemovePolylines() ) ); return aPanel; } @@ -173,7 +177,7 @@ bool HYDROGUI_LandCoverOp::processApply( int& theUpdateFlags, HYDROData_SequenceOfObjects aZonePolylines; QString aStricklerType; - QStringList aSelectedPolylineNames = aPanel->getSelectedPolylineNames(); + QStringList aSelectedPolylineNames = aPanel->getPolylineNames(); QStringList::const_iterator anIt = aSelectedPolylineNames.begin(), aLast = aSelectedPolylineNames.end(); for( ; anIt!=aLast; anIt++ ) { @@ -288,6 +292,57 @@ void HYDROGUI_LandCoverOp::onCreatePreview( const QStringList& thePolylineNames QApplication::restoreOverrideCursor(); } +void HYDROGUI_LandCoverOp::onAddPolylines() +{ + HYDROGUI_LandCoverDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + // Add polylines selected in the module browser + Handle(HYDROData_PolylineXY) aPolyXY; + HYDROGUI_ListModel::Object2VisibleList aSelectedPolylines; + HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() ); + + if ( aSeq.IsEmpty() || !confirmPolylinesChange() ) + return; + + for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) + { + aPolyXY = Handle(HYDROData_PolylineXY)::DownCast( aSeq.Value( anIndex )); + if (!aPolyXY.IsNull()) + aSelectedPolylines.append( HYDROGUI_ListModel::Object2Visible( aPolyXY, true ) ); + } + + aPanel->includePolylines( aSelectedPolylines ); + // TODO: create preview of included polylines +} + +void HYDROGUI_LandCoverOp::onRemovePolylines() +{ + // Remove selected polylines from the calculation case + HYDROGUI_LandCoverDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + QStringList aSelectedList = aPanel->getSelectedPolylineNames(); + if ( aSelectedList.isEmpty() || !confirmPolylinesChange() ) + return; + + HYDROGUI_ListModel::Object2VisibleList aSelectedPolylines; + for (int i = 0; i < aSelectedList.length(); i++) + { + Handle(HYDROData_PolylineXY) anObject = Handle(HYDROData_PolylineXY)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) ); + if ( anObject.IsNull() ) + continue; + + aSelectedPolylines.append( HYDROGUI_ListModel::Object2Visible( anObject, true ) ); + } + + module()->update( UF_OCCViewer ); + aPanel->excludePolylines( aSelectedPolylines ); +} + void HYDROGUI_LandCoverOp::closePreview() { if( myPreviewPrs ) @@ -296,3 +351,31 @@ void HYDROGUI_LandCoverOp::closePreview() myPreviewPrs = 0; } } + +bool HYDROGUI_LandCoverOp::confirmPolylinesChange() const +{ + if ( myEditedObject.IsNull() ) + return true; + + // Check if the land cover object is already modified or not + bool isConfirmed = myEditedObject->IsMustBeUpdated(); + if ( !isConfirmed ) + { + // If not modified check if the land cover has already defined polylines + HYDROData_SequenceOfObjects aSeq = myEditedObject->GetPolylines(); + if ( aSeq.Length() > 0 ) + { + // If there are already defined polylines then ask a user to confirm land cover recalculation + isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(), + tr( "POLYLINES_CHANGED" ), + tr( "CONFIRM_LAND_COVER_RECALCULATION" ), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No ) == QMessageBox::Yes ); + } + else + { + isConfirmed = true; // No polylines - nothing to recalculate + } + } + return isConfirmed; +} diff --git a/src/HYDROGUI/HYDROGUI_LandCoverOp.h b/src/HYDROGUI/HYDROGUI_LandCoverOp.h index a50feb05..fb25f255 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverOp.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverOp.h @@ -47,9 +47,12 @@ protected: protected slots: void onCreatePreview( const QStringList& thePolylineNames ); + void onAddPolylines(); + void onRemovePolylines(); private: void closePreview(); + bool confirmPolylinesChange() const; private: bool myIsEdit; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 998b0f01..0e686cdf 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2450,6 +2450,14 @@ Polyline should consist from one not closed curve. LAND_COVER_STRICKLER_TYPE Strickler type + + INCLUDE + Include >> + + + EXCLUDE + Exclude << + @@ -2466,6 +2474,14 @@ Polyline should consist from one not closed curve. SELECT_STRICKLER_TABLE_FILE The Strickler table file is not chosen + + POLYLINES_CHANGED + Polylines list modification + + + CONFIRM_LAND_COVER_RECALCULATION + Land cover object already exists and will be recalculated after polylines list modification. Do you confirm the recalculation? + -- 2.39.2