From 9b30bb2b629edbaaf7fa12854f3a7ba3ded84d36 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Sat, 22 Apr 2017 17:00:34 +0200 Subject: [PATCH] Various small fixups in csv importer - Use descriptive names instead of numbers in std::get<> - Remove unused parameters - Fix some doxigen comments --- .../csv-imp/assistant-csv-trans-import.cpp | 16 ++---- .../csv-imp/gnc-csv-trans-settings.cpp | 2 +- .../csv-imp/gnc-csv-trans-settings.hpp | 7 +-- src/import-export/csv-imp/gnc-tx-import.cpp | 56 +++++++++---------- src/import-export/csv-imp/gnc-tx-import.hpp | 5 ++ 5 files changed, 39 insertions(+), 47 deletions(-) diff --git a/src/import-export/csv-imp/assistant-csv-trans-import.cpp b/src/import-export/csv-imp/assistant-csv-trans-import.cpp index ce4ff79e0a..05219dab45 100644 --- a/src/import-export/csv-imp/assistant-csv-trans-import.cpp +++ b/src/import-export/csv-imp/assistant-csv-trans-import.cpp @@ -793,7 +793,6 @@ CsvImpTransAssist::preview_settings_delete () void CsvImpTransAssist::preview_settings_save () { - auto title = _("Save the Import Settings."); auto new_name = tx_imp->settings_name(); /* Check if the entry text matches an already existing preset */ @@ -889,7 +888,6 @@ void CsvImpTransAssist::preview_multi_split (bool multi) * separator checkbuttons or the custom separator entry) is * changed. * @param widget The widget that was changed - * @param info The data that is being configured */ void CsvImpTransAssist::preview_update_separators (GtkWidget* widget) { @@ -952,8 +950,6 @@ void CsvImpTransAssist::preview_update_separators (GtkWidget* widget) /** Event handler for clicking one of the format type radio * buttons. This occurs if the format (Fixed-Width or CSV) is changed. - * @param csv_button The "Separated" radio button - * @param info The display of the data being imported */ void CsvImpTransAssist::preview_update_file_format () { @@ -1007,7 +1003,6 @@ void CsvImpTransAssist::preview_update_account () /** Event handler for a new encoding. This is called when the user * selects a new encoding; the data is reparsed and shown to the * user. - * @param selector The widget the user uses to select a new encoding * @param encoding The encoding that the user selected */ void @@ -1080,10 +1075,7 @@ enum PreviewDataTableCols { * user selects a new column type, that column's text must be changed * to the selection, and any other columns containing that selection * must be changed to "None" because we don't allow duplicates. - * @param renderer The renderer of the column the user changed - * @param path There is only 1 row in info->ctreeview, so this is always 0. - * @param new_text The text the user selected - * @param info The display of the data being imported + * @param cbox The combo box the user just clicked to make a change */ void CsvImpTransAssist::preview_update_col_type (GtkComboBox* cbox) { @@ -1470,12 +1462,12 @@ void CsvImpTransAssist::preview_refresh_table () GtkTreeIter iter; gtk_list_store_append (store, &iter); preview_row_fill_state_cells (store, &iter, - std::get<1>(parse_line), std::get<4>(parse_line)); + std::get(parse_line), std::get(parse_line)); /* Fill the data cells. */ - for (auto cell_str_it = std::get<0>(parse_line).cbegin(); cell_str_it != std::get<0>(parse_line).cend(); cell_str_it++) + for (auto cell_str_it = std::get(parse_line).cbegin(); cell_str_it != std::get(parse_line).cend(); cell_str_it++) { - uint32_t pos = PREV_N_FIXED_COLS + cell_str_it - std::get<0>(parse_line).cbegin(); + uint32_t pos = PREV_N_FIXED_COLS + cell_str_it - std::get(parse_line).cbegin(); gtk_list_store_set (store, &iter, pos, cell_str_it->c_str(), -1); } } diff --git a/src/import-export/csv-imp/gnc-csv-trans-settings.cpp b/src/import-export/csv-imp/gnc-csv-trans-settings.cpp index 82b436e662..f3456f0220 100644 --- a/src/import-export/csv-imp/gnc-csv-trans-settings.cpp +++ b/src/import-export/csv-imp/gnc-csv-trans-settings.cpp @@ -245,7 +245,7 @@ CsvTransSettings::load (void) if (key_char && *key_char != '\0') m_encoding = key_char; else - "UTF-8"; + m_encoding = "UTF-8"; m_load_error |= handle_load_error (&key_error, group); if (key_char) g_free (key_char); diff --git a/src/import-export/csv-imp/gnc-csv-trans-settings.hpp b/src/import-export/csv-imp/gnc-csv-trans-settings.hpp index 490eb66785..6bcb4a4cbf 100644 --- a/src/import-export/csv-imp/gnc-csv-trans-settings.hpp +++ b/src/import-export/csv-imp/gnc-csv-trans-settings.hpp @@ -75,9 +75,6 @@ void remove (void); * The internally generated presets are read-only. The others * can be saved to the state file or deleted. * - * @param group The group name where the settings are stored in the - * key file. - * * @return true if there was a problem. */ bool read_only (void); @@ -89,8 +86,8 @@ std::string m_encoding; // File encoding bool m_multi_split; // Assume multiple lines per transaction int m_date_format; // Date Active id int m_currency_format; // Currency Active id -uint32_t m_skip_start_lines; // Number of header rows to skip -uint32_t m_skip_end_lines; // Number of footer rows to skip +uint32_t m_skip_start_lines; // Number of header rows to skip +uint32_t m_skip_end_lines; // Number of footer rows to skip bool m_skip_alt_lines; // Skip alternate rows std::string m_separators; // Separators for csv format diff --git a/src/import-export/csv-imp/gnc-tx-import.cpp b/src/import-export/csv-imp/gnc-tx-import.cpp index 2e102d463d..7dbaff82d0 100644 --- a/src/import-export/csv-imp/gnc-tx-import.cpp +++ b/src/import-export/csv-imp/gnc-tx-import.cpp @@ -59,7 +59,6 @@ const gchar* currency_format_user[] = {N_("Locale"), /** Constructor for GncTxImport. - * @return Pointer to a new GncCSvParseData */ GncTxImport::GncTxImport(GncImpFileFormat format) { @@ -139,7 +138,7 @@ GncImpFileFormat GncTxImport::file_format() * will force a reparsing of the transaction properties (if there are * any) by resetting the first column with a transaction property * it encounters. - * @param multi_split_val Boolean value with desired state (multi-split + * @param multi_split Boolean value with desired state (multi-split * vs two-split). */ void GncTxImport::multi_split (bool multi_split) @@ -172,7 +171,7 @@ bool GncTxImport::multi_split () { return m_settings.m_multi_split; } * in the import data. * In multi-split mode the user has to select an account column so in * that mode the base_account can't be set. - * @param base_acct Pointer to an account or NULL. + * @param base_account Pointer to an account or NULL. */ void GncTxImport::base_account (Account* base_account) { @@ -194,7 +193,7 @@ void GncTxImport::base_account (Account* base_account) /* Set default account for each line's split properties */ for (auto line : m_parsed_lines) - std::get<3>(line)->set_account (m_settings.m_base_account); + std::get(line)->set_account (m_settings.m_base_account); } @@ -276,12 +275,12 @@ void GncTxImport::update_skipped_lines(boost::optional start, boost::o for (uint32_t i = 0; i < m_parsed_lines.size(); i++) { - std::get<4>(m_parsed_lines[i]) = + std::get(m_parsed_lines[i]) = ((i < skip_start_lines()) || // start rows to skip (i >= m_parsed_lines.size() - skip_end_lines()) || // end rows to skip (((i - skip_start_lines()) % 2 == 1) && // skip every second row... skip_alt_lines()) || // ...if requested - (m_skip_errors && !std::get<1>(m_parsed_lines[i]).empty())); // skip lines with errors + (m_skip_errors && !std::get(m_parsed_lines[i]).empty())); // skip lines with errors } } @@ -425,7 +424,7 @@ void GncTxImport::tokenize (bool guessColTypes) if (m_settings.m_base_account) { for (auto line : m_parsed_lines) - std::get<3>(line)->set_account (m_settings.m_base_account); + std::get(line)->set_account (m_settings.m_base_account); } if (guessColTypes) @@ -539,7 +538,7 @@ std::string GncTxImport::verify () auto have_line_errors = false; for (auto line : m_parsed_lines) { - if (!std::get<4>(line) && !std::get<1>(line).empty()) + if (!std::get(line) && !std::get(line).empty()) { have_line_errors = true; break; @@ -720,7 +719,7 @@ void GncTxImport::create_transactions () ++parsed_lines_it) { /* Skip current line if the user specified so */ - if ((std::get<4>(*parsed_lines_it))) + if ((std::get(*parsed_lines_it))) continue; /* Should not throw anymore, otherwise verify needs revision */ @@ -743,11 +742,11 @@ void GncTxImport::update_pre_trans_props (uint32_t row, uint32_t col, GncTransPr if ((prop_type == GncTransPropType::NONE) || (prop_type > GncTransPropType::TRANS_PROPS)) return; /* Only deal with transaction related properties. */ - auto trans_props = std::make_shared (*(std::get<2>(m_parsed_lines[row])).get()); + auto trans_props = std::make_shared (*(std::get(m_parsed_lines[row])).get()); auto value = std::string(); - if (col < std::get<0>(m_parsed_lines[row]).size()) - value = std::get<0>(m_parsed_lines[row]).at(col); + if (col < std::get(m_parsed_lines[row]).size()) + value = std::get(m_parsed_lines[row]).at(col); if (value.empty()) trans_props->reset (prop_type); @@ -762,13 +761,13 @@ void GncTxImport::update_pre_trans_props (uint32_t row, uint32_t col, GncTransPr /* Do nothing, just prevent the exception from escalating up * However log the error if it happens on a row that's not skipped */ - if (!std::get<4>(m_parsed_lines[row])) + if (!std::get(m_parsed_lines[row])) PINFO("User warning: %s", e.what()); } } /* Store the result */ - std::get<2>(m_parsed_lines[row]) = trans_props; + std::get(m_parsed_lines[row]) = trans_props; /* For multi-split input data, we need to check whether this line is part of * a transaction that has already been started by a previous line. */ @@ -779,7 +778,7 @@ void GncTxImport::update_pre_trans_props (uint32_t row, uint32_t col, GncTransPr /* This line is part of an already started transaction * continue with that one instead to make sure the split from this line * gets added to the proper transaction */ - std::get<2>(m_parsed_lines[row]) = m_parent; + std::get(m_parsed_lines[row]) = m_parent; } else { @@ -796,11 +795,11 @@ void GncTxImport::update_pre_split_props (uint32_t row, uint32_t col, GncTransPr if ((prop_type > GncTransPropType::SPLIT_PROPS) || (prop_type <= GncTransPropType::TRANS_PROPS)) return; /* Only deal with split related properties. */ - auto split_props = std::get<3>(m_parsed_lines[row]); + auto split_props = std::get(m_parsed_lines[row]); auto value = std::string(); - if (col < std::get<0>(m_parsed_lines[row]).size()) - value = std::get<0>(m_parsed_lines[row]).at(col); + if (col < std::get(m_parsed_lines[row]).size()) + value = std::get(m_parsed_lines[row]).at(col); if (value.empty()) split_props->reset (prop_type); @@ -815,7 +814,7 @@ void GncTxImport::update_pre_split_props (uint32_t row, uint32_t col, GncTransPr /* Do nothing, just prevent the exception from escalating up * However log the error if it happens on a row that's not skipped */ - if (!std::get<4>(m_parsed_lines[row])) + if (!std::get(m_parsed_lines[row])) PINFO("User warning: %s", e.what()); } } @@ -851,9 +850,9 @@ GncTxImport::set_column_type (uint32_t position, GncTransPropType type, bool for /* Reset date and currency formats for each trans/split props object * to ensure column updates use the most recent one */ - std::get<2>(*parsed_lines_it)->set_date_format (m_settings.m_date_format); - std::get<3>(*parsed_lines_it)->set_date_format (m_settings.m_date_format); - std::get<3>(*parsed_lines_it)->set_currency_format (m_settings.m_currency_format); + std::get(*parsed_lines_it)->set_date_format (m_settings.m_date_format); + std::get(*parsed_lines_it)->set_date_format (m_settings.m_date_format); + std::get(*parsed_lines_it)->set_currency_format (m_settings.m_currency_format); uint32_t row = parsed_lines_it - m_parsed_lines.begin(); @@ -862,7 +861,7 @@ GncTxImport::set_column_type (uint32_t position, GncTransPropType type, bool for */ if (old_type != type) { - auto old_col = std::get<0>(*parsed_lines_it).size(); // Deliberately out of bounds to trigger a reset! + auto old_col = std::get(*parsed_lines_it).size(); // Deliberately out of bounds to trigger a reset! if ((old_type > GncTransPropType::NONE) && (old_type <= GncTransPropType::TRANS_PROPS)) update_pre_trans_props (row, old_col, old_type); @@ -880,9 +879,9 @@ GncTxImport::set_column_type (uint32_t position, GncTransPropType type, bool for update_pre_split_props (row, position, type); /* Report errors if there are any */ - auto trans_errors = std::get<2>(*parsed_lines_it)->errors(); - auto split_errors = std::get<3>(*parsed_lines_it)->errors(m_req_mapped_accts); - std::get<1>(*parsed_lines_it) = + auto trans_errors = std::get(*parsed_lines_it)->errors(); + auto split_errors = std::get(*parsed_lines_it)->errors(m_req_mapped_accts); + std::get(*parsed_lines_it) = trans_errors + (trans_errors.empty() && split_errors.empty() ? std::string() : "\n") + split_errors; @@ -907,14 +906,13 @@ GncTxImport::accounts () uint32_t tacct_col = tacct_col_it - m_settings.m_column_types.begin(); /* Iterate over all parsed lines */ - auto odd_line = false; for (auto parsed_line : m_parsed_lines) { /* Skip current line if the user specified so */ - if ((std::get<4>(parsed_line))) + if ((std::get(parsed_line))) continue; - auto col_strs = std::get<0>(parsed_line); + auto col_strs = std::get(parsed_line); if ((acct_col_it != m_settings.m_column_types.end()) && !col_strs[acct_col].empty()) accts.insert(col_strs[acct_col]); if ((tacct_col_it != m_settings.m_column_types.end()) && !col_strs[tacct_col].empty()) diff --git a/src/import-export/csv-imp/gnc-tx-import.hpp b/src/import-export/csv-imp/gnc-tx-import.hpp index c76382720b..c9eb8cac0a 100644 --- a/src/import-export/csv-imp/gnc-tx-import.hpp +++ b/src/import-export/csv-imp/gnc-tx-import.hpp @@ -73,6 +73,11 @@ extern const gchar* date_format_user[]; * - an optional error string * - a struct to hold user selected properties for a transaction * - a struct to hold user selected properties for one or two splits in the above transaction */ +#define PL_INPUT 0 +#define PL_ERROR 1 +#define PL_PRETRANS 2 +#define PL_PRESPLIT 3 +#define PL_SKIP 4 using parse_line_t = std::tuple,