Version: 9.16.0
QtxSearchTool.h
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, 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
33class QCheckBox;
34class QLineEdit;
35class QShortcut;
36class QTimer;
37class QToolButton;
38class QTreeView;
39
41{
42 Q_OBJECT
43
45 enum {
50 fLast
51 };
52
53public:
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
120public slots:
121 virtual void find();
122 virtual void findNext();
123 virtual void findPrevious();
124 virtual void findFirst();
125 virtual void findLast();
126
127private slots:
128 void find( const QString&, int = fAny );
129 void modifierSwitched();
130
131private:
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
139private:
140 typedef QPointer<QShortcut> ShortcutPtr;
142
143private:
152 QCheckBox* myIsCaseSens;
153 QCheckBox* myIsRegExp;
154 QCheckBox* myWrap;
162 QMap<int, QWidget*> myWidgets;
163};
164
166{
167public:
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{
180public:
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
193protected:
194 virtual Qt::MatchFlags matchFlags( QtxSearchTool* ) const;
195
196private:
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
203private:
206 QPersistentModelIndex myIndex;
207};
208
209#endif // QTXSEARCHTOOL_H
#define QTX_EXPORT
Definition: Qtx.h:36
Orientation
Orientation.
Definition: SalomePyQt.h:147
@ Vertical
Vertical orientation.
Definition: SalomePyQt.h:149
For more information see QT documentation.
Generic searcher class.
Definition: QtxSearchTool.h:166
virtual bool findPrevious(const QString &, QtxSearchTool *)=0
Search previous appropriate item.
virtual bool findLast(const QString &, QtxSearchTool *)=0
Search last appropriate item.
virtual bool findNext(const QString &, QtxSearchTool *)=0
Search next appropriate item.
virtual bool find(const QString &, QtxSearchTool *)=0
Start new search.
virtual bool findFirst(const QString &, QtxSearchTool *)=0
Search first appropriate item.
Context search tool.
Definition: QtxSearchTool.h:41
QLineEdit * myData
Definition: QtxSearchTool.h:146
Searcher * mySearcher
Definition: QtxSearchTool.h:156
QWidget * myModWidget
Definition: QtxSearchTool.h:145
QMap< int, QWidget * > myWidgets
Definition: QtxSearchTool.h:162
QList< ShortcutPtr > ShortcutList
Definition: QtxSearchTool.h:141
QCheckBox * myIsRegExp
Definition: QtxSearchTool.h:153
QToolButton * myToFirst
Definition: QtxSearchTool.h:147
QPointer< QShortcut > ShortcutPtr
Definition: QtxSearchTool.h:140
int myActivators
Definition: QtxSearchTool.h:158
QToolButton * myToLast
Definition: QtxSearchTool.h:148
bool myAutoHideEnabled
Definition: QtxSearchTool.h:161
QTimer * myAutoHideTimer
Definition: QtxSearchTool.h:160
QToolButton * myPrev
Definition: QtxSearchTool.h:150
QToolButton * myClose
Definition: QtxSearchTool.h:151
int myControls
Definition: QtxSearchTool.h:157
QWidget * myBtnWidget
Definition: QtxSearchTool.h:144
QWidget * myWatched
Definition: QtxSearchTool.h:155
@ fPrevious
find previous appropriate
Definition: QtxSearchTool.h:48
@ fNext
find next appropriate
Definition: QtxSearchTool.h:47
@ fAny
find any appropriate
Definition: QtxSearchTool.h:46
@ fFirst
find first appropriate
Definition: QtxSearchTool.h:49
QCheckBox * myIsCaseSens
Definition: QtxSearchTool.h:152
QCheckBox * myWrap
Definition: QtxSearchTool.h:154
ShortcutList myShortcuts
Definition: QtxSearchTool.h:159
QToolButton * myNext
Definition: QtxSearchTool.h:149
A QTreeView class based searcher.
Definition: QtxSearchTool.h:179
int myColumn
Definition: QtxSearchTool.h:205
QTreeView * myView
Definition: QtxSearchTool.h:204
QPersistentModelIndex myIndex
Definition: QtxSearchTool.h:206
@ None
Definition: Plot2d.h:74