Skip to content
Snippets Groups Projects

Feature/219/gui record options

Merged Iiro Rastas requested to merge feature/219/gui-record-options into master
11 files
+ 91
123
Compare changes
  • Side-by-side
  • Inline
Files
11
  • 9b369c0b
    Restore record button functionality · 9b369c0b
    Iiro Rastas authored
    The record button now works as previously. To support this change, a
    tagging system based on the one from feature/guienhance has been added.
    NetConfigurables are now created as peers connect and removed as they
    disconnect, which required changes to ConfigWindow.
@@ -15,23 +15,15 @@ using std::string;
using std::vector;
using ftl::config::json_t;
ConfigWindow::ConfigWindow(nanogui::Widget *parent, ftl::ctrl::Master *ctrl, const ftl::UUID &peer) : ConfigWindow(parent, ctrl, std::optional<ftl::UUID>(peer)) {
}
ConfigWindow::ConfigWindow(nanogui::Widget *parent, ftl::ctrl::Master *ctrl, const std::optional<ftl::UUID> &peer)
: nanogui::Window(parent, "Settings"), ctrl_(ctrl), peer_(peer) {
ConfigWindow::ConfigWindow(nanogui::Widget *parent, ftl::ctrl::Master *ctrl)
: nanogui::Window(parent, "Settings"), ctrl_(ctrl) {
using namespace nanogui;
setLayout(new GroupLayout());
setPosition(Vector2i(parent->width()/2.0f - 100.0f, parent->height()/2.0f - 100.0f));
//setModal(true);
if (peer) {
configurables_ = ctrl->getConfigurables(peer.value());
} else {
configurables_ = ftl::config::list();
}
configurables_ = ftl::config::list();
new Label(this, "Select Configurable","sans-bold");
@@ -52,67 +44,50 @@ ConfigWindow::~ConfigWindow() {
}
class ConfigWindow::References {
public:
References(ftl::NetConfigurable* nc, ftl::config::json_t* config, const std::string* suri) : nc(nc), config(config), suri(suri) {
}
~References() {
delete nc;
delete config;
delete suri;
}
private:
ftl::NetConfigurable* nc;
ftl::config::json_t* config;
const std::string* suri;
};
std::vector<ftl::gui::ConfigWindow::References *> ConfigWindow::_addElements(nanogui::FormHelper *form, ftl::Configurable &nc, const std::string &suri, std::function<ftl::Configurable*(const std::string*, std::vector<References *>&)> construct) {
void ConfigWindow::_addElements(nanogui::FormHelper *form, const std::string &suri) {
using namespace nanogui;
std::vector<References *> references;
auto data = nc.getConfig();
Configurable *configurable = ftl::config::find(suri);
ftl::config::json_t data;
if (configurable) {
data = configurable->getConfig();
}
for (auto i=data.begin(); i!=data.end(); ++i) {
if (i.key() == "$id") continue;
if (i.key() == "$ref" && i.value().is_string()) {
LOG(INFO) << "Follow $ref: " << i.value();
const std::string* suri = new std::string(i.value().get<string>());
ftl::Configurable* rc = construct(suri, references);
auto new_references = _addElements(form, *rc, *suri, construct);
references.insert(references.end(), new_references.begin(), new_references.end());
const std::string suri = std::string(i.value().get<string>());
_addElements(form, suri);
continue;
}
if (i.value().is_boolean()) {
string key = i.key();
form->addVariable<bool>(i.key(), [this,data,key,&nc](const bool &b){
nc.set(key, b);
form->addVariable<bool>(i.key(), [this,data,key,suri](const bool &b){
ftl::config::update(suri+"/"+key, b);
}, [data,key]() -> bool {
return data[key].get<bool>();
});
} else if (i.value().is_number_integer()) {
string key = i.key();
form->addVariable<int>(i.key(), [this,data,key,&nc](const int &f){
nc.set(key, f);
form->addVariable<int>(i.key(), [this,data,key,suri](const int &f){
ftl::config::update(suri+"/"+key, f);
}, [data,key]() -> int {
return data[key].get<int>();
});
} else if (i.value().is_number_float()) {
string key = i.key();
form->addVariable<float>(i.key(), [this,data,key,&nc](const float &f){
nc.set(key, f);
form->addVariable<float>(i.key(), [this,data,key,suri](const float &f){
ftl::config::update(suri+"/"+key, f);
}, [data,key]() -> float {
return data[key].get<float>();
});
} else if (i.value().is_string()) {
string key = i.key();
form->addVariable<string>(i.key(), [this,data,key,&nc](const string &f){
nc.set(key, f);
form->addVariable<string>(i.key(), [this,data,key,suri](const string &f){
ftl::config::update(suri+"/"+key, f);
}, [data,key]() -> string {
return data[key].get<string>();
});
@@ -131,8 +106,6 @@ std::vector<ftl::gui::ConfigWindow::References *> ConfigWindow::_addElements(nan
}
}
}
return references;
}
void ConfigWindow::_buildForm(const std::string &suri) {
@@ -145,50 +118,15 @@ void ConfigWindow::_buildForm(const std::string &suri) {
form->addWindow(Vector2i(100,50), uri.getFragment());
form->window()->setTheme(theme());
ftl::config::json_t* config;
config = new ftl::config::json_t;
const std::string* allocated_suri = new std::string(suri);
std::vector<ftl::gui::ConfigWindow::References *> references;
ftl::Configurable* nc;
if (peer_) {
*config = ctrl_->get(peer_.value(), suri);
nc = new ftl::NetConfigurable(peer_.value(), *allocated_suri, *ctrl_, *config);
_addElements(form, suri);
references = _addElements(form, *nc, *allocated_suri, [this](auto suri, auto &references) {
ftl::config::json_t* config = new ftl::config::json_t;
*config = ctrl_->get(peer_.value(), *suri);
auto nc = new ftl::NetConfigurable(peer_.value(), *suri, *ctrl_, *config);
auto r = new References(nc, config, suri);
references.push_back(r);
return nc;
});
} else {
nc = ftl::config::find(suri);
if (nc) {
references = _addElements(form, *nc, *allocated_suri, [this](auto suri, auto &references) {
return ftl::config::find(*suri);
});
}
}
auto closebutton = form->addButton("Close", [this,form,config,allocated_suri,nc,references]() {
auto closebutton = form->addButton("Close", [this,form]() {
form->window()->setVisible(false);
for(auto r : references) {
delete r;
}
if (peer_) {
delete nc;
}
delete config;
delete allocated_suri;
delete form;
});
closebutton->setIcon(ENTYPO_ICON_CROSS);
}
bool ConfigWindow::exists(const std::string &uri) {
// If the Configurable is a NetConfigurable, the URI is not checked.
return peer_ || ftl::config::find(uri);
}
\ No newline at end of file
return ftl::config::find(uri) != nullptr;
}
Loading