Salome HOME
d444524752d4f50aaa1bf68d7a6059945c588981
[modules/shaper.git] / src / ModuleBase / ModuleBase_ActionInfo.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 /*
3  * ModuleBase_ActionInfo.cpp
4  *
5  *  Created on: Feb 4, 2015
6  *      Author: sbh
7  */
8
9 #include <ModuleBase_ActionInfo.h>
10 #include <ModuleBase_IconFactory.h>
11
12 ModuleBase_ActionInfo::ModuleBase_ActionInfo()
13 {
14   initDefault();
15 }
16
17 ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QString &theText)
18 {
19   initDefault();
20 }
21
22 ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QIcon & theIcon, const QString &theText)
23 {
24   initDefault();
25   icon = theIcon;
26   text = theText;
27 }
28
29 ModuleBase_ActionInfo::~ModuleBase_ActionInfo()
30 {
31 }
32
33 void ModuleBase_ActionInfo::initFrom(QAction* theAction)
34 {
35   // By convenience, QAction for a feature keeps feature's id as data (QVariant);
36   if (theAction->data().isValid()) {
37     id = theAction->data().toString();
38   }
39   checkable = theAction->isCheckable();
40   checked = theAction->isChecked();
41   enabled = theAction->isEnabled();
42   visible = theAction->isVisible();
43   icon = theAction->icon();
44   text = theAction->text();
45   iconText = theAction->iconText();
46   toolTip = theAction->toolTip();
47   // statusTip = theAction->statusTip();
48   // whatsThis = theAction->whatsThis();
49   shortcut = theAction->shortcut();
50   font = theAction->font();
51 }
52
53 void ModuleBase_ActionInfo::initFrom(std::shared_ptr<Config_FeatureMessage> theMessage)
54 {
55   id = QString::fromStdString(theMessage->id());
56   iconFile = QString::fromStdString(theMessage->icon());
57   if (!iconFile.isEmpty()) {
58     icon = ModuleBase_IconFactory::loadIcon(iconFile);
59   }
60   text = QString::fromStdString(theMessage->text());
61   toolTip = QString::fromStdString(theMessage->tooltip());
62   QString aShortcutStr = QString::fromStdString(theMessage->keysequence());
63   if (!aShortcutStr.isEmpty()) {
64     shortcut = QKeySequence(aShortcutStr);
65   }
66   // If feature requires PropertyPannel for input, it should be checkable
67   checkable = theMessage->isUseInput();
68   // If Feature requires modal Dialog box for input
69   modal = theMessage->isModal();
70 }
71
72 void ModuleBase_ActionInfo::initDefault()
73 {
74   id = QString();
75   checkable = false;
76   checked   = false;
77   enabled   = true;
78   visible   = true;
79   icon = QIcon();
80   text = QString();
81   iconText = QString();
82   iconFile = QString();
83   toolTip = QString();
84   // statusTip = QString();
85   // whatsThis = QString();
86   shortcut = QKeySequence();
87   font = QFont();
88 }