WIP: refactoring ongoing.

This commit is contained in:
Matthias Koefferlein
2020-02-07 17:33:53 +01:00
parent ce25d51763
commit 4210198179
7 changed files with 52 additions and 53 deletions
+3 -3
View File
@@ -140,7 +140,8 @@ private:
* point to. A triggered event will be forwarded from this QAction to all referencing Action objects.
*/
class LAYBASIC_PUBLIC Action
: public QObject
: public QObject,
public tl::Object
{
Q_OBJECT
@@ -410,8 +411,7 @@ private:
* respective parameters passed to the constructor or set with the write accessors.
*/
class LAYBASIC_PUBLIC ConfigureAction
: public Action,
public tl::Object
: public Action
{
public:
enum type { setter_type = 0, boolean_type = 1, choice_type = 2 };
+2 -2
View File
@@ -50,7 +50,7 @@ Dispatcher::~Dispatcher ()
}
}
lay::Action *
lay::ConfigureAction *
Dispatcher::create_config_action (const std::string &title, const std::string &cname, const std::string &cvalue)
{
lay::ConfigureAction *ca = new lay::ConfigureAction (this, title, cname, cvalue);
@@ -58,7 +58,7 @@ Dispatcher::create_config_action (const std::string &title, const std::string &c
return ca;
}
lay::Action *
lay::ConfigureAction *
Dispatcher::create_config_action (const std::string &cname, const std::string &cvalue)
{
lay::ConfigureAction *ca = new lay::ConfigureAction (this, std::string (), cname, cvalue);
+2 -2
View File
@@ -124,7 +124,7 @@ public:
*
* The action will be owned by the abstract menu provider but can be deleted to remove it from there.
*/
lay::Action *create_config_action (const std::string &title, const std::string &cname, const std::string &cvalue);
lay::ConfigureAction *create_config_action (const std::string &title, const std::string &cname, const std::string &cvalue);
/**
* @brief Creates a configuration action with the given parameter name and value
@@ -132,7 +132,7 @@ public:
* The action will be owned by the abstract menu provider but can be deleted to remove it from there.
* This version is provided for applications, where the title is set later.
*/
lay::Action *create_config_action (const std::string &cname, const std::string &cvalue);
lay::ConfigureAction *create_config_action (const std::string &cname, const std::string &cvalue);
/**
* @brief Registers a configuration action with the given name
+28 -30
View File
@@ -140,10 +140,8 @@ PluginDeclaration::mode_triggered ()
void
PluginDeclaration::clear_menu_items ()
{
while (! m_menu_actions.empty ()) {
delete m_menu_actions.back ();
m_menu_actions.pop_back ();
}
m_menu_actions.clear ();
m_our_menu_actions.clear ();
}
void
@@ -188,43 +186,40 @@ PluginDeclaration::init_menu (lay::Dispatcher *dispatcher)
for (std::vector<lay::MenuEntry>::const_iterator m = menu_entries.begin (); m != menu_entries.end (); ++m) {
if (m->title.empty ()) {
if (m->separator) {
menu.insert_separator (m->insert_pos, m->menu_name);
} else if (m->sub_menu) {
menu.insert_menu (m->insert_pos, m->menu_name, m->title);
} else {
if (m->sub_menu) {
Action *action = 0;
menu.insert_menu (m->insert_pos, m->menu_name, m->title);
if (! m->cname.empty ()) {
action = dispatcher->create_config_action (m->title, m->cname, m->cvalue);
} else {
Action *action = 0;
action = new Action (m->title);
action->qaction ()->setData (QVariant (tl::to_qstring (m->symbol)));
gtf::action_connect (action->qaction (), SIGNAL (triggered ()), this, SLOT (generic_menu ()));
m_our_menu_actions.push_back (action);
if (! m->cname.empty ()) {
}
action = dispatcher->create_config_action (m->title, m->cname, m->cvalue);
m_menu_actions.push_back (action);
menu.insert_item (m->insert_pos, m->menu_name, *action);
} else {
action = new Action (m->title);
action->qaction ()->setData (QVariant (tl::to_qstring (m->symbol)));
gtf::action_connect (action->qaction (), SIGNAL (triggered ()), this, SLOT (generic_menu ()));
}
m_menu_actions.push_back (action);
menu.insert_item (m->insert_pos, m->menu_name, *action);
if (! m->exclusive_group.empty ()) {
action->add_to_exclusive_group (&menu, m->exclusive_group);
}
if (m->checkable) {
action->set_checkable (true);
}
if (! m->exclusive_group.empty ()) {
action->add_to_exclusive_group (&menu, m->exclusive_group);
}
if (m->checkable) {
action->set_checkable (true);
}
}
@@ -282,8 +277,10 @@ PluginDeclaration::remove_menu_items ()
lay::AbstractMenu *menu = lay::Dispatcher::instance ()->menu ();
menu->delete_items (m_editable_mode_action);
menu->delete_items (m_mouse_mode_action);
for (std::vector <lay::Action *>::const_iterator a = m_menu_actions.begin (); a != m_menu_actions.end (); ++a) {
menu->delete_items (**a);
for (tl::weak_collection <lay::Action>::iterator a = m_menu_actions.begin (); a != m_menu_actions.end (); ++a) {
if (a.operator-> ()) {
menu->delete_items (*a);
}
}
}
@@ -509,6 +506,7 @@ MenuEntry separator (const std::string &menu_name, const std::string &insert_pos
MenuEntry e;
e.menu_name = menu_name;
e.insert_pos = insert_pos;
e.separator = true;
return e;
}
+4 -2
View File
@@ -102,7 +102,7 @@ public:
*/
struct LAYBASIC_PUBLIC MenuEntry
{
MenuEntry () : sub_menu (false), checkable (false) { }
MenuEntry () : sub_menu (false), checkable (false), separator (false) { }
std::string menu_name;
std::string symbol;
@@ -113,6 +113,7 @@ struct LAYBASIC_PUBLIC MenuEntry
std::string exclusive_group;
bool sub_menu;
bool checkable;
bool separator;
};
/**
@@ -464,7 +465,8 @@ private slots:
private:
int m_id;
std::vector <lay::Action *> m_menu_actions;
tl::weak_collection <lay::Action> m_menu_actions;
tl::shared_collection <lay::Action> m_our_menu_actions;
lay::Action m_editable_mode_action;
lay::Action m_mouse_mode_action;
bool m_editable_enabled;