Salome HOME
Facilate action processing with ModuleBase_ActionInfo
[modules/shaper.git] / src / ModuleBase / ModuleBase_ActionInfo.cpp
1 /*
2  * ModuleBase_ActionInfo.cpp
3  *
4  *  Created on: Feb 4, 2015
5  *      Author: sbh
6  */
7
8 #include <ModuleBase_ActionInfo.h>
9
10 ModuleBase_ActionInfo::ModuleBase_ActionInfo()
11 {
12   initDefault();
13 }
14
15 ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QString &theText)
16 {
17   initDefault();
18 }
19
20 ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QIcon & theIcon, const QString &theText)
21 {
22   initDefault();
23   icon = theIcon;
24   text = theText;
25 }
26
27 ModuleBase_ActionInfo::~ModuleBase_ActionInfo()
28 {
29 }
30
31 void ModuleBase_ActionInfo::initFrom(QAction* theAction)
32 {
33   // By convenience, QAction for a feature keeps feature's id as data (QVariant);
34   if (theAction->data().isValid()) {
35     id = theAction->data().toString();
36   }
37   checkable = theAction->isCheckable();
38   checked = theAction->isChecked();
39   enabled = theAction->isEnabled();
40   visible = theAction->isVisible();
41   icon = theAction->icon();
42   text = theAction->text();
43   iconText = theAction->iconText();
44   toolTip = theAction->toolTip();
45   // statusTip = theAction->statusTip();
46   // whatsThis = theAction->whatsThis();
47   shortcut = theAction->shortcut();
48   font = theAction->font();
49 }
50
51 void ModuleBase_ActionInfo::initFrom(std::shared_ptr<Config_FeatureMessage> theMessage)
52 {
53   id = QString::fromStdString(theMessage->id());
54   iconFile = QString::fromStdString(theMessage->icon());
55   if (!iconFile.isEmpty()) {
56     icon = QIcon(iconFile);
57   }
58   text = QString::fromStdString(theMessage->text());
59   toolTip = QString::fromStdString(theMessage->tooltip());
60   QString aShortcutStr = QString::fromStdString(theMessage->keysequence());
61   if (!aShortcutStr.isEmpty()) {
62     shortcut = QKeySequence(aShortcutStr);
63   }
64   // If feature requires PropertyPannel for input, it should be checkable
65   checkable = theMessage->isUseInput();
66 }
67
68 QAction* ModuleBase_ActionInfo::makeAction(QObject* theParent)
69 {
70   QAction* aResult = new QAction(icon, text, theParent);
71   aResult->setCheckable(checkable);
72   aResult->setChecked(checked);
73   aResult->setEnabled(enabled);
74   aResult->setVisible(visible);
75   aResult->setIconText(iconText);
76   aResult->setToolTip(toolTip);
77   // aResult->setStatusTip(statusTip);
78   // aResult->setWhatsThis(whatsThis);
79   aResult->setShortcut(shortcut);
80   aResult->setFont(font);
81   // By convenience, QAction for a feature keeps feature's id as data (QVariant);
82   aResult->setData(id);
83   return aResult;
84 }
85
86 void ModuleBase_ActionInfo::initDefault()
87 {
88   id = QString();
89   checkable = false;
90   checked   = false;
91   enabled   = true;
92   visible   = true;
93   icon = QIcon();
94   text = QString();
95   iconText = QString();
96   iconFile = QString();
97   toolTip = QString();
98   // statusTip = QString();
99   // whatsThis = QString();
100   shortcut = QKeySequence();
101   font = QFont();
102 }