Cherrypick from master 2008-03-07 07:44:13 UTC jfa <jfa@opencascade.com> 'Join modifications from BR_Dev_For_4_0 tag V4_1_1.':
src/ObjBrowser/OB_FindDlg.cxx
src/ObjBrowser/OB_FindDlg.h
src/ObjBrowser/OB_ObjSearch.cxx
src/ObjBrowser/OB_ObjSearch.h
--- /dev/null
+
+#include <OB_FindDlg.h>
+#include <OB_ObjSearch.h>
+#include <OB_Browser.h>
+#include <OB_ListItem.h>
+
+#include <SUIT_DataObject.h>
+#include <SUIT_MessageBox.h>
+
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qcheckbox.h>
+
+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;
+}
--- /dev/null
+
+#ifndef OBJECT_BROWSER_FIND_DIALOG_HEADER
+#define OBJECT_BROWSER_FIND_DIALOG_HEADER
+
+#include <qgroupbox.h>
+
+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
--- /dev/null
+
+#include <OB_ObjSearch.h>
+#include <OB_ListItem.h>
+#include <OB_Browser.h>
+
+#include <qregexp.h>
+
+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<OB_ListItem*>( 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<OB_ListItem*>( *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<OB_ListItem*>( myBrowser->listView()->currentItem() );
+}
--- /dev/null
+
+#ifndef OBJECT_BROWSER_OBJECT_SEARCH_HEADER
+#define OBJECT_BROWSER_OBJECT_SEARCH_HEADER
+
+#include <qstring.h>
+
+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