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.
This commit is contained in:
Matthias Koefferlein 2017-11-05 23:39:50 +01:00
parent daf4ee092e
commit 059c7ee37a
2 changed files with 26 additions and 8 deletions

View File

@ -29,6 +29,7 @@
#include "antConfig.h" #include "antConfig.h"
#include "layConverters.h" #include "layConverters.h"
#include "layQtTools.h" #include "layQtTools.h"
#include "tlExceptions.h"
#include <QInputDialog> #include <QInputDialog>
@ -254,6 +255,7 @@ ConfigPage4::add_clicked ()
} else { } else {
new_one = m_ruler_templates [m_current_template]; 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.insert (m_ruler_templates.begin () + m_current_template, new_one);
m_ruler_templates [m_current_template].title (tl::to_string (QObject::tr ("New Ruler"))); m_ruler_templates [m_current_template].title (tl::to_string (QObject::tr ("New Ruler")));
update_list (); update_list ();
@ -264,7 +266,12 @@ ConfigPage4::add_clicked ()
void void
ConfigPage4::del_clicked () ConfigPage4::del_clicked ()
{ {
BEGIN_PROTECTED
if (m_current_template >= 0 && m_current_template < int (m_ruler_templates.size ())) { 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); m_ruler_templates.erase (m_ruler_templates.begin () + m_current_template);
if (m_current_template > 0) { if (m_current_template > 0) {
--m_current_template; --m_current_template;
@ -276,6 +283,8 @@ ConfigPage4::del_clicked ()
update_list (); update_list ();
show (); show ();
} }
END_PROTECTED
} }
void void
@ -309,6 +318,12 @@ ConfigPage4::update_list ()
mp_ui->template_list->clear (); mp_ui->template_list->clear ();
for (std::vector <ant::Template>::const_iterator t = m_ruler_templates.begin (); t != m_ruler_templates.end (); ++t) { for (std::vector <ant::Template>::const_iterator t = m_ruler_templates.begin (); t != m_ruler_templates.end (); ++t) {
mp_ui->template_list->addItem (tl::to_qstring (t->title ())); 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); mp_ui->template_list->setCurrentRow (m_current_template);
m_current_changed_enabled = true; m_current_changed_enabled = true;

View File

@ -171,6 +171,9 @@ PluginDeclaration::config_finalize ()
void void
PluginDeclaration::initialized (lay::PluginRoot *) 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"); 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); pos_template.set_mode (ant::Template::RulerSingleClick);
register_annotation_template (pos_template); 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"); 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); auto_template.set_mode (ant::Template::RulerAutoMetric);
register_annotation_template (auto_template); register_annotation_template (auto_template);
update_menu ();
} }
void void
@ -217,18 +222,16 @@ PluginDeclaration::update_menu ()
{ {
lay::AbstractMenuProvider *mp = lay::AbstractMenuProvider::instance (); 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 ())) { if (m_current_template < 0 || m_current_template >= int (m_templates.size ())) {
m_current_template = 0; m_current_template = 0;
} }
std::vector<std::string> menu_entries = mp->menu ()->group ("ruler_mode_group"); if (m_current_template >= 0 && m_current_template < int (m_templates.size ())) {
for (std::vector<std::string>::const_iterator m = menu_entries.begin (); m != menu_entries.end (); ++m) { std::vector<std::string> menu_entries = mp->menu ()->group ("ruler_mode_group");
lay::Action action = mp->menu ()->action (*m); for (std::vector<std::string>::const_iterator m = menu_entries.begin (); m != menu_entries.end (); ++m) {
action.set_title (m_templates [m_current_template].title ()); lay::Action action = mp->menu ()->action (*m);
action.set_title (m_templates [m_current_template].title ());
}
} }
std::vector<std::string> tmpl_group = mp->menu ()->group ("ruler_templates_group"); std::vector<std::string> tmpl_group = mp->menu ()->group ("ruler_templates_group");