Re: Problem with a TreeView - speed
- From: Dimitri Holz <d holz innoventis de>
- To: gtkmm-list gnome org, Murray Cumming <murrayc murrayc com>
- Subject: Re: Problem with a TreeView - speed
- Date: Mon, 16 Mar 2009 15:00:40 +0100
____I'm programming C++ and Gtkmm since less than one year and I'm a
student without programming-experiences. Because of that I don't
perfectly ____understand what you mean with using of cell_data_func to
show the visible parts of the row. I found by searching in google this:
On Mon, 2006-03-27 at 17:05 +0200, Murray Cumming wrote:
> Am I right in thinking that GtkTreeView shouldn't call the cell_data
> callback for cells that aren't visible?
>
> The attached test case shows it being called for every row (even if only
> a few are visible in the GtkScrolledWindow), and then called again for
> the visible rows. This is not so nice when I must retrieve the data (in
> my custom model) from a database.
Answering myself, this can be fixed by calling
gtk_tree_view_set_fixed_height_mode(), which in turn needs us to call
gtk_tree_view_column_set_sizing() on each GtkTreeViewColumn.
____But I don't how to use it in my project. So I try to discribe a building of my code:
____I have a class FlowTrafficView that is respnonsible for displaying the CAN-bus-traffic and it has following member-variables -
Glib::RefPtr<Gtk::ListStore> m_oRefPtrListStore;
Gtk::ScrolledWindow m_oScrollableMsgList;
Gtk::TreeView m_oTreeViewMsgList;
struct ModelColumns : public Gtk::TreeModelColumnRecord
{
Gtk::TreeModelColumn<Glib::ustring> Way;
Gtk::TreeModelColumn<Glib::ustring> Timestamp;
Gtk::TreeModelColumn<Glib::ustring> IdMode;
Gtk::TreeModelColumn<Glib::ustring> ID;
Gtk::TreeModelColumn<Glib::ustring> DLC;
Gtk::TreeModelColumn<Glib::ustring> Data;
Gtk::TreeModelColumn<Glib::ustring> FrameMode;
ModelColumns()
{
add(Way);
add(Timestamp);
add(IdMode);
add(ID);
add(DLC);
add(Data);
add(FrameMode);
}
};
const ModelColumns m_oColumns;
____than I have a method that will called only once from a constructor -
void FlowTrafficView::MySetUpGui()
{
/*
* create tree view
*/
m_oRefPtrListStore = Gtk::ListStore::create(m_oColumns);
m_oTreeViewMsgList.set_model(m_oRefPtrListStore);
m_oTreeViewMsgList.set_rules_hint();
Gdk::Color color;
color.set_rgb(62000,62000,59000);
m_oTreeViewMsgList.modify_base(Gtk::STATE_NORMAL,color);
/* column for Way */
{
Gtk::CellRendererText* pRenderer = Gtk::manage(new
Gtk::CellRendererText());
color.set_rgb(20000,20000,20000);
pRenderer->property_foreground_gdk().set_value(color);
int cols_count = m_oTreeViewMsgList.append_column("Way",
*pRenderer);
Gtk::TreeViewColumn* pColumn =
m_oTreeViewMsgList.get_column(cols_count-1);
pColumn->add_attribute(pRenderer->_property_renderable(),
m_oColumns.Way);
color.set_rgb(58000,58000,56000);
pColumn->get_first_cell_renderer()->property_cell_background_gdk() = color;
pColumn->get_first_cell_renderer()->property_xalign() = 0.5;
pColumn->set_resizable(true);
}
/* column for timestamp */
{
Gtk::CellRendererText* pRenderer = Gtk::manage(new
Gtk::CellRendererText());
color.set_rgb(10000,10000,10000);
pRenderer->property_foreground_gdk().set_value(color);
int cols_count = m_oTreeViewMsgList.append_column("Timestamp",
*pRenderer);
Gtk::TreeViewColumn* pColumn =
m_oTreeViewMsgList.get_column(cols_count-1);
pColumn->add_attribute(pRenderer->property_text(),
m_oColumns.Timestamp);
color.set_rgb(53000,53000,50000);
pColumn->get_first_cell_renderer()->property_cell_background_gdk() = color;
pColumn->set_resizable(true);
}
/* column for id-mode */
{
Gtk::CellRendererText* pRenderer = Gtk::manage(new
Gtk::CellRendererText());
color.set_rgb(20000,20000,20000);
pRenderer->property_foreground_gdk().set_value(color);
int cols_count = m_oTreeViewMsgList.append_column("ID-Mode",
*pRenderer);
Gtk::TreeViewColumn* pColumn =
m_oTreeViewMsgList.get_column(cols_count-1);
color.set_rgb(58000,58000,56000);
pColumn->get_first_cell_renderer()->property_cell_background_gdk() = color;
pColumn->add_attribute(pRenderer->property_text(),
m_oColumns.IdMode);
pColumn->get_first_cell_renderer()->property_xalign() = 0.5;
pColumn->set_resizable(true);
}
/* column for id/Name */
{
Gtk::CellRendererText* pRenderer = Gtk::manage( new
Gtk::CellRendererText() );
color.set_rgb(50000,13000,17000);
pRenderer->property_foreground_gdk().set_value(color);
int cols_count =m_oTreeViewMsgList.append_column("ID/Name",
*pRenderer);
Gtk::TreeViewColumn* pColumn
=m_oTreeViewMsgList.get_column(cols_count-1);
color.set_rgb(62000,62000,59000);
pColumn->get_first_cell_renderer()->property_cell_background_gdk() = color;
pColumn->add_attribute(pRenderer->property_text(), m_oColumns.ID);
pColumn->set_resizable(true);
}
/* column for dlc */
{
Gtk::CellRendererText* pRenderer = Gtk::manage( new
Gtk::CellRendererText() );
color.set_rgb(20000,20000,20000);
pRenderer->property_foreground_gdk().set_value(color);
int cols_count = m_oTreeViewMsgList.append_column("DLC",
*pRenderer);
Gtk::TreeViewColumn* pColumn
=m_oTreeViewMsgList.get_column(cols_count-1);
color.set_rgb(58000,58000,56000);
pColumn->get_first_cell_renderer()->property_cell_background_gdk() = color;
pColumn->add_attribute(pRenderer->property_text(), m_oColumns.DLC);
pColumn->get_first_cell_renderer()->property_xalign() = 0.5;
pColumn->set_resizable(true);
}
/* column for message data */
{
Gtk::CellRendererText* pRenderer = Gtk::manage( new
Gtk::CellRendererText() );
color.set_rgb(50000,13000,17000);
pRenderer->property_foreground_gdk().set_value(color);
int cols_count = m_oTreeViewMsgList.append_column("Message
Data ", *pRenderer);
Gtk::TreeViewColumn* pColumn
=m_oTreeViewMsgList.get_column(cols_count-1);
color.set_rgb(62000,62000,59000);
pColumn->get_first_cell_renderer()->property_cell_background_gdk() = color;
pColumn->add_attribute(pRenderer->property_text(), m_oColumns.Data);
pColumn->set_resizable(true);
}
/* column for frame mode */
{
Gtk::CellRendererText* pRenderer = Gtk::manage( new
Gtk::CellRendererText() );
color.set_rgb(40000,40000,40000);
pRenderer->property_foreground_gdk().set_value(color);
int cols_count = m_oTreeViewMsgList.append_column("Frame/Trigger
Mode", *pRenderer);
Gtk::TreeViewColumn* pColumn
=m_oTreeViewMsgList.get_column(cols_count-1);
color.set_rgb(60000,60000,57000);
pColumn->get_first_cell_renderer()->property_cell_background_gdk() = color;
pColumn->add_attribute(pRenderer->property_text(),
m_oColumns.FrameMode);
pColumn->set_expand(true);
}
m_oScrollableMsgList.add(m_oTreeViewMsgList);
m_oScrollableMsgList.set_policy(Gtk::POLICY_AUTOMATIC,
Gtk::POLICY_AUTOMATIC);
.
. Then the treeview will be added to a VBox, calling
show_all_children() .............
.
.
.
}
____and a method that is timer-triggered by one second, which calls an
update-method of FlowTrafficView which gets a std::vector-list of
____CAN-message-objects as reference, after it returns, the vector-list
will be cleared! The Update-method do fill the TreeView:
void FlowTrafficView::Update(const vector<TrafficCanMessage>& i_oMsgList)
{
for(vector<TrafficCanMessage>::const_iterator iter = i_oMsgList.begin();
iter != i_oMsgList.end();
++iter)
{
Gtk::TreeRow oRow =
*(m_oRefPtrListStore->append());
oRow[m_oColumns.Way] = iter->GetWayAsString();
oRow[m_oColumns.Timestamp] =
iter->GetTimestampAsString();
oRow[m_oColumns.IdMode] = iter->GetIDModeAsString();
oRow[m_oColumns.ID] = iter->GetIDAsString();
oRow[m_oColumns.DLC] = iter->GetDLCAsString();
oRow[m_oColumns.Data] = iter->GetDataAsString();
oRow[m_oColumns.FrameMode] = (iter->GetRemoteModeAsString() +
' ' + iter->GetCycleModeAsString());
}
m_oTreeViewMsgList.scroll_to_row(m_oRefPtrListStore->get_path((m_oRefPtrListStore->children().end()--)));
}
____And now the question "Where and how should I use cell_data_func",
can you please describe it closer?
____Thanks in advance !!!!!!!!
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]