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