mirror of
https://github.com/KLayout/klayout.git
synced 2026-08-30 09:49:21 +02:00
WIP: text edit feature for layer mapping edit widget.
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>446</width>
|
||||
<height>205</height>
|
||||
<width>536</width>
|
||||
<height>290</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -29,6 +29,19 @@
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="load_pb">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load File</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="help_label">
|
||||
<property name="sizePolicy">
|
||||
@@ -45,103 +58,114 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="load_pb">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load File</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" rowspan="6" colspan="2">
|
||||
<widget class="QListWidget" name="layer_lv">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Ignored">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QToolButton" name="add_pb">
|
||||
<property name="toolTip">
|
||||
<string>Add a new layer to the list</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../lay/layResources.qrc">
|
||||
<normaloff>:/add.png</normaloff>:/add.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QToolButton" name="delete_pb">
|
||||
<property name="toolTip">
|
||||
<string>Delete the selected layers from the list</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../lay/layResources.qrc">
|
||||
<normaloff>:/clear.png</normaloff>:/clear.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="2" rowspan="3">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>5</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<widget class="QToolButton" name="edit_pb">
|
||||
<property name="toolTip">
|
||||
<string>Edit the current layer</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../lay/layResources.qrc">
|
||||
<normaloff>:/edit.png</normaloff>:/edit.png</iconset>
|
||||
<item row="3" column="0" colspan="3">
|
||||
<widget class="QTabWidget" name="tabs">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>List</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" rowspan="4">
|
||||
<widget class="QListWidget" name="layer_lv">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Ignored">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QToolButton" name="add_pb">
|
||||
<property name="toolTip">
|
||||
<string>Add a new layer to the list</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../lay/lay/layResources.qrc">
|
||||
<normaloff>:/add.png</normaloff>:/add.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QToolButton" name="delete_pb">
|
||||
<property name="toolTip">
|
||||
<string>Delete the selected layers from the list</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../lay/lay/layResources.qrc">
|
||||
<normaloff>:/clear.png</normaloff>:/clear.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QToolButton" name="edit_pb">
|
||||
<property name="toolTip">
|
||||
<string>Edit the current layer</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../lay/lay/layResources.qrc">
|
||||
<normaloff>:/edit.png</normaloff>:/edit.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>5</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Text</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QPlainTextEdit" name="text_edit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../lay/layResources.qrc"/>
|
||||
<include location="../../lay/lay/layResources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
@@ -53,6 +53,8 @@ LayerMappingWidget::LayerMappingWidget (QWidget *parent)
|
||||
|
||||
mp_ui->layer_lv->viewport ()->acceptDrops ();
|
||||
|
||||
connect (mp_ui->tabs, SIGNAL (currentChanged (int)), this, SLOT (current_tab_changed (int)));
|
||||
|
||||
mp_layer_table_file_dialog = new lay::FileDialog (this,
|
||||
tl::to_string (QObject::tr ("Load Layer Table")),
|
||||
tl::to_string (QObject::tr ("Layer properties and text files (*.lyp *.txt);;Layer properties files (*.lyp);;Text files (*.txt);;All files (*)")));
|
||||
@@ -72,6 +74,8 @@ LayerMappingWidget::set_layer_map (const db::LayerMap &lm)
|
||||
{
|
||||
std::vector<unsigned int> layer_ids = lm.get_layers ();
|
||||
|
||||
mp_ui->text_edit->setPlainText (tl::to_qstring (lm.to_string_file_format ()));
|
||||
|
||||
mp_ui->layer_lv->reset ();
|
||||
mp_ui->layer_lv->clear ();
|
||||
|
||||
@@ -88,16 +92,31 @@ LayerMappingWidget::set_layer_map (const db::LayerMap &lm)
|
||||
|
||||
db::LayerMap
|
||||
LayerMappingWidget::get_layer_map () const
|
||||
{
|
||||
return get_layer_map_from_tab (mp_ui->tabs->currentIndex ());
|
||||
}
|
||||
|
||||
db::LayerMap
|
||||
LayerMappingWidget::get_layer_map_from_tab (int tab) const
|
||||
{
|
||||
db::LayerMap lm;
|
||||
for (int i = 0; i < mp_ui->layer_lv->count (); ++i) {
|
||||
std::string t = tl::to_string (mp_ui->layer_lv->item (i)->data (Qt::DisplayRole).toString ());
|
||||
try {
|
||||
lm.map_expr (t, (unsigned int) i);
|
||||
} catch (...) {
|
||||
mp_ui->layer_lv->setCurrentItem (mp_ui->layer_lv->item (i));
|
||||
throw;
|
||||
|
||||
if (tab == 0) {
|
||||
|
||||
for (int i = 0; i < mp_ui->layer_lv->count (); ++i) {
|
||||
std::string t = tl::to_string (mp_ui->layer_lv->item (i)->data (Qt::DisplayRole).toString ());
|
||||
try {
|
||||
lm.add_expr (t, (unsigned int) i);
|
||||
} catch (...) {
|
||||
mp_ui->layer_lv->setCurrentItem (mp_ui->layer_lv->item (i));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
lm = db::LayerMap::from_string_file_format (tl::to_string (mp_ui->text_edit->toPlainText ()));
|
||||
|
||||
}
|
||||
|
||||
return lm;
|
||||
@@ -128,17 +147,19 @@ LayerMappingWidget::load_button_pressed ()
|
||||
mp_ui->layer_lv->reset ();
|
||||
mp_ui->layer_lv->clear ();
|
||||
|
||||
db::LayerMap lm;
|
||||
|
||||
// use those layers which have cellview index 0
|
||||
unsigned int n = 0;
|
||||
for (LayerPropertiesConstIterator lay_iter = props.begin_const_recursive (); ! lay_iter.at_end (); ++lay_iter) {
|
||||
if (! lay_iter->has_children () && lay_iter->source (true /*=real*/).cv_index () == 0) {
|
||||
db::LayerProperties db_lp = lay_iter->source (true /*=real*/).layer_props ();
|
||||
QListWidgetItem *item = new QListWidgetItem (mp_ui->layer_lv);
|
||||
item->setData (Qt::DisplayRole, tl::to_qstring (db_lp.to_string ()));
|
||||
item->setFlags (item->flags () | Qt::ItemIsEditable);
|
||||
mp_ui->layer_lv->addItem (item);
|
||||
lm.map (db_lp, (unsigned int) n++);
|
||||
}
|
||||
}
|
||||
|
||||
set_layer_map (lm);
|
||||
|
||||
// if successful, stop now.
|
||||
success = true;
|
||||
|
||||
@@ -230,5 +251,11 @@ LayerMappingWidget::edit_button_pressed ()
|
||||
END_PROTECTED
|
||||
}
|
||||
|
||||
void
|
||||
LayerMappingWidget::current_tab_changed (int index)
|
||||
{
|
||||
set_layer_map (get_layer_map_from_tab (1 - index));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -84,11 +84,14 @@ private slots:
|
||||
void add_button_pressed ();
|
||||
void delete_button_pressed ();
|
||||
void edit_button_pressed ();
|
||||
void current_tab_changed (int tab);
|
||||
|
||||
private:
|
||||
lay::FileDialog *mp_layer_table_file_dialog;
|
||||
std::string m_layer_table_file;
|
||||
Ui::LayerMappingWidget *mp_ui;
|
||||
|
||||
db::LayerMap get_layer_map_from_tab (int tab) const;
|
||||
};
|
||||
|
||||
} // namespace lay
|
||||
|
||||
Reference in New Issue
Block a user