From: asl Date: Wed, 19 Mar 2014 08:31:45 +0000 (+0000) Subject: filter model has been implemented X-Git-Tag: BR_hydro_v1_0_1~50 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ef586a647f2e64f1d82de79ef926b27afb74183f;p=modules%2Fhydro.git filter model has been implemented --- diff --git a/src/ZLEVEL/HYDROGUI_ZLevelsDlg.cxx b/src/ZLEVEL/HYDROGUI_ZLevelsDlg.cxx index 238badf2..267a1869 100644 --- a/src/ZLEVEL/HYDROGUI_ZLevelsDlg.cxx +++ b/src/ZLEVEL/HYDROGUI_ZLevelsDlg.cxx @@ -27,6 +27,7 @@ #include #include #include +#include HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent ) @@ -38,7 +39,14 @@ HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent ) QHBoxLayout* aListLayout = new QHBoxLayout(); myList = new QListView( this ); - myList->setModel( new HYDROGUI_ZLevelsModel ); + + HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel(); + QSortFilterProxyModel* aFilteredModel = new QSortFilterProxyModel(); + aFilteredModel->setSourceModel( aModel ); + aFilteredModel->setFilterKeyColumn( 0 ); + aFilteredModel->setFilterRole( HYDROGUI_VisibleRole ); + + myList->setModel( aFilteredModel ); myTop = new QPushButton( tr("TOP") ); myUp = new QPushButton( tr("UP") ); @@ -64,6 +72,10 @@ HYDROGUI_ZLevelsDlg::HYDROGUI_ZLevelsDlg( QWidget* theParent ) aDlgButtonsLayout->addWidget( myClose ); aDlgButtonsLayout->addStretch(); aMainLayout->addLayout( aDlgButtonsLayout ); + + connect( myAllObjects, SIGNAL( stateChanged( int ) ), this, SLOT( OnStateChanged() ) ); + + OnStateChanged(); } HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg() @@ -72,6 +84,19 @@ HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg() void HYDROGUI_ZLevelsDlg::setObjects( const QList& theObjects ) { - HYDROGUI_ZLevelsModel* aModel = dynamic_cast( myList->model() ); - aModel->setObjects( theObjects ); -} \ No newline at end of file + QSortFilterProxyModel* aFilterModel = dynamic_cast( myList->model() ); + if( aFilterModel ) + { + HYDROGUI_ZLevelsModel* aModel = dynamic_cast( aFilterModel->sourceModel() ); + if( aModel ) + aModel->setObjects( theObjects ); + } +} + +void HYDROGUI_ZLevelsDlg::OnStateChanged() +{ + QSortFilterProxyModel* aFilterModel = dynamic_cast( myList->model() ); + bool isAll = myAllObjects->isChecked(); + QString anExpr = isAll ? "true|false" : "true"; + aFilterModel->setFilterRegExp( anExpr ); +} diff --git a/src/ZLEVEL/HYDROGUI_ZLevelsDlg.h b/src/ZLEVEL/HYDROGUI_ZLevelsDlg.h index 140e772e..44e3343d 100644 --- a/src/ZLEVEL/HYDROGUI_ZLevelsDlg.h +++ b/src/ZLEVEL/HYDROGUI_ZLevelsDlg.h @@ -43,6 +43,9 @@ public: void setObjects( const QList& theObjects ); +private slots: + void OnStateChanged(); + private: QListView* myList; QPushButton* myTop; diff --git a/src/ZLEVEL/HYDROGUI_ZLevelsModel.cxx b/src/ZLEVEL/HYDROGUI_ZLevelsModel.cxx index 57ce54e7..9702bf77 100644 --- a/src/ZLEVEL/HYDROGUI_ZLevelsModel.cxx +++ b/src/ZLEVEL/HYDROGUI_ZLevelsModel.cxx @@ -64,6 +64,11 @@ QVariant HYDROGUI_ZLevelsModel::data( const QModelIndex &theIndex, int theRole ) return QVariant(); } break; + case HYDROGUI_VisibleRole: + { + bool isVisible = IsObjectVisible( aRow ); + return QVariant( isVisible ).toString(); + } } return aVariant; @@ -77,6 +82,7 @@ int HYDROGUI_ZLevelsModel::rowCount( const QModelIndex &theParent ) const void HYDROGUI_ZLevelsModel::setObjects( const QList& theObjects ) { myObjects = theObjects; + reset(); } bool HYDROGUI_ZLevelsModel::IsObjectVisible( int theIndex ) const diff --git a/src/ZLEVEL/HYDROGUI_ZLevelsModel.h b/src/ZLEVEL/HYDROGUI_ZLevelsModel.h index 5ae5675e..bdacefc7 100644 --- a/src/ZLEVEL/HYDROGUI_ZLevelsModel.h +++ b/src/ZLEVEL/HYDROGUI_ZLevelsModel.h @@ -26,6 +26,8 @@ #include #include +const int HYDROGUI_VisibleRole = Qt::UserRole + 1; + /** * \class HYDROGUI_ZLevelsModel * \brief The class representing custom list model for the Z levels @@ -36,7 +38,7 @@ class HYDROGUI_ZLevelsModel : public QAbstractListModel public: HYDROGUI_ZLevelsModel( QObject* theParent = 0 ); - ~HYDROGUI_ZLevelsModel(); + virtual ~HYDROGUI_ZLevelsModel(); virtual QVariant data( const QModelIndex &theIndex, int theRole = Qt::DisplayRole ) const;