Salome HOME
[bos #40644][CEA](2024-T1) Feature search.
[modules/gui.git] / src / SUIT / SUIT_FindActionDialog.h
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef SUIT_FINDACTIONDIALOG_H
24 #define SUIT_FINDACTIONDIALOG_H
25
26 #include "SUIT.h"
27 #include "SUIT_ShortcutMgr.h"
28 #include <QDialog>
29 #include <QFrame>
30 #include <QTreeWidget>
31 #include <QList>
32 #include <QVariant>
33 #include <memory>
34 #include <map>
35 #include <set>
36 #include <functional>
37 #include <utility>
38
39
40 class QCheckBox;
41 class QLineEdit;
42 class QLabel;
43 class QPushButton;
44 class QKeyEvent;
45 class SUIT_FoundActionTree;
46
47
48 class SUIT_EXPORT SUIT_FindActionDialog : public QDialog
49 {
50   Q_OBJECT
51
52 public:
53   SUIT_FindActionDialog(QWidget* theParent);
54   SUIT_FindActionDialog(const SUIT_FindActionDialog&) = delete;
55   SUIT_FindActionDialog& operator=(const SUIT_FindActionDialog&) = delete;
56   virtual ~SUIT_FindActionDialog() = default;
57
58   void setActiveModuleID(const QString& theModuleID = SUIT_ShortcutMgr::ROOT_MODULE_ID);
59
60 private slots:
61   void onQueryChanged(const QString& theKeyword);
62   void onSearchOptionUnavailableActionsChanged(int);
63   void onSearchOptionInactiveModulesChanged(int);
64
65 private:
66   void updateUI();
67
68   QLineEdit* myQueryLineEdit;
69   QCheckBox* myIncludeUnavailableActionsCB;
70   QCheckBox* myIncludeInactiveModulesCB;
71   SUIT_FoundActionTree* myFoundActionsTree;
72
73   QString myActiveModuleID;
74   SUIT_ActionSearcher myActionSearcher;
75 };
76
77
78 class SUIT_FoundActionTreeItem;
79 class SUIT_FoundActionTreeModule;
80 class SUIT_FoundActionTreeAction;
81
82
83 class SUIT_EXPORT SUIT_FoundActionTree : public QTreeWidget
84 {
85   Q_OBJECT
86
87 public:
88   enum ElementIdx {
89     Name = 0,
90     ToolTip = 1
91   };
92
93   enum class SortKey {
94     MatchMetrics,
95     ID,
96     Name,
97     ToolTip
98   };
99
100   enum class SortOrder {
101     Ascending,
102     Descending
103   };
104
105   SUIT_FoundActionTree(SUIT_FindActionDialog* theParent);
106   SUIT_FoundActionTree(const SUIT_FoundActionTree&) = delete;
107   SUIT_FoundActionTree& operator=(const SUIT_FoundActionTree&) = delete;
108   virtual ~SUIT_FoundActionTree() = default;
109
110   void updateItems(const std::map<QString, std::map<QString, SUIT_ActionSearcher::AssetsAndSearchData>>& theAssets);
111
112   void sort(SUIT_FoundActionTree::SortKey theKey, SUIT_FoundActionTree::SortOrder theOrder);
113
114   void keyPressEvent(QKeyEvent* theEvent);
115
116 protected:
117   bool eventFilter(QObject* theQObject, QEvent* theEvent);
118
119 private:
120   std::pair<SUIT_FoundActionTreeModule*, int> findModuleItem(const QString& theModuleID) const;
121   std::set<SUIT_FoundActionTreeAction*, std::function<bool(SUIT_FoundActionTreeAction*, SUIT_FoundActionTreeAction*)>> createActionSetWithComparator() const;
122
123 private slots:
124   void onItemExecuted(QTreeWidgetItem* theWidgetItem, int theColIdx);
125
126 public:
127   static const QList<std::pair<SUIT_FoundActionTree::SortKey, SUIT_FoundActionTree::SortOrder>> DEFAULT_SORT_SCHEMA;
128
129 private:
130   SUIT_FoundActionTree::SortKey mySortKey;
131   SUIT_FoundActionTree::SortOrder mySortOrder;
132
133   /** {moduleID, isExpanded}[] */
134   std::map<QString, bool> myModuleItemExpansionStates;
135 };
136
137
138 class SUIT_FoundActionTreeItem : public QTreeWidgetItem
139 {
140 public:
141   enum Type {
142     Module = 0,
143     Action = 1,
144   };
145
146 protected:
147   SUIT_FoundActionTreeItem(const QString& theModuleID);
148
149 public:
150   virtual ~SUIT_FoundActionTreeItem() = default;
151   virtual SUIT_FoundActionTreeItem::Type type() const = 0;
152
153   virtual void setAssetsAndSearchData(const SUIT_ActionSearcher::AssetsAndSearchData& theAssetsAndSD, const QString& theLang) = 0;
154   QString name() const;
155   QString toolTip() const;
156
157   virtual QVariant getValue(SUIT_FoundActionTree::SortKey theKey) const = 0;
158
159   virtual bool isEnabled() const = 0;
160
161 public:
162   const QString myModuleID;
163 };
164
165
166 class SUIT_FoundActionTreeModule : public SUIT_FoundActionTreeItem
167 {
168 public:
169   SUIT_FoundActionTreeModule(const QString& theModuleID);
170   virtual ~SUIT_FoundActionTreeModule() = default;
171   virtual SUIT_FoundActionTreeItem::Type type() const { return SUIT_FoundActionTreeItem::Type::Module; };
172
173   /*! \brief Search data is unused. */
174   virtual void setAssetsAndSearchData(const SUIT_ActionSearcher::AssetsAndSearchData& theAssetsAndSD, const QString& theLang);
175
176   virtual QVariant getValue(SUIT_FoundActionTree::SortKey theKey) const;
177
178   virtual bool isEnabled() const;
179 };
180
181
182 class SUIT_FoundActionTreeAction : public SUIT_FoundActionTreeItem
183 {
184 private:
185   SUIT_FoundActionTreeAction(const QString& theModuleID, const QString& theInModuleActionID);
186
187 public:
188   static SUIT_FoundActionTreeAction* create(const QString& theModuleID, const QString& theInModuleActionID);
189   virtual ~SUIT_FoundActionTreeAction() = default;
190   virtual SUIT_FoundActionTreeItem::Type type() const { return SUIT_FoundActionTreeItem::Type::Action; };
191
192   virtual void setAssetsAndSearchData(const SUIT_ActionSearcher::AssetsAndSearchData& theAssetsAndSD, const QString& theLang);
193
194   virtual QVariant getValue(SUIT_FoundActionTree::SortKey theKey) const;
195   double matchMetrics() const { return myMatchMetrics; };
196
197   virtual bool isEnabled() const;
198   bool isEnabledBufferedValue() const { return myIsEnabledBufferedValue; };
199
200   bool trigger() const;
201
202   const QString myInModuleActionID;
203
204 private:
205   double myMatchMetrics;
206   mutable bool myIsEnabledBufferedValue;
207 };
208
209 #endif // SUIT_FINDACTIONDIALOG_H