Re: gtkmm-list Digest, Vol 161, Issue 6



Hi,

I am currently adding data coming from CSV(Comma Separated Values) file.All the data from CSV is string only. As I have 35 rows and 6 Columns of data in string.

class ModelColumns : public Gtk::TreeModel::ColumnRecord
        {
                public:

                ModelColumns()
                {
                              add(m_colA);
                              add(m_colB);
                              add(m_colC);
                              add(m_colD);
                              add(m_colE);
                              add(m_colF);
                }
                    Gtk::TreeModelColumn<Glib::ustring>                        m_colA;
                    Gtk::TreeModelColumn<Glib::ustring>                        m_colB;
                    Gtk::TreeModelColumn<Glib::ustring>                        m_colC;
                    Gtk::TreeModelColumn<Glib::ustring>                        m_colD;
                    Gtk::TreeModelColumn<Glib::ustring>                        m_colE;
                    Gtk::TreeModelColumn<Glib::ustring>                        m_colF;
        };

void LoadBtn()
{
       Gtk::FileChooserDialog dialog("Please select a file to open",
       Gtk::FILE_CHOOSER_ACTION_OPEN);
       dialog.set_transient_for(*this);

        //Add response buttons the the dialog:
        dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
        dialog.add_button("_Open", Gtk::RESPONSE_OK);

        //Add filters, so that only certain file types can be selected:

        auto filter_text = Gtk::FileFilter::create();
        filter_text->set_name("csv files (*.csv)|*.csv");
        filter_text->add_pattern("*");
        dialog.add_filter(filter_text);

        //Show the dialog and wait for a user response:
        int result = dialog.run();

          //Handle the response:
          switch(result)
          {
            case(Gtk::RESPONSE_OK):
            {
                    std::string filename = dialog.get_filename();

                    ifstream in(filename);

                        string line, field;

                        vector< vector<Glib::ustring> > array;  // the 2D array
                        vector<Glib::ustring> v;                // array of values for one line only

                        while ( getline(in,line) )    // get next line in file
                        {
                            v.clear();
                            stringstream ss(line);


                            while (getline(ss,field,','))  // break line into comma delimitted fields
                            {
                                v.push_back(field);  // add each field to the 1D array
                            }

                            array.push_back(v);  // add the 1D array to the 2D array
                        }

              m_refTreeModel =  Gtk::ListStore::create(m_Columns);
              m_TreeView->set_model(m_refTreeModel);
              m_TreeView->append_column("Data1", m_Columns.m_colA);
              m_TreeView->append_column("Data2", m_Columns.m_colB);
              m_TreeView->append_column("Data3", m_Columns.m_colC);
              m_TreeView->append_column("Data4", m_Columns.m_colD);
              m_TreeView->append_column("Data5", m_Columns.m_colE);
              m_TreeView->append_column("Data6", m_Columns.m_colF);

              Gtk::TreeModel::Row row = *(m_refTreeModel->append());
              row[m_Columns.m_colA] = array[0][0]; row[m_Columns.m_colB] = array[0][1]; row[m_Columns.m_colC] = array[0][2];
              row[m_Columns.m_colD] = array[0][3]; row[m_Columns.m_colE] = array[0][4]; row[m_Columns.m_colF] = array[0][5];

              Gtk::TreeModel::Row row1 = *(m_refTreeModel->append());
              row1[m_Columns.m_colA] = array[1][0]; row1[m_Columns.m_colB] = array[1][1]; row1[m_Columns.m_colC] = array[1][2];                       row1[m_Columns.m_colD] = array[1][3]; row1[m_Columns.m_colE] = array[1][4]; row1[m_Columns.m_colF] = array[1][5];

              //35 Rows Like This

              break;
            }
            default:
            {
              break;
            }
        }

}

Like this I am adding 35 rows. Its very Lengthy. I am getting data from string vector as I have added the code for FileChoser Function. I am defining a class for TreeModel as I added.

