mirror of
https://github.com/KLayout/klayout.git
synced 2026-09-07 03:21:34 +02:00
Merge pull request #390 from KLayout/issue-382
Implemented #382: text editor view for user props
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
<ui version="4.0" >
|
||||
<author></author>
|
||||
<comment></comment>
|
||||
<exportmacro></exportmacro>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SelectStippleForm</class>
|
||||
<widget class="QDialog" name="SelectStippleForm" >
|
||||
<property name="geometry" >
|
||||
<widget class="QDialog" name="SelectStippleForm">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
@@ -12,86 +10,102 @@
|
||||
<height>374</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<property name="windowTitle">
|
||||
<string>Select Stipple Pattern</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="margin" >
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<layout class="QVBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QListWidget" name="stipple_items" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>5</hsizetype>
|
||||
<vsizetype>7</vsizetype>
|
||||
<widget class="QListWidget" name="stipple_items">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="acceptDrops" >
|
||||
<property name="acceptDrops">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="showDropIndicator" stdset="0" >
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="dragEnabled" >
|
||||
<property name="dragEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="alternatingRowColors" >
|
||||
<property name="alternatingRowColors">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="selectionMode" >
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="iconSize" >
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>34</width>
|
||||
<height>36</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="movement" >
|
||||
<property name="movement">
|
||||
<enum>QListView::Static</enum>
|
||||
</property>
|
||||
<property name="viewMode" >
|
||||
<property name="viewMode">
|
||||
<enum>QListView::ListMode</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line" >
|
||||
<property name="orientation" >
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame5" >
|
||||
<property name="frameShape" >
|
||||
<widget class="QFrame" name="frame5">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow" >
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="margin" >
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>81</width>
|
||||
<height>31</height>
|
||||
@@ -100,21 +114,21 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ok_button" >
|
||||
<property name="text" >
|
||||
<widget class="QPushButton" name="ok_button">
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
<property name="default" >
|
||||
<property name="default">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancel_button" >
|
||||
<property name="text" >
|
||||
<widget class="QPushButton" name="cancel_button">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
<property name="default" >
|
||||
<property name="default">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -124,11 +138,8 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11" />
|
||||
<pixmapfunction></pixmapfunction>
|
||||
<resources>
|
||||
<include location="layResources.qrc" />
|
||||
</resources>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>ok_button</sender>
|
||||
@@ -136,11 +147,11 @@
|
||||
<receiver>SelectStippleForm</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<hint type="sourcelabel">
|
||||
<x>182</x>
|
||||
<y>334</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<hint type="destinationlabel">
|
||||
<x>163</x>
|
||||
<y>178</y>
|
||||
</hint>
|
||||
@@ -152,11 +163,11 @@
|
||||
<receiver>SelectStippleForm</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<hint type="sourcelabel">
|
||||
<x>275</x>
|
||||
<y>334</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<hint type="destinationlabel">
|
||||
<x>163</x>
|
||||
<y>178</y>
|
||||
</hint>
|
||||
|
||||
@@ -1,179 +1,198 @@
|
||||
<ui version="4.0" >
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>UserPropertiesForm</class>
|
||||
<widget class="QDialog" name="UserPropertiesForm" >
|
||||
<property name="geometry" >
|
||||
<widget class="QDialog" name="UserPropertiesForm">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>424</width>
|
||||
<height>305</height>
|
||||
<height>428</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<property name="windowTitle">
|
||||
<string>User Properties</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<property name="margin" >
|
||||
<layout class="QGridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>0</number>
|
||||
<property name="topMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item row="1" column="0" colspan="2" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>332</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2" >
|
||||
<widget class="QLabel" name="title_lbl" >
|
||||
<property name="text" >
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="title_lbl">
|
||||
<property name="text">
|
||||
<string>User properties</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2" >
|
||||
<widget class="QDialogButtonBox" name="buttonBox" >
|
||||
<property name="orientation" >
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons" >
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" >
|
||||
<widget class="QTreeWidget" name="prop_list" >
|
||||
<property name="rootIsDecorated" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="allColumnsShowFocus" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text" >
|
||||
<string>Key</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text" >
|
||||
<string>Value</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" >
|
||||
<widget class="QFrame" name="edit_frame" >
|
||||
<property name="frameShape" >
|
||||
<item row="3" column="1">
|
||||
<widget class="QFrame" name="edit_frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow" >
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<property name="margin" >
|
||||
<layout class="QGridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="3" column="2" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>61</width>
|
||||
<height>114</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item rowspan="4" row="0" column="0" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>6</width>
|
||||
<height>201</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2" >
|
||||
<widget class="QPushButton" name="edit_pb" >
|
||||
<property name="text" >
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2" >
|
||||
<widget class="QPushButton" name="add_pb" >
|
||||
<property name="text" >
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset resource="layResources.qrc" >:/add.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="2" >
|
||||
<widget class="QPushButton" name="remove_pb" >
|
||||
<property name="text" >
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset resource="layResources.qrc" >:/del.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
<item row="1" column="0">
|
||||
<widget class="QTabWidget" name="mode_tab">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>332</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Table</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="1" rowspan="4">
|
||||
<spacer name="spacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>6</width>
|
||||
<height>201</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="add_pb">
|
||||
<property name="text">
|
||||
<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="2">
|
||||
<widget class="QPushButton" name="remove_pb">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../lay/lay/layResources.qrc">
|
||||
<normaloff>:/del.png</normaloff>:/del.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="edit_pb">
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<spacer name="spacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>61</width>
|
||||
<height>211</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="4">
|
||||
<widget class="QTreeWidget" name="prop_list">
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="allColumnsShowFocus">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Key</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Value</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Text Editor</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTextEdit" name="text_edit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="help_label">
|
||||
<property name="text">
|
||||
<string><html>Use the Variant Notation for key and value (<a href="int:/about/variant_notation.xml">See here for details</a>)</html></string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11" />
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<tabstops>
|
||||
<tabstop>prop_list</tabstop>
|
||||
<tabstop>add_pb</tabstop>
|
||||
<tabstop>remove_pb</tabstop>
|
||||
<tabstop>edit_pb</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="layResources.qrc" />
|
||||
<include location="../../lay/lay/layResources.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
@@ -182,11 +201,11 @@
|
||||
<receiver>UserPropertiesForm</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<hint type="sourcelabel">
|
||||
<x>211</x>
|
||||
<y>282</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<hint type="destinationlabel">
|
||||
<x>211</x>
|
||||
<y>152</y>
|
||||
</hint>
|
||||
@@ -198,11 +217,11 @@
|
||||
<receiver>UserPropertiesForm</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<hint type="sourcelabel">
|
||||
<x>211</x>
|
||||
<y>282</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<hint type="destinationlabel">
|
||||
<x>211</x>
|
||||
<y>152</y>
|
||||
</hint>
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "layLayoutView.h"
|
||||
#include "layCellTreeModel.h"
|
||||
#include "layQtTools.h"
|
||||
#include "layGenericSyntaxHighlighter.h"
|
||||
|
||||
#include "ui_LayerSourceDialog.h"
|
||||
#include "ui_NewLayoutPropertiesDialog.h"
|
||||
@@ -55,6 +56,9 @@
|
||||
#include "ui_UserPropertiesForm.h"
|
||||
#include "ui_UserPropertiesEditForm.h"
|
||||
|
||||
#include <QResource>
|
||||
#include <QBuffer>
|
||||
|
||||
namespace lay
|
||||
{
|
||||
|
||||
@@ -1012,17 +1016,38 @@ FlattenInstOptionsDialog::exec_dialog (int &levels, bool &prune)
|
||||
// UserPropertiesForm implementation
|
||||
|
||||
UserPropertiesForm::UserPropertiesForm (QWidget *parent)
|
||||
: QDialog (parent), m_editable (false)
|
||||
: QDialog (parent), m_editable (false), mp_prep (0)
|
||||
{
|
||||
setObjectName (QString::fromUtf8 ("user_properties_form"));
|
||||
|
||||
mp_ui = new Ui::UserPropertiesForm ();
|
||||
mp_ui->setupUi (this);
|
||||
|
||||
mp_ui->text_edit->setFont (QFont ("Monospace"));
|
||||
mp_ui->text_edit->setAcceptRichText (false);
|
||||
|
||||
connect (mp_ui->add_pb, SIGNAL (clicked ()), this, SLOT (add ()));
|
||||
connect (mp_ui->remove_pb, SIGNAL (clicked ()), this, SLOT (remove ()));
|
||||
connect (mp_ui->edit_pb, SIGNAL (clicked ()), this, SLOT (edit ()));
|
||||
connect (mp_ui->prop_list, SIGNAL (itemDoubleClicked (QTreeWidgetItem *, int)), this, SLOT (dbl_clicked (QTreeWidgetItem *, int)));
|
||||
connect (mp_ui->mode_tab, SIGNAL (currentChanged (int)), this, SLOT (tab_changed (int)));
|
||||
|
||||
activate_help_links (mp_ui->help_label);
|
||||
|
||||
QResource res (tl::to_qstring (":/syntax/ur_text.xml"));
|
||||
QByteArray data ((const char *) res.data (), int (res.size ()));
|
||||
if (res.isCompressed ()) {
|
||||
data = qUncompress (data);
|
||||
}
|
||||
|
||||
QBuffer input (&data);
|
||||
input.open (QIODevice::ReadOnly);
|
||||
mp_hl_basic_attributes.reset (new GenericSyntaxHighlighterAttributes ());
|
||||
mp_hl_attributes.reset (new GenericSyntaxHighlighterAttributes (mp_hl_basic_attributes.get ()));
|
||||
lay::GenericSyntaxHighlighter *hl = new GenericSyntaxHighlighter (mp_ui->text_edit, input, mp_hl_attributes.get ());
|
||||
input.close ();
|
||||
|
||||
hl->setDocument (mp_ui->text_edit->document ());
|
||||
}
|
||||
|
||||
UserPropertiesForm::~UserPropertiesForm ()
|
||||
@@ -1031,35 +1056,12 @@ UserPropertiesForm::~UserPropertiesForm ()
|
||||
mp_ui = 0;
|
||||
}
|
||||
|
||||
bool
|
||||
UserPropertiesForm::show (lay::LayoutView *view, unsigned int cv_index, db::properties_id_type &prop_id)
|
||||
db::PropertiesRepository::properties_set
|
||||
UserPropertiesForm::get_properties (int tab)
|
||||
{
|
||||
bool ret = false;
|
||||
db::PropertiesRepository::properties_set props;
|
||||
|
||||
BEGIN_PROTECTED
|
||||
|
||||
const lay::CellView &cv = view->cellview (cv_index);
|
||||
db::PropertiesRepository &prep = cv->layout ().properties_repository ();
|
||||
|
||||
m_editable = cv->layout ().is_editable ();
|
||||
if (m_editable) {
|
||||
mp_ui->edit_frame->show ();
|
||||
} else {
|
||||
mp_ui->edit_frame->hide ();
|
||||
}
|
||||
|
||||
mp_ui->prop_list->clear ();
|
||||
|
||||
const db::PropertiesRepository::properties_set &props = prep.properties (prop_id);
|
||||
for (db::PropertiesRepository::properties_set::const_iterator p = props.begin (); p != props.end (); ++p) {
|
||||
QTreeWidgetItem *entry = new QTreeWidgetItem (mp_ui->prop_list);
|
||||
entry->setText (0, tl::to_qstring (prep.prop_name (p->first).to_parsable_string ()));
|
||||
entry->setText (1, tl::to_qstring (p->second.to_parsable_string ()));
|
||||
}
|
||||
|
||||
if (exec ()) {
|
||||
|
||||
db::PropertiesRepository::properties_set props;
|
||||
if (tab == 0) {
|
||||
|
||||
QTreeWidgetItemIterator it (mp_ui->prop_list);
|
||||
while (*it) {
|
||||
@@ -1076,13 +1078,92 @@ BEGIN_PROTECTED
|
||||
kex.read (k);
|
||||
kex.expect_end ();
|
||||
|
||||
props.insert (std::make_pair (prep.prop_name_id (k), v));
|
||||
props.insert (std::make_pair (mp_prep->prop_name_id (k), v));
|
||||
|
||||
++it;
|
||||
|
||||
}
|
||||
|
||||
prop_id = prep.properties_id (props);
|
||||
} else {
|
||||
|
||||
std::string text = tl::to_string (mp_ui->text_edit->toPlainText ());
|
||||
std::vector<std::string> lines = tl::split (text, "\n");
|
||||
|
||||
for (std::vector<std::string>::const_iterator l = lines.begin (); l != lines.end (); ++l) {
|
||||
|
||||
tl::Extractor ex (l->c_str ());
|
||||
if (ex.at_end ()) {
|
||||
// empty line
|
||||
} else {
|
||||
|
||||
tl::Variant v, k;
|
||||
ex.read (k);
|
||||
ex.test (":");
|
||||
ex.read (v);
|
||||
ex.expect_end ();
|
||||
|
||||
props.insert (std::make_pair (mp_prep->prop_name_id (k), v));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return props;
|
||||
}
|
||||
|
||||
void
|
||||
UserPropertiesForm::set_properties (const db::PropertiesRepository::properties_set &props)
|
||||
{
|
||||
mp_ui->prop_list->clear ();
|
||||
|
||||
for (db::PropertiesRepository::properties_set::const_iterator p = props.begin (); p != props.end (); ++p) {
|
||||
QTreeWidgetItem *entry = new QTreeWidgetItem (mp_ui->prop_list);
|
||||
entry->setText (0, tl::to_qstring (mp_prep->prop_name (p->first).to_parsable_string ()));
|
||||
entry->setText (1, tl::to_qstring (p->second.to_parsable_string ()));
|
||||
}
|
||||
|
||||
std::string text;
|
||||
for (db::PropertiesRepository::properties_set::const_iterator p = props.begin (); p != props.end (); ++p) {
|
||||
text += mp_prep->prop_name (p->first).to_parsable_string ();
|
||||
text += ": ";
|
||||
text += p->second.to_parsable_string ();
|
||||
text += "\n";
|
||||
}
|
||||
|
||||
mp_ui->text_edit->setPlainText (tl::to_qstring (text));
|
||||
}
|
||||
|
||||
bool
|
||||
UserPropertiesForm::show (lay::LayoutView *view, unsigned int cv_index, db::properties_id_type &prop_id)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
BEGIN_PROTECTED
|
||||
|
||||
const lay::CellView &cv = view->cellview (cv_index);
|
||||
mp_prep = &cv->layout ().properties_repository ();
|
||||
|
||||
m_editable = cv->layout ().is_editable ();
|
||||
if (m_editable) {
|
||||
mp_ui->edit_frame->show ();
|
||||
} else {
|
||||
mp_ui->edit_frame->hide ();
|
||||
}
|
||||
|
||||
mp_ui->text_edit->setReadOnly (! m_editable);
|
||||
mp_ui->prop_list->clear ();
|
||||
|
||||
const db::PropertiesRepository::properties_set &props = mp_prep->properties (prop_id);
|
||||
set_properties (props);
|
||||
|
||||
if (exec ()) {
|
||||
|
||||
if (m_editable) {
|
||||
db::PropertiesRepository::properties_set props = get_properties (mp_ui->mode_tab->currentIndex ());
|
||||
prop_id = mp_prep->properties_id (props);
|
||||
}
|
||||
|
||||
ret = true;
|
||||
|
||||
@@ -1090,6 +1171,8 @@ BEGIN_PROTECTED
|
||||
ret = false;
|
||||
}
|
||||
|
||||
mp_prep = 0;
|
||||
|
||||
END_PROTECTED
|
||||
|
||||
return ret;
|
||||
@@ -1144,6 +1227,50 @@ UserPropertiesForm::dbl_clicked (QTreeWidgetItem *, int)
|
||||
edit ();
|
||||
}
|
||||
|
||||
void
|
||||
UserPropertiesForm::tab_changed (int tab_index)
|
||||
{
|
||||
if (! m_editable) {
|
||||
return;
|
||||
}
|
||||
|
||||
BEGIN_PROTECTED
|
||||
|
||||
int prev_tab = tab_index == 0 ? 1 : 0;
|
||||
|
||||
try {
|
||||
|
||||
// sync content
|
||||
set_properties (get_properties (prev_tab));
|
||||
|
||||
} catch (...) {
|
||||
|
||||
mp_ui->mode_tab->blockSignals (true);
|
||||
mp_ui->mode_tab->setCurrentIndex (prev_tab);
|
||||
mp_ui->mode_tab->blockSignals (false);
|
||||
|
||||
throw;
|
||||
|
||||
}
|
||||
|
||||
END_PROTECTED
|
||||
}
|
||||
|
||||
void
|
||||
UserPropertiesForm::accept ()
|
||||
{
|
||||
BEGIN_PROTECTED
|
||||
|
||||
// Test for errors
|
||||
if (m_editable) {
|
||||
get_properties (mp_ui->mode_tab->currentIndex ());
|
||||
}
|
||||
|
||||
QDialog::accept ();
|
||||
|
||||
END_PROTECTED
|
||||
}
|
||||
|
||||
void
|
||||
UserPropertiesForm::edit ()
|
||||
{
|
||||
|
||||
@@ -27,9 +27,11 @@
|
||||
#include "dbPoint.h"
|
||||
#include "dbVector.h"
|
||||
#include "dbTypes.h"
|
||||
#include "dbPropertiesRepository.h"
|
||||
#include "laybasicCommon.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <memory>
|
||||
|
||||
class QTreeWidgetItem;
|
||||
|
||||
@@ -39,6 +41,11 @@ namespace db
|
||||
struct LayerProperties;
|
||||
}
|
||||
|
||||
namespace lay
|
||||
{
|
||||
class GenericSyntaxHighlighterAttributes;
|
||||
}
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class LayerSourceDialog;
|
||||
@@ -412,11 +419,17 @@ public slots:
|
||||
void remove ();
|
||||
void edit ();
|
||||
void dbl_clicked (QTreeWidgetItem *, int);
|
||||
void tab_changed (int);
|
||||
|
||||
private:
|
||||
bool m_editable;
|
||||
db::PropertiesRepository::properties_set get_properties (int tab);
|
||||
void set_properties (const db::PropertiesRepository::properties_set &props);
|
||||
void accept ();
|
||||
|
||||
bool m_editable;
|
||||
db::PropertiesRepository *mp_prep;
|
||||
Ui::UserPropertiesForm *mp_ui;
|
||||
std::auto_ptr<lay::GenericSyntaxHighlighterAttributes> mp_hl_attributes, mp_hl_basic_attributes;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -432,7 +445,6 @@ public:
|
||||
bool show (QString &key, QString &value);
|
||||
virtual void accept ();
|
||||
|
||||
private:
|
||||
Ui::UserPropertiesEditForm *mp_ui;
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,737 @@
|
||||
|
||||
/*
|
||||
|
||||
KLayout Layout Viewer
|
||||
Copyright (C) 2006-2019 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
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HDR_layGenericSyntaxHighlighter
|
||||
#define HDR_layGenericSyntaxHighlighter
|
||||
|
||||
#include "tlString.h"
|
||||
#include "laybasicCommon.h"
|
||||
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <QString>
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
namespace lay
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Specifies one element in the text block's user data
|
||||
*/
|
||||
struct LAYBASIC_PUBLIC SyntaxHighlighterElement
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor
|
||||
*/
|
||||
SyntaxHighlighterElement ()
|
||||
: start_offset (0), length (0), basic_attribute_id (0)
|
||||
{
|
||||
// .. nothing yet ..
|
||||
}
|
||||
|
||||
size_t start_offset, length;
|
||||
int basic_attribute_id;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The user data the highlighter attaches to the current block
|
||||
*
|
||||
* The user data will contain useful data for bracket detection and other things
|
||||
*/
|
||||
class LAYBASIC_PUBLIC SyntaxHighlighterUserData
|
||||
: public QTextBlockUserData
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
SyntaxHighlighterUserData ()
|
||||
{
|
||||
// .. nothing yet ..
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The elements
|
||||
* These objects will specific the elements that make up the block.
|
||||
*/
|
||||
std::vector<SyntaxHighlighterElement> &elements ()
|
||||
{
|
||||
return m_elements;
|
||||
}
|
||||
|
||||
public:
|
||||
std::vector<SyntaxHighlighterElement> m_elements;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A rule implementation base class
|
||||
*
|
||||
* Rule implementations must implement this base class in order to plug into the
|
||||
* generic syntax highlighter framework.
|
||||
*/
|
||||
class LAYBASIC_PUBLIC GenericSyntaxHighlighterRuleBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Base class constructor
|
||||
*/
|
||||
GenericSyntaxHighlighterRuleBase ();
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~GenericSyntaxHighlighterRuleBase ();
|
||||
|
||||
/**
|
||||
* @brief Matches the given string against this rule
|
||||
*
|
||||
* On success, this method returns true. It will use the input arguments for dynamic rules to replace the %N
|
||||
* placeholders.
|
||||
* If the rule matches, the end_index will be set to the end of the sequence and output_args
|
||||
* will contain any arguments matched.
|
||||
* generationId is a counter that will incremented when a new block is highlighted. This allows caching
|
||||
* matches in some cases (i.e. regexp matcher).
|
||||
*/
|
||||
virtual bool match (const QString &input, unsigned int generation_id, int index, int &end_index, const QList<QString> &input_args, QList<QString> &output_args) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Clone this rule
|
||||
*/
|
||||
virtual GenericSyntaxHighlighterRuleBase *clone () const = 0;
|
||||
|
||||
/**
|
||||
* @brief Dump this rule
|
||||
*/
|
||||
virtual void dump () const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A specialization of GenericSyntaxHighlighterRuleBase which looks for a choice of strings
|
||||
*/
|
||||
class LAYBASIC_PUBLIC GenericSyntaxHighlighterRuleStringList
|
||||
: public GenericSyntaxHighlighterRuleBase
|
||||
{
|
||||
public:
|
||||
GenericSyntaxHighlighterRuleStringList (const QList<QString> &sl);
|
||||
GenericSyntaxHighlighterRuleStringList (const std::set<QString> &s, int ml);
|
||||
|
||||
virtual GenericSyntaxHighlighterRuleBase *clone () const;
|
||||
virtual bool match (const QString &input, unsigned int /*generation_id*/, int index, int &end_index, const QList<QString> & /*input_args*/, QList<QString> & /*output_args*/) const;
|
||||
virtual void dump () const;
|
||||
|
||||
private:
|
||||
std::set<QString> m_s;
|
||||
int m_min_length;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A proxy for the actual rule implementation
|
||||
*
|
||||
* This object will forward the match request to the actual implementation.
|
||||
*/
|
||||
class LAYBASIC_PUBLIC GenericSyntaxHighlighterRule
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor
|
||||
*/
|
||||
GenericSyntaxHighlighterRule ();
|
||||
|
||||
/**
|
||||
* @brief Constructor from a rule base class, attribute ID and target context ID
|
||||
*
|
||||
* This object will become owner of the rule object.
|
||||
*/
|
||||
GenericSyntaxHighlighterRule (GenericSyntaxHighlighterRuleBase *rule, int attribute_id = -1, int target_context_id = 0, bool take_ownership = true);
|
||||
|
||||
/**
|
||||
* @brief Copy constructor
|
||||
*/
|
||||
GenericSyntaxHighlighterRule (const GenericSyntaxHighlighterRule &d);
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~GenericSyntaxHighlighterRule ();
|
||||
|
||||
/**
|
||||
* @brief Assignment operator
|
||||
*/
|
||||
GenericSyntaxHighlighterRule &operator= (const GenericSyntaxHighlighterRule &d);
|
||||
|
||||
/**
|
||||
* @brief Returns true, if this rule does not have an implementation
|
||||
*/
|
||||
bool is_null () const
|
||||
{
|
||||
return mp_rule == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the attribute associated with this context
|
||||
*/
|
||||
void set_attribute_id (int id)
|
||||
{
|
||||
m_attribute_id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the attribute associated with this context
|
||||
*/
|
||||
int attribute_id () const
|
||||
{
|
||||
return m_attribute_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the target context ID
|
||||
*/
|
||||
void set_target_context_id (int id)
|
||||
{
|
||||
m_target_context_id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the target context ID
|
||||
*/
|
||||
int target_context_id () const
|
||||
{
|
||||
return m_target_context_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the lookahead flag
|
||||
*
|
||||
* If true, the rule does not consume the match string
|
||||
*/
|
||||
void set_lookahead (bool f)
|
||||
{
|
||||
m_lookahead = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the lookahead flag
|
||||
*/
|
||||
bool lookahead () const
|
||||
{
|
||||
return m_lookahead;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the matching column
|
||||
*
|
||||
* Set this value to <0 to unset the matching column
|
||||
*/
|
||||
void set_column (int c)
|
||||
{
|
||||
m_column = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the matching column
|
||||
*/
|
||||
int column () const
|
||||
{
|
||||
return m_column;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the first non-space flag
|
||||
*
|
||||
* If true, this rule only matches if the match is the first non-space character
|
||||
* after the current position
|
||||
*/
|
||||
void set_first_non_space (bool f)
|
||||
{
|
||||
m_first_non_space = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the first non-space flag
|
||||
*/
|
||||
bool first_non_space () const
|
||||
{
|
||||
return m_first_non_space;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds a rule as a child rule
|
||||
*/
|
||||
void add_child_rule (const GenericSyntaxHighlighterRule &rule)
|
||||
{
|
||||
if (! rule.is_null ()) {
|
||||
m_child_rules.push_back (rule);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Matches the string against the given rule
|
||||
*
|
||||
* Returns true, if the rule matches. In this case, end_index will be set to the end of the sequence and
|
||||
* output_args will contain any arguments matched.
|
||||
*/
|
||||
bool match (const QString &input, unsigned int generation_id, int index, int &end_index, const QList<QString> &input_args, QList<QString> &output_args) const;
|
||||
|
||||
/**
|
||||
* @brief Dump the contents of this rule
|
||||
*/
|
||||
void dump () const;
|
||||
|
||||
private:
|
||||
GenericSyntaxHighlighterRuleBase *mp_rule;
|
||||
int m_attribute_id;
|
||||
int m_target_context_id;
|
||||
bool m_owner;
|
||||
bool m_lookahead, m_first_non_space;
|
||||
int m_column;
|
||||
|
||||
std::list<GenericSyntaxHighlighterRule> m_child_rules;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A syntax highlighter context
|
||||
*
|
||||
* A context is a number of rules that are applied sequentially. The first match is taken and determines the target context.
|
||||
* Target contexts are identified by an integer context ID, corresponding to the context names in the Kate highlighter scripts.
|
||||
* Special context ID's are 0 (#stay), -n (#pop n times).
|
||||
* A context is associated with an attribute, which is given by an integer ID.
|
||||
*/
|
||||
class LAYBASIC_PUBLIC GenericSyntaxHighlighterContext
|
||||
{
|
||||
public:
|
||||
enum {
|
||||
no_context = 0x7ffffff
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
GenericSyntaxHighlighterContext ();
|
||||
|
||||
/**
|
||||
* @brief Gets the context's Id
|
||||
*/
|
||||
int id () const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the context's name
|
||||
*/
|
||||
const QString &name () const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add a new rule with a target context
|
||||
*/
|
||||
void add_rule (const GenericSyntaxHighlighterRule &rule);
|
||||
|
||||
/**
|
||||
* @brief Sets the fallthrough context
|
||||
*
|
||||
* To disable a fallthrough context, specify no_context for the value.
|
||||
*/
|
||||
void set_fallthrough_context (int context_id)
|
||||
{
|
||||
m_fallthrough_context = context_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the fallthrough context
|
||||
*
|
||||
* This method returns no_context if no fallthrough context was specified.
|
||||
*/
|
||||
int fallthrough_context () const
|
||||
{
|
||||
return m_fallthrough_context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the line-begin context
|
||||
*
|
||||
* To disable a line-begin context, specify no_context for the value.
|
||||
*/
|
||||
void set_linebegin_context (int context_id)
|
||||
{
|
||||
m_linebegin_context = context_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the line-begin context
|
||||
*
|
||||
* This method returns no_context if no line-begin context was specified.
|
||||
*/
|
||||
int linebegin_context () const
|
||||
{
|
||||
return m_linebegin_context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the line-end context
|
||||
*
|
||||
* To disable a line-end context, specify no_context for the value.
|
||||
*/
|
||||
void set_lineend_context (int context_id)
|
||||
{
|
||||
m_lineend_context = context_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the line-end context
|
||||
*
|
||||
* This method returns no_context if no line-end context was specified.
|
||||
*/
|
||||
int lineend_context () const
|
||||
{
|
||||
return m_lineend_context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the attribute associated with this context
|
||||
*/
|
||||
void set_attribute_id (int id)
|
||||
{
|
||||
m_attribute_id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the attribute associated with this context
|
||||
*/
|
||||
int attribute_id () const
|
||||
{
|
||||
return m_attribute_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Include another context
|
||||
*/
|
||||
void include (const GenericSyntaxHighlighterContext &other);
|
||||
|
||||
/**
|
||||
* @brief Match the context against the given string and return true, if any rule matches
|
||||
*
|
||||
* If any rule matches, this method will return true. In that case, end_index to the to the next character inside
|
||||
* "string", output_args will contain the new arguments (if there are any) and new_context will be set to the new
|
||||
* context ID (0 to stay, negative for #pop's).
|
||||
* attribute_id will be set to the ID of the attribute of the rule that was found.
|
||||
*/
|
||||
bool match (const QString &string, unsigned int generation_id, int index, int &end_index, const QList<QString> &input_args, QList<QString> &output_args, int &new_context, int &attribute_id) const;
|
||||
|
||||
/**
|
||||
* @brief Dump the contents of this context
|
||||
*/
|
||||
void dump () const;
|
||||
|
||||
private:
|
||||
friend class GenericSyntaxHighlighterContexts;
|
||||
|
||||
int m_id;
|
||||
QString m_name;
|
||||
int m_fallthrough_context;
|
||||
int m_linebegin_context, m_lineend_context;
|
||||
int m_attribute_id;
|
||||
std::list<GenericSyntaxHighlighterRule> m_rules;
|
||||
|
||||
/**
|
||||
* @brief Sets the context's Id
|
||||
*/
|
||||
void set_id (int id)
|
||||
{
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the context's name
|
||||
*/
|
||||
void set_name (const QString &n)
|
||||
{
|
||||
m_name = n;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A collection of (named) contexts
|
||||
*/
|
||||
class LAYBASIC_PUBLIC GenericSyntaxHighlighterContexts
|
||||
{
|
||||
public:
|
||||
GenericSyntaxHighlighterContexts ();
|
||||
|
||||
/**
|
||||
* @brief Insert a context with the given name
|
||||
*
|
||||
* If an context with that name already exists, it is overwritten
|
||||
*/
|
||||
void insert (const QString &name, const GenericSyntaxHighlighterContext &c);
|
||||
|
||||
/**
|
||||
* @brief Gets the initial context ID
|
||||
*
|
||||
* The initial context is by default the first one that is inserted with "insert".
|
||||
*/
|
||||
int initial_context_id () const
|
||||
{
|
||||
return m_initial_context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets a context by name and creates the context if it does not exist alread
|
||||
*
|
||||
* If a new context is created, a new ID is assigned.
|
||||
*/
|
||||
GenericSyntaxHighlighterContext &context (const QString &name);
|
||||
|
||||
/**
|
||||
* @brief Gets a context by name
|
||||
*
|
||||
* If no context with that name exists, an exception is thrown.
|
||||
*/
|
||||
const GenericSyntaxHighlighterContext &context (const QString &name) const;
|
||||
|
||||
/**
|
||||
* @brief Gets a context by ID (non-const version)
|
||||
*
|
||||
* If no context with that name exists, an exception is thrown.
|
||||
*/
|
||||
GenericSyntaxHighlighterContext &context (int id);
|
||||
|
||||
/**
|
||||
* @brief Gets a context by ID
|
||||
*
|
||||
* If no context with that name exists, an exception is thrown.
|
||||
*/
|
||||
const GenericSyntaxHighlighterContext &context (int id) const;
|
||||
|
||||
/**
|
||||
* @brief Returns true, if there are no contexts
|
||||
*/
|
||||
bool is_empty () const
|
||||
{
|
||||
return m_contexts_by_name.empty ();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dump the contents
|
||||
*/
|
||||
void dump () const;
|
||||
|
||||
private:
|
||||
std::map<QString, GenericSyntaxHighlighterContext> m_contexts_by_name;
|
||||
std::vector<GenericSyntaxHighlighterContext *> m_contexts_by_id;
|
||||
int m_initial_context;
|
||||
};
|
||||
|
||||
enum def_style {
|
||||
dsNormal = 0,
|
||||
dsAlert,
|
||||
dsBaseN,
|
||||
dsChar,
|
||||
dsComment,
|
||||
dsDataType,
|
||||
dsDecVal,
|
||||
dsError,
|
||||
dsFloat,
|
||||
dsFunction,
|
||||
dsKeyword,
|
||||
dsOthers,
|
||||
dsRegionMarker,
|
||||
dsString,
|
||||
dsOperator,
|
||||
dsControlFlow,
|
||||
dsBuiltIn,
|
||||
dsVariable,
|
||||
dsExtension,
|
||||
dsPreprocessor,
|
||||
dsImport,
|
||||
dsVerbatimString,
|
||||
dsSpecialString,
|
||||
dsSpecialChar,
|
||||
dsAttribute,
|
||||
dsLast
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A collection of attributes
|
||||
*/
|
||||
class LAYBASIC_PUBLIC GenericSyntaxHighlighterAttributes
|
||||
{
|
||||
public:
|
||||
typedef std::map<QString, int>::const_iterator const_iterator;
|
||||
|
||||
/**
|
||||
* @brief The constructor
|
||||
*/
|
||||
GenericSyntaxHighlighterAttributes (const GenericSyntaxHighlighterAttributes *basic_attributes = 0);
|
||||
|
||||
/**
|
||||
* @brief Get the iterator delivering the names and ID's (begin)
|
||||
*/
|
||||
const_iterator begin () const
|
||||
{
|
||||
return m_ids.begin ();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the iterator delivering the names and ID's (end)
|
||||
*/
|
||||
const_iterator end () const
|
||||
{
|
||||
return m_ids.end ();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the attribute ID for a given name
|
||||
*
|
||||
* If no attribute with that ID exists, it is created.
|
||||
*/
|
||||
int id (const QString &name);
|
||||
|
||||
/**
|
||||
* @brief Get the attribute ID for a given name
|
||||
*
|
||||
* If no attribute with that ID exists, an exception is thrown
|
||||
*/
|
||||
int id (const QString &name) const;
|
||||
|
||||
/**
|
||||
* @brief Gets the specific style for a given attribute ID
|
||||
*/
|
||||
QTextCharFormat specific_style (int id) const;
|
||||
|
||||
/**
|
||||
* @brief Gets the basic attribute ID for a given attribute ID
|
||||
*/
|
||||
int basic_id (int id) const;
|
||||
|
||||
/**
|
||||
* @brief Set the special styles for a given attribute ID
|
||||
*/
|
||||
void set_style (int id, const QTextCharFormat &format);
|
||||
|
||||
/**
|
||||
* @brief Set the basic style and special styles for a given attribute ID
|
||||
*/
|
||||
void set_styles (int id, int basic_style_id, const QTextCharFormat &format);
|
||||
|
||||
/**
|
||||
* @brief Gets the effective format for a given ID
|
||||
*/
|
||||
QTextCharFormat format_for (int id) const;
|
||||
|
||||
/**
|
||||
* @brief Assign the styles from another set of attributes
|
||||
*
|
||||
* This method does not copy the basic_attributes pointer
|
||||
*/
|
||||
void assign (const GenericSyntaxHighlighterAttributes &other);
|
||||
|
||||
/**
|
||||
* @brief Serialize the attributes to string
|
||||
*/
|
||||
std::string to_string () const;
|
||||
|
||||
/**
|
||||
* @brief Read from a string
|
||||
*/
|
||||
void read (tl::Extractor &ex);
|
||||
|
||||
private:
|
||||
const GenericSyntaxHighlighterAttributes *mp_basic_attributes;
|
||||
std::vector<std::pair<int, QTextCharFormat> > m_attributes;
|
||||
std::map<QString, int> m_ids;
|
||||
|
||||
void add (const QString &name, int id, bool bold, bool italic, bool underline, bool strikeout, const char *foreground, const char *fg_selected, const char *background, const char *bg_selected);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The parser's state
|
||||
*/
|
||||
class LAYBASIC_PUBLIC GenericSyntaxHighlighterState
|
||||
{
|
||||
public:
|
||||
GenericSyntaxHighlighterState (const GenericSyntaxHighlighterContexts *contexts);
|
||||
|
||||
/**
|
||||
* @brief Compares this state against another (less)
|
||||
*/
|
||||
bool operator< (const GenericSyntaxHighlighterState &d) const;
|
||||
|
||||
/**
|
||||
* @brief Compares this state against another (equal)
|
||||
*/
|
||||
bool operator== (const GenericSyntaxHighlighterState &d) const;
|
||||
|
||||
/**
|
||||
* @brief Match the given string and return true if the match succeeds.
|
||||
*
|
||||
* This method will match the given string based on the current state. On success, this method modifies
|
||||
* the state and returns true. On success, end_index to the end of the sequence found, attribute_id will
|
||||
* hold the attribute ID of the rule found. def_attribute_id will always contain the attribute ID of the
|
||||
* previous state, also if the method returns false.
|
||||
*/
|
||||
bool match (const QString &string, unsigned int generation_id, int index, int &end_index, int &def_attribute_id, int &attribute_id);
|
||||
|
||||
/**
|
||||
* @brief Gets the current context ID
|
||||
*/
|
||||
int current_context_id () const;
|
||||
|
||||
private:
|
||||
std::vector<std::pair<int, QList<QString> > > m_stack;
|
||||
const GenericSyntaxHighlighterContexts *mp_contexts;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A generic syntax highlighter using "Kate"'s syntax highlight scripts
|
||||
*/
|
||||
class LAYBASIC_PUBLIC GenericSyntaxHighlighter
|
||||
: public QSyntaxHighlighter
|
||||
{
|
||||
public:
|
||||
GenericSyntaxHighlighter (QObject *parent, QIODevice &input, GenericSyntaxHighlighterAttributes *attributes);
|
||||
|
||||
/**
|
||||
* @brief Implementation of the highlighter
|
||||
*/
|
||||
void highlightBlock(const QString &text);
|
||||
|
||||
private:
|
||||
GenericSyntaxHighlighterContexts m_contexts;
|
||||
std::map<QString, GenericSyntaxHighlighterRuleStringList> m_lists;
|
||||
std::map<GenericSyntaxHighlighterState, int> m_state_cache;
|
||||
std::vector<const GenericSyntaxHighlighterState *> m_states_by_id;
|
||||
GenericSyntaxHighlighterAttributes *mp_attributes;
|
||||
unsigned int m_generation_id;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -177,7 +177,8 @@ SOURCES = \
|
||||
layNetlistCrossReferenceModel.cc \
|
||||
layNetlistBrowserTreeModel.cc \
|
||||
layLibrariesView.cc \
|
||||
layBookmarksView.cc
|
||||
layBookmarksView.cc \
|
||||
layGenericSyntaxHighlighter.cc
|
||||
|
||||
HEADERS = \
|
||||
gtf.h \
|
||||
@@ -275,7 +276,8 @@ HEADERS = \
|
||||
layNetlistCrossReferenceModel.h \
|
||||
layNetlistBrowserTreeModel.h \
|
||||
layLibrariesView.h \
|
||||
layBookmarksView.h
|
||||
layBookmarksView.h \
|
||||
layGenericSyntaxHighlighter.h
|
||||
|
||||
INCLUDEPATH += $$TL_INC $$GSI_INC $$DB_INC $$RDB_INC $$LYM_INC
|
||||
DEPENDPATH += $$TL_INC $$GSI_INC $$DB_INC $$RDB_INC $$LYM_INC
|
||||
|
||||
@@ -44,5 +44,6 @@
|
||||
<file>images/icon_device_bjt_32.png</file>
|
||||
<file>images/icon_device_bjt_24.png</file>
|
||||
<file>images/icon_device_bjt_16.png</file>
|
||||
<file>syntax/ur_text.xml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE language SYSTEM "language.dtd">
|
||||
|
||||
<language name="UserPropertiesTextFormat">
|
||||
|
||||
<highlighting>
|
||||
|
||||
<contexts>
|
||||
|
||||
<context name="Normal" attribute="Normal Text">
|
||||
|
||||
<DetectChar attribute="String" char=""" context="Quoted Key String"/>
|
||||
<DetectChar attribute="Raw String" char="'" context="Apostrophed Key String"/>
|
||||
|
||||
<RegExpr attribute="Float" String="##\s*\-?[0-9]([0-9]|_[0-9])*(\.[0-9]([0-9]|_[0-9])*)?([eE]\-?[1-9]([0-9]|_[0-9])*(\.[0-9]*)?)?" context="After Key"/>
|
||||
<RegExpr attribute="Dec" String="#\s*\-?[1-9]([0-9]|_[0-9])*" context="After Key"/>
|
||||
<RegExpr attribute="Symbol" String="[_A-Za-z0-9]+\b" context="After Key"/>
|
||||
|
||||
<RegExpr attribute="Error" String="[^\s]" context="Error"/>
|
||||
|
||||
</context>
|
||||
|
||||
<context name="After Key" attribute="Normal Text" fallthrough="true" fallthroughContext="Value" lineEndContext="Error">
|
||||
<DetectChar attribute="Normal" char=":" context="Value"/>
|
||||
<RegExpr attribute="Normal" String="\s+" context="#stay"/>
|
||||
</context>
|
||||
|
||||
<context name="Value" attribute="Normal Text" fallthrough="true" fallthroughContext="Error" lineEndContext="Error">
|
||||
|
||||
<DetectChar attribute="String" char=""" context="Quoted Value String"/>
|
||||
<DetectChar attribute="Raw String" char="'" context="Apostrophed Value String"/>
|
||||
|
||||
<RegExpr attribute="Float" String="##\s*\-?[0-9]([0-9]|_[0-9])*(\.[0-9]([0-9]|_[0-9])*)?([eE]\-?[1-9]([0-9]|_[0-9])*(\.[0-9]*)?)?" context="After Value"/>
|
||||
<RegExpr attribute="Dec" String="#\s*\-?[1-9]([0-9]|_[0-9])*" context="After Value"/>
|
||||
<RegExpr attribute="Symbol" String="[_A-Za-z0-9]+\b" context="After Value"/>
|
||||
|
||||
<RegExpr attribute="Normal" String="\s+" context="Value"/>
|
||||
|
||||
</context>
|
||||
|
||||
<context name="After Value" attribute="Normal Text" fallthrough="true" fallthroughContext="Error" lineEndContext="Normal">
|
||||
<RegExpr attribute="Normal" String="\s+" context="#stay"/>
|
||||
</context>
|
||||
|
||||
<context name="Error" attribute="Error" lineEndContext="Normal">
|
||||
</context>
|
||||
|
||||
<context name="Quoted Key String" attribute="String" lineEndContext="Error">
|
||||
<StringDetect attribute="String" String="\\" context="#stay"/>
|
||||
<RegExpr attribute="String" String="\\\"" context="#stay"/>
|
||||
<DetectChar char=""" attribute="String" context="After Key"/>
|
||||
</context>
|
||||
|
||||
<context name="Apostrophed Key String" attribute="Raw String" lineEndContext="Error">
|
||||
<StringDetect attribute="String" String="\\" context="#stay"/>
|
||||
<RegExpr attribute="String" String="\\\'" context="#stay"/>
|
||||
<DetectChar char="'" attribute="Raw String" context="After Key"/>
|
||||
</context>
|
||||
|
||||
<context name="Quoted Value String" attribute="String" lineEndContext="Error">
|
||||
<StringDetect attribute="String" String="\\" context="#stay"/>
|
||||
<RegExpr attribute="String" String="\\\"" context="#stay"/>
|
||||
<DetectChar char=""" attribute="String" context="After Value"/>
|
||||
</context>
|
||||
|
||||
<context name="Apostrophed Value String" attribute="Raw String" lineEndContext="Error">
|
||||
<StringDetect attribute="String" String="\\" context="#stay"/>
|
||||
<RegExpr attribute="String" String="\\\'" context="#stay"/>
|
||||
<DetectChar char="'" attribute="Raw String" context="After Value"/>
|
||||
</context>
|
||||
|
||||
</contexts>
|
||||
|
||||
<itemDatas>
|
||||
<itemData name="Normal Text" defStyleNum="dsNormal"/>
|
||||
|
||||
<itemData name="Dec" defStyleNum="dsDecVal"/>
|
||||
<itemData name="Float" defStyleNum="dsFloat"/>
|
||||
<itemData name="Symbol" defStyleNum="dsString" color="#D40000"/>
|
||||
<itemData name="String" defStyleNum="dsString"/>
|
||||
<itemData name="Raw String" defStyleNum="dsString" color="#DD4A4A" selColor="#DD4A4A"/>
|
||||
|
||||
<!-- use these to mark errors and alerts things -->
|
||||
<itemData name="Error" defStyleNum="dsAlert"/>
|
||||
|
||||
</itemDatas>
|
||||
|
||||
</highlighting>
|
||||
</language>
|
||||
Reference in New Issue
Block a user