Salome HOME
[bos #40644][CEA](2024-T1) Feature search.
[modules/gui.git] / src / Qtx / QtxFindActionDialog.h
1 // Copyright (C) 2007-2024  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 #ifndef QTXFINDACTIONDIALOG_H
21 #define QTXFINDACTIONDIALOG_H
22
23 #include "Qtx.h"
24 #include <QDialog>
25 #include <QFrame>
26 #include <QTreeWidget>
27 #include "SUIT_ShortcutMgr.h"
28 #include <memory>
29 #include <map>
30 #include <set>
31 #include <functional>
32
33
34 class QCheckBox;
35 class QLineEdit;
36 class QLabel;
37 class QPushButton;
38 class QtxFoundActionTree;
39
40
41 class QTX_EXPORT QtxFindActionDialog : public QDialog
42 {
43   Q_OBJECT
44
45 public:
46   QtxFindActionDialog(QWidget* theParent);
47   QtxFindActionDialog(const QtxFindActionDialog&) = delete;
48   QtxFindActionDialog& operator=(const QtxFindActionDialog&) = delete;
49   virtual ~QtxFindActionDialog() = default;
50
51   void setActiveModuleID(const QString& theModuleID = SUIT_ShortcutMgr::ROOT_MODULE_ID);
52
53 private slots:
54   void onQueryChanged(const QString& theKeyword);
55   void onSearchOptionUnavailableActionsChanged(int);
56   void onSearchOptionInactiveModulesChanged(int);
57
58 private:
59   void updateUI();
60
61   QLineEdit* myQueryLineEdit;
62   QCheckBox* myIncludeUnavailableActionsCB;
63   QCheckBox* myIncludeInactiveModulesCB;
64   QtxFoundActionTree* myFoundActionsTree;
65
66   QString myActiveModuleID;
67   SUIT_ActionSearcher myActionSearcher;
68 };
69
70
71 class QtxFoundActionTreeItem;
72 class QtxFoundActionTreeFolder;
73 class QtxFoundActionTreeAction;;
74
75
76 class QTX_EXPORT QtxFoundActionTree : public QTreeWidget
77 {
78   Q_OBJECT
79
80 public:
81   enum ElementIdx {
82     Name = 0,
83     ToolTip = 1
84   };
85
86   enum class SortKey {
87     ID,
88     Name,
89     ToolTip
90   };
91
92   QtxFoundActionTree();
93   QtxFoundActionTree(const QtxFoundActionTree&) = delete;
94   QtxFoundActionTree& operator=(const QtxFoundActionTree&) = delete;
95   virtual ~QtxFoundActionTree() = default;
96
97   void updateItems(const std::map<QString, std::map<QString, SUIT_ActionSearcher::AssetsAndSearchData>>& theAssets);
98
99 private:
100   std::pair<QtxFoundActionTreeFolder*, int> findModuleFolderItem(const QString& theModuleID) const;
101
102 private slots:
103   void onItemDoubleClicked(QTreeWidgetItem* theWidgetItem, int theColIdx);
104 };
105
106
107 class QtxFoundActionTreeItem : public QTreeWidgetItem
108 {
109 public:
110   enum Type {
111     Folder = 0,
112     Action = 1,
113   };
114
115 protected:
116   QtxFoundActionTreeItem(const QString& theModuleID);
117
118 public:
119   virtual ~QtxFoundActionTreeItem() = default;
120   virtual QtxFoundActionTreeItem::Type type() const = 0;
121
122   virtual void setAssets(std::shared_ptr<const SUIT_ActionAssets> theAssets, const QString& theLang) = 0;
123   QString name() const;
124   QString toolTip() const;
125
126   virtual QString getValue(QtxFoundActionTree::SortKey theKey) const = 0;
127
128   virtual bool isEnabled() const = 0;
129
130 public:
131   const QString myModuleID;
132 };
133
134
135 class QtxFoundActionTreeFolder : public QtxFoundActionTreeItem
136 {
137 public:
138   QtxFoundActionTreeFolder(const QString& theModuleID);
139   virtual ~QtxFoundActionTreeFolder() = default;
140   virtual QtxFoundActionTreeItem::Type type() const { return QtxFoundActionTreeItem::Type::Folder; };
141
142   virtual void setAssets(std::shared_ptr<const SUIT_ActionAssets> theAssets, const QString& theLang);
143
144   virtual QString getValue(QtxFoundActionTree::SortKey theKey) const;
145
146   virtual bool isEnabled() const;
147 };
148
149
150 class QtxFoundActionTreeAction : public QtxFoundActionTreeItem
151 {
152 private:
153   QtxFoundActionTreeAction(const QString& theModuleID, const QString& theInModuleActionID);
154
155 public:
156   static QtxFoundActionTreeAction* create(const QString& theModuleID, const QString& theInModuleActionID);
157   virtual ~QtxFoundActionTreeAction() = default;
158   virtual QtxFoundActionTreeItem::Type type() const { return QtxFoundActionTreeItem::Type::Action; };
159
160   virtual void setAssets(std::shared_ptr<const SUIT_ActionAssets> theAssets, const QString& theLang);
161
162   virtual QString getValue(QtxFoundActionTree::SortKey theKey) const;
163
164   virtual bool isEnabled() const;
165
166   void trigger() const;
167
168   const QString myInModuleActionID;
169 };
170
171 #endif // QTXFINDACTIONDIALOG_H