From 6e5824d0dab9d135b207c3771140c411ba0777ab Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 7 Mar 2008 07:44:17 +0000 Subject: [PATCH] This commit was generated by cvs2git to create branch 'For_CTH_V12'. Cherrypick from master 2008-03-07 07:44:13 UTC jfa '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 --- src/ObjBrowser/OB_FindDlg.cxx | 92 +++++++++++++++++++++++++++ src/ObjBrowser/OB_FindDlg.h | 34 ++++++++++ src/ObjBrowser/OB_ObjSearch.cxx | 107 ++++++++++++++++++++++++++++++++ src/ObjBrowser/OB_ObjSearch.h | 39 ++++++++++++ 4 files changed, 272 insertions(+) create mode 100644 src/ObjBrowser/OB_FindDlg.cxx create mode 100644 src/ObjBrowser/OB_FindDlg.h create mode 100644 src/ObjBrowser/OB_ObjSearch.cxx create mode 100644 src/ObjBrowser/OB_ObjSearch.h 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 -- 2.39.2