mirror of https://github.com/KLayout/klayout.git
Enhancement: 'select highlighted objects' from properties dialog (object tree context menu)
This commit is contained in:
parent
872eaabb75
commit
5bd74b73bb
|
|
@ -419,6 +419,19 @@ PropertiesPage::description () const
|
|||
return tl::to_string (tr ("Rulers and Annotations"));
|
||||
}
|
||||
|
||||
void
|
||||
PropertiesPage::confine_selection (const std::vector<size_t> &remaining_entries)
|
||||
{
|
||||
std::vector <ant::Service::obj_iterator> org_selection;
|
||||
m_selection.swap (org_selection);
|
||||
for (auto i = remaining_entries.begin (); i != remaining_entries.end (); ++i) {
|
||||
m_selection.push_back (org_selection [*i]);
|
||||
}
|
||||
|
||||
mp_rulers->set_selection (m_selection);
|
||||
mp_rulers->clear_highlights ();
|
||||
}
|
||||
|
||||
void
|
||||
PropertiesPage::leave ()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ public:
|
|||
virtual void select_entries (const std::vector<size_t> &entries);
|
||||
virtual std::string description (size_t entry) const;
|
||||
virtual std::string description () const;
|
||||
virtual void confine_selection (const std::vector<size_t> &remaining_entries);
|
||||
virtual void update ();
|
||||
virtual void leave ();
|
||||
virtual bool readonly ();
|
||||
|
|
|
|||
|
|
@ -2672,6 +2672,17 @@ Service::get_selection (std::vector <obj_iterator> &sel) const
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
Service::set_selection (const std::vector<obj_iterator> &selection)
|
||||
{
|
||||
m_selected.clear ();
|
||||
for (auto i = selection.begin (); i != selection.end (); ++i) {
|
||||
m_selected.insert (std::make_pair (*i, 0));
|
||||
}
|
||||
|
||||
selection_to_view ();
|
||||
}
|
||||
|
||||
void
|
||||
Service::delete_ruler (obj_iterator pos)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -381,10 +381,15 @@ public:
|
|||
#endif
|
||||
|
||||
/**
|
||||
* @brief Get the selection for the properties page
|
||||
* @brief Gets the selection for the properties page
|
||||
*/
|
||||
void get_selection (std::vector <obj_iterator> &selection) const;
|
||||
|
||||
/**
|
||||
* @brief Sets the selection for the properties page
|
||||
*/
|
||||
void set_selection (const std::vector <obj_iterator> &selection);
|
||||
|
||||
/**
|
||||
* @brief Direct access to the selection
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -330,6 +330,26 @@ InstPropertiesPage::description () const
|
|||
return tl::to_string (tr ("Instances"));
|
||||
}
|
||||
|
||||
void
|
||||
InstPropertiesPage::confine_selection (const std::vector<size_t> &remaining_entries)
|
||||
{
|
||||
std::vector<lay::ObjectInstPath> new_selection;
|
||||
for (auto i = remaining_entries.begin (); i != remaining_entries.end (); ++i) {
|
||||
new_selection.push_back (*m_selection_ptrs [*i]);
|
||||
}
|
||||
|
||||
mp_service->set_selection (new_selection.begin (), new_selection.end ());
|
||||
|
||||
m_selection_ptrs.clear ();
|
||||
m_selection_ptrs.reserve (mp_service->selection_size ());
|
||||
for (edt::EditableSelectionIterator s = mp_service->begin_selection (); ! s.at_end (); ++s) {
|
||||
m_selection_ptrs.push_back (s.operator-> ());
|
||||
}
|
||||
|
||||
m_prop_id = 0;
|
||||
mp_service->clear_highlights ();
|
||||
}
|
||||
|
||||
void
|
||||
InstPropertiesPage::leave ()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ public:
|
|||
virtual void select_entries (const std::vector<size_t> &entries);
|
||||
virtual std::string description (size_t entry) const;
|
||||
virtual std::string description () const;
|
||||
virtual void confine_selection (const std::vector<size_t> &remaining_entries);
|
||||
virtual void leave ();
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -137,12 +137,33 @@ ShapePropertiesPage::icon (size_t entry, int w, int h) const
|
|||
|
||||
return QIcon ();
|
||||
}
|
||||
|
||||
std::string
|
||||
ShapePropertiesPage::description () const
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
void
|
||||
ShapePropertiesPage::confine_selection (const std::vector<size_t> &remaining_entries)
|
||||
{
|
||||
std::vector<lay::ObjectInstPath> new_selection;
|
||||
for (auto i = remaining_entries.begin (); i != remaining_entries.end (); ++i) {
|
||||
new_selection.push_back (*m_selection_ptrs [*i]);
|
||||
}
|
||||
|
||||
mp_service->set_selection (new_selection.begin (), new_selection.end ());
|
||||
|
||||
m_selection_ptrs.clear ();
|
||||
m_selection_ptrs.reserve (mp_service->selection_size ());
|
||||
for (edt::EditableSelectionIterator s = mp_service->begin_selection (); ! s.at_end (); ++s) {
|
||||
m_selection_ptrs.push_back (s.operator-> ());
|
||||
}
|
||||
|
||||
m_prop_id = 0;
|
||||
mp_service->clear_highlights ();
|
||||
}
|
||||
|
||||
void
|
||||
ShapePropertiesPage::leave ()
|
||||
{
|
||||
|
|
@ -661,7 +682,7 @@ BoxPropertiesPage::description (size_t entry) const
|
|||
return ShapePropertiesPage::description (entry) + " - " + tl::sprintf (tl::to_string (tr ("Box%s")), (dbu_trans * sh.box ()).to_string ());
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
BoxPropertiesPage::do_update (const db::Shape &shape, double dbu, const std::string &lname)
|
||||
{
|
||||
m_dbu = dbu;
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ public:
|
|||
virtual void select_entries (const std::vector<size_t> &entries);
|
||||
virtual std::string description (size_t entry) const;
|
||||
virtual std::string description () const;
|
||||
virtual void confine_selection (const std::vector<size_t> &remaining_entries);
|
||||
virtual QIcon icon (size_t entry, int w, int h) const;
|
||||
virtual QIcon icon (int w, int h) const { return lay::PropertiesPage::icon (w, h); }
|
||||
virtual void leave ();
|
||||
|
|
|
|||
|
|
@ -192,6 +192,19 @@ PropertiesPage::description () const
|
|||
return tl::to_string (tr ("Images"));
|
||||
}
|
||||
|
||||
void
|
||||
PropertiesPage::confine_selection (const std::vector<size_t> &remaining_entries)
|
||||
{
|
||||
std::vector <img::Service::obj_iterator> org_selection;
|
||||
m_selection.swap (org_selection);
|
||||
for (auto i = remaining_entries.begin (); i != remaining_entries.end (); ++i) {
|
||||
m_selection.push_back (org_selection [*i]);
|
||||
}
|
||||
|
||||
mp_service->set_selection (m_selection);
|
||||
mp_service->clear_highlights ();
|
||||
}
|
||||
|
||||
void
|
||||
PropertiesPage::leave ()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ public:
|
|||
virtual void select_entries (const std::vector<size_t> &entries);
|
||||
virtual std::string description (size_t entry) const;
|
||||
virtual std::string description () const;
|
||||
virtual void confine_selection (const std::vector<size_t> &remaining_entries);
|
||||
virtual void update ();
|
||||
virtual void leave ();
|
||||
virtual bool readonly ();
|
||||
|
|
|
|||
|
|
@ -1402,6 +1402,17 @@ Service::get_selection (std::vector <obj_iterator> &sel) const
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
Service::set_selection (const std::vector<obj_iterator> &selection)
|
||||
{
|
||||
m_selected.clear ();
|
||||
for (auto i = selection.begin (); i != selection.end (); ++i) {
|
||||
m_selected.insert (std::make_pair (*i, 0));
|
||||
}
|
||||
|
||||
selection_to_view ();
|
||||
}
|
||||
|
||||
void
|
||||
Service::erase_image (obj_iterator pos)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -377,10 +377,15 @@ public:
|
|||
#endif
|
||||
|
||||
/**
|
||||
* @brief Get the selection for the properties page
|
||||
* @brief Gets the selection for the properties page
|
||||
*/
|
||||
void get_selection (std::vector <obj_iterator> &selection) const;
|
||||
|
||||
/**
|
||||
* @brief Sets the selection for the properties page
|
||||
*/
|
||||
void set_selection (const std::vector <obj_iterator> &selection);
|
||||
|
||||
/**
|
||||
* @brief Direct access to the selection
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -119,6 +119,14 @@ public:
|
|||
return QIcon ();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Confines the selection to the given selection indexes
|
||||
*
|
||||
* After this operation, the selection entries are renumbered with only
|
||||
* the remaining ones present.
|
||||
*/
|
||||
virtual void confine_selection (const std::vector<size_t> &remaining_entries) = 0;
|
||||
|
||||
/**
|
||||
* @brief Update the display
|
||||
*
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@
|
|||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::ActionsContextMenu</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
|
|
@ -198,6 +201,14 @@
|
|||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<action name="action_reduce_selection">
|
||||
<property name="text">
|
||||
<string>Select highlighted rows</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Reduce selection to highlighted rows</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
|
|
|
|||
|
|
@ -160,6 +160,16 @@ public:
|
|||
emit dataChanged (index (0, 0, QModelIndex ()), index (rowCount (QModelIndex ()) - 1, columnCount (QModelIndex ()) - 1, QModelIndex ()));
|
||||
}
|
||||
|
||||
void begin_reset_model ()
|
||||
{
|
||||
beginResetModel ();
|
||||
}
|
||||
|
||||
void end_reset_model ()
|
||||
{
|
||||
endResetModel ();
|
||||
}
|
||||
|
||||
private:
|
||||
PropertiesDialog *mp_dialog;
|
||||
int m_icon_width, m_icon_height;
|
||||
|
|
@ -202,9 +212,6 @@ PropertiesDialog::PropertiesDialog (QWidget * /*parent*/, db::Manager *manager,
|
|||
connect (mp_properties_pages [i], SIGNAL (edited ()), this, SLOT (properties_edited ()));
|
||||
}
|
||||
|
||||
// Necessary to maintain the page order for UI regression testing of 0.18 vs. 0.19 (because tl::Collection has changed to order) ..
|
||||
std::reverse (mp_properties_pages.begin (), mp_properties_pages.end ());
|
||||
|
||||
// Add a label as a dummy
|
||||
mp_none = new QLabel (QObject::tr ("No object with properties to display"), mp_ui->content_frame);
|
||||
mp_none->setAlignment (Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
|
|
@ -225,7 +232,6 @@ PropertiesDialog::PropertiesDialog (QWidget * /*parent*/, db::Manager *manager,
|
|||
|
||||
update_title ();
|
||||
|
||||
// if at end disable the "Next" button and return (this may only happen at the first call)
|
||||
mp_tree_model = new PropertiesTreeModel (this, mp_ui->tree->iconSize ().width (), mp_ui->tree->iconSize ().height ());
|
||||
mp_ui->tree->setModel (mp_tree_model);
|
||||
#if QT_VERSION >= 0x50000
|
||||
|
|
@ -235,6 +241,8 @@ PropertiesDialog::PropertiesDialog (QWidget * /*parent*/, db::Manager *manager,
|
|||
#endif
|
||||
mp_ui->tree->expandAll ();
|
||||
|
||||
mp_ui->tree->addAction (mp_ui->action_reduce_selection);
|
||||
|
||||
if (mp_properties_pages.empty ()) {
|
||||
mp_ui->tree->hide ();
|
||||
}
|
||||
|
|
@ -255,6 +263,7 @@ PropertiesDialog::PropertiesDialog (QWidget * /*parent*/, db::Manager *manager,
|
|||
connect (mp_ui->prev_button, SIGNAL (clicked ()), this, SLOT (prev_pressed ()));
|
||||
connect (mp_ui->next_button, SIGNAL (clicked ()), this, SLOT (next_pressed ()));
|
||||
connect (mp_ui->apply_to_all_cbx, SIGNAL (clicked ()), this, SLOT (apply_to_all_pressed ()));
|
||||
connect (mp_ui->action_reduce_selection, SIGNAL (triggered ()), this, SLOT (reduce_selection ()));
|
||||
connect (mp_ui->tree->selectionModel (), SIGNAL (currentChanged (const QModelIndex &, const QModelIndex &)), this, SLOT (current_index_changed (const QModelIndex &, const QModelIndex &)));
|
||||
connect (mp_ui->tree->selectionModel (), SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT (selection_changed ()));
|
||||
}
|
||||
|
|
@ -311,6 +320,98 @@ PropertiesDialog::apply_to_all_pressed ()
|
|||
m_signals_enabled = true;
|
||||
}
|
||||
|
||||
void
|
||||
PropertiesDialog::reduce_selection ()
|
||||
{
|
||||
BEGIN_PROTECTED
|
||||
|
||||
// apply pending changes
|
||||
if (m_index >= 0 && m_index < int (mp_properties_pages.size ()) && ! mp_properties_pages [m_index]->readonly ()) {
|
||||
|
||||
db::Transaction t (mp_manager, tl::to_string (QObject::tr ("Apply changes")), m_transaction_id);
|
||||
|
||||
mp_properties_pages [m_index]->apply (true);
|
||||
mp_properties_pages [m_index]->update ();
|
||||
|
||||
if (! t.is_empty ()) {
|
||||
m_transaction_id = t.id ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// confine the selection
|
||||
|
||||
mp_tree_model->begin_reset_model ();
|
||||
|
||||
auto selection = mp_ui->tree->selectionModel ()->selectedIndexes ();
|
||||
|
||||
for (std::vector <lay::PropertiesPage *>::iterator p = mp_properties_pages.begin (); p != mp_properties_pages.end (); ++p) {
|
||||
|
||||
int page_index = int (p - mp_properties_pages.begin ());
|
||||
std::vector<size_t> object_indexes;
|
||||
|
||||
for (auto i = selection.begin (); i != selection.end (); ++i) {
|
||||
if (mp_tree_model->parent (*i).isValid () && mp_tree_model->page_index (*i) == page_index) {
|
||||
object_indexes.push_back (size_t (mp_tree_model->object_index (*i)));
|
||||
}
|
||||
}
|
||||
|
||||
(*p)->confine_selection (object_indexes);
|
||||
|
||||
}
|
||||
|
||||
m_signals_enabled = false;
|
||||
|
||||
// rebuild the properties pages as only the ones with remaining selection are shown
|
||||
|
||||
for (std::vector <lay::PropertiesPage *>::iterator p = mp_properties_pages.begin (); p != mp_properties_pages.end (); ++p) {
|
||||
delete *p;
|
||||
}
|
||||
mp_properties_pages.clear ();
|
||||
m_index = -1;
|
||||
|
||||
for (lay::Editables::iterator e = mp_editables->begin (); e != mp_editables->end (); ++e) {
|
||||
auto pp = e->properties_pages (mp_manager, mp_ui->content_frame);
|
||||
for (auto p = pp.begin (); p != pp.end (); ++p) {
|
||||
if ((*p)->count () == 0) {
|
||||
delete *p;
|
||||
} else {
|
||||
mp_properties_pages.push_back (*p);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < mp_properties_pages.size (); ++i) {
|
||||
mp_stack->addWidget (mp_properties_pages [i]);
|
||||
connect (mp_properties_pages [i], SIGNAL (edited ()), this, SLOT (properties_edited ()));
|
||||
}
|
||||
|
||||
// count the total number of objects
|
||||
m_objects = mp_editables->selection_size ();
|
||||
m_current_object = 0;
|
||||
|
||||
// look for next usable editable
|
||||
m_index = 0;
|
||||
m_object_indexes.clear ();
|
||||
if (m_index >= int (mp_properties_pages.size ())) {
|
||||
m_index = -1;
|
||||
} else {
|
||||
m_object_indexes.push_back (0);
|
||||
}
|
||||
|
||||
mp_tree_model->end_reset_model ();
|
||||
|
||||
update_title ();
|
||||
|
||||
mp_ui->tree->expandAll ();
|
||||
mp_ui->tree->setCurrentIndex (mp_tree_model->index_for (m_index, 0));
|
||||
|
||||
m_signals_enabled = true;
|
||||
|
||||
update_controls ();
|
||||
|
||||
END_PROTECTED
|
||||
}
|
||||
|
||||
void
|
||||
PropertiesDialog::selection_changed ()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ public slots:
|
|||
void cancel_pressed ();
|
||||
void ok_pressed ();
|
||||
void apply_to_all_pressed ();
|
||||
void reduce_selection ();
|
||||
void current_index_changed (const QModelIndex &index, const QModelIndex &previous);
|
||||
void selection_changed ();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue