www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Gtkd how to add double value to liststore

reply Erdem <farukerdemoncel gmail.com> writes:
I would like to pass some double value to ListStore's constructor 
but it doesn't allows me to do.

import gtk.Main;
import gtk.MainWindow;
import gtk.Box;
import gtk.ListStore;
import gtk.TreeView;
import gtk.TreeViewColumn;
import gtk.TreeIter;
import gtk.CellRendererText;


class MyWindow: MainWindow
{
     Box mainBox;

     this()
     {
         super("Tree view exercise");
         setBorderWidth(10);
         mainBox = new Box(Orientation.HORIZONTAL, 0);
         add(mainBox);


         showAll();
     }
}

class InfoModel: ListStore /* model */
{
     this()
     {
         super([GType.STRING, GType.DOUBLE]);

     }

     void addGoods(string name, double price)
     {
         TreeIter iterator = createIter();
         setValue(iterator, 0, name);
         setValue(iterator, 1, price);
     }
}

class DisplayModel: TreeView /* view */
{
     TreeViewColumn articleColumn;
     TreeViewColumn priceColumn;

     this (ListStore model)
     {
         articleColumn = new TreeViewColumn("Article", new 
CellRendererText(), "text", 0);

     }

}

void main(string[] args)
{
     Main.init(args);
     new MyWindow();
     Main.run();
}

When I try to compile this program it gives this error message:

Error: none of the overloads of 'setValue' are callable using 
argument types (TreeIter, int, double), candidates are:

import/gtk/ListStore.d(273):        
gtk.ListStore.ListStore.setValue(TreeIter iter, int column, 
string value)
import/gtk/ListStore.d(281):        
gtk.ListStore.ListStore.setValue(TreeIter iter, int column, int 
value)
import/gtk/ListStore.d(569):        
gtk.ListStore.ListStore.setValue(TreeIter iter, int column, Value 
value)

Also is it possible to round this double to 2 decimal places when 
presenting data with GtkTreeView.
Jan 14 2017
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 01/14/2017 11:47 AM, Erdem wrote:

     void addGoods(string name, double price)
     {
         TreeIter iterator = createIter();
         setValue(iterator, 0, name);
         setValue(iterator, 1, price);
     }
 }
 Error: none of the overloads of 'setValue' are callable using argument
 types (TreeIter, int, double), candidates are:

 import/gtk/ListStore.d(273):
 gtk.ListStore.ListStore.setValue(TreeIter iter, int column, string value)
 import/gtk/ListStore.d(281):
 gtk.ListStore.ListStore.setValue(TreeIter iter, int column, int value)
 import/gtk/ListStore.d(569):
 gtk.ListStore.ListStore.setValue(TreeIter iter, int column, Value value)
It looks like ListStore is a collection of 'Value's. Does the following work? setValue(iterator, 1, new Value(price)); https://github.com/gtkd-developers/GtkD/blob/3e18afcc5f0b970db1ed042c3818cafebccb35bb/src/gobject/Value.d#L48 Ali
Jan 14 2017
parent Erdem <farukerdemoncel gmail.com> writes:
On Sunday, 15 January 2017 at 01:36:44 UTC, Ali Çehreli wrote:

 It looks like ListStore is a collection of 'Value's. Does the 
 following work?

     setValue(iterator, 1, new Value(price));
Yes it works. Ali bey teşekkürler! :)
Jan 14 2017