GnuCash c935c2f+
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 1741 of file assistant-stock-transaction.cpp.

Constructor & Destructor Documentation

◆ PageTransType()

PageTransType::PageTransType ( GtkBuilder *  builder)

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

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

Member Function Documentation

◆ change_txn_type()

void PageTransType::change_txn_type ( StockAssistantModel model)

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

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

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

◆ get_transaction_type_index()

int PageTransType::get_transaction_type_index ( )

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

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

◆ prepare()

void PageTransType::prepare ( StockAssistantModel model)

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

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

◆ set_transaction_types()

void PageTransType::set_transaction_types ( const TxnTypeVec &  txn_types)

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

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

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

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

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