From 5f412421a532b009cbe9414ee88176d3542f5e0c Mon Sep 17 00:00:00 2001 From: mzn Date: Mon, 27 Oct 2014 11:47:01 +0000 Subject: [PATCH] Feature #477: Keep in Priority table order in Included objects field. --- src/HYDROGUI/HYDROGUI_CalculationDlg.cxx | 12 +++++++++++- src/HYDROGUI/HYDROGUI_CalculationDlg.h | 2 ++ src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx | 10 ++++++++-- src/HYDROGUI/HYDROGUI_OrderedListWidget.h | 1 + src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx | 14 ++++++++++---- src/HYDROGUI/HYDROGUI_PriorityWidget.cxx | 3 ++- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index b57f38b1..9b2bfda7 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -239,6 +239,8 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) ); connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) ); + connect( myGeomObjects, SIGNAL( orderChanged() ), SLOT( onOrderChanged() ) ); + return aPage; } @@ -723,8 +725,16 @@ HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const /** Set rules. @param theRules the list of rules -*/ + */ void HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const { myPriorityWidget->setRules( theRules ); +} + +/** + Slot called when objects order is changed. + */ +void HYDROGUI_CalculationDlg::onOrderChanged() +{ + myPriorityWidget->setObjects( getGeometryObjects() ); } \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index 24604f33..5010b7d2 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -89,6 +89,8 @@ public slots: void onAlreadyExists( QString theName ); void refreshZonesBrowser(); void onDataChanged(); + void onOrderChanged(); + /** * Process items selection: hide/show bathymetry merge type selector. */ diff --git a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx index b4bf9a1b..8c23d224 100644 --- a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx +++ b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx @@ -310,6 +310,8 @@ QStringList HYDROGUI_OrderedListWidget::getAllNames() const */ void HYDROGUI_OrderedListWidget::onMove( int theType ) { + bool isMoved = false; + QSortFilterProxyModel* aFilterModel = dynamic_cast( myList->model() ); if( aFilterModel ) { HYDROGUI_ListModel* aModel = dynamic_cast( aFilterModel->sourceModel() ); @@ -320,10 +322,14 @@ void HYDROGUI_OrderedListWidget::onMove( int theType ) aSelectedSourceIndexes << aFilterModel->mapToSource( anIndex ); } QList aSelectedIds = aModel->getIds( aSelectedSourceIndexes ); - aModel->move( aSelectedIds, ( HYDROGUI_ListModel::OpType )theType, - !myIsHiddenObjectsShown ); + isMoved = aModel->move( aSelectedIds, ( HYDROGUI_ListModel::OpType )theType, + !myIsHiddenObjectsShown ); } } + + if ( isMoved ) { + emit orderChanged(); + } } /** diff --git a/src/HYDROGUI/HYDROGUI_OrderedListWidget.h b/src/HYDROGUI/HYDROGUI_OrderedListWidget.h index 39bf9ebe..31faba84 100644 --- a/src/HYDROGUI/HYDROGUI_OrderedListWidget.h +++ b/src/HYDROGUI/HYDROGUI_OrderedListWidget.h @@ -64,6 +64,7 @@ public: signals: void selectionChanged(); + void orderChanged(); private slots: void onMove( int theType ); diff --git a/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx b/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx index 16023dad..22ae6a91 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx +++ b/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx @@ -230,8 +230,8 @@ QVariant HYDROGUI_PriorityTableModel::headerData( int theSection, } /** - Set objects which could be used for rules. - @param theObjects the list of objects + Set objects which could be used for rules definition. + @param theObjects the ordered list of objects */ void HYDROGUI_PriorityTableModel::setObjects( const QList& theObjects ) { @@ -273,8 +273,11 @@ bool HYDROGUI_PriorityTableModel::createNewRule() } } - // Try to find new pair of objects + // Try to find: + // 1. the new pair of objects + // 2. the priority type corresponding to the objects order Handle(HYDROData_Object) anObject1, anObject2; + HYDROData_PriorityType aPriorityType = GREATER; int aNbObjects = myObjects.count(); for ( int anIndex1 = 0; anIndex1 < aNbObjects; anIndex1++ ) { @@ -288,6 +291,9 @@ bool HYDROGUI_PriorityTableModel::createNewRule() if ( !aRules.contains( QPair( anIndex1, anIndex2 ) ) ) { anObject1 = myObjects.at( anIndex1 ); anObject2 = myObjects.at( anIndex2 ); + if ( anIndex1 > anIndex2 ) { + aPriorityType = LESS; + } isFound = true; break; } @@ -305,7 +311,7 @@ bool HYDROGUI_PriorityTableModel::createNewRule() HYDROData_CustomRule aNewRule; aNewRule.Object1 = anObject1; aNewRule.Object2 = anObject2; - aNewRule.Priority = LESS; + aNewRule.Priority = aPriorityType; aNewRule.MergeType = HYDROData_Zone::Merge_ZMIN; beginResetModel(); diff --git a/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx index fe011338..1545f667 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx +++ b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx @@ -247,7 +247,8 @@ void HYDROGUI_PriorityWidget::onClearRules() } /** - Set objects. + Set objects which could be used for rules definition. + @param theObjects the ordered list of objects */ void HYDROGUI_PriorityWidget::setObjects( const QList& theObjects ) { -- 2.39.2