ModuleBase_WidgetLabel.h
ModuleBase_IPrefMgr.h
ModuleBase_Preferences.h
+ ModuleBase_ActionInfo.h
)
SET(PROJECT_SOURCES
ModuleBase_ResultPrs.cpp
ModuleBase_WidgetLabel.cpp
ModuleBase_Preferences.cpp
+ ModuleBase_ActionInfo.cpp
)
SET(PROJECT_LIBRARIES
Config
+ Events
ModelAPI
GeomAPI
GeomAlgoAPI
--- /dev/null
+/*
+ * ModuleBase_ActionInfo.cpp
+ *
+ * Created on: Feb 4, 2015
+ * Author: sbh
+ */
+
+#include <ModuleBase_ActionInfo.h>
+
+ModuleBase_ActionInfo::ModuleBase_ActionInfo()
+{
+ initDefault();
+}
+
+ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QString &theText)
+{
+ initDefault();
+}
+
+ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QIcon & theIcon, const QString &theText)
+{
+ initDefault();
+ icon = theIcon;
+ text = theText;
+}
+
+ModuleBase_ActionInfo::~ModuleBase_ActionInfo()
+{
+}
+
+void ModuleBase_ActionInfo::initFrom(QAction* theAction)
+{
+ // By convenience, QAction for a feature keeps feature's id as data (QVariant);
+ if (theAction->data().isValid()) {
+ id = theAction->data().toString();
+ }
+ checkable = theAction->isCheckable();
+ checked = theAction->isChecked();
+ enabled = theAction->isEnabled();
+ visible = theAction->isVisible();
+ icon = theAction->icon();
+ text = theAction->text();
+ iconText = theAction->iconText();
+ toolTip = theAction->toolTip();
+ // statusTip = theAction->statusTip();
+ // whatsThis = theAction->whatsThis();
+ shortcut = theAction->shortcut();
+ font = theAction->font();
+}
+
+void ModuleBase_ActionInfo::initFrom(std::shared_ptr<Config_FeatureMessage> theMessage)
+{
+ id = QString::fromStdString(theMessage->id());
+ iconFile = QString::fromStdString(theMessage->icon());
+ if (!iconFile.isEmpty()) {
+ icon = QIcon(iconFile);
+ }
+ text = QString::fromStdString(theMessage->text());
+ toolTip = QString::fromStdString(theMessage->tooltip());
+ QString aShortcutStr = QString::fromStdString(theMessage->keysequence());
+ if (!aShortcutStr.isEmpty()) {
+ shortcut = QKeySequence(aShortcutStr);
+ }
+ // If feature requires PropertyPannel for input, it should be checkable
+ checkable = theMessage->isUseInput();
+}
+
+QAction* ModuleBase_ActionInfo::makeAction(QObject* theParent)
+{
+ QAction* aResult = new QAction(icon, text, theParent);
+ aResult->setCheckable(checkable);
+ aResult->setChecked(checked);
+ aResult->setEnabled(enabled);
+ aResult->setVisible(visible);
+ aResult->setIconText(iconText);
+ aResult->setToolTip(toolTip);
+ // aResult->setStatusTip(statusTip);
+ // aResult->setWhatsThis(whatsThis);
+ aResult->setShortcut(shortcut);
+ aResult->setFont(font);
+ // By convenience, QAction for a feature keeps feature's id as data (QVariant);
+ aResult->setData(id);
+ return aResult;
+}
+
+void ModuleBase_ActionInfo::initDefault()
+{
+ id = QString();
+ checkable = false;
+ checked = false;
+ enabled = true;
+ visible = true;
+ icon = QIcon();
+ text = QString();
+ iconText = QString();
+ iconFile = QString();
+ toolTip = QString();
+ // statusTip = QString();
+ // whatsThis = QString();
+ shortcut = QKeySequence();
+ font = QFont();
+}
--- /dev/null
+/*
+ * ActionInfo.h
+ *
+ * Created on: Feb 4, 2015
+ * Author: sbh
+ */
+
+#ifndef MODULEBASE_ACTIONINFO_H_
+#define MODULEBASE_ACTIONINFO_H_
+
+#include <ModuleBase.h>
+#include <Config_FeatureMessage.h>
+
+#include <QAction>
+#include <QIcon>
+#include <QKeySequence>
+#include <QFont>
+
+#include <memory>
+
+/*!
+ * Structure to pass info about QActions, AppElements_Commands, etc.
+ */
+struct MODULEBASE_EXPORT ModuleBase_ActionInfo
+{
+ QString id;
+
+ bool checkable; //!< action's checkable state
+ bool checked; //!< action's checked state
+ bool enabled; //!< action's enabled state
+ bool visible; //!< action's visibility state
+ QIcon icon; //!< action's icon
+ QString text; //!< action's text
+ QString iconText; //!< action's descriptive icon text
+ QString iconFile; //!< path to icon's file. Can not be initialized from QAction
+ QString toolTip; //!< action's tooltip
+ // QString statusTip;
+ // QString whatsThis;
+ QKeySequence shortcut; //!< action's primary shortcut key
+ QFont font; //!< action's text font
+
+ public:
+ //! Default constructor, \sa initDefault
+ ModuleBase_ActionInfo();
+ //! Initializes structure with default values, except text
+ ModuleBase_ActionInfo(const QString &text);
+ //! Initializes structure with default values, except icon and text
+ ModuleBase_ActionInfo(const QIcon &icon, const QString &text);
+ virtual ~ModuleBase_ActionInfo();
+
+ //! Fills itself with info from given \param theAction
+ void initFrom(QAction* theAction);
+ //! Fills itself with info from given \param theFeatureMessage
+ void initFrom(std::shared_ptr<Config_FeatureMessage> theFeatureMessage);
+ //! Creates new QAction with given parent and data initialized from this structure
+ //! \param theParent - parent of created action
+ QAction* makeAction(QObject* theParent = 0);
+
+ protected:
+ //! Initializes structure with default values, like QAction()
+ void initDefault();
+};
+
+typedef ModuleBase_ActionInfo ActionInfo;
+
+#endif /* XGUI_ACTIONINFO_H_ */
return aAction;
}
+QAction* NewGeom_Module::addFeature(const QString& theWBName, const ActionInfo& theInfo)
+{
+ return addFeature(theWBName,
+ theInfo.id,
+ theInfo.text,
+ theInfo.toolTip,
+ theInfo.icon,
+ theInfo.shortcut);
+}
+
+
//******************************************************
QAction* NewGeom_Module::addDesktopCommand(const QString& theId, const QString& theTitle,
const QString& theTip, const QIcon& theIcon,
#include <LightApp_Module.h>
#include <XGUI_SalomeConnector.h>
+#include <ModuleBase_ActionInfo.h>
+
#include <QStringList>
#include <QMap>
const QKeySequence& theKeys = QKeySequence(),
bool isCheckable = false);
+ virtual QAction* addFeature(const QString& theWBName,
+ const ActionInfo& theInfo);
+
+
virtual QAction* addDesktopCommand(const QString& theId, const QString& theTitle,
const QString& theTip, const QIcon& theIcon,
const QKeySequence& theKeys, bool isCheckable,
}
}
+QKeySequence XGUI_ActionsMgr::registerShortcut(const QKeySequence& theKeySequence)
+{
+ if (myShortcuts.contains(theKeySequence)) {
+ QString aMessage = tr("Shortcut %1 is already defined. Ignore.");
+ aMessage = aMessage.arg(theKeySequence.toString());
+ Events_Error::send(aMessage.toStdString());
+ return QKeySequence();
+ }
+ myShortcuts.append(theKeySequence);
+ return theKeySequence;
+}
+
QKeySequence XGUI_ActionsMgr::registerShortcut(const QString& theKeySequence)
{
if (theKeySequence.isEmpty()) {
return QKeySequence();
}
QKeySequence aResult(theKeySequence);
- if (myShortcuts.contains(aResult)) {
- QString aMessage = tr("Shortcut %1 is already defined. Ignore.").arg(theKeySequence);
- Events_Error::send(aMessage.toStdString());
- return QKeySequence();
- }
- myShortcuts.append(aResult);
+ registerShortcut(aResult);
return aResult;
}
/// Registers shortcut (key sequence) for the command triggering
/// \param theKeySequence a key sequence to register
+ QKeySequence registerShortcut(const QKeySequence& theKeySequence);
+
+ /// This is an overloaded function.
+ /// Registers shortcut (key sequence) for the command triggering
+ /// \param theKeySequence - string that contain a key sequence to register
QKeySequence registerShortcut(const QString& theKeySequence);
//! Redefinition of Events_Listener method
{
}
-void XGUI_HistoryMenu::setHistory(const QList<QAction*>& theActions)
+void XGUI_HistoryMenu::setHistory(const QList<ActionInfo>& theActions)
{
myHistoryList->clear();
- foreach(QAction* anAct, theActions) {
- QListWidgetItem* anItem = new QListWidgetItem(anAct->icon(),
- anAct->text(),
- myHistoryList);
- anAct->deleteLater();
+ foreach(ActionInfo anAct, theActions) {
+ QListWidgetItem* anItem = new QListWidgetItem(anAct.icon, anAct.text, myHistoryList);
}
}
#include <XGUI.h>
#include <QMenu>
+#include <ModuleBase_ActionInfo.h>
+
class QListWidget;
class QToolButton;
class QListWidgetItem;
void actionsSelected(int);
public slots:
- void setHistory(const QList<QAction*>&);
+ void setHistory(const QList<ActionInfo>&);
protected slots:
void setStackSelectedTo(QListWidgetItem *);
#include <QString>
#include <QStringList>
+#include <ModuleBase_ActionInfo.h>
+
class QMainWindow;
class ModuleBase_IViewer;
const QString& theTitle, const QString& theTip, const QIcon& theIcon,
const QKeySequence& theKeys, bool isCheckable) = 0;
+ virtual QAction* addFeature(const QString& theWBName,
+ const ActionInfo& theInfo) = 0;
+
//! Creates a command in Edit menu of SALOME desktop
//! \param theId - an id of the feature
//! \param theTitle - a menu item string
QToolButton* aToolBtn = qobject_cast<QToolButton*>(aGroup->widget(aUndoId));
XGUI_HistoryMenu* aUndoMenu = new XGUI_HistoryMenu(aToolBtn);
- connect(this, SIGNAL(updateUndoHistory(const QList<QAction*>&)),
- aUndoMenu, SLOT(setHistory(const QList<QAction*>&)));
+ connect(this, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
+ aUndoMenu, SLOT(setHistory(const QList<ActionInfo>&)));
connect(aUndoMenu, SIGNAL(actionsSelected(int)),
this, SLOT(onUndo(int)));
aToolBtn = qobject_cast<QToolButton*>(aGroup->widget(aRedoId));
XGUI_HistoryMenu* aRedoMenu = new XGUI_HistoryMenu(aToolBtn);
- connect(this, SIGNAL(updateUndoHistory(const QList<QAction*>&)),
+ connect(this, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
aRedoMenu, SLOT(setHistory(const QList<QAction*>&)));
connect(aRedoMenu, SIGNAL(actionsSelected(int)),
this, SLOT(onUndo(int)));
#endif
return;
}
+ ActionInfo aFeatureInfo;
+ aFeatureInfo.initFrom(theMessage);
// Remember features icons
- myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
+ myIcons[QString::fromStdString(theMessage->id())] = aFeatureInfo.iconFile;
QString aWchName = QString::fromStdString(theMessage->workbenchId());
- QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
- bool isUsePropPanel = theMessage->isUseInput();
- QString aFeatureId = QString::fromStdString(theMessage->id());
+ QStringList aNestedFeatures =
+ QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
+ QString aDocKind = QString::fromStdString(theMessage->documentKind());
if (isSalomeMode()) {
- QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureId,
- QString::fromStdString(theMessage->text()),
- QString::fromStdString(theMessage->tooltip()),
- QIcon(QString::fromStdString(theMessage->icon())),
- QKeySequence(),
- isUsePropPanel);
- salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts));
- salomeConnector()->setDocumentKind(aFeatureId, QString::fromStdString(theMessage->documentKind()));
+ QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureInfo);
+ salomeConnector()->setNestedActions(aFeatureInfo.id, aNestedFeatures);
+ salomeConnector()->setDocumentKind(aFeatureInfo.id, aDocKind);
myActionsMgr->addCommand(aAction);
myModule->actionCreated(aAction);
if (!aGroup) {
aGroup = aPage->addGroup(aGroupName);
}
- QString aDocKind = QString::fromStdString(theMessage->documentKind());
// Check if hotkey sequence is already defined:
- QKeySequence aHotKey = myActionsMgr->registerShortcut(
- QString::fromStdString(theMessage->keysequence()));
+ QKeySequence aHotKey = myActionsMgr->registerShortcut(aFeatureInfo.shortcut);
+ if(aHotKey != aFeatureInfo.shortcut) {
+ aFeatureInfo.shortcut = aHotKey;
+ }
// Create feature...
- AppElements_Command* aCommand = aGroup->addFeature(aFeatureId,
- QString::fromStdString(theMessage->text()),
- QString::fromStdString(theMessage->tooltip()),
- QIcon(theMessage->icon().c_str()),
- aDocKind,
- aHotKey,
- isUsePropPanel);
- aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts));
+ AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo, aDocKind);
+ aCommand->setNestedCommands(aNestedFeatures);
myActionsMgr->addCommand(aCommand);
myModule->actionCreated(aCommand);
}
{
std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
std::list<std::string>::iterator it = aUndoList.begin();
- QList<QAction*> aUndoRes;
+ QList<ActionInfo> aUndoRes;
for ( ; it != aUndoList.end(); it++) {
QString anId = QString::fromStdString(*it);
QIcon aIcon;
if (myIcons.contains(anId))
aIcon = QIcon(myIcons[anId]);
- aUndoRes << new QAction(aIcon, anId, NULL);
+ aUndoRes << ActionInfo(aIcon, anId);
}
emit updateUndoHistory(aUndoRes);
std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
it = aRedoList.begin();
- QList<QAction*> aRedoRes;
+ QList<ActionInfo> aRedoRes;
for ( ; it != aRedoList.end(); it++) {
QString anId = QString::fromStdString(*it);
QIcon aIcon;
if (myIcons.contains(anId))
aIcon = QIcon(myIcons[anId]);
- aRedoRes << new QAction(aIcon, anId, NULL);
+ aRedoRes << ActionInfo(aIcon, anId);
}
emit updateRedoHistory(aUndoRes);
}
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
+#include <ModuleBase_ActionInfo.h>
+
#include <QObject>
#include <QMap>
#include <QKeySequence>
//! the application is started
void applicationStarted();
- void updateUndoHistory(const QList<QAction*>&);
- void updateRedoHistory(const QList<QAction*>&);
+ void updateUndoHistory(const QList<ActionInfo>&);
+ void updateRedoHistory(const QList<ActionInfo>&);
public slots:
/// Update of commands status