1 /* 2 * This file is part of d-dazzle. 3 * 4 * d-dazzle is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * d-dazzle is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with d-dazzle; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 module dazzle.GraphModel; 20 21 private import dazzle.GraphColumn; 22 private import dazzle.c.functions; 23 public import dazzle.c.types; 24 private import glib.ConstructionException; 25 private import gobject.ObjectG; 26 private import gobject.Signals; 27 private import gobject.Value; 28 private import std.algorithm; 29 30 31 /** */ 32 public class GraphModel : ObjectG 33 { 34 /** the main Gtk struct */ 35 protected DzlGraphModel* dzlGraphModel; 36 37 /** Get the main Gtk struct */ 38 public DzlGraphModel* getGraphModelStruct(bool transferOwnership = false) 39 { 40 if (transferOwnership) 41 ownedRef = false; 42 return dzlGraphModel; 43 } 44 45 /** the main Gtk struct as a void* */ 46 protected override void* getStruct() 47 { 48 return cast(void*)dzlGraphModel; 49 } 50 51 /** 52 * Sets our main struct and passes it to the parent class. 53 */ 54 public this (DzlGraphModel* dzlGraphModel, bool ownedRef = false) 55 { 56 this.dzlGraphModel = dzlGraphModel; 57 super(cast(GObject*)dzlGraphModel, ownedRef); 58 } 59 60 61 /** */ 62 public static GType getType() 63 { 64 return dzl_graph_view_model_get_type(); 65 } 66 67 /** */ 68 public this() 69 { 70 auto p = dzl_graph_view_model_new(); 71 72 if(p is null) 73 { 74 throw new ConstructionException("null returned by new"); 75 } 76 77 this(cast(DzlGraphModel*) p, true); 78 } 79 80 /** */ 81 public static long iterGetTimestamp(DzlGraphModelIter* iter) 82 { 83 return dzl_graph_view_model_iter_get_timestamp(iter); 84 } 85 86 /** */ 87 public static void iterGetValue(DzlGraphModelIter* iter, uint column, Value value) 88 { 89 dzl_graph_view_model_iter_get_value(iter, column, (value is null) ? null : value.getValueStruct()); 90 } 91 92 /** */ 93 public static bool iterNext(DzlGraphModelIter* iter) 94 { 95 return dzl_graph_view_model_iter_next(iter) != 0; 96 } 97 98 /** 99 * Sets an individual value within a specific column. 100 * 101 * Params: 102 * iter = the iter to set 103 * column = the column to set 104 * value = the new value for the column 105 * 106 * Since: 3.30 107 */ 108 public static void iterSetValue(DzlGraphModelIter* iter, uint column, Value value) 109 { 110 dzl_graph_view_model_iter_set_value(iter, column, (value is null) ? null : value.getValueStruct()); 111 } 112 113 /** */ 114 public uint addColumn(GraphColumn column) 115 { 116 return dzl_graph_view_model_add_column(dzlGraphModel, (column is null) ? null : column.getGraphColumnStruct()); 117 } 118 119 /** */ 120 public long getEndTime() 121 { 122 return dzl_graph_view_model_get_end_time(dzlGraphModel); 123 } 124 125 /** */ 126 public bool getIterFirst(DzlGraphModelIter* iter) 127 { 128 return dzl_graph_view_model_get_iter_first(dzlGraphModel, iter) != 0; 129 } 130 131 /** */ 132 public bool getIterLast(DzlGraphModelIter* iter) 133 { 134 return dzl_graph_view_model_get_iter_last(dzlGraphModel, iter) != 0; 135 } 136 137 /** */ 138 public uint getMaxSamples() 139 { 140 return dzl_graph_view_model_get_max_samples(dzlGraphModel); 141 } 142 143 /** */ 144 public uint getNColumns() 145 { 146 return dzl_graph_view_model_get_n_columns(dzlGraphModel); 147 } 148 149 /** */ 150 public GTimeSpan getTimespan() 151 { 152 return dzl_graph_view_model_get_timespan(dzlGraphModel); 153 } 154 155 /** */ 156 public void push(out DzlGraphModelIter iter, long timestamp) 157 { 158 dzl_graph_view_model_push(dzlGraphModel, &iter, timestamp); 159 } 160 161 /** */ 162 public void setMaxSamples(uint nRows) 163 { 164 dzl_graph_view_model_set_max_samples(dzlGraphModel, nRows); 165 } 166 167 /** */ 168 public void setTimespan(GTimeSpan timespan) 169 { 170 dzl_graph_view_model_set_timespan(dzlGraphModel, timespan); 171 } 172 173 /** */ 174 gulong addOnChanged(void delegate(GraphModel) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 175 { 176 return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 177 } 178 }