GnuCash 038f90a+
Loading...
Searching...
No Matches
Public Member Functions
PageTransType Class Reference

Page classes generate the several pages of the assistant. More...

Public Member Functions

 PageTransType (GtkBuilder *builder)
 
void prepare (StockAssistantModel *model)
 
int get_transaction_type_index ()
 
void set_transaction_types (const TxnTypeVec &txn_types)
 
void set_txn_type_explanation (const gchar *txt)
 Sets the explanation text for the selected transaction type, allowing the user to make sure that the selected transaction matches what they want to do.
 
void connect (StockAssistantModel *model)
 
void change_txn_type (StockAssistantModel *model)
 

Detailed Description

Page classes generate the several pages of the assistant.

In general they have two functions, prepare and connect, plus a callback for each widget on the page and helper functions.

Pages are displayed only if the split is enabled in the transaction info. For most pages that means that the info is set to ENABLED_CREDIT or ENABLED_DEBIT, but for the stock amount page the info must be set to AMOUNT_CREDIT or AMOUNT_DEBIT. DISABLED is a placeholder as 0 is not testable.

Empty entries in amount edits are treated as 0 if the TxnTypeInfo for the split has ALLOW_ZERO set. Negative numbers are permitted only if ALLOW_NEGATIVE is set; that's used for amounts where the sign cannot be determined from the transaction type (like capital gains) or where it makes sense for consistency (like the new balance for a stock split in a short position.)

Prepare is called before a page is displayed and performs specializtion for the transaction type and populates widgets with already-known values; the latter may be available if the user has visited the page before for this transaction.

Connect connects the page's widgets signals with the handlers that transfer data to the model. The Transaction Type page.

This page collects the transaction type that's used to select the TxnTypeInfo that drives the rest of the process.

Definition at line 1744 of file assistant-stock-transaction.cpp.

Constructor & Destructor Documentation

◆ PageTransType()

PageTransType::PageTransType ( GtkBuilder *  builder)

Definition at line 1765 of file assistant-stock-transaction.cpp.

1766 : m_page(get_widget(builder, "transaction_type_page")),
1767 m_type(get_widget(builder, "transaction_type_page_combobox")),
1768 m_explanation(get_widget(builder, "transaction_type_page_explanation"))
1769{
1770 g_object_set_data(G_OBJECT(m_type), "owner", this);
1771}

Member Function Documentation

◆ change_txn_type()

void PageTransType::change_txn_type ( StockAssistantModel model)

Definition at line 1817 of file assistant-stock-transaction.cpp.

1818{
1819 auto type_idx = get_transaction_type_index();
1820 if (type_idx < 0) // combo isn't initialized yet.
1821 return;
1822
1823 if (!model->set_txn_type(type_idx))
1824 return;
1825 auto txn_type{model->txn_type()};
1826 set_txn_type_explanation (_(txn_type->explanation));
1827}
void set_txn_type_explanation(const gchar *txt)
Sets the explanation text for the selected transaction type, allowing the user to make sure that the ...
const std::optional< TxnTypeInfo > & txn_type()
Accessor.
bool set_txn_type(guint type_idx)
Setter.

◆ connect()

void PageTransType::connect ( StockAssistantModel model)

Definition at line 1830 of file assistant-stock-transaction.cpp.

1831{
1832 g_signal_connect(m_type, "changed",
1833 G_CALLBACK (page_trans_type_changed_cb), model);
1834}

◆ get_transaction_type_index()

int PageTransType::get_transaction_type_index ( )

Definition at line 1794 of file assistant-stock-transaction.cpp.

1795{
1796 return gtk_combo_box_get_active (GTK_COMBO_BOX (m_type));
1797}

◆ prepare()

void PageTransType::prepare ( StockAssistantModel model)

Definition at line 1782 of file assistant-stock-transaction.cpp.

1783{
1784 const auto& txn_types{model->get_txn_types()};
1785 if (!txn_types)
1786 return;
1787
1788 set_transaction_types(txn_types.value());
1789 change_txn_type (model);
1790 g_signal_connect(m_page, "focus", G_CALLBACK(assistant_page_set_focus), m_type);
1791}
const std::optional< TxnTypeVec > & get_txn_types()
Accessor function.

◆ set_transaction_types()

void PageTransType::set_transaction_types ( const TxnTypeVec &  txn_types)

Definition at line 1800 of file assistant-stock-transaction.cpp.

1801{
1802 auto combo = GTK_COMBO_BOX_TEXT (m_type);
1803 gtk_combo_box_text_remove_all (combo);
1804 std::for_each (txn_types.begin(), txn_types.end(),
1805 [&combo](const auto& it)
1806 { gtk_combo_box_text_append_text (combo, _(it.friendly_name)); });
1807 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
1808}

◆ set_txn_type_explanation()

void PageTransType::set_txn_type_explanation ( const gchar *  txt)

Sets the explanation text for the selected transaction type, allowing the user to make sure that the selected transaction matches what they want to do.

Parameters
transactionexplanation from the tranaction type's txntypeinfo.

Definition at line 1811 of file assistant-stock-transaction.cpp.

1812{
1813 gtk_label_set_text (GTK_LABEL (this->m_explanation), txt);
1814}

The documentation for this class was generated from the following file: