From 8bcb56ab7c4363221fcce7209b2a339f31422198 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 17 Apr 2008 06:32:22 +0000 Subject: [PATCH] Improve tree view searcher tool: enable re-definition of match flags in a subclasses --- src/Qtx/QtxSearchTool.cxx | 68 +++++++++++++++++++++++++++++++++------ src/Qtx/QtxSearchTool.h | 7 ++++ 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/src/Qtx/QtxSearchTool.cxx b/src/Qtx/QtxSearchTool.cxx index fc34dc985..1f0601619 100644 --- a/src/Qtx/QtxSearchTool.cxx +++ b/src/Qtx/QtxSearchTool.cxx @@ -584,6 +584,7 @@ void QtxSearchTool::enableAutoHide( bool enable ) \return \c true if case sensitive search is performed \sa isRegExpSearch(), isSearchWrapped(), setControls() + \sa setCaseSensitive(), setRegExpSearch(), setSearchWrapped() */ bool QtxSearchTool::isCaseSensitive() const { @@ -598,6 +599,7 @@ bool QtxSearchTool::isCaseSensitive() const \return \c true if regular expression search is performed \sa isCaseSensitive(), isSearchWrapped(), setControls() + \sa setCaseSensitive(), setRegExpSearch(), setSearchWrapped() */ bool QtxSearchTool::isRegExpSearch() const { @@ -612,12 +614,49 @@ bool QtxSearchTool::isRegExpSearch() const \return \c true if search wrapping is enabled \sa isCaseSensitive(), isRegExpSearch(), setControls() + \sa setCaseSensitive(), setRegExpSearch(), setSearchWrapped() */ bool QtxSearchTool::isSearchWrapped() const { return myControls & Wrap && myWrap->isChecked(); } +/*! + \brief Set 'case sensitive search' option value. + \param on new option state + \sa setRegExpSearch(), setSearchWrapped(), setControls() + \sa isCaseSensitive(), isRegExpSearch(), isSearchWrapped() +*/ +void QtxSearchTool::setCaseSensitive( bool on ) +{ + if ( myControls & Case ) + myIsCaseSens->setChecked( on ); +} + +/*! + \brief Set 'regular expression search' option value. + \param on new option state + \sa setCaseSensitive(), setSearchWrapped(), setControls() + \sa isCaseSensitive(), isRegExpSearch(), isSearchWrapped() +*/ +void QtxSearchTool::setRegExpSearch( bool on ) +{ + if ( myControls & RegExp ) + myIsRegExp->setChecked( on ); +} + +/*! + \brief Set 'search wrapping' option value. + \param on new option state + \sa setCaseSensitive(), setRegExpSearch(), setControls() + \sa isCaseSensitive(), isRegExpSearch(), isSearchWrapped() +*/ +void QtxSearchTool::setSearchWrapped( bool on ) +{ + if ( myControls & Wrap ) + myWrap->setChecked( on ); +} + /*! \brief Customize event handling. \param e event @@ -1327,6 +1366,24 @@ bool QtxTreeViewSearcher::findLast( const QString& text, QtxSearchTool* st ) return false; } +/*! + \brief Get match flags to be used by the searcher. + \param st search tool widget +*/ +Qt::MatchFlags QtxTreeViewSearcher::matchFlags( QtxSearchTool* st ) const +{ + Qt::MatchFlags fl = Qt::MatchRecursive; + + if ( st->isCaseSensitive() ) + fl = fl | Qt::MatchCaseSensitive; + if ( st->isRegExpSearch() ) + fl = fl | Qt::MatchRegExp; + else + fl = fl | Qt::MatchContains; + + return fl; +} + /*! \brief Find all appropriate items. \internal @@ -1337,20 +1394,13 @@ QModelIndexList QtxTreeViewSearcher::findItems( const QString& text, QtxSearchTo { QString s = text; - Qt::MatchFlags fl = Qt::MatchRecursive; - - if ( st->isCaseSensitive() ) - fl = fl | Qt::MatchCaseSensitive; - if ( st->isRegExpSearch() ) { - fl = fl | Qt::MatchRegExp; + Qt::MatchFlags fl = matchFlags( st ); + if ( fl & Qt::MatchRegExp ) { if ( !s.startsWith( "^" ) && !s.startsWith( ".*" ) ) s.prepend( ".*" ); if ( !s.endsWith( "$" ) && !s.endsWith( ".*" ) ) s.append( ".*" ); } - else { - fl = fl | Qt::MatchContains; - } if ( myView->model() ) return myView->model()->match( myView->model()->index( 0, myColumn ), diff --git a/src/Qtx/QtxSearchTool.h b/src/Qtx/QtxSearchTool.h index 653a0f819..f91d00ff0 100644 --- a/src/Qtx/QtxSearchTool.h +++ b/src/Qtx/QtxSearchTool.h @@ -110,6 +110,10 @@ public: bool isRegExpSearch() const; bool isSearchWrapped() const; + void setCaseSensitive( bool ); + void setRegExpSearch( bool ); + void setSearchWrapped( bool ); + virtual bool event( QEvent* ); virtual bool eventFilter( QObject*, QEvent* ); @@ -186,6 +190,9 @@ public: virtual bool findFirst( const QString&, QtxSearchTool* ); virtual bool findLast( const QString&, QtxSearchTool* ); +protected: + virtual Qt::MatchFlags matchFlags( QtxSearchTool* ) const; + private: QModelIndexList findItems( const QString&, QtxSearchTool* ); QModelIndex findNearest( const QModelIndex&, const QModelIndexList&, bool ); -- 2.39.2