]> saetta.ns0.it Git - libgdaex/commitdiff
QueryEditor: added and implemented always_ordered and order_default field properties...
authorAndrea Zagli <andrea.zagli@email.it>
Sat, 5 Mar 2016 09:49:59 +0000 (10:49 +0100)
committerAndrea Zagli <andrea.zagli@email.it>
Sat, 5 Mar 2016 10:09:28 +0000 (11:09 +0100)
data/gdaex_query_editor.dtd
src/queryeditor.c
src/queryeditor.h
tests/query_editor.xml

index 2156c6ce99aece8f3cba68355e1e512b706e9361..238b889caeaece22be511b59ded3a779d8c4e569 100644 (file)
@@ -13,7 +13,7 @@
        table_name CDATA #REQUIRED
 >
 
-<!ELEMENT field (name, name_visible?, description?, alias?, type, for_show, always_showed, for_where, available_where_type, for_order, decode)>
+<!ELEMENT field (name, name_visible?, description?, alias?, type, for_show, always_showed, for_where, available_where_type, for_order, always_ordered, order_default, decode)>
 
 <!ELEMENT table_name (#PCDATA)>
 <!ELEMENT name_visible (#PCDATA)>
@@ -25,6 +25,8 @@
 <!ELEMENT for_where (#PCDATA)>
 <!ELEMENT available_where_type (#PCDATA)>
 <!ELEMENT for_order (#PCDATA)>
+<!ELEMENT always_ordered (#PCDATA)>
+<!ELEMENT order_default (#PCDATA)>
 
 <!ELEMENT decode (table_name, join_type, field_name_to_join, field_name_to_show, alias)>
 
@@ -42,4 +44,4 @@
 <!ELEMENT fields_joined (field_left, field_right)>
 
 <!ELEMENT field_left (#PCDATA)>
-<!ELEMENT field_right (#PCDATA)>
\ No newline at end of file
+<!ELEMENT field_right (#PCDATA)>
index 27a3b58e4b305532c82ef1e5045e6b3ca25793b4..2b92ac382be1ec6d62b21bc8cdf2bcbfc8d8ac9e 100644 (file)
@@ -103,6 +103,7 @@ static void gdaex_query_editor_refresh_gui_add_fields (GdaExQueryEditor *qe,
                                                        GtkTreeIter *iter_parent);
 
 static void gdaex_query_editor_refill_always_show (GdaExQueryEditor *qe);
+static void gdaex_query_editor_refill_always_order (GdaExQueryEditor *qe);
 
 static void gdaex_query_editor_store_remove_iter (GdaExQueryEditor *qe,
                                        GtkTreeSelection *sel,
@@ -141,6 +142,7 @@ static void gdaex_query_editor_on_notebook_switch_page (GtkNotebook *notebook,
                                                                                                                gpointer user_data);
 
 static void gdaex_query_editor_show_add_iter (GdaExQueryEditor *qe, GtkTreeIter *iter);
+static void gdaex_query_editor_order_add_iter (GdaExQueryEditor *qe, GtkTreeIter *iter);
 
 static void gdaex_query_editor_on_btn_show_add_clicked (GtkButton *button,
                                     gpointer user_data);
@@ -1384,6 +1386,21 @@ gdaex_query_editor_load_tables_from_xml (GdaExQueryEditor *qe,
                                                                                                {
                                                                                                        field->for_order = zak_utils_string_to_boolean (xmlNodeGetContent (cur));
                                                                                                }
+                                                                                       else if (xmlStrcmp (cur->name, "always_ordered") == 0)
+                                                                                               {
+                                                                                                       field->always_ordered = zak_utils_string_to_boolean (xmlNodeGetContent (cur));
+                                                                                               }
+                                                                                       else if (xmlStrcmp (cur->name, "order_default") == 0)
+                                                                                               {
+                                                                                                       if (g_strcmp0 (xmlNodeGetContent (cur), "ASC") == 0)
+                                                                                                               {
+                                                                                                                       field->order_default = GDAEX_QE_ORDER_ASC;
+                                                                                                               }
+                                                                                                       else
+                                                                                                               {
+                                                                                                                       field->order_default = GDAEX_QE_ORDER_DESC;
+                                                                                                               }
+                                                                                               }
                                                                                        else if (xmlStrcmp (cur->name, "decode") == 0)
                                                                                                {
                                                                                                        xdecode = cur->children;
@@ -1619,6 +1636,7 @@ gdaex_query_editor_clean_choices (GdaExQueryEditor *qe)
        gtk_list_store_clear (priv->lstore_order);
 
        gdaex_query_editor_refill_always_show (qe);
+       gdaex_query_editor_refill_always_order (qe);
 
        gtk_button_clicked (GTK_BUTTON (gtk_builder_get_object (priv->gtkbuilder, "button16")));
 }
@@ -3120,6 +3138,10 @@ gdaex_query_editor_refresh_gui_add_fields (GdaExQueryEditor *qe,
                                {
                                        gdaex_query_editor_show_add_iter (qe, &iter);
                                }
+                       if (field->for_order && field->always_ordered)
+                               {
+                                       gdaex_query_editor_order_add_iter (qe, &iter);
+                               }
                }
 }
 
@@ -3163,6 +3185,46 @@ gdaex_query_editor_refill_always_show (GdaExQueryEditor *qe)
                }
 }
 
+static void
+gdaex_query_editor_refill_always_order (GdaExQueryEditor *qe)
+{
+       GdaExQueryEditorPrivate *priv;
+
+       GtkTreeIter iter_table;
+       GtkTreeIter iter;
+
+       gchar *table_name;
+       gchar *field_name;
+
+       GdaExQueryEditorTable *table;
+       GdaExQueryEditorField *field;
+
+       priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe);
+
+       if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->tstore_fields), &iter_table))
+               {
+                       do
+                               {
+                                       if (gtk_tree_model_iter_children (GTK_TREE_MODEL (priv->tstore_fields), &iter, &iter_table))
+                                               {
+                                                       do
+                                                               {
+                                                                       gtk_tree_model_get (GTK_TREE_MODEL (priv->tstore_fields), &iter,
+                                                                                           COL_FIELDS_TABLE_NAME, &table_name,
+                                                                                           COL_FIELDS_NAME, &field_name,
+                                                                                           -1);
+                                                                       table = g_hash_table_lookup (priv->tables, table_name);
+                                                                       field = g_hash_table_lookup (table->fields, field_name);
+                                                                       if (field->always_ordered)
+                                                                               {
+                                                                                       gdaex_query_editor_order_add_iter (qe, &iter);
+                                                                               }
+                                                               } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->tstore_fields), &iter));
+                                               }
+                               } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->tstore_fields), &iter_table));
+               }
+}
+
 static void
 gdaex_query_editor_store_remove_iter (GdaExQueryEditor *qe,
                                       GtkTreeSelection *sel,
@@ -3932,6 +3994,47 @@ gdaex_query_editor_show_add_iter (GdaExQueryEditor *qe, GtkTreeIter *iter)
        g_free (field_name);
 }
 
