codekiddy2 / Visual-Studio-gtkmm

Visual Studio 2015 Projects to build gtkmm from nowhere up to gtkmm itself
32 stars 6 forks source link

Problem with Gtk::TreeView and Gtk::TreeModelFilter #7

Closed cmmsrg closed 8 years ago

cmmsrg commented 8 years ago

Hi codekiddy2,

I'm using your pre-built Gtkmm binaries (gtkmm 3.16 for Visual Studio 2015 Debug x64). Thanks! But I have a problem relating to Gtk::TreeView and Gtk::TreeModelFilter.

In concrete terms, I try to execute an official Gtkmm example (https://git.gnome.org/browse/gtkmm-documentation/tree/examples/book/treeview/filter), but I don't succeed.

Software execution is broken during ExampleWindow class costruction, more specifically at line Gtk::TreeModel::Row row = *(m_refTreeModel->append());. Here is relevant code:

#include <gtkmm.h>
#include <iostream>

class ExampleWindow : public Gtk::Window
{
public:
    ExampleWindow();
    virtual ~ExampleWindow();

protected:
    //Signal handlers:
    void on_button_quit();

    //Tree model columns:
    class ModelColumns : public Gtk::TreeModel::ColumnRecord
    {
    public:

        ModelColumns()
        { add(m_col_id); add(m_col_name); add(m_col_show); }

        Gtk::TreeModelColumn<unsigned int> m_col_id;
        Gtk::TreeModelColumn<Glib::ustring> m_col_name;
        Gtk::TreeModelColumn<bool> m_col_show; //filter on this value
    };

    ModelColumns m_Columns;

    //Child widgets:
    Gtk::Box m_VBox;

    Gtk::ScrolledWindow m_ScrolledWindow;
    Gtk::TreeView m_TreeView;
    Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
    Glib::RefPtr<Gtk::TreeModelFilter> m_refTreeModelFilter;

    Gtk::ButtonBox m_ButtonBox;
    Gtk::Button m_Button_Quit;
};

ExampleWindow::ExampleWindow()
    : m_VBox(Gtk::ORIENTATION_VERTICAL),
    m_Button_Quit("Quit")
{
    set_title("Gtk::TreeView (TreeModelFilter) example");
    set_border_width(5);
    set_default_size(400, 200);

    add(m_VBox);

    //Add the TreeView, inside a ScrolledWindow, with the button underneath:
    m_ScrolledWindow.add(m_TreeView);

    //Only show the scrollbars when they are necessary:
    m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);

    m_VBox.pack_start(m_ScrolledWindow);
    m_VBox.pack_start(m_ButtonBox, Gtk::PACK_SHRINK);

    m_ButtonBox.pack_start(m_Button_Quit, Gtk::PACK_SHRINK);
    m_ButtonBox.set_border_width(5);
    m_ButtonBox.set_layout(Gtk::BUTTONBOX_END);
    m_Button_Quit.signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_button_quit) );

    //Create the Tree model:
    m_refTreeModel = Gtk::ListStore::create(m_Columns);

    //Put the TreeModel inside a filter model:
    m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);
    m_refTreeModelFilter->set_visible_func
    (
        [this] (const Gtk::TreeModel::const_iterator& iter) -> bool
        {
            if(!iter)
                return true;

            auto row = *iter;
            return row[m_Columns.m_col_show];
        }
    );

    m_TreeView.set_model(m_refTreeModelFilter);

    //Fill the TreeView's model
    Gtk::TreeModel::Row row = *(m_refTreeModel->append());  // <== C R A S H    H E R E ! ! !
    row[m_Columns.m_col_id] = 1;
    row[m_Columns.m_col_name] = "Billy Bob";
    row[m_Columns.m_col_show] = true;

    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_id] = 2;
    row[m_Columns.m_col_name] = "Joey Jojo";
    row[m_Columns.m_col_show] = true;

    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_id] = 3;
    row[m_Columns.m_col_name] = "Rob McRoberts";
    //This should cause this row to be filtered out (now shown).
    row[m_Columns.m_col_show] = false;

    //Add the TreeView's view columns:
    m_TreeView.append_column("ID", m_Columns.m_col_id);
    m_TreeView.append_column("Name", m_Columns.m_col_name);
    m_TreeView.append_column_editable("Show", m_Columns.m_col_show);

    //Make all the columns reorderable:
    //This is not necessary, but it's nice to show the feature.
    //You can use TreeView::set_column_drag_function() to more
    //finely control column drag and drop.
    for(guint i = 0; i < 2; i++)
    {
        auto pColumn = m_TreeView.get_column(i);
        pColumn->set_reorderable();
    }

    show_all_children();
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
    hide();
}

int main(int argc, char *argv[])
{
    auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example");

    ExampleWindow window;

    //Shows the window and returns when it is closed.
    return app->run(window);
}

Moreover, Visual Studio shows a popup stating following message:

What is the problem? Would you help me to fix it :)? Thanks a lot!

Sergio​ Cammarata​

codekiddy2 commented 8 years ago

Hi cmmsrg, Thank you for reporting this issue, I'm currently compiling and upgrading new version of pre-built libraries, download link to new libs will be available in few days.

From what I gathered there are new updates from MS in VS Update 2, and some settings used to compile current pre-built libs are not compatible any more (compile setting), not sure but before uploading new pre-built package I'll test your sample code and you'll be notified here in this issue about updates.

Thank you again, see you in few days!

cmmsrg commented 8 years ago

It's perfect. Thanks a lot for your commitment, your project is great!

See you soon!

codekiddy2 commented 8 years ago

Hello again cmmsrg!

as promised new build result was added to release section, in addition x86 build was added. for details and download links see release section

sorry, couldn't upload sooner, very little free time available :/

Thank you again for reporting, if error is still there or you encounter other problems please let me know, thanks!

cmmsrg commented 8 years ago

Hi codekiddy2!

Problem related to Gtk::TreeView and Gtk::TreeModelFilter is fixed! Thank-thank-thank you very much!!

Just 2 little issues:

GtkTreeView row:nth-child(even)
{
...
} 
GtkTreeView row:nth-child(odd)
{
...
} 

But it didn't work. My working fix was to add MyTreeView.set_rules_hint(true); in my C++ code and add lines shown below in my css file:

GtkTreeView row:even
{
...
} 
GtkTreeView row:odd
{
...
} 

But this was really strange because Gtk::TreeView::set_rules_hint is deprecated since Gtkmm 3.14!

My fix no longer works with your latest binaries, because Gtk::TreeView::set_rules_hint is truly deprecated.

Why are official instructions inoperative? How to fix it?

Thanks!!

codekiddy2 commented 8 years ago

H, thanks again for report!

the $(INCLUDE_DIR)intl will be corrected next time, it looks like this include directory doesn't play the role for simple projects and somehow I missed that :/

the GtkTreeView row:nth-child(even) seems to be a bug since 3.14 or something, because there are several reports like this one from people around complaining about this.

For now I would wait for new release of Gtk+ and gtkmm, current gtk+,gtkmm 3.20 doesn't compile well, unstable version 3.21 doesn't mention these fixes yet, so reporting this issue on gtkmm mailing list should give better response, at least to let gtkmm devs know about this problem.