+ Extend Command framework to allow to update QAction
This commit is contained in:
parent
0fec404c6d
commit
c91018946c
|
@ -672,6 +672,10 @@ void Command::languageChange()
|
|||
}
|
||||
}
|
||||
|
||||
void Command::updateAction(int)
|
||||
{
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// MacroCommand
|
||||
//===========================================================================
|
||||
|
@ -1049,3 +1053,20 @@ void CommandManager::testActive(void)
|
|||
}
|
||||
}
|
||||
|
||||
void CommandManager::addCommandMode(const char* sContext, const char* sName)
|
||||
{
|
||||
_sCommandModes[sContext].push_back(sName);
|
||||
}
|
||||
|
||||
void CommandManager::updateCommands(const char* sContext, int mode)
|
||||
{
|
||||
std::map<std::string, std::list<std::string> >::iterator it = _sCommandModes.find(sContext);
|
||||
if (it != _sCommandModes.end()) {
|
||||
for (std::list<std::string>::iterator jt = it->second.begin(); jt != it->second.end(); ++jt) {
|
||||
Command* cmd = getCommandByName(jt->c_str());
|
||||
if (cmd) {
|
||||
cmd->updateAction(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,9 +84,12 @@ public:
|
|||
protected:
|
||||
/// Creates the used Action when adding to a widget. The default implementation does nothing.
|
||||
virtual Action * createAction(void);
|
||||
|
||||
public:
|
||||
/// Reassigns QAction stuff after the language has changed.
|
||||
virtual void languageChange() = 0;
|
||||
/// Updates the QAction with respect to the passed mode.
|
||||
virtual void updateAction(int mode) = 0;
|
||||
/// The C++ class name is needed as context for the translation framework
|
||||
virtual const char* className() const = 0;
|
||||
//@}
|
||||
|
@ -219,6 +222,8 @@ public:
|
|||
static bool isActiveObjectValid(void);
|
||||
/// Translate command
|
||||
void languageChange();
|
||||
/// Updates the QAction with respect to the passed mode.
|
||||
void updateAction(int mode);
|
||||
//@}
|
||||
|
||||
/** @name Helper methods for issuing commands to the Python interpreter */
|
||||
|
@ -464,14 +469,19 @@ public:
|
|||
*/
|
||||
void runCommandByName (const char* sName) const;
|
||||
|
||||
/// method is OBSOLET use GetModuleCommands() or GetAllCommands()
|
||||
/// method is OBSOLETE use GetModuleCommands() or GetAllCommands()
|
||||
const std::map<std::string, Command*>& getCommands() const { return _sCommands; }
|
||||
/// get frequently called by the AppWnd to check the commands are active.
|
||||
void testActive(void);
|
||||
|
||||
void addCommandMode(const char* sContext, const char* sName);
|
||||
void updateCommands(const char* sContext, int mode);
|
||||
|
||||
private:
|
||||
/// Destroys all commands in the manager and empties the list.
|
||||
void clearCommands();
|
||||
std::map<std::string,Command*> _sCommands;
|
||||
std::map<std::string, Command*> _sCommands;
|
||||
std::map<std::string, std::list<std::string> > _sCommandModes;
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
@ -544,6 +554,24 @@ protected: \
|
|||
virtual Gui::Action * createAction(void);\
|
||||
};
|
||||
|
||||
/** The Command Macro Standard + isActive() + updateAction()
|
||||
* This macro makes it easier to define a new command.
|
||||
* The parameters are the class name
|
||||
* @author Werner Mayer
|
||||
*/
|
||||
#define DEF_STD_CMD_AU(X) class X : public Gui::Command \
|
||||
{\
|
||||
public:\
|
||||
X();\
|
||||
virtual ~X(){}\
|
||||
virtual void updateAction(int mode); \
|
||||
virtual const char* className() const\
|
||||
{ return #X; }\
|
||||
protected: \
|
||||
virtual void activated(int iMsg);\
|
||||
virtual bool isActive(void);\
|
||||
};
|
||||
|
||||
/** The Command Macro Standard + isActive() + createAction()
|
||||
* + languageChange()
|
||||
* This macro makes it easier to define a new command.
|
||||
|
@ -564,6 +592,27 @@ protected: \
|
|||
virtual Gui::Action * createAction(void);\
|
||||
};
|
||||
|
||||
/** The Command Macro Standard + isActive() + createAction()
|
||||
* + languageChange() + updateAction()
|
||||
* This macro makes it easier to define a new command.
|
||||
* The parameters are the class name
|
||||
* @author Werner Mayer
|
||||
*/
|
||||
#define DEF_STD_CMD_ACLU(X) class X : public Gui::Command \
|
||||
{\
|
||||
public:\
|
||||
X();\
|
||||
virtual ~X(){}\
|
||||
virtual void languageChange(); \
|
||||
virtual void updateAction(int mode); \
|
||||
virtual const char* className() const\
|
||||
{ return #X; }\
|
||||
protected: \
|
||||
virtual void activated(int iMsg);\
|
||||
virtual bool isActive(void);\
|
||||
virtual Gui::Action * createAction(void);\
|
||||
};
|
||||
|
||||
/** The Command Macro view
|
||||
* This macro makes it easier to define a new command for the 3D View
|
||||
* It activate the command only when a 3DView is active.
|
||||
|
|
Loading…
Reference in New Issue
Block a user