Advanced search features for the cell selection form too

* Case sensitive/insensitive (persistent)
* Expressions yes/no (persistent)
* Clear button
* Tab keys to navigate between found cells
This commit is contained in:
Matthias Koefferlein 2017-03-05 00:57:42 +01:00
parent 7ddc6bf9df
commit 5f6c6a3264
3 changed files with 394 additions and 548 deletions

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>CellSelectionForm</class> <class>CellSelectionForm</class>
<widget class="QDialog" name="CellSelectionForm"> <widget class="QDialog" name="CellSelectionForm">
@ -13,12 +14,21 @@
<string>Select Cell</string> <string>Select Cell</string>
</property> </property>
<layout class="QVBoxLayout"> <layout class="QVBoxLayout">
<property name="margin" >
<number>9</number>
</property>
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </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> <item>
<widget class="QFrame" name="frame8"> <widget class="QFrame" name="frame8">
<property name="frameShape"> <property name="frameShape">
@ -28,7 +38,16 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QGridLayout"> <layout class="QGridLayout">
<property name="margin" > <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="spacing"> <property name="spacing">
@ -43,12 +62,21 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QHBoxLayout"> <layout class="QHBoxLayout">
<property name="margin" >
<number>0</number>
</property>
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<widget class="QPushButton" name="pb_hide"> <widget class="QPushButton" name="pb_hide">
<property name="text"> <property name="text">
@ -68,7 +96,7 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -79,12 +107,10 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item rowspan="2" row="3" column="0" > <item row="3" column="0" rowspan="2">
<widget class="QTreeView" name="lv_cells"> <widget class="QTreeView" name="lv_cells">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>1</horstretch> <horstretch>1</horstretch>
<verstretch>1</verstretch> <verstretch>1</verstretch>
</sizepolicy> </sizepolicy>
@ -97,12 +123,10 @@
</property> </property>
</widget> </widget>
</item> </item>
<item rowspan="2" row="4" column="2" > <item row="4" column="2" rowspan="2">
<widget class="QFrame" name="frame_6"> <widget class="QFrame" name="frame_6">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<hsizetype>5</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>1</horstretch> <horstretch>1</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -114,7 +138,16 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QGridLayout"> <layout class="QGridLayout">
<property name="margin" > <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="spacing"> <property name="spacing">
@ -123,9 +156,7 @@
<item row="2" column="2"> <item row="2" column="2">
<widget class="QToolButton" name="tb_set_child"> <widget class="QToolButton" name="tb_set_child">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<hsizetype>5</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -140,7 +171,7 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -151,9 +182,7 @@
<item row="1" column="1" colspan="2"> <item row="1" column="1" colspan="2">
<widget class="QTreeView" name="lv_children"> <widget class="QTreeView" name="lv_children">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>1</horstretch> <horstretch>1</horstretch>
<verstretch>1</verstretch> <verstretch>1</verstretch>
</sizepolicy> </sizepolicy>
@ -176,7 +205,7 @@
<string/> <string/>
</property> </property>
<property name="pixmap"> <property name="pixmap">
<pixmap resource="layResources.qrc" >:/right.png</pixmap> <pixmap resource="../lay/layResources.qrc">:/right.png</pixmap>
</property> </property>
</widget> </widget>
</item> </item>
@ -191,7 +220,7 @@
<property name="sizeType"> <property name="sizeType">
<enum>QSizePolicy::Fixed</enum> <enum>QSizePolicy::Fixed</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0">
<size> <size>
<width>451</width> <width>451</width>
<height>16</height> <height>16</height>
@ -208,19 +237,21 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QGridLayout"> <layout class="QGridLayout">
<property name="margin" > <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<item row="1" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Selected cell</string>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="layout_lbl"> <widget class="QLabel" name="layout_lbl">
<property name="text"> <property name="text">
@ -228,34 +259,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1" > <item row="1" column="0">
<widget class="QLineEdit" name="le_cell_name" > <widget class="QLabel" name="label_2">
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="1" colspan="3" >
<widget class="QComboBox" name="cb_views" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="3" >
<widget class="QLabel" name="label" >
<property name="text"> <property name="text">
<string>(* and ? can be used to match any text)</string> <string>Search</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="lay::DecoratedLineEdit" name="le_cell_name">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property> </property>
</widget> </widget>
</item> </item>
@ -268,17 +285,41 @@
<string>...</string> <string>...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="layResources.qrc" >:/find.png</iconset> <iconset resource="../lay/layResources.qrc">
<normaloff>:/find.png</normaloff>:/find.png</iconset>
</property> </property>
<property name="autoRaise"> <property name="autoRaise">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1" colspan="4">
<widget class="QComboBox" name="cb_views">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="3" colspan="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item rowspan="2" row="4" column="1" > <item row="4" column="1" rowspan="2">
<widget class="QFrame" name="frame_8"> <widget class="QFrame" name="frame_8">
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
@ -287,21 +328,28 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QVBoxLayout"> <layout class="QVBoxLayout">
<property name="margin" >
<number>0</number>
</property>
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="3" column="2"> <item row="3" column="2">
<widget class="QFrame" name="frame_5"> <widget class="QFrame" name="frame_5">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<hsizetype>5</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>1</horstretch> <horstretch>1</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -313,7 +361,16 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QGridLayout"> <layout class="QGridLayout">
<property name="margin" > <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="spacing"> <property name="spacing">
@ -324,7 +381,7 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -335,9 +392,7 @@
<item row="2" column="2"> <item row="2" column="2">
<widget class="QToolButton" name="tb_set_parent"> <widget class="QToolButton" name="tb_set_parent">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<hsizetype>5</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -350,9 +405,7 @@
<item row="1" column="1" colspan="2"> <item row="1" column="1" colspan="2">
<widget class="QTreeView" name="lv_parents"> <widget class="QTreeView" name="lv_parents">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>1</horstretch> <horstretch>1</horstretch>
<verstretch>1</verstretch> <verstretch>1</verstretch>
</sizepolicy> </sizepolicy>
@ -375,7 +428,7 @@
<string/> <string/>
</property> </property>
<property name="pixmap"> <property name="pixmap">
<pixmap resource="layResources.qrc" >:/right.png</pixmap> <pixmap resource="../lay/layResources.qrc">:/right.png</pixmap>
</property> </property>
</widget> </widget>
</item> </item>
@ -400,7 +453,7 @@
<property name="sizeType"> <property name="sizeType">
<enum>QSizePolicy::Fixed</enum> <enum>QSizePolicy::Fixed</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>20</width>
<height>10</height> <height>10</height>
@ -424,12 +477,21 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QHBoxLayout"> <layout class="QHBoxLayout">
<property name="margin" >
<number>0</number>
</property>
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<widget class="QPushButton" name="apply_button"> <widget class="QPushButton" name="apply_button">
<property name="text"> <property name="text">
@ -445,7 +507,7 @@
<property name="sizeType"> <property name="sizeType">
<enum>QSizePolicy::Expanding</enum> <enum>QSizePolicy::Expanding</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0">
<size> <size>
<width>91</width> <width>91</width>
<height>31</height> <height>31</height>
@ -476,8 +538,15 @@
</layout> </layout>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>lay::DecoratedLineEdit</class>
<extends>QLineEdit</extends>
<header>layWidgets.h</header>
</customwidget>
</customwidgets>
<resources> <resources>
<include location="layResources.qrc" /> <include location="../lay/layResources.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -44,6 +44,9 @@
namespace lay namespace lay
{ {
static const std::string cfg_cell_selection_search_case_sensitive ("cell-selection-search-case-sensitive");
static const std::string cfg_cell_selection_search_use_expressions ("cell-selection-search-use-expression");
// ------------------------------------------------------------ // ------------------------------------------------------------
CellSelectionForm::CellSelectionForm (QWidget *parent, lay::LayoutView *view, const char *name, bool simple_mode) CellSelectionForm::CellSelectionForm (QWidget *parent, lay::LayoutView *view, const char *name, bool simple_mode)
@ -61,6 +64,38 @@ CellSelectionForm::CellSelectionForm (QWidget *parent, lay::LayoutView *view, co
Ui::CellSelectionForm::setupUi (this); Ui::CellSelectionForm::setupUi (this);
le_cell_name->set_tab_signal_enabled (true);
mp_use_regular_expressions = new QAction (this);
mp_use_regular_expressions->setCheckable (true);
mp_use_regular_expressions->setChecked (true);
mp_use_regular_expressions->setText (tr ("Use expressions (use * and ? for any character)"));
mp_case_sensitive = new QAction (this);
mp_case_sensitive->setCheckable (true);
mp_case_sensitive->setChecked (true);
mp_case_sensitive->setText (tr ("Case sensitive search"));
if (lay::PluginRoot::instance ()) {
bool cs = true;
lay::PluginRoot::instance ()->config_get (cfg_cell_selection_search_case_sensitive, cs);
mp_case_sensitive->setChecked (cs);
bool ue = true;
lay::PluginRoot::instance ()->config_get (cfg_cell_selection_search_use_expressions, ue);
mp_use_regular_expressions->setChecked (ue);
}
QMenu *m = new QMenu (le_cell_name);
m->addAction (mp_use_regular_expressions);
m->addAction (mp_case_sensitive);
connect (mp_use_regular_expressions, SIGNAL (triggered ()), this, SLOT (name_changed ()));
connect (mp_case_sensitive, SIGNAL (triggered ()), this, SLOT (name_changed ()));
le_cell_name->set_clear_button_enabled (true);
le_cell_name->set_options_button_enabled (true);
le_cell_name->set_options_menu (m);
// signals and slots connections // signals and slots connections
connect (cancel_button, SIGNAL(clicked()), this, SLOT(reject())); connect (cancel_button, SIGNAL(clicked()), this, SLOT(reject()));
connect (cb_views, SIGNAL(activated(int)), this, SLOT(view_changed(int))); connect (cb_views, SIGNAL(activated(int)), this, SLOT(view_changed(int)));
@ -68,14 +103,17 @@ CellSelectionForm::CellSelectionForm (QWidget *parent, lay::LayoutView *view, co
connect (tb_set_child, SIGNAL(clicked()), this, SLOT(set_child())); connect (tb_set_child, SIGNAL(clicked()), this, SLOT(set_child()));
connect (pb_hide, SIGNAL(clicked()), this, SLOT(hide_cell())); connect (pb_hide, SIGNAL(clicked()), this, SLOT(hide_cell()));
connect (pb_show, SIGNAL(clicked()), this, SLOT(show_cell())); connect (pb_show, SIGNAL(clicked()), this, SLOT(show_cell()));
connect (le_cell_name, SIGNAL(textChanged(const QString&)), this, SLOT(name_changed(const QString&))); connect (le_cell_name, SIGNAL(textChanged(const QString&)), this, SLOT(name_changed()));
connect (ok_button, SIGNAL(clicked()), this, SLOT(accept())); connect (ok_button, SIGNAL(clicked()), this, SLOT(accept()));
connect (apply_button, SIGNAL(clicked()), this, SLOT(apply_clicked())); connect (apply_button, SIGNAL(clicked()), this, SLOT(apply_clicked()));
connect (find_next, SIGNAL(clicked()), this, SLOT(find_next_clicked())); connect (find_next, SIGNAL(clicked()), this, SLOT(find_next_clicked()));
connect (le_cell_name, SIGNAL(tab_pressed()), this, SLOT(find_next_clicked()));
connect (le_cell_name, SIGNAL(backtab_pressed()), this, SLOT(find_prev_clicked()));
connect (lv_parents, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(parent_changed(const QModelIndex &))); connect (lv_parents, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(parent_changed(const QModelIndex &)));
connect (lv_children, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(child_changed(const QModelIndex &))); connect (lv_children, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(child_changed(const QModelIndex &)));
m_cellviews.reserve (mp_view->cellviews ()); m_cellviews.reserve (mp_view->cellviews ());
for (unsigned int i = 0; i < mp_view->cellviews (); ++i) { for (unsigned int i = 0; i < mp_view->cellviews (); ++i) {
m_cellviews.push_back (mp_view->cellview (i)); m_cellviews.push_back (mp_view->cellview (i));
@ -232,10 +270,27 @@ CellSelectionForm::view_changed (int cv)
void void
CellSelectionForm::accept () CellSelectionForm::accept ()
{ {
store_config ();
commit_cv (); commit_cv ();
QDialog::accept (); QDialog::accept ();
} }
void
CellSelectionForm::reject ()
{
store_config ();
QDialog::reject ();
}
void
CellSelectionForm::store_config ()
{
if (lay::PluginRoot::instance ()) {
lay::PluginRoot::instance ()->config_set (cfg_cell_selection_search_case_sensitive, mp_case_sensitive->isChecked ());
lay::PluginRoot::instance ()->config_set (cfg_cell_selection_search_use_expressions, mp_use_regular_expressions->isChecked ());
}
}
void void
CellSelectionForm::apply_clicked() CellSelectionForm::apply_clicked()
{ {
@ -385,10 +440,33 @@ CellSelectionForm::find_next_clicked ()
} }
void void
CellSelectionForm::name_changed (const QString &s) CellSelectionForm::find_prev_clicked ()
{
lay::CellTreeModel *model = dynamic_cast<lay::CellTreeModel *> (lv_cells->model ());
if (! model) {
return;
}
QModelIndex mi = model->locate_prev ();
if (mi.isValid ()) {
m_cells_cb_enabled = false;
lv_cells->selectionModel ()->setCurrentIndex (mi, QItemSelectionModel::SelectCurrent);
lv_cells->scrollTo (mi);
update_children_list ();
update_parents_list ();
m_cells_cb_enabled = true;
}
}
void
CellSelectionForm::name_changed ()
{ {
if (m_name_cb_enabled) { if (m_name_cb_enabled) {
QString s = le_cell_name->text ();
lay::CellTreeModel *model = dynamic_cast<lay::CellTreeModel *> (lv_cells->model ()); lay::CellTreeModel *model = dynamic_cast<lay::CellTreeModel *> (lv_cells->model ());
if (! model) { if (! model) {
return; return;
@ -396,7 +474,7 @@ CellSelectionForm::name_changed (const QString &s)
QModelIndex mi; QModelIndex mi;
if (!s.isEmpty ()) { if (!s.isEmpty ()) {
mi = model->locate (tl::to_string (s).c_str (), true); mi = model->locate (tl::to_string (s).c_str (), mp_use_regular_expressions->isChecked (), mp_case_sensitive->isChecked ());
} else { } else {
model->clear_locate (); model->clear_locate ();
} }
@ -459,264 +537,6 @@ CellSelectionForm::hide_cell ()
// ------------------------------------------------------------ // ------------------------------------------------------------
SimpleCellSelectionForm::SimpleCellSelectionForm (QWidget *parent, db::Layout *layout, const char *name)
: QDialog (parent), Ui::SimpleCellSelectionForm (),
mp_layout (layout),
m_name_cb_enabled (true),
m_cells_cb_enabled (true),
m_children_cb_enabled (true),
m_parents_cb_enabled (true),
m_update_all_dm (this, &SimpleCellSelectionForm::update_all),
m_cell_index (-1)
{
setObjectName (QString::fromUtf8 (name));
Ui::SimpleCellSelectionForm::setupUi (this);
// signals and slots connections
connect (cancel_button, SIGNAL(clicked()), this, SLOT(reject()));
connect (tb_set_parent, SIGNAL(clicked()), this, SLOT(set_parent()));
connect (tb_set_child, SIGNAL(clicked()), this, SLOT(set_child()));
connect (le_cell_name, SIGNAL(textChanged(const QString&)), this, SLOT(name_changed(const QString&)));
connect (ok_button, SIGNAL(clicked()), this, SLOT(accept()));
connect (find_next, SIGNAL(clicked()), this, SLOT(find_next_clicked()));
connect (lv_parents, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(parent_changed(const QModelIndex &)));
connect (lv_children, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(child_changed(const QModelIndex &)));
lv_cells->header ()->hide ();
lv_cells->setRootIsDecorated (false);
lv_children->header ()->hide ();
lv_children->setRootIsDecorated (false);
lv_parents->header ()->hide ();
lv_parents->setRootIsDecorated (false);
ok_button->setText (QObject::tr ("Ok"));
cancel_button->setText (QObject::tr ("Cancel"));
update_cell_list ();
}
void
SimpleCellSelectionForm::set_selected_cell_index (db::cell_index_type ci)
{
if (ci != m_cell_index) {
m_cell_index = ci;
select_entry (m_cell_index);
}
}
void
SimpleCellSelectionForm::update_cell_list ()
{
if (lv_cells->model ()) {
delete lv_cells->model ();
}
lay::CellTreeModel *model = new lay::CellTreeModel (lv_cells, mp_layout, lay::CellTreeModel::Flat);
lv_cells->setModel (model);
// connect can only happen after setModel()
connect (lv_cells->selectionModel (), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(cell_changed(const QModelIndex &, const QModelIndex &)));
select_entry (m_cell_index);
}
void
SimpleCellSelectionForm::update_parents_list ()
{
m_parents_cb_enabled = false;
if (lv_parents->model ()) {
delete lv_parents->model ();
}
if (mp_layout->is_valid_cell_index (m_cell_index)) {
lv_parents->setModel (new lay::CellTreeModel (lv_parents, mp_layout, lay::CellTreeModel::Flat | lay::CellTreeModel::Parents, &mp_layout->cell (m_cell_index)));
}
m_parents_cb_enabled = true;
}
void
SimpleCellSelectionForm::update_children_list ()
{
m_children_cb_enabled = false;
if (lv_children->model ()) {
delete lv_children->model ();
}
if (mp_layout->is_valid_cell_index (m_cell_index)) {
lv_children->setModel (new lay::CellTreeModel (lv_children, mp_layout, lay::CellTreeModel::Flat | lay::CellTreeModel::Children, &mp_layout->cell (m_cell_index)));
}
m_children_cb_enabled = true;
}
void
SimpleCellSelectionForm::cell_changed (const QModelIndex &current, const QModelIndex &)
{
if (m_cells_cb_enabled) {
m_name_cb_enabled = false;
lay::CellTreeModel *model = dynamic_cast<lay::CellTreeModel *> (lv_cells->model ());
if (model) {
le_cell_name->setText (tl::to_qstring (model->cell_name (current)));
m_cell_index = model->cell_index (current);
model->clear_locate ();
} else {
m_cell_index = -1;
}
m_name_cb_enabled = true;
update_children_list ();
update_parents_list ();
}
}
void
SimpleCellSelectionForm::set_child ()
{
child_changed (lv_children->selectionModel ()->currentIndex ());
}
void
SimpleCellSelectionForm::child_changed(const QModelIndex &current)
{
if (m_children_cb_enabled && current.isValid ()) {
lay::CellTreeModel *model = dynamic_cast<lay::CellTreeModel *> (lv_children->model ());
if (model) {
select_entry (model->cell_index (lv_children->selectionModel ()->currentIndex ()));
}
}
}
void
SimpleCellSelectionForm::set_parent ()
{
parent_changed (lv_parents->selectionModel ()->currentIndex ());
}
void
SimpleCellSelectionForm::parent_changed(const QModelIndex &current)
{
if (m_parents_cb_enabled && current.isValid ()) {
lay::CellTreeModel *model = dynamic_cast<lay::CellTreeModel *> (lv_parents->model ());
if (model) {
select_entry (model->cell_index (lv_parents->selectionModel ()->currentIndex ()));
}
}
}
void
SimpleCellSelectionForm::select_entry (lay::CellView::cell_index_type ci)
{
m_cells_cb_enabled = false;
m_cell_index = ci;
lay::CellTreeModel *model = dynamic_cast<lay::CellTreeModel *> (lv_cells->model ());
if (! model) {
return;
}
// select the current entry
QModelIndex mi;
for (int c = 0; c < model->toplevel_items (); ++c) {
lay::CellTreeItem *item = model->toplevel_item (c);
if (item->cell_index () == ci) {
mi = model->model_index (item);
break;
}
}
if (mi.isValid ()) {
m_cells_cb_enabled = false;
lv_cells->selectionModel ()->setCurrentIndex (mi, QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
lv_cells->scrollTo (mi);
m_cells_cb_enabled = true;
m_name_cb_enabled = false;
le_cell_name->setText (tl::to_qstring (model->cell_name (mi)));
model->clear_locate ();
m_name_cb_enabled = true;
// do child list updates in a user event handler. Otherwise changing the models
// immediately interferes with Qt's internal logic. So we do an deferred update.
m_update_all_dm ();
}
m_cells_cb_enabled = true;
}
void
SimpleCellSelectionForm::update_all ()
{
update_children_list ();
update_parents_list ();
}
void
SimpleCellSelectionForm::find_next_clicked ()
{
lay::CellTreeModel *model = dynamic_cast<lay::CellTreeModel *> (lv_cells->model ());
if (! model) {
return;
}
QModelIndex mi = model->locate_next ();
if (mi.isValid ()) {
m_cells_cb_enabled = false;
lv_cells->selectionModel ()->setCurrentIndex (mi, QItemSelectionModel::SelectCurrent);
lv_cells->scrollTo (mi);
m_cell_index = model->cell_index (mi);
update_children_list ();
update_parents_list ();
m_cells_cb_enabled = true;
} else {
m_cell_index = -1;
}
}
void
SimpleCellSelectionForm::name_changed (const QString &s)
{
if (m_name_cb_enabled) {
lay::CellTreeModel *model = dynamic_cast<lay::CellTreeModel *> (lv_cells->model ());
if (! model) {
return;
}
QModelIndex mi = model->locate (tl::to_string (s).c_str (), true);
if (mi.isValid ()) {
m_cells_cb_enabled = false;
lv_cells->selectionModel ()->setCurrentIndex (mi, QItemSelectionModel::SelectCurrent);
lv_cells->scrollTo (mi);
m_cell_index = model->cell_index (mi);
update_children_list ();
update_parents_list ();
m_cells_cb_enabled = true;
} else {
m_cell_index = -1;
}
}
}
// ------------------------------------------------------------
LibraryCellSelectionForm::LibraryCellSelectionForm (QWidget *parent, db::Layout *layout, const char *name, bool all_cells) LibraryCellSelectionForm::LibraryCellSelectionForm (QWidget *parent, db::Layout *layout, const char *name, bool all_cells)
: QDialog (parent), Ui::LibraryCellSelectionForm (), : QDialog (parent), Ui::LibraryCellSelectionForm (),
mp_lib (0), mp_layout (layout), mp_lib (0), mp_layout (layout),

View File

@ -24,7 +24,8 @@
#ifndef HDR_layCellSelectionForm #ifndef HDR_layCellSelectionForm
#define HDR_layCellSelectionForm #define HDR_layCellSelectionForm
#include <QObject> // required during the dependency pass #include <QAction>
#include "ui_CellSelectionForm.h" #include "ui_CellSelectionForm.h"
#include "ui_SimpleCellSelectionForm.h" #include "ui_SimpleCellSelectionForm.h"
#include "ui_LibraryCellSelectionForm.h" #include "ui_LibraryCellSelectionForm.h"
@ -62,17 +63,18 @@ public:
const lay::CellView &selected_cellview () const; const lay::CellView &selected_cellview () const;
public slots: public slots:
virtual void view_changed(int); void view_changed(int);
virtual void cell_changed(const QModelIndex &current, const QModelIndex &); void cell_changed(const QModelIndex &current, const QModelIndex &);
virtual void child_changed(const QModelIndex &current); void child_changed(const QModelIndex &current);
virtual void parent_changed(const QModelIndex &current); void parent_changed(const QModelIndex &current);
virtual void name_changed(const QString &); void name_changed();
virtual void set_parent(); void set_parent();
virtual void set_child(); void set_child();
virtual void hide_cell(); void hide_cell();
virtual void show_cell(); void show_cell();
virtual void apply_clicked(); void apply_clicked();
virtual void find_next_clicked(); void find_next_clicked();
void find_prev_clicked();
private: private:
lay::LayoutView *mp_view; lay::LayoutView *mp_view;
@ -84,6 +86,8 @@ private:
bool m_parents_cb_enabled; bool m_parents_cb_enabled;
tl::DeferredMethod<CellSelectionForm> m_update_all_dm; tl::DeferredMethod<CellSelectionForm> m_update_all_dm;
bool m_simple_mode; bool m_simple_mode;
QAction *mp_use_regular_expressions;
QAction *mp_case_sensitive;
void update_cell_list (); void update_cell_list ();
void update_parents_list (); void update_parents_list ();
@ -91,56 +95,9 @@ private:
void update_all (); void update_all ();
void select_entry (lay::CellView::cell_index_type n); void select_entry (lay::CellView::cell_index_type n);
void commit_cv (); void commit_cv ();
void store_config ();
void accept (); void accept ();
}; void reject ();
/**
* @brief A form to select a cell from a layout
*/
class LAYBASIC_PUBLIC SimpleCellSelectionForm
: public QDialog, private Ui::SimpleCellSelectionForm
{
Q_OBJECT
public:
SimpleCellSelectionForm (QWidget *parent, db::Layout *layout, const char *name);
/**
* @brief Obtain the selected cell's index
*/
db::cell_index_type selected_cell_index () const
{
return m_cell_index;
}
/**
* @brief Set the selected cell's index
*/
void set_selected_cell_index (db::cell_index_type ci);
public slots:
virtual void cell_changed(const QModelIndex &current, const QModelIndex &);
virtual void child_changed(const QModelIndex &current);
virtual void parent_changed(const QModelIndex &current);
virtual void name_changed(const QString &);
virtual void set_parent();
virtual void set_child();
virtual void find_next_clicked();
private:
db::Layout *mp_layout;
bool m_name_cb_enabled;
bool m_cells_cb_enabled;
bool m_children_cb_enabled;
bool m_parents_cb_enabled;
tl::DeferredMethod<SimpleCellSelectionForm> m_update_all_dm;
db::cell_index_type m_cell_index;
void update_cell_list ();
void update_parents_list ();
void update_children_list ();
void update_all ();
void select_entry (lay::CellView::cell_index_type n);
}; };
/** /**