1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef SUIT_FINDACTIONDIALOG_H
24 #define SUIT_FINDACTIONDIALOG_H
27 #include "SUIT_ShortcutMgr.h"
30 #include <QTreeWidget>
45 class SUIT_FoundActionTree;
48 class SUIT_EXPORT SUIT_FindActionDialog : public QDialog
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;
58 void setActiveModuleID(const QString& theModuleID = SUIT_ShortcutMgr::ROOT_MODULE_ID);
61 void onQueryChanged(const QString& theKeyword);
62 void onSearchOptionUnavailableActionsChanged(int);
63 void onSearchOptionInactiveModulesChanged(int);
68 QLineEdit* myQueryLineEdit;
69 QCheckBox* myIncludeUnavailableActionsCB;
70 QCheckBox* myIncludeInactiveModulesCB;
71 SUIT_FoundActionTree* myFoundActionsTree;
73 QString myActiveModuleID;
74 SUIT_ActionSearcher myActionSearcher;
78 class SUIT_FoundActionTreeItem;
79 class SUIT_FoundActionTreeModule;
80 class SUIT_FoundActionTreeAction;
83 class SUIT_EXPORT SUIT_FoundActionTree : public QTreeWidget
100 enum class SortOrder {
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;
110 void updateItems(const std::map<QString, std::map<QString, SUIT_ActionSearcher::AssetsAndSearchData>>& theAssets);
112 void sort(SUIT_FoundActionTree::SortKey theKey, SUIT_FoundActionTree::SortOrder theOrder);
114 void keyPressEvent(QKeyEvent* theEvent);
117 bool eventFilter(QObject* theQObject, QEvent* theEvent);
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;
124 void onItemExecuted(QTreeWidgetItem* theWidgetItem, int theColIdx);
127 static const QList<std::pair<SUIT_FoundActionTree::SortKey, SUIT_FoundActionTree::SortOrder>> DEFAULT_SORT_SCHEMA;
130 SUIT_FoundActionTree::SortKey mySortKey;
131 SUIT_FoundActionTree::SortOrder mySortOrder;
133 /** {moduleID, isExpanded}[] */
134 std::map<QString, bool> myModuleItemExpansionStates;
138 class SUIT_FoundActionTreeItem : public QTreeWidgetItem
147 SUIT_FoundActionTreeItem(const QString& theModuleID);
150 virtual ~SUIT_FoundActionTreeItem() = default;
151 virtual SUIT_FoundActionTreeItem::Type type() const = 0;
153 virtual void setAssetsAndSearchData(const SUIT_ActionSearcher::AssetsAndSearchData& theAssetsAndSD, const QString& theLang) = 0;
154 QString name() const;
155 QString toolTip() const;
157 virtual QVariant getValue(SUIT_FoundActionTree::SortKey theKey) const = 0;
159 virtual bool isEnabled() const = 0;
162 const QString myModuleID;
166 class SUIT_FoundActionTreeModule : public SUIT_FoundActionTreeItem
169 SUIT_FoundActionTreeModule(const QString& theModuleID);
170 virtual ~SUIT_FoundActionTreeModule() = default;
171 virtual SUIT_FoundActionTreeItem::Type type() const { return SUIT_FoundActionTreeItem::Type::Module; };
173 /*! \brief Search data is unused. */
174 virtual void setAssetsAndSearchData(const SUIT_ActionSearcher::AssetsAndSearchData& theAssetsAndSD, const QString& theLang);
176 virtual QVariant getValue(SUIT_FoundActionTree::SortKey theKey) const;
178 virtual bool isEnabled() const;
182 class SUIT_FoundActionTreeAction : public SUIT_FoundActionTreeItem
185 SUIT_FoundActionTreeAction(const QString& theModuleID, const QString& theInModuleActionID);
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; };
192 virtual void setAssetsAndSearchData(const SUIT_ActionSearcher::AssetsAndSearchData& theAssetsAndSD, const QString& theLang);
194 virtual QVariant getValue(SUIT_FoundActionTree::SortKey theKey) const;
195 double matchMetrics() const { return myMatchMetrics; };
197 virtual bool isEnabled() const;
198 bool isEnabledBufferedValue() const { return myIsEnabledBufferedValue; };
200 bool trigger() const;
202 const QString myInModuleActionID;
205 double myMatchMetrics;
206 mutable bool myIsEnabledBufferedValue;
209 #endif // SUIT_FINDACTIONDIALOG_H