#include "gtl_gui_scr_qml_widget.h" #include "ui_gtl_gui_scr_qml_widget.h" namespace gtl { namespace gui { scr_qml_widget::scr_qml_widget(gtl::data_model* model, QWidget *parent) : QWidget(parent), ui(new Ui::qml_widget) { ui->setupUi(this); _selection_data_model = new gtl::selection_data_model(this); _selection_data_model->setSourceModel(model); ui->hw->setModel(_selection_data_model); ui->hw->expandAll(); gtl::scr::engine* engine = new gtl::scr::engine(this); _widget = new gtl::gui::scr_quick_widget(engine, this); ui->splitter->insertWidget(1, _widget); _qml_editor = new gtl::gui::scr_editor(this); ui->splitter->insertWidget(2, _qml_editor); connect(_qml_editor, >l::gui::scr_editor::init_menu, this, &scr_qml_widget::init_scr_editors_menu); _run_action = new QAction(QIcon(":/player/play"), "Run", this); connect(_run_action, &QAction::triggered, this, &scr_qml_widget::run); } scr_qml_widget::~scr_qml_widget() { delete ui; } void scr_qml_widget::save(QDomElement &root_element) { QDomElement selection_element = root_element.ownerDocument().createElement("selection"); root_element.appendChild(selection_element); _selection_data_model->save(selection_element); QDomElement qml_element = root_element.ownerDocument().createElement("qml"); root_element.appendChild(qml_element); qml_element.setAttribute("text", _qml_editor->toPlainText()); QDomElement splitter_element = root_element.ownerDocument().createElement("splitter"); root_element.appendChild(splitter_element); splitter_element.setAttribute("state", QString(ui->splitter->saveState().toBase64())); } void scr_qml_widget::load(const QDomElement &root_element) { QDomElement selection_element = root_element.firstChildElement("selection"); _selection_data_model->load(selection_element); _qml_editor->clear(); QDomElement qml_element = root_element.firstChildElement("qml"); _qml_editor->appendPlainText(qml_element.attribute("text", "")); QDomElement splitter_element = root_element.firstChildElement("splitter"); ui->splitter->restoreState(QByteArray::fromBase64(splitter_element.attribute("state", "").toUtf8())); } QAction *scr_qml_widget::run_action() const { return _run_action; } void scr_qml_widget::init_scr_editors_menu(QMenu *menu) { menu->addSeparator(); menu->addAction(_run_action); } void scr_qml_widget::run() { std::vector ad; _selection_data_model->get_selections(std::back_inserter(ad)); _widget->run(ad.begin(), ad.end(), _qml_editor->toPlainText()); } } }