Skip to content

Commit

Permalink
Remove the UI interface from GncOptionDB.
Browse files Browse the repository at this point in the history
UI operations occur only in dialog-option so there's no need to expose
them from GncOptionDB.
  • Loading branch information
jralls committed Jul 11, 2021
1 parent cbf7d70 commit 1bea809
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 131 deletions.
7 changes: 0 additions & 7 deletions libgnucash/app-utils/gnc-optiondb-impl.hpp
Expand Up @@ -56,13 +56,6 @@ class GncOptionDB
void unregister_option(const char* section, const char* name);
void set_default_section(const char* section);
const GncOptionSection* const get_default_section() const noexcept;
void set_ui_item(const char* section, const char* name, GncOptionUIItem* ui_item);
GncOptionUIItem* const get_ui_item(const char* section, const char* name);
GncOptionUIType get_ui_type(const char* section, const char* name);
void set_ui_from_option(const char* section, const char* name,
std::function<void(GncOption&)> func);
void set_option_from_ui(const char* section, const char* name,
std::function<void(GncOption&)> func);
std::string lookup_string_option(const char* section,
const char* name);
template <typename ValueType>
Expand Down
44 changes: 0 additions & 44 deletions libgnucash/app-utils/gnc-optiondb.cpp
Expand Up @@ -87,50 +87,6 @@ GncOptionDB::get_default_section() const noexcept
return nullptr;
}

void
GncOptionDB::set_ui_item(const char* section, const char* name,
GncOptionUIItem* ui_item)
{
auto option = find_option(section, name);
if (!option) return;
option->get().set_ui_item(ui_item);
}

GncOptionUIItem* const
GncOptionDB::get_ui_item(const char* section, const char* name)
{
auto option = find_option(section, name);
if (!option) return nullptr;
return option->get().get_ui_item();
}

GncOptionUIType
GncOptionDB::get_ui_type(const char* section, const char* name)
{
auto option = find_option(section, name);
if (!option) return GncOptionUIType::INTERNAL;
return option->get().get_ui_type();
}

void
GncOptionDB::set_ui_from_option(const char* section, const char* name,
std::function<void(GncOption&)> func)
{
auto option = find_option(section, name);
if (!option) return;
func(option->get());
}

void
GncOptionDB::set_option_from_ui(const char* section, const char* name,
std::function<void(GncOption&)> func)
{
auto option = find_option(section, name);
if (!option) return;
func(option->get());
}


std::optional<std::reference_wrapper<GncOptionSection>>
GncOptionDB::find_section(const std::string& section)
{
Expand Down
80 changes: 0 additions & 80 deletions libgnucash/app-utils/test/gtest-gnc-optiondb.cpp
Expand Up @@ -205,86 +205,6 @@ TEST_F(GncOptionDBTest, test_register_date_interval_option)
ASSERT_TRUE(m_db->set_option("foo", "bar", time));
EXPECT_EQ(time, m_db->find_option("foo", "bar")->get().get_value<time64>());
}

class GncUIType
{
public:
void set_value(const std::string& value) { m_value = value; }
const std::string& get_value() const { return m_value; }
private:
std::string m_value;
};

class GncOptionUIItem
{
public:
GncOptionUIItem(GncUIType* widget) : m_widget{widget} {}
GncUIType* m_widget;
};

class GncOptionUITest : public ::testing::Test
{
protected:
GncOptionUITest() :
m_option{"foo", "bar", "baz", "Phony Option", std::string{"waldo"},
GncOptionUIType::STRING} {}

GncOption m_option;
};

class GncOptionDBUITest : public ::testing::Test
{
protected:
GncOptionDBUITest() : m_db{gnc_option_db_new()}
{
gnc_register_string_option(m_db, "foo", "bar", "baz", "Phony Option",
std::string{"waldo"});
gnc_register_text_option(m_db, "foo", "sausage", "links",
"Phony Option", std::string{"waldo"});
gnc_register_string_option(m_db, "qux", "grault", "baz", "Phony Option",
std::string{""});
gnc_register_text_option(m_db, "qux", "garply", "fred",
"Phony Option", std::string{"waldo"});
}

GncOptionDBPtr m_db;
};

TEST_F(GncOptionDBUITest, test_set_ui_item)
{
GncUIType entry;
GncOptionUIItem ui_item(&entry);
m_db->set_ui_item("foo", "bar", &ui_item);
EXPECT_EQ(&entry, m_db->get_ui_item("foo", "bar")->m_widget);
}

TEST_F(GncOptionDBUITest, test_ui_value_from_option)
{
GncUIType entry;
GncOptionUIItem ui_item(&entry);
const char* value{"waldo"};
m_db->set_ui_item("foo", "bar", &ui_item);
m_db->set_ui_from_option("foo", "bar", [](GncOption& option){
auto new_ui_item = option.get_ui_item();
new_ui_item->m_widget->set_value(option.get_value<std::string>());
});
EXPECT_STREQ(value, entry.get_value().c_str());
}

TEST_F(GncOptionDBUITest, test_option_value_from_ui)
{
GncUIType entry;
GncOptionUIItem ui_item(&entry);
const char* value{"pepper"};
m_db->set_ui_item("foo", "bar", &ui_item);
entry.set_value(value);
m_db->set_option_from_ui("foo", "bar", [](GncOption& option){
auto new_ui_item = option.get_ui_item()->m_widget;
option.set_value(new_ui_item->get_value());
});
EXPECT_STREQ(value, m_db->lookup_string_option("foo", "bar").c_str());
}

class GncOptionDBIOTest : public ::testing::Test
{
protected:
Expand Down

0 comments on commit 1bea809

Please sign in to comment.