From: mzn Date: Tue, 21 Oct 2014 11:55:50 +0000 (+0000) Subject: Implement table of rules. X-Git-Tag: BR_hydro_v_1_0_4~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=317431d65778c8a444ad012b356e1f3c2ff6c038;p=modules%2Fhydro.git Implement table of rules. --- diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index fc5dfac4..a1928801 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -100,6 +100,7 @@ set(PROJECT_HEADERS HYDROGUI_ListSelector.h HYDROGUI_ZLayers.h HYDROGUI_PriorityWidget.h + HYDROGUI_PriorityTableModel.h ) QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) @@ -202,6 +203,7 @@ set(PROJECT_SOURCES HYDROGUI_ZLayers.cxx HYDROGUI_ZLayers2.cxx HYDROGUI_PriorityWidget.cxx + HYDROGUI_PriorityTableModel.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index a8c978db..3406908a 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -507,6 +507,8 @@ void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects HYDROGUI_Tool::FindObjectByName( module(), anObjName ); myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) ); } + + myPriorityWidget->setObjects( getGeometryObjects() ); } void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects ) @@ -522,6 +524,8 @@ void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects // Remove the object from the list of included objects myGeomObjects->removeObjectByName( anObjName ); } + + myPriorityWidget->setObjects( getGeometryObjects() ); } void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName ) @@ -682,4 +686,43 @@ void HYDROGUI_CalculationDlg::setMoveZonesEnabled( const bool theIsEnabled ) foreach ( QTreeView* aView, myBrowser->findChildren() ) { aView->setDragEnabled ( theIsEnabled ); } +} + +/** + Get included geometry objects. + @return the list of geometry objects + */ +QList HYDROGUI_CalculationDlg::getGeometryObjects() +{ + QList anEntities = myGeomObjects->getObjects(); + QList anObjects; + + foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) { + Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity ); + if ( anObj.IsNull() ) { + continue; + } + + anObjects << anObj; + } + + return anObjects; +} + +/** + Get rules. + @return the list of rules + */ +HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const +{ + return myPriorityWidget->getRules(); +} + +/** + Set rules. + @param theRules the list of rules +*/ +void HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const +{ + myPriorityWidget->setRules( theRules ); } \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index e58dfa73..59b28e98 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -75,6 +75,9 @@ public: void setMoveZonesEnabled( const bool theIsEnabled ); + HYDROData_ListOfRules getRules() const; + void setRules( const HYDROData_ListOfRules& theRules ) const; + public slots: void setMode( int theMode ); void setBoundary( const QString& theObjName ); @@ -122,6 +125,7 @@ protected: virtual bool acceptCurrent() const; private: + QList getGeometryObjects(); QWizardPage* createObjectsPage(); QWizardPage* createGroupsPage(); diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index f6238938..4cb4e9c8 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -149,6 +149,24 @@ void HYDROGUI_CalculationOp::startOperation() aSeq = myEditedObject->GetGeometryObjects(); getNamesAndEntries( aSeq, aList, anEntryList ); aPanel->includeGeomObjects( aList ); + + // set rules + HYDROData_ListOfRules aRules; + Handle(HYDROData_Object) anObject1, anObject2; + HYDROData_PriorityType aPriority; + HYDROData_Zone::MergeAltitudesType aMergeType; + for ( int anIndex = 0; anIndex < myEditedObject->GetRulesCount(); anIndex++ ) { + if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType ) ) { + HYDROData_CustomRule aRule; + aRule.Object1 = anObject1; + aRule.Object2 = anObject2; + aRule.Priority = aPriority; + aRule.MergeType = aMergeType; + + aRules << aRule; + } + } + aPanel->setRules( aRules ); } } else @@ -629,6 +647,13 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) } } aPanel->setMoveZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL ); + + // Set priority rules + myEditedObject->ClearRules(); + foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) { + myEditedObject->AddRule( aRule.Object1, aRule.Priority, + aRule.Object2, aRule.MergeType ); + } if ( myEditedObject->IsMustBeUpdated() ) { diff --git a/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx b/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx new file mode 100644 index 00000000..c0e1dacb --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx @@ -0,0 +1,346 @@ +// 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_PriorityTableModel.h" + + +/** + Constructor. + @param theParent the parent object +*/ +HYDROGUI_PriorityTableModel::HYDROGUI_PriorityTableModel( QObject* theParent ) + : QAbstractTableModel( theParent ) +{ +} + +/** + Destructor. +*/ +HYDROGUI_PriorityTableModel::~HYDROGUI_PriorityTableModel() +{ +} + +/** + */ +Qt::ItemFlags HYDROGUI_PriorityTableModel::flags( const QModelIndex & theIndex ) const +{ + return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; +} + +/** + */ +QVariant HYDROGUI_PriorityTableModel::data( const QModelIndex &theIndex, int theRole ) const +{ + QVariant aVariant; + + int aRow = theIndex.row(); + int aColumn = theIndex.column(); + + if ( !theIndex.isValid() || aRow > myRules.size() ) { + return aVariant; + } + + if ( theRole == Qt::DisplayRole ) { + HYDROData_CustomRule aRule = myRules.at(aRow); + + if ( aColumn == 0 ) { + aVariant = aRule.Object1->GetName(); + } else if ( aColumn == 1 ) { + aVariant = priorityToString( aRule.Priority ); + } else if ( aColumn == 2 ) { + aVariant = aRule.Object2->GetName(); + } else if ( aColumn == 3 ) { + aVariant = mergeTypeToString( aRule.MergeType ); + } + } else if ( theRole == Qt::EditRole ) { + HYDROData_CustomRule aRule = myRules.at(aRow); + + if ( aColumn == 0 ) { + aVariant = aRule.Object1->GetName(); + } else if ( aColumn == 1 ) { + aVariant = aRule.Priority; + } else if ( aColumn == 2 ) { + aVariant = aRule.Object2->GetName(); + } else if ( aColumn == 3 ) { + aVariant = aRule.MergeType; + } + } else if ( theRole == Qt::UserRole ) { + if ( aColumn == 0 || aColumn == 2 ) { + aVariant = getAvailableObjects(); + } else if ( aColumn == 1 ) { + QMap aMap; + aMap.insert( priorityToString( LESS ), LESS ); + aMap.insert( priorityToString( GREATER ), GREATER ); + aVariant = QVariant( aMap ); + } else if ( aColumn == 3 ) { + QMap aMap; + aMap.insert( mergeTypeToString( HYDROData_Zone::Merge_Object ), HYDROData_Zone::Merge_Object ); + aMap.insert( mergeTypeToString( HYDROData_Zone::Merge_ZMIN ), HYDROData_Zone::Merge_ZMIN ); + aMap.insert( mergeTypeToString( HYDROData_Zone::Merge_ZMAX ), HYDROData_Zone::Merge_ZMAX ); + aVariant = QVariant( aMap ); + } + } else if ( theRole == Qt::TextAlignmentRole ) { + aVariant = Qt::AlignCenter; + } + + return aVariant; +} + +/** + */ +bool HYDROGUI_PriorityTableModel::setData( const QModelIndex & theIndex, const QVariant & theValue, int theRole ) +{ + int aRow = theIndex.row(); + if ( !theIndex.isValid() || aRow > myRules.size() ) { + return false; + } + + bool aRes = false; + + if ( theRole == Qt::EditRole ) { + int aColumn = theIndex.column(); + + if ( aColumn == 0 || aColumn == 2 ) { + Handle(HYDROData_Object) anObject; + QString anObjName = theValue.toString(); + foreach ( const Handle(HYDROData_Object) anObj, myObjects ) { + if ( anObj->GetName() == anObjName ) { + anObject = anObj; + break; + } + } + if ( !anObject.IsNull() ) { + if ( aColumn == 0 ) { + myRules[aRow].Object1 = anObject; + } else { + myRules[aRow].Object2 = anObject; + } + + aRes = true; + } + } else if ( aColumn == 1 ) { + myRules[aRow].Priority = (HYDROData_PriorityType)theValue.toInt(); + } else if ( aColumn == 3 ) { + myRules[aRow].MergeType = (HYDROData_Zone::MergeAltitudesType)theValue.toInt();; + } + } + + return aRes; +} + +/** + */ +int HYDROGUI_PriorityTableModel::rowCount( const QModelIndex &theParent ) const +{ + return myRules.count(); +} + +/** + */ +int HYDROGUI_PriorityTableModel::columnCount( const QModelIndex &theParent ) const +{ + return 4; +} + +/** + Set rules. + @param theRules the list of rules +*/ +void HYDROGUI_PriorityTableModel::setRules( const HYDROData_ListOfRules& theRules ) +{ + myRules = theRules; + + reset(); +} + +/** + Get rules. + @return the list of rules +*/ +HYDROData_ListOfRules HYDROGUI_PriorityTableModel::getRules() const +{ + return myRules; +} + +/** +*/ +QVariant HYDROGUI_PriorityTableModel::headerData( int theSection, + Qt::Orientation theOrientation, + int theRole ) const +{ + QVariant aData; + + if ( theRole != Qt::DisplayRole ) { + return aData; + } + + if ( theOrientation == Qt::Horizontal ) { + switch( theSection ) + { + case 0: + aData = tr( "OBJECT1" ); + break; + case 1: + aData = tr( "PRIORITY" ); + break; + case 2: + aData = tr( "OBJECT2" ); + break; + case 3: + aData = tr( "BATHYMETRY" ); + break; + }; + } else if ( theOrientation == Qt::Vertical ) { + aData = theSection + 1; + } + + return aData; +} + +/** + Set objects which could be used for rules. + @param theObjects the list of objects + */ +void HYDROGUI_PriorityTableModel::setObjects( const QList& theObjects ) +{ + myObjects = theObjects; + + QMutableListIterator anIter( myRules ); + while ( anIter.hasNext() ) { + HYDROData_CustomRule aRule = anIter.next(); + if ( !myObjects.contains( aRule.Object1 ) || + !myObjects.contains( aRule.Object2 ) ) { + anIter.remove(); + } + } + + reset(); +} + +/** + Create new rule. + */ +void HYDROGUI_PriorityTableModel::createNewRule() +{ + if ( myObjects.count() < 2 ) { + return; + } + + HYDROData_CustomRule aNewRule; + aNewRule.Object1 = myObjects.at(0); + aNewRule.Object2 = myObjects.at(1); + aNewRule.Priority = LESS; + aNewRule.MergeType = HYDROData_Zone::Merge_ZMIN; + + myRules << aNewRule; + + reset(); +} + +/** + */ +bool HYDROGUI_PriorityTableModel::removeRows ( int theRow, int theCount, const QModelIndex & theParent ) +{ + bool aRes = false; + + if ( theRow + theCount <= myRules.count() ) { + for ( int i = 1; i <= theCount; i++ ) { + myRules.removeAt( theRow ); + } + aRes = true; + reset(); + } + + return true; +} + +/** + Get available objects. + @return the list of object names + */ +QStringList HYDROGUI_PriorityTableModel::getAvailableObjects() const +{ + QStringList aNames; + + foreach ( const Handle(HYDROData_Object) anObj, myObjects ) { + if ( !anObj.IsNull() ) { + aNames << anObj->GetName(); + } + } + + return aNames; +} + +/** + Remove the rows. + @params theRows the list of rows to remove + */ +void HYDROGUI_PriorityTableModel::removeRows ( const QList theRows ) +{ + QList aSortedRows = theRows; + qSort( aSortedRows ); + + int aRowToRemove = -1; + int aNbRemoved = 0; + foreach ( int aRow, aSortedRows ) { + aRowToRemove = aRow - aNbRemoved; + if ( removeRow( aRowToRemove ) ) { + aNbRemoved++; + } + } +} + +/** + Get priority string representation. + @param thePriority the priority + */ +QString HYDROGUI_PriorityTableModel::priorityToString( const int thePriority ) const +{ + switch( thePriority ) + { + case LESS: + return tr( "LESS" ); + case GREATER: + return tr( "GREATER" ); + default: + return QString(); + }; +} + +/** + Get merge type string representation. + @param theMergeType the merge type + */ +QString HYDROGUI_PriorityTableModel::mergeTypeToString( const int theMergeType ) const +{ + switch( theMergeType ) + { + case HYDROData_Zone::Merge_Object: + return tr( "PRIORITY" ); + case HYDROData_Zone::Merge_ZMIN: + return tr( "ZMIN" ); + case HYDROData_Zone::Merge_ZMAX: + return tr( "ZMAX" ); + default: + return QString(); + }; +} diff --git a/src/HYDROGUI/HYDROGUI_PriorityTableModel.h b/src/HYDROGUI/HYDROGUI_PriorityTableModel.h new file mode 100644 index 00000000..bd113ac4 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PriorityTableModel.h @@ -0,0 +1,86 @@ +// 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_PriorityTableModel_H +#define HYDROGUI_PriorityTableModel_H + +#include +#include + +#include +#include + + +class HYDROGUI_Module; + + +/** + * \class HYDROGUI_PriorityTableModel + * \brief The class representing custom table model for the priority rules + */ +class HYDRO_EXPORT HYDROGUI_PriorityTableModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + HYDROGUI_PriorityTableModel( QObject* theParent = 0 ); + virtual ~HYDROGUI_PriorityTableModel(); + + virtual Qt::ItemFlags flags( const QModelIndex & theIndex ) const; + + virtual QVariant data( const QModelIndex &theIndex, int theRole = Qt::DisplayRole ) const; + virtual bool setData( const QModelIndex & theIndex, const QVariant & theValue, int theRole = Qt::EditRole ); + + virtual int rowCount( const QModelIndex &theParent = QModelIndex() ) const; + virtual int columnCount( const QModelIndex &theParent = QModelIndex() ) const; + + virtual QVariant headerData( int theSection, + Qt::Orientation theOrientation, + int theRole = Qt::DisplayRole ) const; + + virtual bool removeRows ( int theRow, int theCount, const QModelIndex & theParent = QModelIndex() ); + + void removeRows ( const QList theRows ); + + void setRules( const HYDROData_ListOfRules& theObjects ); + HYDROData_ListOfRules getRules() const; + + void setObjects( const QList& theObjects ); + + void createNewRule(); + +protected: + QStringList getAvailableObjects() const; + + QString priorityToString( const int thePriority ) const; + QString mergeTypeToString( const int theMergeType ) const; + +private: + friend class test_HYDROGUI_PriorityTableModel; + + HYDROGUI_Module* myModule; + + HYDROData_ListOfRules myRules; + QList myObjects; +}; + +#endif \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx index 7200311e..719503bb 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx +++ b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx @@ -22,15 +22,109 @@ #include "HYDROGUI_PriorityWidget.h" +#include "HYDROGUI_PriorityTableModel.h" + +#include "HYDROData_PriorityQueue.h" + +#include #include +#include #include -#include +#include + + +/** + Custom item delegate (combobox) + */ +class HYDROGUI_PriorityWidget::Delegate : public QStyledItemDelegate +{ +public: + Delegate( QObject* theParent = 0 ); + + QWidget* createEditor( QWidget*, const QStyleOptionViewItem&, + const QModelIndex& ) const; + + void setEditorData( QWidget*, const QModelIndex& ) const; + void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const; +}; + +/** + Constructor. + @param theParent the parent object + */ +HYDROGUI_PriorityWidget::Delegate::Delegate( QObject* theParent ) + : QStyledItemDelegate( theParent ) +{ +} + +/** + */ +QWidget* HYDROGUI_PriorityWidget::Delegate::createEditor( + QWidget* theParent, const QStyleOptionViewItem& theOption, + const QModelIndex& theIndex ) const +{ + QComboBox* aComboBox = new QComboBox( theParent ); + + if ( theIndex.column() == 1 || theIndex.column() == 3 ) { + QMap aMap = theIndex.data( Qt::UserRole ).toMap(); + foreach ( QString aText, aMap.keys() ) { + aComboBox->addItem( aText, aMap.value( aText ).toInt() ); + } + } else if ( theIndex.column() == 0 || theIndex.column() == 2 ) { + QStringList anItems = theIndex.data( Qt::UserRole ).toStringList(); + QStringList anObjNames = theIndex.data( Qt::UserRole ).toStringList(); + aComboBox->addItems( anObjNames ); + } + + return aComboBox; +} + +/** + */ +void HYDROGUI_PriorityWidget::Delegate::setEditorData( + QWidget* theEditor, const QModelIndex& theIndex ) const +{ + QComboBox* aComboBox = dynamic_cast( theEditor ); + + if ( aComboBox ) { + int anIndex = -1; + + if ( theIndex.column() == 0 || theIndex.column() == 2 ) { + QString aText = theIndex.data( Qt::EditRole ).toString(); + anIndex = aComboBox->findText( aText ); + } else { + QVariant aData = theIndex.data( Qt::EditRole ).toInt(); + anIndex = aComboBox->findData( aData ); + } + + if ( anIndex >= 0 ) { + aComboBox->setCurrentIndex( anIndex ); + } + } +} + +/** + */ +void HYDROGUI_PriorityWidget::Delegate::setModelData( + QWidget* theEditor, QAbstractItemModel* theModel, const QModelIndex& theIndex) const +{ + QComboBox* aComboBox = dynamic_cast( theEditor ); + + if ( aComboBox ) { + int aColumn = theIndex.column(); + if ( aColumn == 0 || aColumn == 2 ) { + theModel->setData( theIndex, aComboBox->currentText() ); + } else { + theModel->setData( theIndex, aComboBox->itemData( aComboBox->currentIndex() ) ); + } + } +} /** Constructor. @param theParent the parent widget -*/ + */ HYDROGUI_PriorityWidget::HYDROGUI_PriorityWidget( QWidget* theParent ) : QWidget( theParent ) { @@ -40,11 +134,19 @@ HYDROGUI_PriorityWidget::HYDROGUI_PriorityWidget( QWidget* theParent ) aMainLayout->setSpacing( 5 ); // Buttons - myAdd = new QPushButton( tr( "ADD" ) ); - myRemove = new QPushButton( tr( "REMOVE" ) ); + myAdd = new QToolButton; + myAdd->setText( tr( "ADD" ) ); + myRemove = new QToolButton; + myRemove->setText( tr( "REMOVE" ) ); + myRemove->setEnabled( false ); // Table view myTable = new QTableView( this ); + myTable->setItemDelegate( new Delegate( this ) ); + myTable->setEditTriggers( QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked ); + + // Set the custom model + myTable->setModel( new HYDROGUI_PriorityTableModel() ); // Layout // buttons @@ -58,27 +160,102 @@ HYDROGUI_PriorityWidget::HYDROGUI_PriorityWidget( QWidget* theParent ) aMainLayout->addWidget( myTable ); // Connections - connect( myAdd, SIGNAL( clicked() ), this, SLOT( onAdd() ) ); - connect( myRemove, SIGNAL( clicked() ), this, SLOT( onRemove() ) ); + connect( myAdd, SIGNAL( clicked() ), this, SLOT( onAddRule() ) ); + connect( myRemove, SIGNAL( clicked() ), this, SLOT( onRemoveRule() ) ); + connect ( myTable->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), + this, SLOT( onSelectionChanged() ) ); } /** Destructor. -*/ + */ HYDROGUI_PriorityWidget::~HYDROGUI_PriorityWidget() { } /** Adds the new rule. -*/ + */ void HYDROGUI_PriorityWidget::onAddRule() { + HYDROGUI_PriorityTableModel* aModel = + dynamic_cast( myTable->model() ); + if( aModel ) { + aModel->createNewRule(); + } + myTable->resizeColumnsToContents(); + onSelectionChanged(); } /** Removes the selected rule. -*/ + */ void HYDROGUI_PriorityWidget::onRemoveRule() { + HYDROGUI_PriorityTableModel* aModel = + dynamic_cast( myTable->model() ); + + if (aModel) { + QList aRows; + + QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedRows(); + foreach ( const QModelIndex& anIndex, aSelectedIndexes ) { + aRows << anIndex.row(); + } + aModel->removeRows( aRows ); + } + myTable->resizeColumnsToContents(); + onSelectionChanged(); +} + +/** + Set objects. + */ +void HYDROGUI_PriorityWidget::setObjects( const QList& theObjects ) +{ + HYDROGUI_PriorityTableModel* aModel = + dynamic_cast( myTable->model() ); + if( aModel ) { + aModel->setObjects( theObjects ); + } +} + +/** + Get rules. + @return the list of rules + */ +HYDROData_ListOfRules HYDROGUI_PriorityWidget::getRules() const +{ + HYDROData_ListOfRules aRules; + + HYDROGUI_PriorityTableModel* aModel = + dynamic_cast( myTable->model() ); + if( aModel ) { + aRules = aModel->getRules(); + } + + return aRules; +} + +/** + Set rules. + @param theRules the list of rules +*/ +void HYDROGUI_PriorityWidget::setRules( const HYDROData_ListOfRules& theRules ) const +{ + HYDROGUI_PriorityTableModel* aModel = + dynamic_cast( myTable->model() ); + if( aModel ) { + aModel->setRules( theRules ); + } + myTable->resizeColumnsToContents(); +} + +/** + Slot called on table selection change. +*/ +void HYDROGUI_PriorityWidget::onSelectionChanged() +{ + QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedRows(); + myRemove->setEnabled( aSelectedIndexes.count() > 0 ); } \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_PriorityWidget.h b/src/HYDROGUI/HYDROGUI_PriorityWidget.h index 48d4e737..ff4ea338 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityWidget.h +++ b/src/HYDROGUI/HYDROGUI_PriorityWidget.h @@ -25,10 +25,13 @@ #include +#include +#include + #include class QTableView; -class QPushButton; +class QToolButton; /** * \class HYDROGUI_PriorityWidget @@ -41,20 +44,27 @@ class HYDRO_EXPORT HYDROGUI_PriorityWidget : public QWidget { Q_OBJECT + class Delegate; + public: HYDROGUI_PriorityWidget( QWidget* theParent ); virtual ~HYDROGUI_PriorityWidget(); - void setObjects( const QStringList& theObjects ); + void setObjects( const QList& theObjects ); + + HYDROData_ListOfRules getRules() const; + void setRules( const HYDROData_ListOfRules& theRules ) const; protected slots: void onAddRule(); void onRemoveRule(); + void onSelectionChanged(); + private: QTableView* myTable; ///< the table view - QPushButton* myAdd; ///< the add rule button - QPushButton* myRemove; ///< the remove rule button + QToolButton* myAdd; ///< the add rule button + QToolButton* myRemove; ///< the remove rule button }; #endif diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index fd6a96a4..48a3a1fb 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2172,5 +2172,41 @@ Polyline should consist from one not closed curve. Remove + + + HYDROGUI_PriorityTableModel + + LESS + < + + + GREATER + > + + + PRIORITY + Priority + + + ZMIN + Zmin + + + ZMAX + Zmax + + + OBJECT1 + Object 1 + + + OBJECT2 + Object 2 + + + BATHYMETRY + Bathymetry + +