Add radio buttons

master
Marko Semet 2019-03-14 11:13:10 +01:00
parent d58455d2d7
commit 161e6062e3
4 changed files with 201 additions and 4 deletions

View File

@ -22,6 +22,8 @@ namespace sirEdit::data {
View addTool(Tool tool) const;
bool saveToFile();
friend sirEdit::data::Serializer;
};
@ -47,6 +49,7 @@ namespace sirEdit::data {
public:
HistoricalView(View view);
~HistoricalView();
const View& getStaticView() const {
return this->staticView;

View File

@ -13,6 +13,9 @@ struct HistoricalData {
sirEdit::data::HistoricalView::HistoricalView(View view) : staticView(move(view)) {
this->data = static_pointer_cast<void>(make_shared<HistoricalData>());
}
sirEdit::data::HistoricalView::~HistoricalView() {
// TODO: Check that thread stopped and all is safed
}
void sirEdit::data::HistoricalView::addTool(Tool tool) {
this->staticView = this->staticView.addTool(tool);

View File

@ -17,11 +17,12 @@ using namespace std;
class RawData {
public:
unique_ptr<SkillFile> skillFile;
std::string file;
vector<unique_ptr<Type>> allTypes;
vector<Type*> baseTypes;
RawData(SkillFile* sf) : skillFile(sf) {
RawData(SkillFile* sf, std::string file) : skillFile(sf), file(move(file)) {
// Load Typs
{
// Phase 1: gen Types
@ -73,8 +74,8 @@ class RawData {
};
extern shared_ptr<Serializer> sirEdit::data::Serializer::openFile(const string& file) {
SkillFile* sf = SkillFile::read(file);
Serializer* result = new Serializer(std::move(std::static_pointer_cast<void>(std::make_shared<RawData>(sf))));
SkillFile* sf = SkillFile::open(file);
Serializer* result = new Serializer(std::move(std::static_pointer_cast<void>(std::make_shared<RawData>(sf, file))));
return move(shared_ptr<Serializer>(result));
}
@ -119,3 +120,25 @@ extern View sirEdit::data::View::addTool(Tool tool) const {
return move(result);
}
extern bool sirEdit::data::View::saveToFile() {
ViewData* viewData = static_pointer_cast<ViewData>(this->__raw).get();
// Remoe old tools
for(auto& i: *(viewData->raw->skillFile->Tool)) {
// TODO: delete
}
// Add tools
for(auto& i : viewData->tools) {
sir::Tool* tool = viewData->raw->skillFile->Tool->add();
{
auto tmp = viewData->raw->skillFile->strings->add(i.getName().c_str());
tool->setName(tmp);
}
}
// Save
viewData->raw->skillFile->flush();
return true;
}

View File

@ -1,6 +1,8 @@
#include "mainWindow.hpp"
#include <gtkmm.h>
#include <iostream>
//
// Model for type list
//
@ -9,9 +11,19 @@ class TypeListModel : public Gtk::TreeModel::ColumnRecord
public:
Gtk::TreeModelColumn<size_t> data_id;
Gtk::TreeModelColumn<Glib::ustring> data_name;
Gtk::TreeModelColumn<bool> data_status_r;
Gtk::TreeModelColumn<bool> data_status_w;
Gtk::TreeModelColumn<bool> data_status_d;
Gtk::TreeModelColumn<bool> data_status_u;
Gtk::TreeModelColumn<bool> data_status_no;
TypeListModel() {
this->add(data_id);
this->add(data_status_no);
this->add(data_status_u);
this->add(data_status_r);
this->add(data_status_w);
this->add(data_status_d);
this->add(data_name);
}
};
@ -25,9 +37,19 @@ class FieldListModel : public Gtk::TreeModel::ColumnRecord
{
public:
Gtk::TreeModelColumn<Glib::ustring> data_name;
Gtk::TreeModelColumn<bool> data_status_r;
Gtk::TreeModelColumn<bool> data_status_w;
Gtk::TreeModelColumn<bool> data_status_e;
Gtk::TreeModelColumn<bool> data_status_u;
Gtk::TreeModelColumn<bool> data_status_no;
FieldListModel() {
this->add(data_name);
this->add(data_status_no);
this->add(data_status_u);
this->add(data_status_r);
this->add(data_status_w);
this->add(data_status_e);
}
};
static FieldListModel fieldListModel;
@ -42,6 +64,54 @@ inline void buildTreeSubRows(Gtk::TreeStore::Row& row, const sirEdit::data::Type
}
}
class Chooser : public Gtk::CellRenderer {
private:
Gtk::ButtonBox widget;
Gtk::OffscreenWindow ow;
template<class T>
Gtk::Button* newButton(T name) {
Gtk::Button* button = new Gtk::ToggleButton();
button->add(*(new Gtk::Label(name)));
return button;
}
public:
Chooser() {
this->widget.add(*(newButton("R")));
this->widget.add(*(newButton("W")));
this->widget.add(*(newButton("C")));
this->widget.add(*(newButton("U")));
this->widget.add(*(newButton("-")));
this->widget.get_style_context()->add_class("linked");
this->ow.add(this->widget);
this->ow.show_all();
}
Gtk::SizeRequestMode get_request_mode_vfunc() const {
return this->widget.get_request_mode();
}
void get_preferred_width_vfunc(Gtk::Widget& widget, int& minimum_width, int& natural_width) const {
int tmp;
this->widget.get_preferred_width(minimum_width, tmp);
natural_width = minimum_width;
}
void get_preferred_height_for_width_vfunc(Gtk::Widget& widget, int width, int& minimum_height, int& natural_height) const {
this->widget.get_preferred_height_for_width(width, minimum_height, natural_height);
}
void get_preferred_height_vfunc(Gtk::Widget& widget, int& minimum_height, int& natural_height) const {
this->widget.get_preferred_height(minimum_height, natural_height);
}
void get_preferred_width_for_height_vfunc(Gtk::Widget& widget, int height, int& minimum_width, int& natural_width) const {
this->widget.get_preferred_width_for_height(height, minimum_width, natural_width);
}
void render_vfunc(const ::Cairo::RefPtr< ::Cairo::Context>& cr, Gtk::Widget& widget, const Gdk::Rectangle& background_area, const Gdk::Rectangle& cell_area, Gtk::CellRendererState flags) {
this->ow.set_size_request(cell_area.get_width(), cell_area.get_height());
Gdk::Cairo::set_source_pixbuf(cr, this->ow.get_pixbuf(), cell_area.get_x(), cell_area.get_y());
cr->paint();
}
};
//
// Show widget
//
@ -78,8 +148,53 @@ extern Gtk::Widget* sirEdit::gui::createToolEdit(std::string name, const sirEdit
view_left->set_model(typeListData);
view_left->set_search_column(typeListModel.data_name);
{
auto tmp = new Gtk::CellRendererToggle();
tmp->signal_toggled().connect([](Glib::ustring test) -> void {
std::cout << test << std::endl;
});
tmp->set_property("radio", true);
view_left->append_column("-", *tmp);
view_left->get_column(0)->add_attribute(tmp->property_active(), typeListModel.data_status_no);
}
{
auto tmp = new Gtk::CellRendererToggle();
tmp->signal_toggled().connect([](Glib::ustring test) -> void {
std::cout << test << std::endl;
});
tmp->set_property("radio", true);
view_left->append_column("u", *tmp);
view_left->get_column(1)->add_attribute(tmp->property_active(), typeListModel.data_status_u);
}
{
auto tmp = new Gtk::CellRendererToggle();
tmp->signal_toggled().connect([](Glib::ustring test) -> void {
std::cout << test << std::endl;
});
tmp->set_property("radio", true);
view_left->append_column("r", *tmp);
view_left->get_column(2)->add_attribute(tmp->property_active(), typeListModel.data_status_r);
}
{
auto tmp = new Gtk::CellRendererToggle();
tmp->signal_toggled().connect([](Glib::ustring test) -> void {
std::cout << test << std::endl;
});
tmp->set_property("radio", true);
view_left->append_column("w", *tmp);
view_left->get_column(3)->add_attribute(tmp->property_active(), typeListModel.data_status_w);
}
{
auto tmp = new Gtk::CellRendererToggle();
tmp->signal_toggled().connect([](Glib::ustring test) -> void {
std::cout << test << std::endl;
});
tmp->set_property("radio", true);
view_left->append_column("d", *tmp);
view_left->get_column(4)->add_attribute(tmp->property_active(), typeListModel.data_status_d);
}
view_left->append_column("Types", typeListModel.data_name);
auto nameColumn = view_left->get_column(0);
auto nameColumn = view_left->get_column(5);
view_left->set_activate_on_single_click(true);
view_left->expand_all();
view_left->set_expander_column(*nameColumn);
@ -88,7 +203,55 @@ extern Gtk::Widget* sirEdit::gui::createToolEdit(std::string name, const sirEdit
fieldListData->set_sort_column(fieldListModel.data_name, Gtk::SortType::SORT_ASCENDING);
view_right->set_model(fieldListData);
view_right->set_search_column(fieldListModel.data_name);
//Chooser* cl = new Chooser();
//view_right->append_column("Status", *cl);
{
auto tmp = new Gtk::CellRendererToggle();
tmp->signal_toggled().connect([](Glib::ustring test) -> void {
std::cout << test << std::endl;
});
tmp->set_property("radio", true);
view_right->append_column("-", *tmp);
view_right->get_column(0)->add_attribute(tmp->property_active(), typeListModel.data_status_no);
}
{
auto tmp = new Gtk::CellRendererToggle();
tmp->signal_toggled().connect([](Glib::ustring test) -> void {
std::cout << test << std::endl;
});
tmp->set_property("radio", true);
view_right->append_column("u", *tmp);
view_right->get_column(1)->add_attribute(tmp->property_active(), fieldListModel.data_status_u);
}
{
auto tmp = new Gtk::CellRendererToggle();
tmp->signal_toggled().connect([](Glib::ustring test) -> void {
std::cout << test << std::endl;
});
tmp->set_property("radio", true);
view_right->append_column("r", *tmp);
view_right->get_column(2)->add_attribute(tmp->property_active(), fieldListModel.data_status_r);
}
{
auto tmp = new Gtk::CellRendererToggle();
tmp->signal_toggled().connect([](Glib::ustring test) -> void {
std::cout << test << std::endl;
});
tmp->set_property("radio", true);
view_right->append_column("w", *tmp);
view_right->get_column(3)->add_attribute(tmp->property_active(), fieldListModel.data_status_w);
}
{
auto tmp = new Gtk::CellRendererToggle();
tmp->signal_toggled().connect([](Glib::ustring test) -> void {
std::cout << test << std::endl;
});
tmp->set_property("radio", true);
view_right->append_column("e", *tmp);
view_right->get_column(4)->add_attribute(tmp->property_active(), fieldListModel.data_status_e);
}
view_right->append_column("Name", fieldListModel.data_name);
view_right->set_expander_column(*(view_right->get_column(5)));
view_left->signal_row_activated().connect([view](const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column) -> void {
Gtk::TreeModel::iterator iter = typeListData->get_iter(path);
@ -99,6 +262,11 @@ extern Gtk::Widget* sirEdit::gui::createToolEdit(std::string name, const sirEdit
for(auto& i: type->getFields()) {
Gtk::TreeStore::Row tmp = *(fieldListData->append());
tmp[fieldListModel.data_name] = i.getName();
tmp[fieldListModel.data_status_r] = false;
tmp[fieldListModel.data_status_w] = false;
tmp[fieldListModel.data_status_e] = false;
tmp[fieldListModel.data_status_u] = false;
tmp[fieldListModel.data_status_no] = true;
}
}
});