#include "gtl_gui_scr_table.h" namespace gtl { namespace gui { scr_table::scr_table(gtl::data_model* model, QWidget* parent) : QTableView(parent) { _ui.setupUi(this); _engine = new gtl::scr::engine_table(this); _editor = new gtl::gui::scr_editor(this); _ui.splitter_2->addWidget(_editor); _selection_data_model = new gtl::selection_data_model(/*_model*/this); _selection_data_model->setSourceModel(model); _ui.data_tree->setModel(_selection_data_model); _ui.data_tree->expandAll(); _ui.table->setModel(_engine->model()); connect(_selection_data_model, >l::selection_data_model::selected, _engine, >l::scr::engine::add_ad); connect(_selection_data_model, >l::selection_data_model::deselected, _engine, >l::scr::engine::remove_ad); connect(_engine, >l::scr::engine::analog_inputs_changed, this, &scr_table::evaluate); } scr_table::~scr_table() { _engine = nullptr; } void scr_table::save(QDomElement &root_element) { QDomElement selection_element = root_element.ownerDocument().createElement("selection"); root_element.appendChild(selection_element); _selection_data_model->save(selection_element); QDomElement script_element = root_element.ownerDocument().createElement("script"); root_element.appendChild(script_element); script_element.setAttribute("text", _editor->toPlainText()); QDomElement splitter_element = root_element.ownerDocument().createElement("splitter"); root_element.appendChild(splitter_element); splitter_element.setAttribute("state", QString(_ui.splitter->saveState().toBase64())); QDomElement splitter_2_element = root_element.ownerDocument().createElement("splitter_2"); root_element.appendChild(splitter_2_element); splitter_2_element.setAttribute("state", QString(_ui.splitter_2->saveState().toBase64())); } void scr_table::load(const QDomElement &root_element) { QDomElement selection_element = root_element.firstChildElement("selection"); _selection_data_model->load(selection_element); _editor->clear(); QDomElement script_element = root_element.firstChildElement("script"); _editor->appendPlainText(script_element.attribute("text", "")); evaluate(); QDomElement splitter_element = root_element.firstChildElement("splitter"); _ui.splitter->restoreState(QByteArray::fromBase64(splitter_element.attribute("state", "").toUtf8())); QDomElement splitter_element_2 = root_element.firstChildElement("splitter_2"); _ui.splitter_2->restoreState(QByteArray::fromBase64(splitter_element_2.attribute("state", "").toUtf8())); } void scr_table::evaluate() { if(_engine) static_cast(_engine)->evaluate(_editor->toPlainText()); } } }