[glom] ComboChoices_WithTreeModel: Use unique_ptr<> for columns.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] ComboChoices_WithTreeModel: Use unique_ptr<> for columns.
- Date: Sat, 6 Feb 2016 16:35:54 +0000 (UTC)
commit 8f3101c6c62dc9a930833e2caa07e0f7e667bb25
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Feb 5 22:29:36 2016 +0100
ComboChoices_WithTreeModel: Use unique_ptr<> for columns.
.../datawidget/combochoiceswithtreemodel.cc | 37 +++++--------------
.../datawidget/combochoiceswithtreemodel.h | 4 +-
2 files changed, 12 insertions(+), 29 deletions(-)
---
diff --git a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
index 2a4212d..1f5a03b 100644
--- a/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
+++ b/glom/mode_data/datawidget/combochoiceswithtreemodel.cc
@@ -66,30 +66,28 @@ void ComboChoicesWithTreeModel::create_model_non_db(guint columns_count)
//Create the TreeModelColumns, adding them to the ColumnRecord:
- m_vec_model_columns_value_fixed.resize(columns_count, 0);
+ m_vec_model_columns_value_fixed.resize(columns_count);
for(guint i = 0; i < columns_count; ++i)
{
//Create a value column for all columns
//for instance for later value comparison.
- auto model_column = new type_model_column_value_fixed();
-
- //Store it so we can use it and delete it later:
- m_vec_model_columns_value_fixed[i] = model_column;
-
+ auto model_column = std::make_unique<type_model_column_value_fixed>();
record.add(*model_column);
+
+ //Store it so we can use it and delete it later:
+ m_vec_model_columns_value_fixed[i] = std::move(model_column);
}
//Create a text column, for use by a GtkComboBox with has-entry, which allows no other column type:
//Note that get_fixed_model_text_column() assumes that this is the last column:
- m_vec_model_columns_string_fixed.resize(1, 0);
+ m_vec_model_columns_string_fixed.resize(1); //TODO: Shouldn't this be 0?
if(columns_count > 0)
{
- auto model_column = new type_model_column_string_fixed();
-
- //Store it so we can use it and delete it later:
- m_vec_model_columns_string_fixed.push_back(model_column);
-
+ auto model_column = std::make_unique<type_model_column_string_fixed>();
record.add(*model_column);
+
+ //Store it so we can use it and delete it later:
+ m_vec_model_columns_string_fixed.push_back(std::move(model_column));
}
//Create the model:
@@ -98,21 +96,6 @@ void ComboChoicesWithTreeModel::create_model_non_db(guint columns_count)
void ComboChoicesWithTreeModel::delete_model()
{
- //Delete the vector's items:
- for(const auto& model_column : m_vec_model_columns_string_fixed)
- {
- delete model_column;
- }
- m_vec_model_columns_string_fixed.clear();
-
- //Delete the vector's items:
- for(const auto& model_column : m_vec_model_columns_value_fixed)
- {
- delete model_column;
- }
- m_vec_model_columns_value_fixed.clear();
-
- m_refModel.reset();
}
/* TODO: Remove this
diff --git a/glom/mode_data/datawidget/combochoiceswithtreemodel.h
b/glom/mode_data/datawidget/combochoiceswithtreemodel.h
index c9a5099..3d4b6d2 100644
--- a/glom/mode_data/datawidget/combochoiceswithtreemodel.h
+++ b/glom/mode_data/datawidget/combochoiceswithtreemodel.h
@@ -59,11 +59,11 @@ protected:
typedef Gtk::TreeModelColumn<Glib::ustring> type_model_column_string_fixed;
- typedef std::vector< type_model_column_string_fixed* > type_vec_model_columns_string_fixed;
+ typedef std::vector<std::unique_ptr<type_model_column_string_fixed>> type_vec_model_columns_string_fixed;
type_vec_model_columns_string_fixed m_vec_model_columns_string_fixed; //If set_choices_fixed() was used.
typedef Gtk::TreeModelColumn<Gnome::Gda::Value> type_model_column_value_fixed;
- typedef std::vector< type_model_column_value_fixed* > type_vec_model_columns_value_fixed;
+ typedef std::vector<std::unique_ptr<type_model_column_value_fixed>> type_vec_model_columns_value_fixed;
type_vec_model_columns_value_fixed m_vec_model_columns_value_fixed; //If set_choices_fixed() was used.
/** Get the index of the extra column, at the end, that is just a
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]