mirror of
https://github.com/KLayout/klayout.git
synced 2026-09-06 01:07:36 +02:00
WIP: preparing integration of editor options pages and config pages into plugin API
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
|
||||
/*
|
||||
|
||||
KLayout Layout Viewer
|
||||
Copyright (C) 2006-2025 Matthias Koefferlein
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#if defined(HAVE_QT)
|
||||
|
||||
#include "tlInternational.h"
|
||||
#include "layEditorOptionsPage.h"
|
||||
#include "layEditorOptionsPages.h"
|
||||
#include "layLayoutViewBase.h"
|
||||
|
||||
namespace lay
|
||||
{
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// EditorOptionsPage implementation
|
||||
|
||||
EditorOptionsPage::EditorOptionsPage (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher)
|
||||
: QWidget (0), mp_owner (0), m_active (true), mp_plugin_declaration (0), mp_dispatcher (dispatcher), mp_view (view)
|
||||
{
|
||||
attach_events ();
|
||||
}
|
||||
|
||||
EditorOptionsPage::~EditorOptionsPage ()
|
||||
{
|
||||
set_owner (0);
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPage::attach_events ()
|
||||
{
|
||||
detach_from_all_events ();
|
||||
view ()->active_cellview_changed_event.add (this, &EditorOptionsPage::on_active_cellview_changed);
|
||||
int cv_index = view ()->active_cellview_index ();
|
||||
if (cv_index >= 0) {
|
||||
view ()->cellview (cv_index)->technology_changed_event.add (this, &EditorOptionsPage::on_technology_changed);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPage::on_active_cellview_changed ()
|
||||
{
|
||||
active_cellview_changed ();
|
||||
attach_events ();
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPage::on_technology_changed ()
|
||||
{
|
||||
technology_changed (view ()->active_cellview_ref ()->tech_name ());
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPage::set_owner (EditorOptionsPages *owner)
|
||||
{
|
||||
if (mp_owner) {
|
||||
mp_owner->unregister_page (this);
|
||||
}
|
||||
mp_owner = owner;
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPage::activate (bool active)
|
||||
{
|
||||
if (m_active != active) {
|
||||
m_active = active;
|
||||
if (mp_owner) {
|
||||
mp_owner->activate_page (this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,105 +0,0 @@
|
||||
|
||||
/*
|
||||
|
||||
KLayout Layout Viewer
|
||||
Copyright (C) 2006-2025 Matthias Koefferlein
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#if defined(HAVE_QT)
|
||||
|
||||
#ifndef HDR_layEditorOptionsPage
|
||||
#define HDR_layEditorOptionsPage
|
||||
|
||||
#include "layuiCommon.h"
|
||||
|
||||
#include "tlObject.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace lay
|
||||
{
|
||||
|
||||
class PluginDeclaration;
|
||||
class Dispatcher;
|
||||
class LayoutViewBase;
|
||||
class Plugin;
|
||||
class CellView;
|
||||
class EditorOptionsPages;
|
||||
|
||||
/**
|
||||
* @brief The base class for a object properties page
|
||||
*/
|
||||
class LAYUI_PUBLIC EditorOptionsPage
|
||||
: public QWidget, public tl::Object
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EditorOptionsPage (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher);
|
||||
virtual ~EditorOptionsPage ();
|
||||
|
||||
virtual std::string title () const = 0;
|
||||
virtual int order () const = 0;
|
||||
virtual void apply (lay::Dispatcher * /*root*/) { }
|
||||
virtual void setup (lay::Dispatcher * /*root*/) { }
|
||||
virtual void commit_recent (lay::Dispatcher * /*root*/) { }
|
||||
|
||||
bool active () const { return m_active; }
|
||||
void activate (bool active);
|
||||
void set_owner (EditorOptionsPages *owner);
|
||||
|
||||
const lay::PluginDeclaration *plugin_declaration () const { return mp_plugin_declaration; }
|
||||
void set_plugin_declaration (const lay::PluginDeclaration *pd) { mp_plugin_declaration = pd; }
|
||||
|
||||
protected slots:
|
||||
void edited ()
|
||||
{
|
||||
apply (dispatcher ());
|
||||
}
|
||||
|
||||
protected:
|
||||
lay::Dispatcher *dispatcher () const
|
||||
{
|
||||
return mp_dispatcher;
|
||||
}
|
||||
|
||||
lay::LayoutViewBase *view () const
|
||||
{
|
||||
return mp_view;
|
||||
}
|
||||
|
||||
virtual void active_cellview_changed () { }
|
||||
virtual void technology_changed (const std::string & /*tech*/) { }
|
||||
|
||||
private:
|
||||
EditorOptionsPages *mp_owner;
|
||||
bool m_active;
|
||||
const lay::PluginDeclaration *mp_plugin_declaration;
|
||||
lay::Dispatcher *mp_dispatcher;
|
||||
lay::LayoutViewBase *mp_view;
|
||||
|
||||
void on_active_cellview_changed ();
|
||||
void on_technology_changed ();
|
||||
void attach_events ();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // defined(HAVE_QT)
|
||||
@@ -1,218 +0,0 @@
|
||||
|
||||
/*
|
||||
|
||||
KLayout Layout Viewer
|
||||
Copyright (C) 2006-2025 Matthias Koefferlein
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#if defined(HAVE_QT)
|
||||
|
||||
#include "tlInternational.h"
|
||||
#include "layEditorOptionsPages.h"
|
||||
#include "tlExceptions.h"
|
||||
#include "layPlugin.h"
|
||||
#include "layLayoutViewBase.h"
|
||||
#include "layQtTools.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTabWidget>
|
||||
#include <QToolButton>
|
||||
#include <QCompleter>
|
||||
#include <QLineEdit>
|
||||
|
||||
namespace lay
|
||||
{
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// EditorOptionsPages implementation
|
||||
|
||||
struct EOPCompareOp
|
||||
{
|
||||
bool operator() (lay::EditorOptionsPage *a, lay::EditorOptionsPage *b) const
|
||||
{
|
||||
return a->order () < b->order ();
|
||||
}
|
||||
};
|
||||
|
||||
EditorOptionsPages::EditorOptionsPages (QWidget *parent, const std::vector<lay::EditorOptionsPage *> &pages, lay::Dispatcher *dispatcher)
|
||||
: QFrame (parent), mp_dispatcher (dispatcher)
|
||||
{
|
||||
QVBoxLayout *ly1 = new QVBoxLayout (this);
|
||||
ly1->setContentsMargins (0, 0, 0, 0);
|
||||
|
||||
mp_pages = new QTabWidget (this);
|
||||
mp_pages->setSizePolicy (QSizePolicy (QSizePolicy::Ignored, QSizePolicy::Ignored));
|
||||
ly1->addWidget (mp_pages);
|
||||
|
||||
m_pages = pages;
|
||||
for (std::vector <lay::EditorOptionsPage *>::const_iterator p = m_pages.begin (); p != m_pages.end (); ++p) {
|
||||
(*p)->set_owner (this);
|
||||
}
|
||||
|
||||
update (0);
|
||||
setup ();
|
||||
}
|
||||
|
||||
EditorOptionsPages::~EditorOptionsPages ()
|
||||
{
|
||||
while (m_pages.size () > 0) {
|
||||
delete m_pages.front ();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPages::focusInEvent (QFocusEvent * /*event*/)
|
||||
{
|
||||
// Sends the focus to the current page's last focus owner
|
||||
if (mp_pages->currentWidget () && mp_pages->currentWidget ()->focusWidget ()) {
|
||||
mp_pages->currentWidget ()->focusWidget ()->setFocus ();
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorOptionsPages::has_content () const
|
||||
{
|
||||
for (std::vector <lay::EditorOptionsPage *>::const_iterator p = m_pages.begin (); p != m_pages.end (); ++p) {
|
||||
// NOTE: we ignore unspecific pages because they are always visible and don't contribute specific content
|
||||
if ((*p)->active () && (*p)->plugin_declaration () != 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPages::unregister_page (lay::EditorOptionsPage *page)
|
||||
{
|
||||
std::vector <lay::EditorOptionsPage *> pages;
|
||||
for (std::vector <lay::EditorOptionsPage *>::const_iterator p = m_pages.begin (); p != m_pages.end (); ++p) {
|
||||
if (*p != page) {
|
||||
pages.push_back (*p);
|
||||
}
|
||||
}
|
||||
m_pages = pages;
|
||||
update (0);
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPages::activate_page (lay::EditorOptionsPage *page)
|
||||
{
|
||||
try {
|
||||
if (page->active ()) {
|
||||
page->setup (mp_dispatcher);
|
||||
}
|
||||
} catch (...) {
|
||||
// catch any errors related to configuration file errors etc.
|
||||
}
|
||||
|
||||
update (page);
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPages::update (lay::EditorOptionsPage *page)
|
||||
{
|
||||
std::vector <lay::EditorOptionsPage *> sorted_pages = m_pages;
|
||||
std::sort (sorted_pages.begin (), sorted_pages.end (), EOPCompareOp ());
|
||||
|
||||
if (! page && m_pages.size () > 0) {
|
||||
page = m_pages.back ();
|
||||
}
|
||||
|
||||
while (mp_pages->count () > 0) {
|
||||
mp_pages->removeTab (0);
|
||||
}
|
||||
int index = -1;
|
||||
for (std::vector <lay::EditorOptionsPage *>::iterator p = sorted_pages.begin (); p != sorted_pages.end (); ++p) {
|
||||
if ((*p)->active ()) {
|
||||
if ((*p) == page) {
|
||||
index = mp_pages->count ();
|
||||
}
|
||||
mp_pages->addTab (*p, tl::to_qstring ((*p)->title ()));
|
||||
} else {
|
||||
(*p)->setParent (0);
|
||||
}
|
||||
}
|
||||
if (index < 0) {
|
||||
index = mp_pages->currentIndex ();
|
||||
}
|
||||
if (index >= int (mp_pages->count ())) {
|
||||
index = mp_pages->count () - 1;
|
||||
}
|
||||
mp_pages->setCurrentIndex (index);
|
||||
|
||||
setVisible (mp_pages->count () > 0);
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPages::setup ()
|
||||
{
|
||||
try {
|
||||
|
||||
for (std::vector <lay::EditorOptionsPage *>::iterator p = m_pages.begin (); p != m_pages.end (); ++p) {
|
||||
if ((*p)->active ()) {
|
||||
(*p)->setup (mp_dispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
// make the display consistent with the status (this is important for
|
||||
// PCell parameters where the PCell may be asked to modify the parameters)
|
||||
do_apply ();
|
||||
|
||||
} catch (...) {
|
||||
// catch any errors related to configuration file errors etc.
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPages::do_apply ()
|
||||
{
|
||||
for (std::vector <lay::EditorOptionsPage *>::iterator p = m_pages.begin (); p != m_pages.end (); ++p) {
|
||||
if ((*p)->active ()) {
|
||||
// NOTE: we apply to the root dispatcher, so other dispatchers (views) get informed too.
|
||||
(*p)->apply (mp_dispatcher->dispatcher ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPages::apply ()
|
||||
{
|
||||
BEGIN_PROTECTED
|
||||
do_apply ();
|
||||
END_PROTECTED_W (this)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Indicates an error on a line edit
|
||||
|
||||
template <class Value>
|
||||
static void configure_from_line_edit (lay::Dispatcher *dispatcher, QLineEdit *le, const std::string &cfg_name)
|
||||
{
|
||||
try {
|
||||
Value value = Value (0);
|
||||
tl::from_string_ext (tl::to_string (le->text ()), value);
|
||||
dispatcher->config_set (cfg_name, tl::to_string (value));
|
||||
lay::indicate_error (le, (tl::Exception *) 0);
|
||||
} catch (tl::Exception &ex) {
|
||||
lay::indicate_error (le, &ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,87 +0,0 @@
|
||||
|
||||
/*
|
||||
|
||||
KLayout Layout Viewer
|
||||
Copyright (C) 2006-2025 Matthias Koefferlein
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#if defined(HAVE_QT)
|
||||
|
||||
#ifndef HDR_layEditorOptionsPages
|
||||
#define HDR_layEditorOptionsPages
|
||||
|
||||
#include "layuiCommon.h"
|
||||
#include "layEditorOptionsPage.h"
|
||||
|
||||
#include <tlVariant.h>
|
||||
|
||||
#include <QFrame>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class QTabWidget;
|
||||
class QLabel;
|
||||
|
||||
namespace lay
|
||||
{
|
||||
|
||||
class PluginDeclaration;
|
||||
class Dispatcher;
|
||||
class Plugin;
|
||||
|
||||
/**
|
||||
* @brief The object properties dialog
|
||||
*/
|
||||
class LAYUI_PUBLIC EditorOptionsPages
|
||||
: public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EditorOptionsPages (QWidget *parent, const std::vector<lay::EditorOptionsPage *> &pages, lay::Dispatcher *root);
|
||||
~EditorOptionsPages ();
|
||||
|
||||
void unregister_page (lay::EditorOptionsPage *page);
|
||||
void activate_page (lay::EditorOptionsPage *page);
|
||||
void focusInEvent (QFocusEvent *event);
|
||||
|
||||
const std::vector <lay::EditorOptionsPage *> &pages () const
|
||||
{
|
||||
return m_pages;
|
||||
}
|
||||
|
||||
bool has_content () const;
|
||||
|
||||
public slots:
|
||||
void apply ();
|
||||
void setup ();
|
||||
|
||||
private:
|
||||
std::vector <lay::EditorOptionsPage *> m_pages;
|
||||
lay::Dispatcher *mp_dispatcher;
|
||||
QTabWidget *mp_pages;
|
||||
|
||||
void update (lay::EditorOptionsPage *page);
|
||||
void do_apply ();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // defined(HAVE_QT)
|
||||
@@ -104,8 +104,6 @@ SOURCES = \
|
||||
layEditStippleWidget.cc \
|
||||
layEditStipplesForm.cc \
|
||||
layEditorOptionsFrame.cc \
|
||||
layEditorOptionsPage.cc \
|
||||
layEditorOptionsPages.cc \
|
||||
layFileDialog.cc \
|
||||
layGenericSyntaxHighlighter.cc \
|
||||
layHierarchyControlPanel.cc \
|
||||
@@ -164,8 +162,6 @@ HEADERS = \
|
||||
layEditStippleWidget.h \
|
||||
layEditStipplesForm.h \
|
||||
layEditorOptionsFrame.h \
|
||||
layEditorOptionsPage.h \
|
||||
layEditorOptionsPages.h \
|
||||
layFileDialog.h \
|
||||
layGenericSyntaxHighlighter.h \
|
||||
layHierarchyControlPanel.h \
|
||||
|
||||
Reference in New Issue
Block a user