GnuCash 7574033+
Loading...
Searching...
No Matches
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 1742 of file assistant-stock-transaction.cpp.

Constructor & Destructor Documentation

◆ PageTransType()

PageTransType::PageTransType ( GtkBuilder * builder)

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

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

Member Function Documentation

◆ change_txn_type()

void PageTransType::change_txn_type ( StockAssistantModel * model)

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

1816{
1817 auto type_idx = get_transaction_type_index();
1818 if (type_idx < 0) // combo isn't initialized yet.
1819 return;
1820
1821 if (!model->set_txn_type(type_idx))
1822 return;
1823 auto txn_type{model->txn_type()};
1824 set_txn_type_explanation (_(txn_type->explanation));
1825}
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 1828 of file assistant-stock-transaction.cpp.

1829{
1830 g_signal_connect(m_type, "changed",
1831 G_CALLBACK (page_trans_type_changed_cb), model);
1832}

◆ get_transaction_type_index()

int PageTransType::get_transaction_type_index ( )

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

1793{
1794 return gtk_combo_box_get_active (GTK_COMBO_BOX (m_type));
1795}

◆ prepare()

void PageTransType::prepare ( StockAssistantModel * model)

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

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

◆ set_transaction_types()

void PageTransType::set_transaction_types ( const TxnTypeVec & txn_types)

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

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

◆ 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 1809 of file assistant-stock-transaction.cpp.

1810{
1811 gtk_label_set_text (GTK_LABEL (this->m_explanation), txt);
1812}

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