From 059c7ee37a6d8b1136f4fc288d1d1b7432a798be Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 5 Nov 2017 23:39:50 +0100 Subject: [PATCH] Ruler setup enhanced - Issue: on an entirely fresh installation the "Ruler" entry was not visible. Now, a new standard template called "Ruler" is present. - Ruler templates with categories cannot be deleted any more and are shown with italic font. If they were deleted, they would show up again after restart. --- src/ant/ant/antConfigPage.cc | 15 +++++++++++++++ src/ant/ant/antPlugin.cc | 19 +++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/ant/ant/antConfigPage.cc b/src/ant/ant/antConfigPage.cc index 58b2433f3..a0474b536 100644 --- a/src/ant/ant/antConfigPage.cc +++ b/src/ant/ant/antConfigPage.cc @@ -29,6 +29,7 @@ #include "antConfig.h" #include "layConverters.h" #include "layQtTools.h" +#include "tlExceptions.h" #include @@ -254,6 +255,7 @@ ConfigPage4::add_clicked () } else { new_one = m_ruler_templates [m_current_template]; } + new_one.category (std::string ()); m_ruler_templates.insert (m_ruler_templates.begin () + m_current_template, new_one); m_ruler_templates [m_current_template].title (tl::to_string (QObject::tr ("New Ruler"))); update_list (); @@ -264,7 +266,12 @@ ConfigPage4::add_clicked () void ConfigPage4::del_clicked () { +BEGIN_PROTECTED + if (m_current_template >= 0 && m_current_template < int (m_ruler_templates.size ())) { + if (! m_ruler_templates [m_current_template].category ().empty ()) { + throw tl::Exception (tl::to_string (tr ("This ruler is a built-in template and cannot be deleted"))); + } m_ruler_templates.erase (m_ruler_templates.begin () + m_current_template); if (m_current_template > 0) { --m_current_template; @@ -276,6 +283,8 @@ ConfigPage4::del_clicked () update_list (); show (); } + +END_PROTECTED } void @@ -309,6 +318,12 @@ ConfigPage4::update_list () mp_ui->template_list->clear (); for (std::vector ::const_iterator t = m_ruler_templates.begin (); t != m_ruler_templates.end (); ++t) { mp_ui->template_list->addItem (tl::to_qstring (t->title ())); + if (! t->category ().empty ()) { + QListWidgetItem *item = mp_ui->template_list->item (int (t - m_ruler_templates.begin ())); + QFont font = item->font (); + font.setItalic (true); + item->setFont (font); + } } mp_ui->template_list->setCurrentRow (m_current_template); m_current_changed_enabled = true; diff --git a/src/ant/ant/antPlugin.cc b/src/ant/ant/antPlugin.cc index 37ba19546..4f92edb75 100644 --- a/src/ant/ant/antPlugin.cc +++ b/src/ant/ant/antPlugin.cc @@ -171,6 +171,9 @@ PluginDeclaration::config_finalize () void PluginDeclaration::initialized (lay::PluginRoot *) { + ant::Template ruler_template (tl::to_string (QObject::tr ("Ruler")), "$X", "$Y", "$D", ant::Object::STY_ruler, ant::Object::OL_diag, true, lay::AC_Global, "_ruler"); + register_annotation_template (ruler_template); + ant::Template pos_template (tl::to_string (QObject::tr ("Cross")), "", "", "$U,$V", ant::Object::STY_cross_both, ant::Object::OL_diag, true, lay::AC_Global, "_cross"); pos_template.set_mode (ant::Template::RulerSingleClick); register_annotation_template (pos_template); @@ -178,6 +181,8 @@ PluginDeclaration::initialized (lay::PluginRoot *) ant::Template auto_template (tl::to_string (QObject::tr ("Measure")), "$X", "$Y", "$D", ant::Object::STY_ruler, ant::Object::OL_diag, true, lay::AC_Global, "_measure"); auto_template.set_mode (ant::Template::RulerAutoMetric); register_annotation_template (auto_template); + + update_menu (); } void @@ -217,18 +222,16 @@ PluginDeclaration::update_menu () { lay::AbstractMenuProvider *mp = lay::AbstractMenuProvider::instance (); - if (m_templates.empty ()) { - m_templates.push_back (Template ()); - } - if (m_current_template < 0 || m_current_template >= int (m_templates.size ())) { m_current_template = 0; } - std::vector menu_entries = mp->menu ()->group ("ruler_mode_group"); - for (std::vector::const_iterator m = menu_entries.begin (); m != menu_entries.end (); ++m) { - lay::Action action = mp->menu ()->action (*m); - action.set_title (m_templates [m_current_template].title ()); + if (m_current_template >= 0 && m_current_template < int (m_templates.size ())) { + std::vector menu_entries = mp->menu ()->group ("ruler_mode_group"); + for (std::vector::const_iterator m = menu_entries.begin (); m != menu_entries.end (); ++m) { + lay::Action action = mp->menu ()->action (*m); + action.set_title (m_templates [m_current_template].title ()); + } } std::vector tmpl_group = mp->menu ()->group ("ruler_templates_group");