mirror of
https://github.com/KLayout/klayout.git
synced 2026-08-31 10:06:28 +02:00
0.25.5 to 0.25.6 delta ported to pymod
- Bugfix for klayoutmatthias/issue-191 - Consistent configuration for layout views
This commit is contained in:
@@ -849,18 +849,28 @@ Class<gsi::ButtonStateNamespace> decl_ButtonState ("lay", "ButtonState",
|
||||
);
|
||||
|
||||
static std::vector<std::string>
|
||||
get_config_names (lay::PluginRoot *view)
|
||||
get_config_names (lay::PluginRoot *root)
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
view->get_config_names (names);
|
||||
root->get_config_names (names);
|
||||
return names;
|
||||
}
|
||||
|
||||
lay::PluginRoot *config_root_instance ()
|
||||
static lay::PluginRoot *config_root_instance ()
|
||||
{
|
||||
return lay::PluginRoot::instance ();
|
||||
}
|
||||
|
||||
static tl::Variant get_config (lay::PluginRoot *root, const std::string &name)
|
||||
{
|
||||
std::string value;
|
||||
if (root->config_get (name, value)) {
|
||||
return tl::Variant (value);
|
||||
} else {
|
||||
return tl::Variant ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Exposes the PluginRoot interface
|
||||
*
|
||||
@@ -868,7 +878,7 @@ lay::PluginRoot *config_root_instance ()
|
||||
* identify the plugin root node for configuration. The Plugin nature of this interface
|
||||
* is somewhat artificial and may be removed later.
|
||||
*
|
||||
* TODO: this is a duplicate of the respective methods in LayoutView and MainWindow.
|
||||
* TODO: this is a duplicate of the respective methods in LayoutView and Application.
|
||||
* This is intentional since we don't want to spend the only derivation path on this.
|
||||
* Once there is a mixin concept, provide a path through that concept.
|
||||
*/
|
||||
@@ -898,13 +908,13 @@ Class<lay::PluginRoot> decl_PluginRoot ("lay", "PluginRoot",
|
||||
"exist. If it does and an error occured, the error message is printed\n"
|
||||
"on stderr. In both cases, false is returned.\n"
|
||||
) +
|
||||
method ("get_config", (bool (lay::PluginRoot::*) (const std::string &, std::string &) const) &lay::PluginRoot::config_get,
|
||||
"@brief Get the value of a local configuration parameter\n"
|
||||
method_ext ("get_config", &get_config,
|
||||
"@brief Gets the value of a local configuration parameter\n"
|
||||
"\n"
|
||||
"@args name\n"
|
||||
"@param name The name of the configuration parameter whose value shall be obtained (a string)\n"
|
||||
"\n"
|
||||
"@return The value of the parameter\n"
|
||||
"@return The value of the parameter or nil if there is no such parameter\n"
|
||||
) +
|
||||
method ("set_config", (void (lay::PluginRoot::*) (const std::string &, const std::string &)) &lay::PluginRoot::config_set,
|
||||
"@brief Set a local configuration parameter with the given name to the given value\n"
|
||||
@@ -936,11 +946,16 @@ Class<lay::PluginRoot> decl_PluginRoot ("lay", "PluginRoot",
|
||||
),
|
||||
"@brief Root of the configuration space in the plugin context\n"
|
||||
"\n"
|
||||
"This class provides access to the root configuration space. This object provides access to the configuration space in the context "
|
||||
"of plugin programming.\n"
|
||||
"Plugins are organized in a configuration tree. Configuration settings are propagated down to the individual plugins. "
|
||||
"If there is a main window, the configuration root is identical with this object, so configuration settings "
|
||||
"applied in the configuration root are available to all views.\n"
|
||||
"This class provides access to the root configuration space in the context "
|
||||
"of plugin programming. You can use this class to obtain configuration parameters "
|
||||
"from the configuration tree during plugin initialization. However, the "
|
||||
"preferred way of plugin configuration is through \\Plugin#configure.\n"
|
||||
"\n"
|
||||
"Currently, the application object provides an identical entry point for configuration modification. "
|
||||
"For example, \"Application::instance.set_config\" is identical to \"PluginRoot::instance.set_config\". "
|
||||
"Hence there is little motivation for the PluginRoot class currently and "
|
||||
"this interface may be modified or removed in the future."
|
||||
"\n"
|
||||
"\n"
|
||||
"This class has been introduced in version 0.25.\n"
|
||||
);
|
||||
|
||||
@@ -247,9 +247,9 @@ const int timer_interval = 500;
|
||||
|
||||
static LayoutView *ms_current = 0;
|
||||
|
||||
LayoutView::LayoutView (db::Manager *manager, bool editable, lay::PluginRoot *root, QWidget *parent, const char *name, unsigned int options)
|
||||
LayoutView::LayoutView (db::Manager *manager, bool editable, lay::Plugin *plugin_parent, QWidget *parent, const char *name, unsigned int options)
|
||||
: QFrame (parent),
|
||||
lay::Plugin (root),
|
||||
lay::Plugin (plugin_parent),
|
||||
m_editable (editable),
|
||||
m_options (options),
|
||||
m_annotation_shapes (manager),
|
||||
@@ -259,7 +259,7 @@ LayoutView::LayoutView (db::Manager *manager, bool editable, lay::PluginRoot *ro
|
||||
tl::DeferredMethodScheduler::instance ();
|
||||
|
||||
setObjectName (QString::fromUtf8 (name));
|
||||
init (manager, root, parent);
|
||||
init (manager, plugin_root_maybe_null (), parent);
|
||||
}
|
||||
|
||||
LayoutView::LayoutView (lay::LayoutView *source, db::Manager *manager, bool editable, lay::PluginRoot *root, QWidget *parent, const char *name, unsigned int options)
|
||||
@@ -537,7 +537,9 @@ LayoutView::init (db::Manager *mgr, lay::PluginRoot *root, QWidget * /*parent*/)
|
||||
connect (mp_timer, SIGNAL (timeout ()), this, SLOT (timer ()));
|
||||
mp_timer->start (timer_interval);
|
||||
|
||||
create_plugins (root);
|
||||
if (root) {
|
||||
create_plugins (root);
|
||||
}
|
||||
|
||||
m_new_layer_props.layer = 1;
|
||||
m_new_layer_props.datatype = 0;
|
||||
@@ -4468,6 +4470,8 @@ LayoutView::background_color (QColor c)
|
||||
mp_canvas->set_colors (c, contrast, mp_canvas->active_color ());
|
||||
|
||||
update_content ();
|
||||
|
||||
background_color_changed_event ();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -182,7 +182,7 @@ public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
LayoutView (db::Manager *mgr, bool editable, lay::PluginRoot *root, QWidget *parent = 0, const char *name = "view", unsigned int options = (unsigned int) LV_Normal);
|
||||
LayoutView (db::Manager *mgr, bool editable, lay::Plugin *plugin_parent, QWidget *parent = 0, const char *name = "view", unsigned int options = (unsigned int) LV_Normal);
|
||||
|
||||
/**
|
||||
* @brief Constructor (clone from another view)
|
||||
@@ -651,6 +651,11 @@ public:
|
||||
*/
|
||||
tl::Event viewport_changed_event;
|
||||
|
||||
/**
|
||||
* @brief This event is triggered if the background color changed
|
||||
*/
|
||||
tl::Event background_color_changed_event;
|
||||
|
||||
/**
|
||||
* @brief An event signalling that the layer list has changed.
|
||||
*
|
||||
|
||||
@@ -305,7 +305,7 @@ Plugin::config_set (const std::string &name, const std::string &value)
|
||||
}
|
||||
}
|
||||
|
||||
do_config_set (name, value);
|
||||
do_config_set (name, value, false);
|
||||
|
||||
// schedule a configuration finalization call (once for all config_set calls)
|
||||
dm_finalize_config ();
|
||||
@@ -363,6 +363,25 @@ Plugin::get_config_names (std::vector<std::string> &names) const
|
||||
}
|
||||
}
|
||||
|
||||
PluginRoot *
|
||||
Plugin::plugin_root ()
|
||||
{
|
||||
PluginRoot *pr = plugin_root_maybe_null ();
|
||||
tl_assert (pr != 0);
|
||||
return pr;
|
||||
}
|
||||
|
||||
PluginRoot *
|
||||
Plugin::plugin_root_maybe_null ()
|
||||
{
|
||||
Plugin *p = this;
|
||||
while (p->mp_parent) {
|
||||
p = p->mp_parent;
|
||||
}
|
||||
|
||||
return dynamic_cast<PluginRoot *> (p);
|
||||
}
|
||||
|
||||
void
|
||||
Plugin::do_config_setup (Plugin *target)
|
||||
{
|
||||
@@ -371,7 +390,7 @@ Plugin::do_config_setup (Plugin *target)
|
||||
}
|
||||
// local configurations override the parent's configuration, i.e. are applied after the parents settings
|
||||
for (std::map<std::string, std::string>::const_iterator p = m_repository.begin (); p != m_repository.end (); ++p) {
|
||||
target->do_config_set (p->first, p->second);
|
||||
target->do_config_set (p->first, p->second, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,8 +404,14 @@ Plugin::do_config_end ()
|
||||
}
|
||||
|
||||
bool
|
||||
Plugin::do_config_set (const std::string &name, const std::string &value)
|
||||
Plugin::do_config_set (const std::string &name, const std::string &value, bool for_child)
|
||||
{
|
||||
if (for_child) {
|
||||
// this is the case when we impose a configuration from the parent: in this case we
|
||||
// have to remove it from the repository of local parameters.
|
||||
m_repository.erase (name);
|
||||
}
|
||||
|
||||
try {
|
||||
if (configure (name, value)) {
|
||||
// taken by us - don't propagate to the children
|
||||
@@ -398,7 +423,7 @@ Plugin::do_config_set (const std::string &name, const std::string &value)
|
||||
|
||||
// propagate to all children (not only the first that takes it!)
|
||||
for (tl::weak_collection<Plugin>::iterator c = m_children.begin (); c != m_children.end (); ++c) {
|
||||
c->do_config_set (name, value);
|
||||
c->do_config_set (name, value, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -532,7 +532,8 @@ public:
|
||||
*
|
||||
* In order to make configuration changes effective, this method
|
||||
* must be called. It calls config_finalize recursively on the
|
||||
* children.
|
||||
* children. In GUI-enabled applications this step is optional
|
||||
* and is performed automatically through a timer.
|
||||
*/
|
||||
void config_end ();
|
||||
|
||||
@@ -632,6 +633,19 @@ public:
|
||||
*/
|
||||
void get_config_names (std::vector<std::string> &names) const;
|
||||
|
||||
/**
|
||||
* @brief Gets the plugin root (the parent plugin not having another parent)
|
||||
* The returned pointer is guaranteed to be non-zero.
|
||||
*/
|
||||
PluginRoot *plugin_root ();
|
||||
|
||||
/**
|
||||
* @brief Gets the plugin root (the parent plugin not having another parent)
|
||||
* This version may return null, if the plugin is instantiated without a
|
||||
* root.
|
||||
*/
|
||||
PluginRoot *plugin_root_maybe_null ();
|
||||
|
||||
/**
|
||||
* @brief Menu command handler
|
||||
*
|
||||
@@ -761,7 +775,7 @@ private:
|
||||
/**
|
||||
* @brief Do the actual set or pass to the children if not taken
|
||||
*/
|
||||
bool do_config_set (const std::string &name, const std::string &value);
|
||||
bool do_config_set (const std::string &name, const std::string &value, bool for_child);
|
||||
|
||||
/**
|
||||
* @brief Recursively call config_finalize
|
||||
|
||||
Reference in New Issue
Block a user