From 60eb84958f5d61227f79a9bc5d47867b5d4e2c68 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 21 Nov 2007 13:09:38 +0000 Subject: [PATCH] Gets modification of ASL: "functionality for search of object in the object browser by it's name" from 2007/11/19 --- src/ObjBrowser/OB_Browser.cxx | 22 +++++- 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 ++++++ 5 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 src/ObjBrowser/OB_FindDlg.cxx create mode 100644 src/ObjBrowser/OB_FindDlg.h diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index 7a0226919..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 @@ -153,8 +158,8 @@ OB_Browser::OB_Browser( QWidget* parent, QAbstractItemModel* model ) connect( myView, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); - //connect( myView, SIGNAL( doubleClicked( QListViewItem* ) ), - // this, SLOT( onDoubleClicked( QListViewItem* ) ) ); + connect( myView, SIGNAL( doubleClicked( QListViewItem* ) ), + this, SLOT( onDoubleClicked( QListViewItem* ) ) ); } @@ -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