⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtkliststore.html

📁 最新gtk中文资料集
💻 HTML
📖 第 1 页 / 共 5 页
字号:
  COLUMN_INT,  COLUMN_BOOLEAN,  N_COLUMNS};{  GtkListStore *list_store;  GtkTreePath *path;  GtkTreeIter iter;  gint i;  list_store = gtk_list_store_new (N_COLUMNS,                                   G_TYPE_STRING,                                   G_TYPE_INT,                                   G_TYPE_BOOLEAN);  for (i = 0; i &lt; 10; i++)    {      gchar *some_data;      some_data = get_some_data (i);      /* Add a new row to the model */      gtk_list_store_append (list_store, &amp;iter);      gtk_list_store_set (list_store, &amp;iter,                          COLUMN_STRING, some_data,                          COLUMN_INT, i,                          COLUMN_BOOLEAN,  FALSE,                          -1);      /* As the store will keep a copy of the string internally, we       * free some_data.       */      g_free (some_data);    }  /* Modify a particular row */  path = gtk_tree_path_new_from_string ("4");  gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store),                           &amp;iter,                           path);  gtk_tree_path_free (path);  gtk_list_store_set (list_store, &amp;iter,                      COLUMN_BOOLEAN, TRUE,                      -1);}</pre></div></div><br class="example-break"><div class="refsect2" lang="en"><a name="id3848564"></a><h3>Performance Considerations</h3><p>Internally, the <a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a> was implemented with a linked list with atail pointer prior to GTK+ 2.6.  As a result, it was fast at datainsertion and deletion, and not fast at random data access.  The<a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a> sets the <a class="link" href="GtkTreeModel.html#GTK-TREE-MODEL-ITERS-PERSIST:CAPS"><span class="type">GTK_TREE_MODEL_ITERS_PERSIST</span></a> flag, which meansthat <a class="link" href="GtkTreeModel.html#GtkTreeIter"><span class="type">GtkTreeIter</span></a>s can be cached while the row exists.  Thus, ifaccess to a particular row is needed often and your code is expected torun on older versions of GTK+, it is worth keeping the iter around.</p><p>It is important to note that only the methods <a class="link" href="GtkListStore.html#gtk-list-store-insert-with-values"><code class="function">gtk_list_store_insert_with_values()</code></a> and <a class="link" href="GtkListStore.html#gtk-list-store-insert-with-valuesv"><code class="function">gtk_list_store_insert_with_valuesv()</code></a> are atomic, in the sense that the row is being appended to the store and the values filled in in a single operation with regard to <a class="link" href="GtkTreeModel.html" title="GtkTreeModel"><span class="type">GtkTreeModel</span></a> signaling.In contrast, using e.g. <a class="link" href="GtkListStore.html#gtk-list-store-append"><code class="function">gtk_list_store_append()</code></a> and then <a class="link" href="GtkListStore.html#gtk-list-store-set"><code class="function">gtk_list_store_set()</code></a> will first create a row, which triggers the <a class="link" href="GtkTreeModel.html#GtkTreeModel-row-inserted"><span class="type">"row-inserted"</span></a> signal on <a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a>. The row, however, is still empty, and any signal handler connecting to "row-inserted" on this particular store should be preparedfor the situation that the row might be empty. This is especially important if you are wrapping the <a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a> inside a <a class="link" href="GtkTreeModelFilter.html" title="GtkTreeModelFilter"><span class="type">GtkTreeModelFilter</span></a> and areusing a <a class="link" href="GtkTreeModelFilter.html#GtkTreeModelFilterVisibleFunc"><span class="type">GtkTreeModelFilterVisibleFunc</span></a>. Using any of the non-atomic operations to append rows to the <a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a> will cause the <a class="link" href="GtkTreeModelFilter.html#GtkTreeModelFilterVisibleFunc"><span class="type">GtkTreeModelFilterVisibleFunc</span></a> to be visited with an empty row first; the function must be prepared for that.</p></div><hr><div class="refsect2" lang="en"><a name="GtkListStore-BUILDER-UI"></a><h3>GtkListStore as GtkBuildable</h3><p>The GtkListStore implementation of the GtkBuildable interface allowsto specify the model columns with a &lt;columns&gt; element that maycontain multiple &lt;column&gt; elements, each specifying one modelcolumn. The "type" attribute specifies the data type for the column.</p><p>Additionally, it is possible to specify content for the list storein the UI definition, with the &lt;data&gt; element. It can containmultiple &lt;row&gt; elements, each specifying to content for onerow of the list model. Inside a &lt;row&gt;, the &lt;col&gt; elementsspecify the content for individual cells.</p><p>Note that it is probably more common to define your models in the code, and one might consider it a layering violation to specify the content of a list store in a UI definition,<span class="emphasis"><em>data</em></span>, not <span class="emphasis"><em>presentation</em></span>, and common wisdom is to separate the two, as far as possible. </p><div class="example"><a name="id3848802"></a><p class="title"><b>Example&#160;22.&#160;A UI Definition fragment for a list store</b></p><div class="example-contents"><pre class="programlisting">&lt;object class="GtkListStore"&gt;  &lt;columns&gt;    &lt;column type="gchararray"/&gt;    &lt;column type="gchararray"/&gt;    &lt;column type="gint"/&gt;  &lt;/columns&gt;  &lt;data&gt;    &lt;row&gt;      &lt;col id="0"&gt;John&lt;/col&gt;      &lt;col id="1"&gt;Doe&lt;/col&gt;      &lt;col id="2"&gt;25&lt;/col&gt;    &lt;/row&gt;    &lt;row&gt;      &lt;col id="0"&gt;Johan&lt;/col&gt;      &lt;col id="1"&gt;Dahlin&lt;/col&gt;      &lt;col id="2"&gt;50&lt;/col&gt;    &lt;/row&gt;  &lt;/data&gt;&lt;/object&gt;</pre></div></div><br class="example-break"></div></div><div class="refsect1" lang="en"><a name="id3848816"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3848834"></a><h3><a name="GtkListStore-struct"></a>GtkListStore</h3><a class="indexterm" name="id3848847"></a><pre class="programlisting">typedef struct _GtkListStore GtkListStore;</pre><p></p></div><hr><div class="refsect2" lang="en"><a name="id3848862"></a><h3><a name="gtk-list-store-new"></a>gtk_list_store_new ()</h3><a class="indexterm" name="id3848876"></a><pre class="programlisting"><a class="link" href="GtkListStore.html" title="GtkListStore">GtkListStore</a>*       gtk_list_store_new                  (<ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> n_columns,                                                         ...);</pre><p>Creates a new list store as with <em class="parameter"><code>n_columns</code></em> columns each of the types passedin.  Note that only types derived from standard GObject fundamental types are supported. </p><p>As an example, <code class="literal">gtk_tree_store_new (3, G_TYPE_INT, G_TYPE_STRING,GDK_TYPE_PIXBUF);</code> will create a new <a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a> with three columns, of typeint, string and <ahref="/usr/share/gtk-doc/html/gdk-pixbuf/gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf"><span class="type">GdkPixbuf</span></a> respectively.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>n_columns</code></em>&#160;:</span></p></td><td> number of columns in the list store</td></tr><tr><td><p><span class="term"><em class="parameter"><code>...</code></em>&#160;:</span></p></td><td> all <ahref="/usr/share/gtk-doc/html/gobject/gobject-Type-Information.html#GType"><span class="type">GType</span></a> types for the columns, from first to last</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td> a new <a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3849004"></a><h3><a name="gtk-list-store-newv"></a>gtk_list_store_newv ()</h3><a class="indexterm" name="id3849017"></a><pre class="programlisting"><a class="link" href="GtkListStore.html" title="GtkListStore">GtkListStore</a>*       gtk_list_store_newv                 (<ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> n_columns,                                                         <ahref="/usr/share/gtk-doc/html/gobject/gobject-Type-Information.html#GType">GType</a> *types);</pre><p>Non-vararg creation function.  Used primarily by language bindings.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>n_columns</code></em>&#160;:</span></p></td><td> number of columns in the list store</td></tr><tr><td><p><span class="term"><em class="parameter"><code>types</code></em>&#160;:</span></p></td><td> an array of <ahref="/usr/share/gtk-doc/html/gobject/gobject-Type-Information.html#GType"><span class="type">GType</span></a> types for the columns, from first to last</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td> a new <a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3849118"></a><h3><a name="gtk-list-store-set-column-types"></a>gtk_list_store_set_column_types ()</h3><a class="indexterm" name="id3849131"></a><pre class="programlisting">void                gtk_list_store_set_column_types     (<a class="link" href="GtkListStore.html" title="GtkListStore">GtkListStore</a> *list_store,                                                         <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> n_columns,                                                         <ahref="/usr/share/gtk-doc/html/gobject/gobject-Type-Information.html#GType">GType</a> *types);</pre><p>This function is meant primarily for <span class="type">GObjects</span> that inherit from <a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a>,and should only be used when constructing a new <a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a>.  It will notfunction after a row has been added, or a method on the <a class="link" href="GtkTreeModel.html" title="GtkTreeModel"><span class="type">GtkTreeModel</span></a>interface is called.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>list_store</code></em>&#160;:</span></p></td><td> A <a class="link" href="GtkListStore.html" title="GtkListStore"><span class="type">GtkListStore</span></a></td>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -