Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QtxSearchTool.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 // File : QtxSearchTool.h
21 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
22 //
23 #ifndef QTXSEARCHTOOL_H
24 #define QTXSEARCHTOOL_H
25 
26 #include "Qtx.h"
27 #include <QFrame>
28 #include <QList>
29 #include <QMap>
30 #include <QPersistentModelIndex>
31 #include <QPointer>
32 
33 class QCheckBox;
34 class QLineEdit;
35 class QShortcut;
36 class QTimer;
37 class QToolButton;
38 class QTreeView;
39 
41 {
42  Q_OBJECT
43 
45  enum {
46  fAny,
50  fLast
51  };
52 
53 public:
54  class Searcher;
55 
57  typedef enum {
58  Search = 0x00000001,
59  Next = 0x00000002,
60  Prev = 0x00000004,
61  First = 0x00000008,
62  Last = 0x00000010,
63  Close = 0x00000020,
64  Case = 0x00000040,
65  RegExp = 0x00000080,
66  Wrap = 0x00000100,
67  Basic = Search | Next | Prev | Close,
68  Standard = Basic | First | Last,
69  Modifiers = Case | RegExp | Wrap,
70  All = Standard | Modifiers
71  } Controls;
72 
73  typedef enum {
74  None = 0x00000000,
75  HotKey = 0x00000001,
76  SlashKey = 0x00000002,
77  StandardKey = 0x00000004,
78  PrintKey = 0x00000008,
79  Any = HotKey | SlashKey | StandardKey | PrintKey
80  } Activator;
81 
84  virtual ~QtxSearchTool();
85 
86  QWidget* watchedWidget() const;
87  void setWatchedWidget( QWidget* );
88 
89  Searcher* searcher() const;
90  void setSearcher( Searcher* );
91 
92  int activators() const;
93  void setActivators( const int );
94 
95  int controls() const;
96  void setControls( const int );
97 
98  QList<QKeySequence> shortcuts() const;
99  void setShortcuts( const QKeySequence& );
100  void setShortcuts( const QList<QKeySequence>& );
101 
102  int addCustomWidget( QWidget*, int = -1 );
103  QWidget* customWidget( int ) const;
104  int customWidgetId( QWidget* ) const;
105 
106  bool isAutoHideEnabled() const;
107  void enableAutoHide( bool );
108 
109  bool isCaseSensitive() const;
110  bool isRegExpSearch() const;
111  bool isSearchWrapped() const;
112 
113  void setCaseSensitive( bool );
114  void setRegExpSearch( bool );
115  void setSearchWrapped( bool );
116 
117  virtual bool event( QEvent* );
118  virtual bool eventFilter( QObject*, QEvent* );
119 
120 public slots:
121  virtual void find();
122  virtual void findNext();
123  virtual void findPrevious();
124  virtual void findFirst();
125  virtual void findLast();
126 
127 private slots:
128  void find( const QString&, int = fAny );
129  void modifierSwitched();
130 
131 private:
132  void init( Qt::Orientation );
133  bool focused() const;
134  void clearShortcuts();
135  void initShortcuts( const QList<QKeySequence>& );
136  void updateShortcuts();
137  void updateControls();
138 
139 private:
140  typedef QPointer<QShortcut> ShortcutPtr;
142 
143 private:
152  QCheckBox* myIsCaseSens;
153  QCheckBox* myIsRegExp;
154  QCheckBox* myWrap;
162  QMap<int, QWidget*> myWidgets;
163 };
164 
166 {
167 public:
168  Searcher();
169  virtual ~Searcher();
170 
171  virtual bool find( const QString&, QtxSearchTool* ) = 0;
172  virtual bool findNext( const QString&, QtxSearchTool* ) = 0;
173  virtual bool findPrevious( const QString&, QtxSearchTool* ) = 0;
174  virtual bool findFirst( const QString&, QtxSearchTool* ) = 0;
175  virtual bool findLast( const QString&, QtxSearchTool* ) = 0;
176 };
177 
179 {
180 public:
181  QtxTreeViewSearcher( QTreeView*, int = 0 );
182  virtual ~QtxTreeViewSearcher();
183 
184  int searchColumn() const;
185  void setSearchColumn( int );
186 
187  virtual bool find( const QString&, QtxSearchTool* );
188  virtual bool findNext( const QString&, QtxSearchTool* );
189  virtual bool findPrevious( const QString&, QtxSearchTool* );
190  virtual bool findFirst( const QString&, QtxSearchTool* );
191  virtual bool findLast( const QString&, QtxSearchTool* );
192 
193 protected:
194  virtual Qt::MatchFlags matchFlags( QtxSearchTool* ) const;
195 
196 private:
197  QModelIndexList findItems( const QString&, QtxSearchTool* );
198  QModelIndex findNearest( const QModelIndex&, const QModelIndexList&, bool );
199  void showItem( const QModelIndex& );
200  QString getId( const QModelIndex& );
201  int compareIndices( const QModelIndex&, const QModelIndex& );
202 
203 private:
205  int myColumn;
206  QPersistentModelIndex myIndex;
207 };
208 
209 #endif // QTXSEARCHTOOL_H