+static void
+gdaex_query_editor_order_add_iter (GdaExQueryEditor *qe, GtkTreeIter *iter)
+{
+       GdaExQueryEditorPrivate *priv;
+
+       gchar *table_name;
+       gchar *field_name;
+       GdaExQueryEditorTable *table;
+       GdaExQueryEditorField *field;
+
+       GtkWidget *wpage;
+
+       priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe);
+
+       gtk_tree_model_get (GTK_TREE_MODEL (priv->tstore_fields), iter,
+                                               COL_FIELDS_TABLE_NAME, &table_name,
+                                               COL_FIELDS_NAME, &field_name,
+                                               -1);
+
+       table = g_hash_table_lookup (priv->tables, table_name);
+       field = g_hash_table_lookup (table->fields, field_name);
+
+       gtk_list_store_append (priv->lstore_order, iter);
+       gtk_list_store_set (priv->lstore_order, iter,
+                                               COL_ORDER_TABLE_NAME, field->table_name,
+                                               COL_ORDER_NAME, field_name,
+                                               COL_ORDER_VISIBLE_NAME, g_strconcat (table->name_visible, " - ", field->name_visible, NULL),
+                                               COL_ORDER_ORDER, field->order_default == GDAEX_QE_ORDER_ASC ? "ASC" : "DESC",
+                                               COL_ORDER_ORDER_VISIBLE, field->order_default == GDAEX_QE_ORDER_ASC ? _("Ascending") : _("Descending"),
+                                               -1);
+
+       wpage = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), GDAEX_QE_PAGE_ORDER);
+       if (gtk_widget_get_visible (wpage))
+               {
+                       gtk_tree_selection_select_iter (priv->sel_order, iter);
+               }
+
+       g_free (table_name);
+       g_free (field_name);
+}
+
 static void
 gdaex_query_editor_on_btn_show_add_clicked (GtkButton *button,
                                     gpointer user_data)
