diff --git a/src/laybasic/CellSelectionForm.ui b/src/laybasic/CellSelectionForm.ui index d3d3f7abb..659d671a5 100644 --- a/src/laybasic/CellSelectionForm.ui +++ b/src/laybasic/CellSelectionForm.ui @@ -1,7 +1,8 @@ - + + CellSelectionForm - - + + 0 0 @@ -9,66 +10,93 @@ 612 - + Select Cell - - - 9 - - + + 6 + + 9 + + + 9 + + + 9 + + + 9 + - - + + QFrame::NoFrame - + QFrame::Raised - - + + 0 - + + 0 + + + 0 + + + 0 + + 6 - - - + + + QFrame::NoFrame - + QFrame::Raised - - - 0 - - + + 6 + + 0 + + + 0 + + + 0 + + + 0 + - - + + Hide Cell - - + + Show Cell - + Qt::Horizontal - + 40 20 @@ -79,68 +107,71 @@ - - - - - 7 - 7 + + + + 1 1 - + QAbstractItemView::ExtendedSelection - + true - - - - - 5 - 5 + + + + 1 0 - + QFrame::NoFrame - + QFrame::Raised - - + + 0 - + + 0 + + + 0 + + + 0 + + 6 - - - - - 5 - 5 + + + + 0 0 - + Select - + - + Qt::Horizontal - + 40 20 @@ -148,50 +179,48 @@ - - - - - 7 - 7 + + + + 1 1 - + true - - - + + + Children - - - + + + - - :/right.png + + :/right.png - + - + Qt::Vertical - + QSizePolicy::Fixed - + 451 16 @@ -199,132 +228,87 @@ - - - + + + QFrame::NoFrame - + QFrame::Raised - - + + 0 - + + 0 + + + 0 + + + 0 + + 6 - - - - Selected cell - - - - - - + + + Layout - - - - - 7 - 0 + + + + Search + + + + + + + 1 1 - - - - - 7 - 0 - 1 - 1 - - - - - - - - (* and ? can be used to match any text) - - - - - - + + + Find Next - + ... - - :/find.png + + + :/find.png:/find.png - + true - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 6 - - - - - - - - - 5 - 5 - 1 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 6 - - - - + + + + + 1 + 1 + + + + + + + Qt::Horizontal - + 40 20 @@ -332,59 +316,128 @@ - - - - - 5 - 5 + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + 1 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 0 0 - + Select - - - - - 7 - 7 + + + + 1 1 - + true - - - + + + Parents - - - + + + - - :/right.png + + :/right.png - - - + + + Cell list @@ -394,13 +447,13 @@ - + Qt::Vertical - + QSizePolicy::Fixed - + 20 10 @@ -409,43 +462,52 @@ - - + + Qt::Horizontal - - + + QFrame::NoFrame - + QFrame::Raised - - - 0 - - + + 6 + + 0 + + + 0 + + + 0 + + + 0 + - - + + Show In Tree - + Qt::Horizontal - + QSizePolicy::Expanding - + 91 31 @@ -454,18 +516,18 @@ - - + + Ok - + true - - + + Cancel @@ -475,9 +537,16 @@ - + + + + lay::DecoratedLineEdit + QLineEdit +
layWidgets.h
+
+
- +
diff --git a/src/laybasic/layCellSelectionForm.cc b/src/laybasic/layCellSelectionForm.cc index 4c7f22409..af66f9d8d 100644 --- a/src/laybasic/layCellSelectionForm.cc +++ b/src/laybasic/layCellSelectionForm.cc @@ -44,6 +44,9 @@ 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) @@ -61,6 +64,38 @@ CellSelectionForm::CellSelectionForm (QWidget *parent, lay::LayoutView *view, co 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 connect (cancel_button, SIGNAL(clicked()), this, SLOT(reject())); 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 (pb_hide, SIGNAL(clicked()), this, SLOT(hide_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 (apply_button, SIGNAL(clicked()), this, SLOT(apply_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_children, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(child_changed(const QModelIndex &))); + m_cellviews.reserve (mp_view->cellviews ()); for (unsigned int i = 0; i < mp_view->cellviews (); ++i) { m_cellviews.push_back (mp_view->cellview (i)); @@ -232,10 +270,27 @@ CellSelectionForm::view_changed (int cv) void CellSelectionForm::accept () { + store_config (); commit_cv (); 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 CellSelectionForm::apply_clicked() { @@ -384,11 +439,34 @@ CellSelectionForm::find_next_clicked () } } -void -CellSelectionForm::name_changed (const QString &s) +void +CellSelectionForm::find_prev_clicked () +{ + lay::CellTreeModel *model = dynamic_cast (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) { + QString s = le_cell_name->text (); + lay::CellTreeModel *model = dynamic_cast (lv_cells->model ()); if (! model) { return; @@ -396,7 +474,7 @@ CellSelectionForm::name_changed (const QString &s) QModelIndex mi; 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 { 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 ¤t, const QModelIndex &) -{ - if (m_cells_cb_enabled) { - - m_name_cb_enabled = false; - - lay::CellTreeModel *model = dynamic_cast (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 ¤t) -{ - if (m_children_cb_enabled && current.isValid ()) { - lay::CellTreeModel *model = dynamic_cast (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 ¤t) -{ - if (m_parents_cb_enabled && current.isValid ()) { - lay::CellTreeModel *model = dynamic_cast (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 (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 (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 (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) : QDialog (parent), Ui::LibraryCellSelectionForm (), mp_lib (0), mp_layout (layout), diff --git a/src/laybasic/layCellSelectionForm.h b/src/laybasic/layCellSelectionForm.h index c99653808..d8cbe5b97 100644 --- a/src/laybasic/layCellSelectionForm.h +++ b/src/laybasic/layCellSelectionForm.h @@ -24,7 +24,8 @@ #ifndef HDR_layCellSelectionForm #define HDR_layCellSelectionForm -#include // required during the dependency pass +#include + #include "ui_CellSelectionForm.h" #include "ui_SimpleCellSelectionForm.h" #include "ui_LibraryCellSelectionForm.h" @@ -62,17 +63,18 @@ public: const lay::CellView &selected_cellview () const; public slots: - virtual void view_changed(int); - virtual void cell_changed(const QModelIndex ¤t, const QModelIndex &); - virtual void child_changed(const QModelIndex ¤t); - virtual void parent_changed(const QModelIndex ¤t); - virtual void name_changed(const QString &); - virtual void set_parent(); - virtual void set_child(); - virtual void hide_cell(); - virtual void show_cell(); - virtual void apply_clicked(); - virtual void find_next_clicked(); + void view_changed(int); + void cell_changed(const QModelIndex ¤t, const QModelIndex &); + void child_changed(const QModelIndex ¤t); + void parent_changed(const QModelIndex ¤t); + void name_changed(); + void set_parent(); + void set_child(); + void hide_cell(); + void show_cell(); + void apply_clicked(); + void find_next_clicked(); + void find_prev_clicked(); private: lay::LayoutView *mp_view; @@ -84,6 +86,8 @@ private: bool m_parents_cb_enabled; tl::DeferredMethod m_update_all_dm; bool m_simple_mode; + QAction *mp_use_regular_expressions; + QAction *mp_case_sensitive; void update_cell_list (); void update_parents_list (); @@ -91,56 +95,9 @@ private: void update_all (); void select_entry (lay::CellView::cell_index_type n); void commit_cv (); + void store_config (); void accept (); -}; - -/** - * @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 ¤t, const QModelIndex &); - virtual void child_changed(const QModelIndex ¤t); - virtual void parent_changed(const QModelIndex ¤t); - 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 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); + void reject (); }; /**