Use treestore instead of liststore for database

This commit is contained in:
zvon 2020-02-09 16:57:37 +01:00
parent 59247b1c4f
commit 564c7b09e2
2 changed files with 6 additions and 10 deletions

View File

@ -1,6 +1,5 @@
#include <gtkmm/box.h> #include <gtkmm/box.h>
#include <gtkmm/button.h> #include <gtkmm/button.h>
#include <gtkmm/liststore.h>
#include <gtkmm/messagedialog.h> #include <gtkmm/messagedialog.h>
#include <gtkmm/scrolledwindow.h> #include <gtkmm/scrolledwindow.h>
#include <thread> #include <thread>
@ -77,7 +76,7 @@ DatabaseWindow::DatabaseWindow( bool _linux,
button_quit->set_size_request( 80, 30 ); button_quit->set_size_request( 80, 30 );
// set database model // set database model
m_model = Gtk::ListStore::create( m_columns_database ); m_model = Gtk::TreeStore::create( m_columns_database );
m_tree_database->set_model( m_model ); m_tree_database->set_model( m_model );
for ( auto &x : dbGetShows() ) { for ( auto &x : dbGetShows() ) {
@ -89,7 +88,7 @@ DatabaseWindow::DatabaseWindow( bool _linux,
row[m_columns_database.m_col_path] = x["PATH"]; row[m_columns_database.m_col_path] = x["PATH"];
row[m_columns_database.m_col_lang] = x["LANGUAGE"]; row[m_columns_database.m_col_lang] = x["LANGUAGE"];
row[m_columns_database.m_col_show_id] = x["TVID"]; row[m_columns_database.m_col_show_id] = x["TVID"];
row[m_columns_database.m_col_dvd] = ( x["DVD"] == "1" ? "Yes" : "No" ); row[m_columns_database.m_col_dvd] = x["DVD"] == "1";
} }
m_tree_database->append_column( "Show", m_columns_database.m_col_show ); m_tree_database->append_column( "Show", m_columns_database.m_col_show );
@ -125,10 +124,7 @@ void DatabaseWindow::save() {
std::string path = x[m_columns_database.m_col_path]; std::string path = x[m_columns_database.m_col_path];
std::string lang = x[m_columns_database.m_col_lang]; std::string lang = x[m_columns_database.m_col_lang];
std::string show_id = x[m_columns_database.m_col_show_id]; std::string show_id = x[m_columns_database.m_col_show_id];
std::string dvd_string = x[m_columns_database.m_col_dvd]; bool dvd = x[m_columns_database.m_col_dvd];
std::transform( dvd_string.begin(), dvd_string.end(),
dvd_string.begin(), ::tolower );
bool dvd = dvd_string == "yes";
changeDB( index, path, lang, show_id, dvd ); changeDB( index, path, lang, show_id, dvd );
} }
} }

View File

@ -1,7 +1,7 @@
#ifndef GTKMM_DATABASE_WINDOW #ifndef GTKMM_DATABASE_WINDOW
#define GTKMM_DATABASE_WINDOW #define GTKMM_DATABASE_WINDOW
#include <gtkmm/liststore.h> #include <gtkmm/treestore.h>
#include <gtkmm/treeview.h> #include <gtkmm/treeview.h>
#include <gtkmm/window.h> #include <gtkmm/window.h>
#include <unordered_set> #include <unordered_set>
@ -43,11 +43,11 @@ protected:
Gtk::TreeModelColumn< std::string > m_col_path; Gtk::TreeModelColumn< std::string > m_col_path;
Gtk::TreeModelColumn< std::string > m_col_lang; Gtk::TreeModelColumn< std::string > m_col_lang;
Gtk::TreeModelColumn< std::string > m_col_show_id; Gtk::TreeModelColumn< std::string > m_col_show_id;
Gtk::TreeModelColumn< std::string > m_col_dvd; Gtk::TreeModelColumn< bool > m_col_dvd;
}; };
DatabaseColumns m_columns_database; DatabaseColumns m_columns_database;
Glib::RefPtr< Gtk::ListStore > m_model; Glib::RefPtr< Gtk::TreeStore > m_model;
bool linux; bool linux;
Glib::RefPtr< Gtk::Application > app; Glib::RefPtr< Gtk::Application > app;