14bbbdcb |
1 | // Created on: 2017-06-16 |
2 | // Created by: Natalia ERMOLAEVA |
3 | // Copyright (c) 2017 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef DFBrowser_SearchLine_H |
17 | #define DFBrowser_SearchLine_H |
18 | |
0cb512c0 |
19 | #include <inspector/DFBrowser_SearchLineModel.hxx> // to include DFBrowser_SearchItemInfo |
20 | |
14bbbdcb |
21 | #include <Standard.hxx> |
22 | #include <TDocStd_Application.hxx> |
23 | #include <TDF_Label.hxx> |
24 | |
25 | #include <QCompleter> |
26 | #include <QFrame> |
27 | #include <QLineEdit> |
28 | |
29 | class DFBrowser_Module; |
30 | class DFBrowser_SearchLineModel; |
31 | |
32 | class QAbstractItemModel; |
33 | class QLineEdit; |
34 | class QToolButton; |
35 | class QStringList; |
36 | |
37 | //! \class DFBrowser_SearchLine |
38 | //! It contains a line edit control with auto completion and search button |
39 | class DFBrowser_SearchLine : public QFrame |
40 | { |
41 | Q_OBJECT |
42 | public: |
43 | |
44 | //! Constructor |
45 | Standard_EXPORT DFBrowser_SearchLine (QWidget* theParent); |
46 | |
47 | //! Destructor |
48 | virtual ~DFBrowser_SearchLine() Standard_OVERRIDE {} |
49 | |
50 | //! Creates search line model filled by the module. It is necessary for auto completion of line edit |
51 | //! \param theModule a current module |
52 | Standard_EXPORT void SetModule (DFBrowser_Module* theModule); |
53 | |
54 | //! Returns the current module |
55 | Standard_EXPORT DFBrowser_Module* GetModule(); |
56 | |
57 | //! Fills the search line model by OCAF document values |
58 | //! \param theDocumentValues container of document index to container of entry/attribute name to item information |
59 | //! \param theDocumentInfoValues container of a document index to entry/attribute name |
60 | Standard_EXPORT void SetValues (const QMap<int, QMap<QString, DFBrowser_SearchItemInfo > >& theDocumentValues, |
61 | const QMap<int, QStringList>& theDocumentInfoValues); |
62 | |
63 | //! Clears cache of values in search line model |
64 | Standard_EXPORT void ClearValues(); |
65 | |
66 | //! Returns completer model |
67 | Standard_EXPORT QAbstractItemModel* GetModel() { return myLineControl->completer()->model(); } |
68 | |
69 | //! Returns completion completer model |
70 | Standard_EXPORT QAbstractItemModel* GetCompletionModel() { return myLineControl->completer()->completionModel(); } |
71 | |
72 | //! Returns the current line edit text |
73 | QString Text() const { return myLineControl->text(); } |
74 | |
75 | //! Sets the current text value |
76 | //! \param theValue a string value |
77 | void SetText (const QString& theValue) { myLineControl->setText (theValue); } |
78 | |
79 | signals: |
80 | |
81 | //! Signals that is emitted by text changed in line edit control |
82 | void searchActivated(); |
83 | |
84 | private slots: |
85 | |
86 | //! Updates icon of search button depending on text is empty and emits searchActivated signal |
87 | void onTextChanged (const QString& theText); |
88 | //! Set completion prefix in completer model |
89 | void onReturnPressed() { myLineControl->completer()->setCompletionPrefix (myLineControl->text()); } |
90 | //! Set empty text if the current text is not empty: new search is started |
91 | void onSearchButtonClicked(); |
92 | |
93 | private: |
94 | |
95 | QLineEdit* myLineControl; //!< line editor control |
96 | QToolButton* mySearchButton; //! < search button |
97 | }; |
98 | |
99 | #endif |