@@ -4714,48 +4817,16 @@ gdaex_query_editor_on_btn_order_add_clicked (GtkButton *button,
        GdaExQueryEditorPrivate *priv;
 
        GtkTreeIter iter;
-       GtkWidget *dialog;
 
-       gchar *table_name;
-       gchar *field_name;
-
-       GdaExQueryEditorTable *table;
-       GdaExQueryEditorField *field;
-
-       GtkWidget *wpage;
+       GtkWidget *dialog;
 
        qe = (GdaExQueryEditor *)user_data;
        priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe);
 
        if (gtk_tree_selection_get_selected (priv->sel_fields, NULL, &iter))
                {
-                       gtk_tree_model_get (GTK_TREE_MODEL (priv->tstore_fields), &iter,
-                                           COL_FIELDS_TABLE_NAME, &table_name,
-                                           COL_FIELDS_NAME, &field_name,
-                                           -1);
-
-                       table = g_hash_table_lookup (priv->tables, table_name);
-                       field = g_hash_table_lookup (table->fields, field_name);
-
-                       gtk_list_store_append (priv->lstore_order, &iter);
-                       gtk_list_store_set (priv->lstore_order, &iter,
-                                           COL_ORDER_TABLE_NAME, field->table_name,
-                                           COL_ORDER_NAME, field_name,
-                                           COL_ORDER_VISIBLE_NAME, g_strconcat (table->name_visible, " - ", field->name_visible, NULL),
-                                           COL_ORDER_ORDER, "ASC",
-                                           COL_ORDER_ORDER_VISIBLE, _("Ascending"),
-                                           -1);
-
-                       wpage = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), GDAEX_QE_PAGE_ORDER);
-                       if (gtk_widget_get_visible (wpage))
-                               {
-                                       gtk_tree_selection_select_iter (priv->sel_order, &iter);
-                               }
-
+                       gdaex_query_editor_order_add_iter (qe, &iter);
                        gdaex_query_editor_on_sel_fields_changed (NULL, user_data);
-
-                       g_free (table_name);
-                       g_free (field_name);
                }
        else
                {
@@ -4815,6 +4886,7 @@ gdaex_query_editor_on_btn_order_clean_clicked (GtkButton *button,
        GdaExQueryEditorPrivate *priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe);
 
        gtk_list_store_clear (priv->lstore_order);
+       gdaex_query_editor_refill_always_order (qe);
 
        gtk_button_clicked (GTK_BUTTON (gtk_builder_get_object (priv->gtkbuilder, "button16")));
 }
@@ -4857,6 +4929,8 @@ gdaex_query_editor_on_sel_order_changed (GtkTreeSelection *treeselection,
                        table = g_hash_table_lookup (priv->tables, table_name);
                        field = g_hash_table_lookup (table->fields, field_name);
 
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "button12")), !field->always_ordered);
+
                        if (!GTK_IS_BOX (priv->hbox_order))
                                {
                                        priv->hbox_order = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
index b5f3dd28355d845654bf853df0d3de11ef450276..cdefb8f27d15b5bd1034e95ccc861db5d1d3e6f9 100644 (file)
@@ -102,6 +102,12 @@ typedef enum
                GDAEX_QE_JOIN_TYPE_LEFT
        } GdaExQueryEditorJoinType;
 
+typedef enum
+       {
+               GDAEX_QE_ORDER_ASC,
+               GDAEX_QE_ORDER_DESC
+       } GdaExQueryEditorOrderType;
+
 #define GDAEX_QE_WHERE_TYPE_STRING GDAEX_QE_WHERE_TYPE_STARTS | GDAEX_QE_WHERE_TYPE_CONTAINS | GDAEX_QE_WHERE_TYPE_ENDS | GDAEX_QE_WHERE_TYPE_ISTARTS | GDAEX_QE_WHERE_TYPE_ICONTAINS | GDAEX_QE_WHERE_TYPE_IENDS
 
 #define GDAEX_QE_WHERE_TYPE_NUMBER GDAEX_QE_WHERE_TYPE_EQUAL | GDAEX_QE_WHERE_TYPE_GREAT | GDAEX_QE_WHERE_TYPE_GREAT_EQUAL | GDAEX_QE_WHERE_TYPE_LESS | GDAEX_QE_WHERE_TYPE_LESS_EQUAL | GDAEX_QE_WHERE_TYPE_BETWEEN
@@ -122,6 +128,8 @@ typedef struct
                gboolean for_where;
                guint available_where_type;
                gboolean for_order;
+               gboolean always_ordered;
+               GdaExQueryEditorOrderType order_default;
 
                GdaExQueryEditorIWidget *iwidget_from;
                GdaExQueryEditorIWidget *iwidget_to;
index 3404fdc917f292c29c540ba4ab74dab7cc7290e9..5096f61b53643563eed70f21be051a5861dbfbfc 100644 (file)
@@ -32,6 +32,8 @@
                        <description>The client's surname</description>
                        <type>text</type>
                        <available_where_type>string|is_null</available_where_type>
+                       <always_ordered>true</always_ordered>
+                       <order_default>DESC</order_default>
                </field>
                <field>
                        <name>age</name>
@@ -74,6 +76,7 @@
                        <description>If married</description>
                        <type>boolean</type>
                        <available_where_type>equal</available_where_type>
+                       <order_default>DESC</order_default>
                </field>
        </fields>