From: asl Date: Mon, 19 Nov 2007 07:49:35 +0000 (+0000) Subject: functionality for search of object in the object browser by it's name X-Git-Tag: V4_1_0rc2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e47fcecc8a37c5d8d9fd82ec2cfca4dc0e823f78;p=modules%2Fgui.git functionality for search of object in the object browser by it's name --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index ccebcbede..c60c1b53e 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -64,6 +64,7 @@ #include #include #include +#include #ifndef DISABLE_GLVIEWER #include @@ -1668,6 +1669,7 @@ QWidget* LightApp_Application::createWindow( const int flag ) if ( flag == WT_ObjectBrowser ) { OB_Browser* ob = new OB_Browser( desktop() ); + ob->setSearch( new OB_ObjSearch( ob ) ); ob->setAutoUpdate( true ); //ob->setAutoOpenLevel( 1 ); // commented by ASV as a fix to bug IPAL10107 ob->setCaption( tr( "OBJECT_BROWSER" ) ); @@ -2322,6 +2324,7 @@ void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* th thePopup->insertSeparator(); thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) ); + thePopup->insertItem( tr( "MEN_FIND" ), this, SLOT( onFind() ) ); } /*! @@ -2557,3 +2560,8 @@ bool LightApp_Application::checkDataObject(LightApp_DataObject* theObj) return false; } + +void LightApp_Application::onFind() +{ + objectBrowser()->enableSearch( true ); +} diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 9bbecfed7..bdabb3ef8 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -217,6 +217,7 @@ protected slots: private slots: void onSelection(); void onRefresh(); + void onFind(); void onPreferences(); void onMRUActivated( QString ); void onPreferenceChanged( QString&, QString&, QString& ); diff --git a/src/LightApp/resources/LightApp_msg_en.po b/src/LightApp/resources/LightApp_msg_en.po index 1cd5b1e21..6075d309c 100644 --- a/src/LightApp/resources/LightApp_msg_en.po +++ b/src/LightApp/resources/LightApp_msg_en.po @@ -254,6 +254,9 @@ msgstr "Quick directory list" msgid "LightApp_Application::MEN_REFRESH" msgstr "Refresh" +msgid "LightApp_Application::MEN_FIND" +msgstr "Find" + msgid "LightApp_Application::PREF_GROUP_SUPERV" msgstr "Graph Supervisor" diff --git a/src/ObjBrowser/Makefile.am b/src/ObjBrowser/Makefile.am index ff1db50cb..ba4e735b3 100755 --- a/src/ObjBrowser/Makefile.am +++ b/src/ObjBrowser/Makefile.am @@ -30,17 +30,22 @@ salomeinclude_HEADERS=\ OB_Browser.h \ OB_ListItem.h \ OB_ListView.h \ - OB_Filter.h + OB_Filter.h \ + OB_FindDlg.h \ + OB_ObjSearch.h dist_libObjBrowser_la_SOURCES= \ OB_Browser.cxx \ OB_ListItem.cxx \ OB_ListView.cxx \ - OB_Filter.cxx + OB_Filter.cxx \ + OB_FindDlg.cxx \ + OB_ObjSearch.cxx MOC_FILES= \ OB_Browser_moc.cxx \ - OB_ListView_moc.cxx + OB_ListView_moc.cxx \ + OB_FindDlg_moc.cxx nodist_libObjBrowser_la_SOURCES= $(MOC_FILES) nodist_salomeres_DATA = OB_msg_en.qm diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index 647cac4cf..41232b9a2 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -21,6 +21,7 @@ #include "OB_Filter.h" #include "OB_ListItem.h" #include "OB_ListView.h" +#include "OB_FindDlg.h" #include #include @@ -306,8 +307,12 @@ myRootDecorated( true ) myView->installEventFilter( this ); myView->viewport()->installEventFilter( this ); + myFindDlg = new OB_FindDlg( this ); + myFindDlg->hide(); + QVBoxLayout* main = new QVBoxLayout( this ); - main->addWidget( myView ); + main->addWidget( myView, 1 ); + main->addWidget( myFindDlg, 0 ); myShowToolTips = true; myTooltip = new ToolTip( this, myView->viewport() ); @@ -1651,3 +1656,17 @@ void OB_Browser::setModified() myModifiedTime = clock(); } +OB_ObjSearch* OB_Browser::getSearch() const +{ + return myFindDlg->getSearch(); +} + +void OB_Browser::setSearch( OB_ObjSearch* s ) +{ + myFindDlg->setSearch( s ); +} + +void OB_Browser::enableSearch( const bool on ) +{ + myFindDlg->setShown( on ); +} diff --git a/src/ObjBrowser/OB_Browser.h b/src/ObjBrowser/OB_Browser.h index 2edf0239c..e7524fb68 100755 --- a/src/ObjBrowser/OB_Browser.h +++ b/src/ObjBrowser/OB_Browser.h @@ -38,6 +38,8 @@ class QToolTip; class OB_Filter; class OB_ListView; class OB_ListItem; +class OB_ObjSearch; +class OB_FindDlg; class OB_Updater { @@ -139,6 +141,10 @@ public: OB_Updater* getUpdater() const; virtual void setUpdater( OB_Updater* theUpdate = 0 ); + OB_ObjSearch* getSearch() const; + void setSearch( OB_ObjSearch* ); + void enableSearch( const bool ); + signals: void selectionChanged(); void doubleClicked( SUIT_DataObject* ); @@ -207,6 +213,7 @@ private: bool myShowToolTips; bool myRootDecorated; int myAutoOpenLevel; + OB_FindDlg *myFindDlg; friend class OB_Browser::ToolTip; diff --git a/src/ObjBrowser/OB_FindDlg.cxx b/src/ObjBrowser/OB_FindDlg.cxx new file mode 100644 index 000000000..07ed30dd5 --- /dev/null +++ b/src/ObjBrowser/OB_FindDlg.cxx @@ -0,0 +1,92 @@ + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +OB_FindDlg::OB_FindDlg( QWidget* parent ) +: QGroupBox( 1, Qt::Horizontal, tr( "FIND" ), parent ), + mySearch( 0 ) +{ + QFrame *btns = new QFrame( this ), *checks = new QFrame( this ); + + myData = new QLineEdit( btns ); + myToFirst = new QPushButton( "|<<", btns ); + myToLast = new QPushButton( ">>|", btns ); + myNext = new QPushButton( ">>", btns ); + myPrev = new QPushButton( "<<", btns ); + myClose = new QPushButton( tr( "CLOSE" ), checks ); + myIsCaseSens = new QCheckBox( tr( "CASE_SENSITIVE" ), checks ); + myIsRegExp = new QCheckBox( tr( "IS_REG_EXP" ), checks ); + int w = 30, h = myToFirst->height(); + myToFirst->setMaximumSize( w, h ); + myToLast->setMaximumSize( w, h ); + myNext->setMaximumSize( w, h ); + myPrev->setMaximumSize( w, h ); + + QHBoxLayout* l = new QHBoxLayout( btns, 5, 5 ); + l->addWidget( myToFirst, 0 ); + l->addWidget( myPrev, 0 ); + l->addWidget( myData, 1 ); + l->addWidget( myNext, 0 ); + l->addWidget( myToLast, 0 ); + + QHBoxLayout* c = new QHBoxLayout( checks, 5, 5 ); + c->addWidget( myIsCaseSens, 0 ); + c->addWidget( myIsRegExp, 0 ); + c->addWidget( myClose, 0 ); + + connect( myToFirst, SIGNAL( clicked() ), this, SLOT( onFind() ) ); + connect( myToLast, SIGNAL( clicked() ), this, SLOT( onFind() ) ); + connect( myNext, SIGNAL( clicked() ), this, SLOT( onFind() ) ); + connect( myPrev, SIGNAL( clicked() ), this, SLOT( onFind() ) ); + connect( myClose, SIGNAL( clicked() ), this, SLOT( onClose() ) ); +} + +OB_FindDlg::~OB_FindDlg() +{ +} + +void OB_FindDlg::onClose() +{ + hide(); +} + +void OB_FindDlg::onFind() +{ + OB_ListItem* it = 0; + mySearch->setPattern( myData->text(), myIsRegExp->isChecked(), myIsCaseSens->isChecked() ); + if( sender()==myToFirst ) + it = mySearch->findFirst(); + else if( sender()==myNext ) + it = mySearch->findNext(); + else if( sender()==myPrev ) + it = mySearch->findPrev(); + else if( sender()==myToLast ) + it = mySearch->findLast(); + if( it ) + { + mySearch->browser()->setSelected( it->dataObject(), false ); + mySearch->browser()->listView()->ensureItemVisible( it ); + } + else + SUIT_MessageBox::info1( this, tr( "FIND" ), tr( "NOT_FOUND" ), tr( "OK" ) ); +} + +OB_ObjSearch* OB_FindDlg::getSearch() const +{ + return mySearch; +} + +void OB_FindDlg::setSearch( OB_ObjSearch* s ) +{ + mySearch = s; +} diff --git a/src/ObjBrowser/OB_FindDlg.h b/src/ObjBrowser/OB_FindDlg.h new file mode 100644 index 000000000..4c8230d81 --- /dev/null +++ b/src/ObjBrowser/OB_FindDlg.h @@ -0,0 +1,34 @@ + +#ifndef OBJECT_BROWSER_FIND_DIALOG_HEADER +#define OBJECT_BROWSER_FIND_DIALOG_HEADER + +#include + +class OB_ObjSearch; +class QLineEdit; +class QPushButton; +class QCheckBox; + +class OB_FindDlg : public QGroupBox +{ + Q_OBJECT + +public: + OB_FindDlg( QWidget* = 0 ); + virtual ~OB_FindDlg(); + + OB_ObjSearch* getSearch() const; + void setSearch( OB_ObjSearch* ); + +private slots: + void onFind(); + void onClose(); + +private: + QLineEdit* myData; + QPushButton *myToFirst, *myToLast, *myNext, *myPrev, *myClose; + QCheckBox *myIsCaseSens, *myIsRegExp; + OB_ObjSearch* mySearch; +}; + +#endif diff --git a/src/ObjBrowser/OB_ObjSearch.cxx b/src/ObjBrowser/OB_ObjSearch.cxx new file mode 100644 index 000000000..84d9c2c61 --- /dev/null +++ b/src/ObjBrowser/OB_ObjSearch.cxx @@ -0,0 +1,107 @@ + +#include +#include +#include + +#include + +OB_ObjSearch::OB_ObjSearch( OB_Browser* b ) +: myBrowser( b ) +{ +} + +OB_ObjSearch::~OB_ObjSearch() +{ +} + +OB_ListItem* OB_ObjSearch::tail( const bool first ) const +{ + QListView* lv = myBrowser->listView(); + return dynamic_cast( first ? lv->firstChild() : lv->lastItem() ); +} + +OB_ListItem* OB_ObjSearch::next( OB_ListItem* i, const bool forward ) const +{ + QListViewItemIterator it( i ); + if( forward ) + it++; + else + it--; + return dynamic_cast( *it ); +} + +SUIT_DataObject* OB_ObjSearch::data( OB_ListItem* i ) const +{ + return i ? i->dataObject() : 0; +} + +void OB_ObjSearch::setPattern( const QString& data, const bool is_reg_exp, const bool is_case_sens ) +{ + myData = data; + myIsRegExp = is_reg_exp; + myIsCaseSens = is_case_sens; +} + +bool OB_ObjSearch::matches( SUIT_DataObject* obj ) const +{ + if( !obj ) + return false; + + QString txt = obj->name(); + if( myIsRegExp ) + { + QRegExp re( myData ); + re.setCaseSensitive( myIsCaseSens ); + return txt.contains( re ); + } + else + return txt.contains( myData, myIsCaseSens ); +} + +OB_Browser* OB_ObjSearch::browser() const +{ + return myBrowser; +} + +OB_ListItem* OB_ObjSearch::findFirst() const +{ + return find( tail( true ), true, false, false ); +} + +OB_ListItem* OB_ObjSearch::findLast() const +{ + return find( tail( false ), false, false, false ); +} + +OB_ListItem* OB_ObjSearch::findNext() const +{ + return find( current(), true, true, true ); +} + +OB_ListItem* OB_ObjSearch::findPrev() const +{ + return find( current(), false, true, true ); +} + +OB_ListItem* OB_ObjSearch::find( OB_ListItem* i, const bool forward, + const bool ignore_first, const bool cyclic ) const +{ + if( !i ) + i = tail( forward ); + + if( ignore_first ) + i = next( i, forward ); + + while( i && !matches( data( i ) ) ) + i = next( i, forward ); + + if( !i && cyclic ) + return find( tail( forward ), forward, false, false ); + + return i; +} + +OB_ListItem* OB_ObjSearch::current() const +{ + return dynamic_cast( myBrowser->listView()->currentItem() ); +} diff --git a/src/ObjBrowser/OB_ObjSearch.h b/src/ObjBrowser/OB_ObjSearch.h new file mode 100644 index 000000000..6106d9fef --- /dev/null +++ b/src/ObjBrowser/OB_ObjSearch.h @@ -0,0 +1,39 @@ + +#ifndef OBJECT_BROWSER_OBJECT_SEARCH_HEADER +#define OBJECT_BROWSER_OBJECT_SEARCH_HEADER + +#include + +class OB_ListItem; +class OB_Browser; +class SUIT_DataObject; + +class OB_ObjSearch +{ +public: + OB_ObjSearch( OB_Browser* ); + virtual ~OB_ObjSearch(); + + void setPattern( const QString&, const bool, const bool ); + OB_Browser* browser() const; + + OB_ListItem* findFirst() const; + OB_ListItem* findLast() const; + OB_ListItem* findNext() const; + OB_ListItem* findPrev() const; + +protected: + virtual OB_ListItem* current() const; + virtual OB_ListItem* tail( const bool ) const; + virtual OB_ListItem* next( OB_ListItem*, const bool ) const; + virtual SUIT_DataObject* data( OB_ListItem* ) const; + virtual bool matches( SUIT_DataObject* ) const; + OB_ListItem* find( OB_ListItem*, const bool, const bool, const bool ) const; + +private: + OB_Browser* myBrowser; + QString myData; + bool myIsRegExp, myIsCaseSens; +}; + +#endif diff --git a/src/ObjBrowser/resources/OB_msg_en.po b/src/ObjBrowser/resources/OB_msg_en.po index 4b18212e9..2209af5a6 100755 --- a/src/ObjBrowser/resources/OB_msg_en.po +++ b/src/ObjBrowser/resources/OB_msg_en.po @@ -30,3 +30,17 @@ msgstr "" msgid "MEN_EXPAND_ALL" msgstr "Expand All" +msgid "OB_FindDlg::FIND" +msgstr "Find" + +msgid "OB_FindDlg::CLOSE" +msgstr "Close" + +msgid "OB_FindDlg::CASE_SENSITIVE" +msgstr "Case sensitive" + +msgid "OB_FindDlg::IS_REG_EXP" +msgstr "Regular expression" + +msgid "OB_FindDlg::NOT_FOUND" +msgstr "There is no object is found"