mirror of https://github.com/KLayout/klayout.git
WIP: refactoring ongoing.
This commit is contained in:
parent
ce25d51763
commit
4210198179
|
|
@ -203,9 +203,6 @@ PluginDeclaration::initialized (lay::Dispatcher *root)
|
|||
void
|
||||
PluginDeclaration::uninitialize (lay::Dispatcher *)
|
||||
{
|
||||
for (std::vector<lay::Action *>::iterator a = m_actions.begin (); a != m_actions.end (); ++a) {
|
||||
delete *a;
|
||||
}
|
||||
m_actions.clear ();
|
||||
}
|
||||
|
||||
|
|
@ -226,9 +223,13 @@ PluginDeclaration::update_current_template ()
|
|||
}
|
||||
|
||||
if (m_templates.size () > 1) {
|
||||
int it = 0;
|
||||
for (std::vector<Template>::const_iterator tt = m_templates.begin (); tt != m_templates.end () && it < int (m_actions.size ()); ++tt, ++it) {
|
||||
m_actions[it]->set_checked (it == m_current_template);
|
||||
|
||||
tl::weak_collection<lay::ConfigureAction>::iterator it = m_actions.begin ();
|
||||
int index = 0;
|
||||
for (std::vector<Template>::const_iterator tt = m_templates.begin (); tt != m_templates.end () && it != m_actions.end (); ++tt, ++it, ++index) {
|
||||
if (it.operator -> ()) {
|
||||
it->set_checked (index == m_current_template);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -263,19 +264,17 @@ PluginDeclaration::update_menu ()
|
|||
}
|
||||
}
|
||||
|
||||
for (std::vector<lay::Action *>::iterator a = m_actions.begin (); a != m_actions.end (); ++a) {
|
||||
delete *a;
|
||||
}
|
||||
m_actions.clear ();
|
||||
|
||||
if (m_templates.size () > 1) {
|
||||
int it = 0;
|
||||
for (std::vector<Template>::const_iterator tt = m_templates.begin (); tt != m_templates.end (); ++tt, ++it) {
|
||||
m_actions.push_back (mp->create_config_action (tt->title (), cfg_current_ruler_template, tl::to_string (it)));
|
||||
m_actions.back ()->set_checkable (true);
|
||||
m_actions.back ()->set_checked (it == m_current_template);
|
||||
lay::ConfigureAction *action = mp->create_config_action (tt->title (), cfg_current_ruler_template, tl::to_string (it));
|
||||
m_actions.push_back (action);
|
||||
action->set_checkable (true);
|
||||
action->set_checked (it == m_current_template);
|
||||
for (std::vector<std::string>::const_iterator t = tmpl_group.begin (); t != tmpl_group.end (); ++t) {
|
||||
mp->menu ()->insert_item (*t + ".end", "ruler_template_" + tl::to_string (it), *m_actions.back ());
|
||||
mp->menu ()->insert_item (*t + ".end", "ruler_template_" + tl::to_string (it), *action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ private:
|
|||
|
||||
std::vector<ant::Template> m_templates;
|
||||
int m_current_template;
|
||||
std::vector<lay::Action *> m_actions;
|
||||
tl::weak_collection<lay::ConfigureAction> m_actions;
|
||||
bool m_current_template_updated;
|
||||
bool m_templates_updated;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue