WIP: tech controller and tech setup dialog

Some bug fixes (description was not updated in tree,
base path of new tech was not set, dirs were not reused
for new tech).

Some enhancements (tech setup dialog's window state
is persisted etc.)
This commit is contained in:
Matthias Koefferlein 2017-04-16 00:27:28 +02:00
parent 6b6b45714f
commit 516c3ff925
4 changed files with 52 additions and 23 deletions

View File

@ -504,14 +504,6 @@ TechSetupDialog::TechSetupDialog (QWidget *parent)
connect (add_pb, SIGNAL (clicked ()), this, SLOT (add_clicked ()));
connect (delete_pb, SIGNAL (clicked ()), this, SLOT (delete_clicked ()));
connect (rename_pb, SIGNAL (clicked ()), this, SLOT (rename_clicked ()));
if (s_first_show) {
TipDialog td (this,
tl::to_string (QObject::tr ("<html><body>To get started with the technology manager, read the documentation provided: <a href=\"int:/about/technology_manager.xml\">About Technology Management</a>.</body></html>")),
"tech-manager-basic-tips");
td.exec_dialog ();
s_first_show = false;
}
}
TechSetupDialog::~TechSetupDialog ()
@ -559,6 +551,14 @@ TechSetupDialog::update ()
int
TechSetupDialog::exec (lay::Technologies &technologies)
{
if (s_first_show) {
TipDialog td (this,
tl::to_string (QObject::tr ("<html><body>To get started with the technology manager, read the documentation provided: <a href=\"int:/about/technology_manager.xml\">About Technology Management</a>.</body></html>")),
"tech-manager-basic-tips");
td.exec_dialog ();
s_first_show = false;
}
m_technologies = technologies;
update ();
@ -613,12 +613,17 @@ BEGIN_PROTECTED
QDir root = QDir (tl::to_qstring (lay::TechnologyController::instance ()->default_root ()));
QDir tech_dir (root.filePath (tn));
if (tech_dir.exists ()) {
throw tl::Exception (tl::to_string (QObject::tr ("A target folder with path '%1' already exists").arg (tech_dir.path ())));
if (QMessageBox::question (this, QObject::tr ("Creating Technology"),
QObject::tr ("A target folder with path '%1' already exists\nUse this directory for the new technology?").arg (tech_dir.path ()),
QMessageBox::No | QMessageBox::Yes) == QMessageBox::No) {
throw tl::CancelException ();
}
}
lay::Technology *nt = new lay::Technology (*t);
nt->set_tech_file_path (tl::to_string (tech_dir.absoluteFilePath (tn + QString::fromUtf8 (".lyt"))));
nt->set_default_base_path (tl::to_string (tech_dir.absolutePath ()));
nt->set_persisted (false);
nt->set_name (tl::to_string (tn));
nt->set_description (std::string ());
@ -990,9 +995,11 @@ TechSetupDialog::commit_tech_component ()
mp_current_editor->commit ();
}
if (mp_current_tech && mp_current_tech_component && !mp_current_tech->is_readonly ()) {
if (mp_current_tech && !mp_current_tech->is_readonly ()) {
mp_current_tech->set_component (mp_current_tech_component->clone ());
if (mp_current_tech_component) {
mp_current_tech->set_component (mp_current_tech_component->clone ());
}
// because commit may have changed the description text, update the technology titles
for (int i = tech_tree->topLevelItemCount (); i > 0; --i) {

View File

@ -26,6 +26,7 @@
#include "layMainWindow.h"
#include "layApplication.h"
#include "layConfig.h"
#include "layQtTools.h"
#include "laybasicConfig.h"
#include <QMessageBox>
@ -36,6 +37,8 @@
namespace lay
{
static const std::string cfg_tech_editor_window_state ("tech-editor-window-state");
std::string tech_string_from_name (const std::string &tn)
{
if (tn.empty ()) {
@ -65,20 +68,18 @@ TechnologyController::instance ()
}
void
TechnologyController::initialize (lay::PluginRoot * /*root*/)
{
// .. nothing yet ..
}
void
TechnologyController::initialized (lay::PluginRoot *root)
TechnologyController::initialize (lay::PluginRoot *root)
{
mp_mw = dynamic_cast <lay::MainWindow *> (root);
if (mp_mw) {
mp_editor = new lay::TechSetupDialog (mp_mw);
mp_editor->setModal (false);
}
}
void
TechnologyController::initialized (lay::PluginRoot * /*root*/)
{
update_menu ();
connect_events ();
}
@ -94,6 +95,7 @@ void
TechnologyController::get_options (std::vector < std::pair<std::string, std::string> > &options) const
{
options.push_back (std::pair<std::string, std::string> (cfg_initial_technology, ""));
options.push_back (std::pair<std::string, std::string> (cfg_tech_editor_window_state, ""));
}
void
@ -153,7 +155,12 @@ TechnologyController::update_active_technology ()
{
lay::Technology *active_tech = 0;
if (mp_mw && mp_mw->current_view () && mp_mw->current_view ()->active_cellview_index () >= 0 && mp_mw->current_view ()->active_cellview_index () <= int (mp_mw->current_view ()->cellviews ())) {
active_tech = lay::Technologies::instance ()->technology_by_name (mp_mw->current_view ()->active_cellview ()->tech_name ());
std::string tn = mp_mw->current_view ()->active_cellview ()->tech_name ();
if (lay::Technologies::instance ()->has_technology (tn)) {
active_tech = lay::Technologies::instance ()->technology_by_name (tn);
}
}
if (mp_active_technology != active_tech) {
@ -192,6 +199,7 @@ TechnologyController::technologies_changed ()
}
update_menu ();
emit technologies_edited ();
}
void
@ -210,6 +218,10 @@ TechnologyController::configure (const std::string &name, const std::string &val
m_current_technology_updated = true;
}
} else if (name == cfg_tech_editor_window_state) {
lay::restore_dialog_state (mp_editor, value);
} else if (name == cfg_technologies) {
if (! value.empty ()) {
@ -295,6 +307,10 @@ TechnologyController::update_menu ()
m_current_technology = lay::LayoutView::current ()->active_cellview ()->tech_name ();
}
if (! lay::Technologies::instance()->has_technology (m_current_technology)) {
m_current_technology = std::string ();
}
std::string title = tech_string_from_name (m_current_technology);
size_t ntech = 0;
@ -307,7 +323,7 @@ TechnologyController::update_menu ()
for (std::vector<std::string>::const_iterator t = tech_group.begin (); t != tech_group.end (); ++t) {
lay::Action action = pr->menu ()->action (*t);
action.set_title (title);
action.set_visible (ntech > 1);
action.set_enabled (ntech > 1);
std::vector<std::string> items = pr->menu ()->items (*t);
for (std::vector<std::string>::const_iterator i = items.begin (); i != items.end (); ++i) {
pr->menu ()->delete_item (*i);
@ -428,10 +444,13 @@ TechnologyController::show_editor ()
QMessageBox::Ok);
}
update_menu ();
emit technologies_edited ();
technologies_changed ();
}
if (mp_mw) {
mp_mw->config_set (cfg_tech_editor_window_state, lay::save_dialog_state (mp_editor));
}
}
const std::string &

View File

@ -873,7 +873,6 @@ AbstractMenu::build (QToolBar *t, std::list<AbstractMenuItem> &items)
}
}
}
QMenu *

View File

@ -103,6 +103,10 @@ save_dialog_state (QWidget *w)
void
restore_dialog_state (QWidget *dialog, const std::string &s)
{
if (! dialog) {
return;
}
tl::Extractor ex (s.c_str ());
while (! ex.at_end ()) {