From 8330b491692959961a82bfc2fe0b45f375f84be3 Mon Sep 17 00:00:00 2001 From: asl Date: Mon, 19 Nov 2007 07:47:28 +0000 Subject: [PATCH] functionality for search of object in the object browser by it's name --- src/ObjBrowser/Makefile.am | 9 ++- src/ObjBrowser/OB_Browser.cxx | 18 +++++ src/ObjBrowser/OB_Browser.h | 6 +- src/ObjBrowser/OB_FindDlg.cxx | 110 ++++++++++++++++++++++++++ src/ObjBrowser/OB_FindDlg.h | 31 ++++++++ src/ObjBrowser/resources/OB_msg_en.ts | 23 ++++++ 6 files changed, 193 insertions(+), 4 deletions(-) create mode 100644 src/ObjBrowser/OB_FindDlg.cxx create mode 100644 src/ObjBrowser/OB_FindDlg.h diff --git a/src/ObjBrowser/Makefile.am b/src/ObjBrowser/Makefile.am index 42d007ffa..4672b0132 100755 --- a/src/ObjBrowser/Makefile.am +++ b/src/ObjBrowser/Makefile.am @@ -27,14 +27,16 @@ lib_LTLIBRARIES = libObjBrowser.la salomeinclude_HEADERS= \ OB.h \ - OB_Browser.h + OB_Browser.h \ + OB_FindDlg.h # OB_ListItem.h \ OB_ListView.h OB_Filter.h dist_libObjBrowser_la_SOURCES= \ - OB_Browser.cxx + OB_Browser.cxx \ + OB_FindDlg.cxx # OB_ListView.cxx OB_ListItem.cxx \ @@ -42,7 +44,8 @@ dist_libObjBrowser_la_SOURCES= \ OB_Filter.cxx MOC_FILES= \ - OB_Browser_moc.cxx + OB_Browser_moc.cxx \ + OB_FindDlg_moc.cxx # OB_ListView_moc.cxx diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index ea3c955f2..4e20fb928 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -21,6 +21,7 @@ // #include "OB_Browser.h" +#include "OB_FindDlg.h" //#include "OB_Filter.h" //#include "OB_ListItem.h" @@ -137,8 +138,12 @@ OB_Browser::OB_Browser( QWidget* parent, QAbstractItemModel* model ) myView->setSelectionMode( QAbstractItemView::ExtendedSelection ); myView->setAllColumnsShowFocus( true ); + myFindDlg = new OB_FindDlg( this ); + myFindDlg->hide(); + QVBoxLayout* main = new QVBoxLayout( this ); main->addWidget( myView ); + main->addWidget( myFindDlg ); main->setMargin( 0 ); // TODO: decide what to do with tooltip @@ -816,6 +821,16 @@ void OB_Browser::onCollapseAll() } } +/*! + \brief Called when "Find" popup menu command is activated. + + Activates the find properties frame +*/ +void OB_Browser::onFind() +{ + myFindDlg->show(); +} + /*! SLOT: called if SUIT object is destroyed */ @@ -936,6 +951,9 @@ void OB_Browser::contextMenuPopup( QMenu* menu ) if ( opened ) menu->addAction( tr( "MEN_COLLAPSE_ALL" ), this, SLOT( onCollapseAll() ) ); + menu->addSeparator(); + menu->addAction( tr( "MEN_FIND" ), this, SLOT( onFind() ) ); + menu->addSeparator(); } diff --git a/src/ObjBrowser/OB_Browser.h b/src/ObjBrowser/OB_Browser.h index df6836b69..9c0ffa2bb 100755 --- a/src/ObjBrowser/OB_Browser.h +++ b/src/ObjBrowser/OB_Browser.h @@ -40,6 +40,7 @@ class QAbstractItemModel; class QAbstractItemDelegate; class QToolTip; class QtxTreeView; +class OB_FindDlg; class OB_EXPORT OB_Browser : public QWidget, public SUIT_PopupClient { @@ -105,6 +106,8 @@ public: //OB_Updater* getUpdater() const; //virtual void setUpdater( OB_Updater* theUpdate = 0 ); + QtxTreeView* treeView() const; + signals: void selectionChanged(); //void doubleClicked( SUIT_DataObject* ); @@ -113,6 +116,7 @@ signals: private slots: void onExpandAll(); void onCollapseAll(); + void onFind(); //void onDestroyed( SUIT_DataObject* ); //void onDoubleClicked ( QListViewItem* ); //void onDropped( QPtrList, QListViewItem*, int ); @@ -120,7 +124,6 @@ private slots: protected: //void adjustWidth( QListViewItem* ); //virtual void updateText(); - QtxTreeView* treeView() const; virtual void contextMenuEvent( QContextMenuEvent* ); @@ -158,6 +161,7 @@ private: private: QtxTreeView* myView; + OB_FindDlg* myFindDlg; // TODO: decide what to do with tooltip //QToolTip* myTooltip; //QMap myColumnIds; diff --git a/src/ObjBrowser/OB_FindDlg.cxx b/src/ObjBrowser/OB_FindDlg.cxx new file mode 100644 index 000000000..83f23e7d7 --- /dev/null +++ b/src/ObjBrowser/OB_FindDlg.cxx @@ -0,0 +1,110 @@ + +#include +#include + +#include + +#include +#include +#include +#include + +OB_FindDlg::OB_FindDlg( OB_Browser* b ) +: QGroupBox( tr( "FIND" ), b ), + myBrowser( b ) +{ + QVBoxLayout *vbox = new QVBoxLayout(); + + QFrame *btns = new QFrame( this ), *checks = new QFrame( this ); + vbox->addWidget( btns ); + vbox->addWidget( checks ); + setLayout( vbox ); + + 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 ); + 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 ); + c->addWidget( myIsCaseSens, 0 ); + //c->addWidget( myIsRegExp, 0 ); + myIsRegExp->hide();//temporary hidden + + 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() +{ + const QModelIndexList& l = myBrowser->selectedIndexes(); + QModelIndex current; + if( l.count()>0 ) + current = l.first(); + + Qt::MatchFlags fl = Qt::MatchContains | Qt::MatchRecursive; + if( myIsCaseSens->isChecked() ) + fl = fl | Qt::MatchCaseSensitive; + if( myIsRegExp->isChecked() ) + fl = fl | Qt::MatchRegExp; + + QModelIndexList found = myBrowser->model()->match( myBrowser->model()->index( 0, 0 ), + 0, myData->text(), -1, fl ); + QModelIndex f; + if( found.count()>0 ) + if( sender()==myToFirst ) + f = found.first(); + else if( sender()==myToLast ) + f = found.last(); + else + { + int ind = found.indexOf( current ); + if( ind<0 ) + ind = 0; + if( sender()==myNext ) + { + ind++; + if( ind>=found.count() ) + ind = 0; + f = found[ ind ]; + } + else if( sender()==myPrev ) + { + ind--; + if( ind<0 ) + ind = found.count()-1; + f = found[ ind ]; + } + } + myBrowser->select( f, true, false ); + myBrowser->treeView()->scrollTo( f ); +} diff --git a/src/ObjBrowser/OB_FindDlg.h b/src/ObjBrowser/OB_FindDlg.h new file mode 100644 index 000000000..adb00bc93 --- /dev/null +++ b/src/ObjBrowser/OB_FindDlg.h @@ -0,0 +1,31 @@ + +#ifndef OBJECT_BROWSER_FIND_DIALOG_HEADER +#define OBJECT_BROWSER_FIND_DIALOG_HEADER + +#include + +class OB_Browser; +class QLineEdit; +class QPushButton; +class QCheckBox; + +class OB_FindDlg : public QGroupBox +{ + Q_OBJECT + +public: + OB_FindDlg( OB_Browser* ); + virtual ~OB_FindDlg(); + +private slots: + void onFind(); + void onClose(); + +private: + QLineEdit* myData; + QPushButton *myToFirst, *myToLast, *myNext, *myPrev, *myClose; + QCheckBox *myIsCaseSens, *myIsRegExp; + OB_Browser* myBrowser; +}; + +#endif diff --git a/src/ObjBrowser/resources/OB_msg_en.ts b/src/ObjBrowser/resources/OB_msg_en.ts index aede9db21..9c620222c 100644 --- a/src/ObjBrowser/resources/OB_msg_en.ts +++ b/src/ObjBrowser/resources/OB_msg_en.ts @@ -9,5 +9,28 @@ MEN_COLLAPSE_ALL Collapse All + + MEN_FIND + Find + + + + OB_FindDlg + + FIND + Find + + + CLOSE + Close + + + CASE_SENSITIVE + Case sensitive + + + IS_REG_EXP + Regular expression + -- 2.39.2