Regrads
Deepak, India.

On Tue, Sep 19, 2017 at 5:30 PM, <gtkmm-list-request gnome org> wrote:
Send gtkmm-list mailing list submissions to
        gtkmm-list gnome org

To subscribe or unsubscribe via the World Wide Web, visit
        https://mail.gnome.org/mailman/listinfo/gtkmm-list
or, via email, send a message with subject or body 'help' to
        gtkmm-list-request gnome org

You can reach the person managing the list at
        gtkmm-list-owner gnome org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of gtkmm-list digest..."


Today's Topics:

   1. TreeModel (Deepak Chiradoni)
   2. Re: TreeModel (Daniel Boles)
   3. glibmm 2.54.1 released (Kjell Ahlstedt)


----------------------------------------------------------------------

Message: 1
Date: Mon, 18 Sep 2017 18:16:18 +0530
From: Deepak Chiradoni <deepakachiradoni gmail com>
To: gtkmm-list gnome org
Subject: TreeModel
Message-ID:
        <CA+9UgBkFUngGVL8de=R-TzFNHX_dYz3BxWq_rha7ftn-YJcwdw@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hello Everyone,

I am using GTKMM Glade tool for GUI developing. I want to insert more rows
around 35 rows in treemodel. Is there any option for inserting rows using
loops. I am adding 35 rows appending rows 35 times. The code becoming very
large and difficult to manipulate in future. Is there any looping option
for appending more rows? It has 6 columns. Please help me to make code
optimized.

Regards
Deepak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.gnome.org/archives/gtkmm-list/attachments/20170918/f1b92f8b/attachment.html>

------------------------------

Message: 2
Date: Mon, 18 Sep 2017 14:08:33 +0100
From: Daniel Boles <dboles src gmail com>
To: gtkmm-list <gtkmm-list gnome org>
Subject: Re: TreeModel
Message-ID:
        <CAKChMKOCkp5M9dXSq-3kQ5_5-XNa=2F2D31S8mS1KuPcrQZbgQ@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

It would certainly help if you show an excerpt of what kind of data you
currently add, and how. Then we can figure out how to make that into
something loopable.

Generally, though, I think the idea would be that you would define a struct
containing the data you want to insert, then loop over a set of that (e.g.
a vector or initializer_list) inserting into the model from the
corresponding fields.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.gnome.org/archives/gtkmm-list/attachments/20170918/4d0bf4a1/attachment.html>

------------------------------

Message: 3
Date: Mon, 18 Sep 2017 20:26:48 +0200
From: Kjell Ahlstedt <kjellahlstedt gmail com>
To: gnome-announce-list gnome org, gtkmm-list gnome org
Subject: glibmm 2.54.1 released
Message-ID: <77f4afc9-1d45-35d0-7dcf-0edb651d17d9 gmail com>
Content-Type: text/plain; charset="windows-1252"; Format="flowed"

C++ bindings for Glib.

glibmm 2.54 wraps glib 2.54

Home page: http://www.gtkmm.org
Download: https://download.gnome.org/sources/glibmm/
Documentation: https://developer.gnome.org/glibmm/2.54/

*** Changes

2.54.1 (stable):

Glib:
* Variant: Don't use std::index_sequence from C++14.
 ? (Kjell Ahlstedt, Jonathan Wakely) Bug #787648 (Armin K.)

Documentation:
* Note that Gio::Application::property_resource_base_path() shall not
 ? be used. It has a bug that's hard to fix without breaking ABI.
 ? (Kjell Ahlstedt) Bug #787496 (Daniel Boles)

gmmproc:
* Convert all property documentation to C++.
 ? (Kjell Ahlstedt) Bug #787698 (Daniel Boles)

Kjell Ahlstedt
kjellahlstedt gmail com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.gnome.org/archives/gtkmm-list/attachments/20170918/c3dcbb88/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkmm-list


------------------------------

End of gtkmm-list Digest, Vol 161, Issue 6
******************************************



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