[niepce] ui: Don't expose columns from the tree model



commit 04f1ab9fa7b4197c0189f8185b27ed3dca854587
Author: Hubert Figuière <hub figuiere net>
Date:   Sat Jan 18 11:16:37 2020 -0500

    ui: Don't expose columns from the tree model

 src/niepce/ui/filmstripcontroller.cpp | 12 +-----------
 src/niepce/ui/gridviewmodule.cpp      | 15 ++++-----------
 src/niepce/ui/imageliststore.cpp      |  2 +-
 src/niepce/ui/imageliststore.hpp      |  2 --
 src/niepce/ui/moduleshell.cpp         |  5 ++---
 5 files changed, 8 insertions(+), 28 deletions(-)
---
diff --git a/src/niepce/ui/filmstripcontroller.cpp b/src/niepce/ui/filmstripcontroller.cpp
index e22584d..6bca0c2 100644
--- a/src/niepce/ui/filmstripcontroller.cpp
+++ b/src/niepce/ui/filmstripcontroller.cpp
@@ -59,7 +59,6 @@ Gtk::IconView * FilmStripController::image_list()
 
 eng::library_id_t FilmStripController::get_selected()
 {
-    eng::library_id_t id = 0;
     DBG_OUT("get selected in filmstrip");
     std::vector<Gtk::TreePath> paths = m_thumbview->get_selected_items();
 
@@ -69,16 +68,7 @@ eng::library_id_t FilmStripController::get_selected()
 
     Gtk::TreePath path(*(paths.begin()));
     DBG_OUT("found path %s", path.to_string().c_str());
-    Gtk::TreeRow row = *(m_store->get_iter(path));
-    if(row) {
-        DBG_OUT("found row");
-        eng::LibFilePtr libfile = row[m_store->columns().m_libfile];
-        if(libfile) {
-            id = engine_db_libfile_id(libfile.get());
-        }
-    }
-
-    return id;
+    return m_store->get_libfile_id_at_path(path);
 }
 
 void FilmStripController::select_image(eng::library_id_t id)
diff --git a/src/niepce/ui/gridviewmodule.cpp b/src/niepce/ui/gridviewmodule.cpp
index eb57c8d..9ce98de 100644
--- a/src/niepce/ui/gridviewmodule.cpp
+++ b/src/niepce/ui/gridviewmodule.cpp
@@ -129,11 +129,11 @@ Gtk::Widget * GridViewModule::buildWidget()
   Glib::RefPtr<Gtk::CellArea> cell_area = m_librarylistview->property_cell_area();
   cell_area->pack_start(*libcell, FALSE);
   cell_area->add_attribute(*libcell, "pixbuf",
-                                  m_model->columns().m_pix.index());
+                           ImageListStore::Columns::THUMB_INDEX);
   cell_area->add_attribute(*libcell, "libfile",
-                                  m_model->columns().m_libfile.index());
+                           ImageListStore::Columns::FILE_INDEX);
   cell_area->add_attribute(*libcell, "status",
-                                  m_model->columns().m_file_status.index());
+                           ImageListStore::Columns::FILE_STATUS_INDEX);
 
   m_scrollview.add(*m_librarylistview);
   m_scrollview.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
@@ -183,14 +183,7 @@ eng::library_id_t GridViewModule::get_selected()
     if(!paths.empty()) {
         Gtk::TreePath path(*(paths.begin()));
         DBG_OUT("found path %s", path.to_string().c_str());
-        Gtk::TreeRow row = *(m_model->get_iter(path));
-        if(row) {
-            DBG_OUT("found row");
-            eng::LibFilePtr libfile = row[m_model->columns().m_libfile];
-            if(libfile) {
-                id = engine_db_libfile_id(libfile.get());
-            }
-        }
+        id = m_model->get_libfile_id_at_path(path);
     }
     DBG_OUT("get_selected %Ld", (long long)id);
     return id;
diff --git a/src/niepce/ui/imageliststore.cpp b/src/niepce/ui/imageliststore.cpp
index a59befb..b9ae872 100644
--- a/src/niepce/ui/imageliststore.cpp
+++ b/src/niepce/ui/imageliststore.cpp
@@ -92,7 +92,7 @@ Gtk::TreePath ImageListStore::get_path_from_id(eng::library_id_t id) const
 eng::library_id_t ImageListStore::get_libfile_id_at_path(const Gtk::TreePath& path)
 {
     auto iter = get_iter(path);
-    eng::LibFilePtr libfile = (*iter)[columns().m_libfile];
+    eng::LibFilePtr libfile = (*iter)[m_columns.m_libfile];
     if (libfile) {
         return engine_db_libfile_id(libfile.get());
     }
diff --git a/src/niepce/ui/imageliststore.hpp b/src/niepce/ui/imageliststore.hpp
index aa85839..a5bb3bd 100644
--- a/src/niepce/ui/imageliststore.hpp
+++ b/src/niepce/ui/imageliststore.hpp
@@ -62,8 +62,6 @@ public:
         Gtk::TreeModelColumn<eng::FileStatus> m_file_status;
     };
 
-    const Columns & columns() const
-        { return m_columns; }
     Gtk::TreePath get_path_from_id(eng::library_id_t id) const;
     Gtk::TreeIter get_iter_from_id(eng::library_id_t id) const;
     eng::library_id_t get_libfile_id_at_path(const Gtk::TreePath& path);
diff --git a/src/niepce/ui/moduleshell.cpp b/src/niepce/ui/moduleshell.cpp
index 8e79ee4..a91e6b0 100644
--- a/src/niepce/ui/moduleshell.cpp
+++ b/src/niepce/ui/moduleshell.cpp
@@ -260,9 +260,8 @@ void ModuleShell::on_image_activated(eng::library_id_t id)
 {
     DBG_OUT("on image activated %Ld", (long long)id);
     auto store = m_selection_controller->get_list_store();
-    auto iter = store->get_iter_from_id(id);
-    if(iter) {
-        auto libfile = (*iter)[store->columns().m_libfile];
+    auto libfile = store->get_file(id);
+    if (libfile) {
         m_darkroom->set_image(libfile);
         m_shell.activatePage("darkroom");
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]