From 31b607fc1f70b4df94353a7a72c050fc3282a373 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 26 Feb 2008 11:28:15 +0000 Subject: [PATCH] New search functionality from QtxSearcher. --- src/ObjBrowser/OB_Browser.cxx | 90 ++++++++++++++++++---------- src/ObjBrowser/OB_Browser.h | 19 +++--- src/ObjBrowser/OB_FindDlg.cxx | 110 ---------------------------------- src/ObjBrowser/OB_FindDlg.h | 31 ---------- src/ObjBrowser/ObjBrowser.pro | 4 +- 5 files changed, 70 insertions(+), 184 deletions(-) delete mode 100644 src/ObjBrowser/OB_FindDlg.cxx delete mode 100644 src/ObjBrowser/OB_FindDlg.h diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index 68be1af1c..af5b48288 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -21,13 +21,13 @@ // #include "OB_Browser.h" -#include "OB_FindDlg.h" //#include "OB_Filter.h" //#include "OB_ListItem.h" //#include "OB_ListView.h" #include +#include //#include #include @@ -138,13 +138,16 @@ OB_Browser::OB_Browser( QWidget* parent, QAbstractItemModel* model ) myView->setSelectionMode( QAbstractItemView::ExtendedSelection ); myView->setAllColumnsShowFocus( true ); - myFindDlg = new OB_FindDlg( this ); - myFindDlg->hide(); + mySearchTool = new QtxSearchTool( this, myView ); + mySearchTool->setFrameStyle( QFrame::NoFrame | QFrame::Plain ); + mySearchTool->setActivators( QtxSearchTool::StandardKey | QtxSearchTool::SlashKey ); + mySearchTool->setSearcher( new QtxTreeViewSearcher( myView ) ); QVBoxLayout* main = new QVBoxLayout( this ); main->addWidget( myView ); - main->addWidget( myFindDlg ); + main->addWidget( mySearchTool ); main->setMargin( 0 ); + main->setSpacing( 3 ); // TODO: decide what to do with tooltip //myShowToolTips = true; @@ -158,8 +161,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* ) ) ); } @@ -172,15 +175,6 @@ OB_Browser::~OB_Browser() //setUpdater( 0 ); } -/*! - \brief Get popup menu client type. - \return popup client type -*/ -QString OB_Browser::popupClientType() const -{ - return "ObjectBrowser"; -} - /*! \brief Get data model. \return data model @@ -265,6 +259,41 @@ void OB_Browser::setSortMenuEnabled( const bool enabled ) myView->setSortMenuEnabled( enabled ); } +/*! + \brief Get search tool widget. + \return search tool widget + \sa isSearchToolEnabled(), setSearchToolEnabled() +*/ +QtxSearchTool* OB_Browser::searchTool() const +{ + return mySearchTool; +} + +/*! + \brief Check if search tool is enabled. + \return \c true if search tool is enabled + \sa setSearchToolEnabled(), searchTool() +*/ +bool OB_Browser::isSearchToolEnabled() const +{ + return mySearchTool->isEnabled(); +} + +/*! + \brief Enable/disable search tool. + \param enable pass \c true to enable search tool + \sa isSearchToolEnabled(), searchTool() +*/ +void OB_Browser::setSearchToolEnabled( const bool enable ) +{ + if ( mySearchTool->isEnabled() == enable ) + return; + + mySearchTool->setEnabled( enable ); + if ( !mySearchTool->isEnabled() ) + mySearchTool->hide(); +} + /*! \brief Get number of levels which should be automatically expanded when updating the data tree. @@ -771,7 +800,15 @@ QtxTreeView* OB_Browser::treeView() const */ void OB_Browser::contextMenuEvent( QContextMenuEvent* e ) { - contextMenuRequest( e ); + QMenu* popup = new QMenu(); + + createPopupMenu( popup ); + + Qtx::simplifySeparators( popup ); + + if ( !popup->actions().isEmpty() ) + popup->exec( e->globalPos() ); + delete popup; } /*! @@ -821,16 +858,6 @@ 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 */ @@ -928,7 +955,7 @@ void OB_Browser::updateText( QListViewItem* item ) \brief Add custom actions to the popup menu. \param menu popup menu */ -void OB_Browser::contextMenuPopup( QMenu* menu ) +void OB_Browser::createPopupMenu( QMenu* menu ) { menu->addSeparator(); @@ -951,10 +978,11 @@ 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(); + if ( isSearchToolEnabled() ) { + menu->addSeparator(); + menu->addAction( tr( "MEN_FIND" ), searchTool(), SLOT( find() ) ); + menu->addSeparator(); + } } /*! diff --git a/src/ObjBrowser/OB_Browser.h b/src/ObjBrowser/OB_Browser.h index 9c0ffa2bb..1979c8100 100755 --- a/src/ObjBrowser/OB_Browser.h +++ b/src/ObjBrowser/OB_Browser.h @@ -25,8 +25,6 @@ #include "OB.h" -#include - #include #include #include @@ -39,10 +37,11 @@ class QAbstractItemModel; class QAbstractItemDelegate; class QToolTip; +class QMenu; class QtxTreeView; -class OB_FindDlg; +class QtxSearchTool; -class OB_EXPORT OB_Browser : public QWidget, public SUIT_PopupClient +class OB_EXPORT OB_Browser : public QWidget { Q_OBJECT @@ -53,8 +52,6 @@ public: OB_Browser( QWidget* = 0, QAbstractItemModel* = 0 ); virtual ~OB_Browser(); - virtual QString popupClientType() const; - QAbstractItemModel* model() const; void setModel( QAbstractItemModel* ); @@ -67,6 +64,10 @@ public: bool sortMenuEnabled() const; void setSortMenuEnabled( const bool ); + QtxSearchTool* searchTool() const; + bool isSearchToolEnabled() const; + void setSearchToolEnabled( const bool ); + int autoOpenLevel() const; void setAutoOpenLevel( const int ); void openLevels( const int = -1 ); @@ -97,8 +98,6 @@ public: // TODO: QTreeView::resizeColumnToContents() can be used instead //virtual void setWidthMode( QListView::WidthMode ); - virtual void contextMenuPopup( QMenu* ); - unsigned long getModifiedTime() const; void setModified(); @@ -116,7 +115,6 @@ signals: private slots: void onExpandAll(); void onCollapseAll(); - void onFind(); //void onDestroyed( SUIT_DataObject* ); //void onDoubleClicked ( QListViewItem* ); //void onDropped( QPtrList, QListViewItem*, int ); @@ -126,6 +124,7 @@ protected: //virtual void updateText(); virtual void contextMenuEvent( QContextMenuEvent* ); + virtual void createPopupMenu( QMenu* ); private: //typedef QMap ItemMap; @@ -161,7 +160,7 @@ private: private: QtxTreeView* myView; - OB_FindDlg* myFindDlg; + QtxSearchTool* mySearchTool; // 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 deleted file mode 100644 index 83f23e7d7..000000000 --- a/src/ObjBrowser/OB_FindDlg.cxx +++ /dev/null @@ -1,110 +0,0 @@ - -#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 deleted file mode 100644 index adb00bc93..000000000 --- a/src/ObjBrowser/OB_FindDlg.h +++ /dev/null @@ -1,31 +0,0 @@ - -#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/ObjBrowser.pro b/src/ObjBrowser/ObjBrowser.pro index cf69ff847..7b95f3b9d 100644 --- a/src/ObjBrowser/ObjBrowser.pro +++ b/src/ObjBrowser/ObjBrowser.pro @@ -4,8 +4,8 @@ DESTDIR = ../../$(CONFIG_ID)/lib MOC_DIR = ../../moc OBJECTS_DIR = ../../$(CONFIG_ID)/obj/$$TARGET -INCLUDEPATH += ../../include ../Qtx ../SUIT -LIBS += -L../../$(CONFIG_ID)/lib -lQtx -lSUIT +INCLUDEPATH += ../../include ../Qtx +LIBS += -L../../$(CONFIG_ID)/lib -lQtx CONFIG -= debug release debug_and_release CONFIG += qt thread debug dll shared -- 2.39.2