GnuCash 7574033+
Loading...
Searching...
No Matches
GncFinishTreeview Class Reference

Public Member Functions

 GncFinishTreeview (GtkBuilder *builder)
void load (const EntryVec &list_of_splits)
 Extract the information from the StockTransactionEntries in the vector created by the model's make_list_of_splits function and write it into the list view.

Detailed Description

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

Constructor & Destructor Documentation

◆ GncFinishTreeview()

GncFinishTreeview::GncFinishTreeview ( GtkBuilder * builder)

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

2310 :
2311 m_treeview{get_widget (builder, "transaction_view")}
2312{
2313 auto view = GTK_TREE_VIEW (m_treeview);
2314 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW(view), gnc_tree_view_get_grid_lines_pref ());
2315
2316 auto store = gtk_list_store_new (NUM_SPLIT_COLS, G_TYPE_STRING, G_TYPE_STRING,
2317 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
2318 G_TYPE_STRING, G_TYPE_STRING);
2319 gtk_tree_view_set_model(view, GTK_TREE_MODEL(store));
2320 gtk_tree_selection_set_mode (gtk_tree_view_get_selection (view),
2321 GTK_SELECTION_NONE);
2322 g_object_unref(store);
2323
2324 auto renderer = gtk_cell_renderer_text_new();
2325 auto column = gtk_tree_view_column_new_with_attributes
2326 (_("Account"), renderer, "text", SPLIT_COL_ACCOUNT, nullptr);
2327 gtk_tree_view_append_column(view, column);
2328
2329 renderer = gtk_cell_renderer_text_new();
2330 g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, nullptr);
2331 column = gtk_tree_view_column_new_with_attributes
2332 (_("Memo"), renderer, "text", SPLIT_COL_MEMO, nullptr);
2333 gtk_tree_view_column_set_expand (column, true);
2334 gtk_tree_view_append_column(view, column);
2335
2336 renderer = gtk_cell_renderer_text_new();
2337 gtk_cell_renderer_set_alignment (renderer, 1.0, 0.5);
2338 gtk_cell_renderer_set_padding (renderer, 5, 0);
2339 column = gtk_tree_view_column_new_with_attributes
2340 (_("Debit"), renderer, "text", SPLIT_COL_DEBIT, nullptr);
2341 gtk_tree_view_append_column(view, column);
2342
2343 renderer = gtk_cell_renderer_text_new();
2344 gtk_cell_renderer_set_alignment (renderer, 1.0, 0.5);
2345 gtk_cell_renderer_set_padding (renderer, 5, 0);
2346 column = gtk_tree_view_column_new_with_attributes
2347 (_("Credit"), renderer, "text", SPLIT_COL_CREDIT, nullptr);
2348 gtk_tree_view_append_column(view, column);
2349
2350 renderer = gtk_cell_renderer_text_new();
2351 gtk_cell_renderer_set_alignment (renderer, 1.0, 0.5);
2352 gtk_cell_renderer_set_padding (renderer, 5, 0);
2353 column = gtk_tree_view_column_new_with_attributes
2354 (_("Units"), renderer,
2355 "text", SPLIT_COL_UNITS,
2356 "foreground", SPLIT_COL_UNITS_COLOR,
2357 nullptr);
2358 gtk_tree_view_append_column(view, column);
2359 gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(m_treeview),
2360 SPLIT_COL_TOOLTIP);}

Member Function Documentation

◆ load()

void GncFinishTreeview::load ( const EntryVec & list_of_splits)

Extract the information from the StockTransactionEntries in the vector created by the model's make_list_of_splits function and write it into the list view.

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

2364{
2365 auto gtv = GTK_TREE_VIEW(m_treeview);
2366 bool negative_in_red = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL,
2367 GNC_PREF_NEGATIVE_IN_RED);
2368 auto list = GTK_LIST_STORE(gtk_tree_view_get_model(gtv));
2369 gtk_list_store_clear(list);
2370 for (const auto &entry : list_of_splits) {
2371 GtkTreeIter iter;
2372 auto memo{entry->memo()};
2373 auto tooltip = (memo && *memo ?
2374 g_markup_escape_text(memo, -1) : strdup(""));
2375 /* print_value and print_amount rely on xaccPrintAmount that
2376 * uses static memory so the result needs to be copied
2377 * immediately or the second call overwrites the results of
2378 * the first one.
2379 */
2380 auto char2str{[](const char* str) -> std::string {
2381 return std::string{ str ? str : "" }; }};
2382 auto amount{char2str(entry->print_value())};
2383 auto units{char2str(entry->has_amount() ?
2384 entry->print_amount(entry->debit_side() ? entry->amount() :
2385 gnc_numeric_neg(entry->amount())) : "")};
2386 auto units_in_red{negative_in_red && !entry->debit_side()};
2387 gtk_list_store_append(list, &iter);
2388 gtk_list_store_set(
2389 list, &iter,
2390 SPLIT_COL_ACCOUNT,
2391 entry->print_account(), SPLIT_COL_MEMO,
2392 entry->memo(), SPLIT_COL_TOOLTIP, tooltip, SPLIT_COL_DEBIT,
2393 entry->debit_side() ? amount.c_str() : nullptr,
2394 SPLIT_COL_CREDIT,
2395 entry->debit_side() ? nullptr : amount.c_str(),
2396 SPLIT_COL_UNITS, units.c_str(),
2397 SPLIT_COL_UNITS_COLOR, units_in_red ? "red" : nullptr, -1);
2398 g_free(tooltip);
2399 }
2400}
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.

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