Skip to content

Commit

Permalink
Provide an accessor to GncOptionAccountValue::m_allowed
Browse files Browse the repository at this point in the history
To enable its use by gnc_account_sel_filter
  • Loading branch information
jralls committed Jul 11, 2021
1 parent 102f36c commit dc876d4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions libgnucash/app-utils/CMakeLists.txt
Expand Up @@ -92,6 +92,7 @@ set(app_utils_ALL_LIBRARIES
gnc-engine
gnc-locale-tax
gnucash-guile
${GLIB_LDFLAGS}
${GIO_LDFLAGS}
${LIBXML2_LDFLAGS}
${LIBXSLT_LDFLAGS}
Expand Down
18 changes: 18 additions & 0 deletions libgnucash/app-utils/gnc-option-impl.cpp
Expand Up @@ -48,6 +48,24 @@ GncOptionAccountValue::validate(const GncOptionAccountList& values) const
return true;
}

/**
* Create a GList of account types to pass to gnc_account_sel_set_acct_filters.
* gnc_account_sel_set_acct_filters copies the list so the intermediary caller
* is responsible for freeing the list.
*
* @return an allocated GList* or nullptr if the list is empty.
*/
GList*
GncOptionAccountValue::account_type_list() const noexcept
{
if (m_allowed.empty())
return nullptr;
GList* retval;
for (auto type : m_allowed)
retval = g_list_prepend(retval, GINT_TO_POINTER(type));
return g_list_reverse(retval);
}

static constexpr int days_in_month[12]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

static void
Expand Down
1 change: 1 addition & 0 deletions libgnucash/app-utils/gnc-option-impl.hpp
Expand Up @@ -584,6 +584,7 @@ class GncOptionAccountValue : public OptionClassifier
//throw!
m_value = values;
}
GList* account_type_list() const noexcept;
bool is_changed() const noexcept { return m_value != m_default_value; }
GncOptionUIType get_ui_type() const noexcept { return m_ui_type; }
void make_internal() { m_ui_type = GncOptionUIType::INTERNAL; }
Expand Down
12 changes: 12 additions & 0 deletions libgnucash/app-utils/gnc-option.cpp
Expand Up @@ -256,6 +256,18 @@ GncOption::permissible_value_description(std::size_t index) const
}, *m_option);
}

GList*
GncOption::account_type_list() const noexcept
{
return std::visit([] (const auto& option) -> GList* {
if constexpr (std::is_same_v<std::decay_t<decltype(option)>,
GncOptionAccountValue>)
return option.account_type_list();
else
return nullptr;
}, *m_option);
}

std::ostream&
GncOption::out_stream(std::ostream& oss) const
{
Expand Down
6 changes: 6 additions & 0 deletions libgnucash/app-utils/gnc-option.hpp
Expand Up @@ -24,6 +24,11 @@
#ifndef GNC_OPTION_HPP_
#define GNC_OPTION_HPP_

extern "C"
{
#include <glib.h>
}

#include <string>
#include <iostream>
#include <variant>
Expand Down Expand Up @@ -86,6 +91,7 @@ class GncOption
const std::string& permissible_value(std::size_t index) const;
const std::string& permissible_value_name(std::size_t index) const;
const std::string& permissible_value_description(std::size_t index) const;
GList* account_type_list() const noexcept;
std::ostream& out_stream(std::ostream& oss) const;
std::istream& in_stream(std::istream& iss);
std::ostream& to_scheme(std::ostream& oss) const;
Expand Down

0 comments on commit dc876d4

Please sign in to comment.