diff --git a/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp b/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp index 3e39920cc1c..fa1f368c127 100644 --- a/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp +++ b/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp @@ -35,6 +35,7 @@ #include #include +#include "gnc-list-model-container.hpp" #include "gnc-ui.h" #include "gnc-uri-utils.h" #include "gnc-ui-util.h" @@ -921,31 +922,25 @@ void CsvImpPriceAssist::preview_settings_save () { auto new_name = price_imp->settings_name(); + GncListModelContainer tree_model_container{gtk_combo_box_get_model (settings_combo)}; /* Check if the entry text matches an already existing preset */ GtkTreeIter iter; if (!gtk_combo_box_get_active_iter (settings_combo, &iter)) { - - auto model = gtk_combo_box_get_model (settings_combo); - bool valid = gtk_tree_model_get_iter_first (model, &iter); - while (valid) + for (auto iter : tree_model_container) { // Walk through the list, reading each row - CsvPriceImpSettings *preset; - gtk_tree_model_get (model, &iter, SET_GROUP, &preset, -1); - - if (preset && (preset->m_name == std::string(new_name))) + auto preset = iter.get_column(SET_GROUP); + if (preset && preset->m_name == new_name) { - auto response = gnc_ok_cancel_dialog (GTK_WINDOW(csv_imp_asst), - GTK_RESPONSE_OK, - "%s", _("Setting name already exists, overwrite?")); + auto response = gnc_ok_cancel_dialog (GTK_WINDOW(csv_imp_asst), GTK_RESPONSE_OK, + "%s", _("Setting name already exists, overwrite?")); if (response != GTK_RESPONSE_OK) return; break; } - valid = gtk_tree_model_iter_next (model, &iter); } } @@ -957,24 +952,13 @@ CsvImpPriceAssist::preview_settings_save () // Update the settings store preview_populate_settings_combo(); - auto model = gtk_combo_box_get_model (settings_combo); - - // Get the first entry in model - GtkTreeIter iter; - bool valid = gtk_tree_model_get_iter_first (model, &iter); - while (valid) - { - // Walk through the list, reading each row - gchar *name = nullptr; - gtk_tree_model_get (model, &iter, SET_NAME, &name, -1); - - if (g_strcmp0 (name, new_name.c_str()) == 0) // Set Active, the one Saved. - gtk_combo_box_set_active_iter (settings_combo, &iter); - g_free (name); - - valid = gtk_tree_model_iter_next (model, &iter); - } + for (auto iter : tree_model_container) + if (iter.get_column_string (SET_NAME) == new_name) // Set Active, the one Saved. + { + gtk_combo_box_set_active_iter (settings_combo, &iter.get_iter()); + break; + } } else gnc_error_dialog (GTK_WINDOW(csv_imp_asst), @@ -1516,7 +1500,6 @@ CsvImpPriceAssist::preview_row_fill_state_cells (GtkListStore *store, GtkTreeIte GtkWidget* CsvImpPriceAssist::preview_cbox_factory (GtkTreeModel* model, uint32_t colnum) { - GtkTreeIter iter; auto cbox = gtk_combo_box_new_with_model(model); /* Set up a renderer for this combobox. */ @@ -1526,18 +1509,14 @@ CsvImpPriceAssist::preview_cbox_factory (GtkTreeModel* model, uint32_t colnum) gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT(cbox), renderer, "text", COL_TYPE_NAME); - auto valid = gtk_tree_model_get_iter_first (model, &iter); - while (valid) + for (auto iter : GncListModelContainer (model)) { - gint stored_col_type; - gtk_tree_model_get (model, &iter, - COL_TYPE_ID, &stored_col_type, -1); - if (stored_col_type == static_cast( price_imp->column_types_price()[colnum])) + if (iter.get_column_int(COL_TYPE_ID) == static_cast( price_imp->column_types_price()[colnum])) + { + gtk_combo_box_set_active_iter (GTK_COMBO_BOX(cbox), &iter.get_iter()); break; - valid = gtk_tree_model_iter_next(model, &iter); + } } - if (valid) - gtk_combo_box_set_active_iter (GTK_COMBO_BOX(cbox), &iter); g_object_set_data (G_OBJECT(cbox), "col-num", GUINT_TO_POINTER(colnum)); g_signal_connect (G_OBJECT(cbox), "changed",