~ubuntu-branches/ubuntu/precise/glom/precise-updates

« back to all changes in this revision

Viewing changes to glom/mode_design/layout/layout_item_dialogs/dialog_groupby_sortfields.cc

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-10-09 16:50:36 UTC
  • mfrom: (1.1.42 upstream)
  • Revision ID: james.westby@ubuntu.com-20091009165036-orinvwmohk838xxl
Tags: 1.12.2-0ubuntu1
* New upstream version:
  - FFE LP: #391664
* debian/control:
  - Bump python-gnome2-extras-dev build-dep to >= 2.25.3.
  - Bump libgdamm3.0-dev build-dep to libgdamm4.0-dev >= 3.99.14.
  - Change libgda3-dev build-dep to libgda-4.0-dev.
  - Change libgda3-postgres dependency to libgda-4.0-postgres.
  - Bump libgtkmm-2.4-dev build-dep to >= 2.14.
  - Add build-dep on libgconfmm-2.6-dev.
  - Bump libgoocanvasmm-dev build-dep to >= 0.14.0.
  - Remove build-dep on libbakery-2.6-dev.
  - Bump postgresql-8.3 dependency to postgresql-8.4.
  - Change scrollkeeper build-dep to rarian-compat.
  - Rename libglom{0,-dev} -> libglom-1.12-{0,dev}. Upstream include
    APIVER in the library name now.
* debian/rules:
  - Update --with-postgres-utils configure flag to point to the new
    path.
  - Drop deprecated --disable-scrollkeeper configure flag.
  - Update DEB_SHLIBDEPS_INCLUDE with new libglom-1.12-0 package name.
  - Don't include /usr/share/cdbs/1/rules/simple-patchsys.mk - there
    are currently no patches.
* debian/libglom-1.12-0.install:
  - Updated for new version.
* debian/libglom-1.12-dev.install:
  - Install pc and header files.
* debian/glom-doc.install:
  - Updated for new version.
* debian/glom.install:
  - Updated for new version.
* Fix debian/watch.
* Dropped obsolete 10-distro-install-postgres-change.patch.
* Built against latest libgoocanvasmm (LP: #428445).
* Also closes LP: #230007, LP: #393229, LP: #393231, LP: #394507,
  LP: #394887, LP: #394894, LP: #397409, LP: #381563.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Glom
 
2
 *
 
3
 * Copyright (C) 2001-2004 Murray Cumming
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License as
 
7
 * published by the Free Software Foundation; either version 2 of the
 
8
 * License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful, but
 
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public
 
16
 * License along with this program; if not, write to the
 
17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
 * Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
#include "dialog_groupby_sortfields.h"
 
22
#include "dialog_field_layout.h"
 
23
 
 
24
//#include <libgnome/gnome-i18n.h>
 
25
#include <glibmm/i18n.h>
 
26
 
 
27
namespace Glom
 
28
{
 
29
 
 
30
Dialog_GroupBy_SortFields::Dialog_GroupBy_SortFields(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder)
 
31
: Dialog_Layout(cobject, builder, false /* means no table title */),
 
32
  m_treeview_fields(0),
 
33
  m_button_field_up(0),
 
34
  m_button_field_down(0),
 
35
  m_button_field_add(0),
 
36
  m_button_field_delete(0),
 
37
  m_button_field_edit(0),
 
38
  m_label_table_name(0)
 
39
{
 
40
  builder->get_widget("label_table_name", m_label_table_name);
 
41
 
 
42
  builder->get_widget("treeview_fields", m_treeview_fields);
 
43
  if(m_treeview_fields)
 
44
  {
 
45
    m_model_fields = Gtk::ListStore::create(m_ColumnsFields);
 
46
    m_treeview_fields->set_model(m_model_fields);
 
47
 
 
48
    // Append the View columns:
 
49
    Gtk::TreeView::Column* column_name = Gtk::manage( new Gtk::TreeView::Column(_("Name")) );
 
50
    m_treeview_fields->append_column(*column_name);
 
51
 
 
52
    Gtk::CellRendererText* renderer_name = Gtk::manage(new Gtk::CellRendererText);
 
53
    column_name->pack_start(*renderer_name);
 
54
    column_name->set_cell_data_func(*renderer_name, sigc::mem_fun(*this, &Dialog_GroupBy_SortFields::on_cell_data_name));
 
55
 
 
56
    m_treeview_fields->append_column_editable(_("Ascending"), m_ColumnsFields.m_col_ascending);
 
57
 
 
58
    //Sort by sequence, so we can change the order by changing the values in the hidden sequence column.
 
59
    m_model_fields->set_sort_column(m_ColumnsFields.m_col_sequence, Gtk::SORT_ASCENDING);
 
60
 
 
61
 
 
62
    //Respond to changes of selection:
 
63
    Glib::RefPtr<Gtk::TreeView::Selection> refSelection = m_treeview_fields->get_selection();
 
64
    if(refSelection)
 
65
    {
 
66
      refSelection->signal_changed().connect( sigc::mem_fun(*this, &Dialog_GroupBy_SortFields::on_treeview_fields_selection_changed) );
 
67
    }
 
68
 
 
69
    m_model_fields->signal_row_changed().connect( sigc::mem_fun(*this, &Dialog_GroupBy_SortFields::on_treemodel_row_changed) );
 
70
  }
 
71
 
 
72
 
 
73
  builder->get_widget("button_field_up", m_button_field_up);
 
74
  m_button_field_up->signal_clicked().connect( sigc::mem_fun(*this, &Dialog_GroupBy_SortFields::on_button_field_up) );
 
75
 
 
76
  builder->get_widget("button_field_down", m_button_field_down);
 
77
  m_button_field_down->signal_clicked().connect( sigc::mem_fun(*this, &Dialog_GroupBy_SortFields::on_button_field_down) );
 
78
 
 
79
  builder->get_widget("button_field_delete", m_button_field_delete);
 
80
  m_button_field_delete->signal_clicked().connect( sigc::mem_fun(*this, &Dialog_GroupBy_SortFields::on_button_delete) );
 
81
 
 
82
  builder->get_widget("button_field_add", m_button_field_add);
 
83
  m_button_field_add->signal_clicked().connect( sigc::mem_fun(*this, &Dialog_GroupBy_SortFields::on_button_add_field) );
 
84
 
 
85
  builder->get_widget("button_field_edit", m_button_field_edit);
 
86
  m_button_field_edit->signal_clicked().connect( sigc::mem_fun(*this, &Dialog_GroupBy_SortFields::on_button_edit_field) );
 
87
 
 
88
  show_all_children();
 
89
}
 
90
 
 
91
Dialog_GroupBy_SortFields::~Dialog_GroupBy_SortFields()
 
92
{
 
93
}
 
94
 
 
95
void Dialog_GroupBy_SortFields::set_fields(const Glib::ustring& table_name, const LayoutItem_GroupBy::type_list_sort_fields& fields)
 
96
{
 
97
  m_modified = false;
 
98
  m_table_name = table_name;
 
99
 
 
100
  Document* document = get_document();
 
101
 
 
102
  //Update the tree models from the document
 
103
  if(document)
 
104
  {
 
105
    //Set the table name and title:
 
106
    m_label_table_name->set_text(table_name);
 
107
 
 
108
 
 
109
    //Show the field layout
 
110
    typedef std::list< Glib::ustring > type_listStrings;
 
111
 
 
112
    m_model_fields->clear();
 
113
    guint field_sequence = 0;
 
114
    for(LayoutItem_GroupBy::type_list_sort_fields::const_iterator iter = fields.begin(); iter != fields.end(); ++iter)
 
115
    {
 
116
      sharedptr<const LayoutItem_Field> item = sharedptr<const LayoutItem_Field>::cast_dynamic(iter->first);
 
117
 
 
118
      Gtk::TreeModel::iterator iterTree = m_model_fields->append();
 
119
      Gtk::TreeModel::Row row = *iterTree;
 
120
 
 
121
      row[m_ColumnsFields.m_col_layout_item] = item;
 
122
      row[m_ColumnsFields.m_col_ascending] = iter->second;
 
123
      row[m_ColumnsFields.m_col_sequence] = field_sequence;
 
124
      ++field_sequence;
 
125
    }
 
126
 
 
127
    //treeview_fill_sequences(m_model_fields, m_ColumnsFields.m_col_sequence); //The document should have checked this already, but it does not hurt to check again.
 
128
  }
 
129
 
 
130
  m_modified = false;
 
131
}
 
132
 
 
133
void Dialog_GroupBy_SortFields::enable_buttons()
 
134
{
 
135
  //Fields:
 
136
  Glib::RefPtr<Gtk::TreeView::Selection> refSelection = m_treeview_fields->get_selection();
 
137
  if(refSelection)
 
138
  {
 
139
    Gtk::TreeModel::iterator iter = refSelection->get_selected();
 
140
    if(iter)
 
141
    {
 
142
      //Disable Up if It can't go any higher.
 
143
      bool enable_up = true;
 
144
      if(iter == m_model_fields->children().begin())
 
145
        enable_up = false;  //It can't go any higher.
 
146
 
 
147
      m_button_field_up->set_sensitive(enable_up);
 
148
 
 
149
 
 
150
      //Disable Down if It can't go any lower.
 
151
      Gtk::TreeModel::iterator iterNext = iter;
 
152
      iterNext++;
 
153
 
 
154
      bool enable_down = true;
 
155
      if(iterNext == m_model_fields->children().end())
 
156
        enable_down = false;
 
157
 
 
158
      m_button_field_down->set_sensitive(enable_down);
 
159
 
 
160
      m_button_field_delete->set_sensitive(true);
 
161
    }
 
162
    else
 
163
    {
 
164
      //Disable all buttons that act on a selection:
 
165
      m_button_field_down->set_sensitive(false);
 
166
      m_button_field_up->set_sensitive(false);
 
167
      m_button_field_delete->set_sensitive(false);
 
168
    }
 
169
  }
 
170
 
 
171
 
 
172
}
 
173
 
 
174
 
 
175
void Dialog_GroupBy_SortFields::on_button_field_up()
 
176
{
 
177
  move_treeview_selection_up(m_treeview_fields, m_ColumnsFields.m_col_sequence);
 
178
}
 
179
 
 
180
void Dialog_GroupBy_SortFields::on_button_field_down()
 
181
{
 
182
  move_treeview_selection_down(m_treeview_fields, m_ColumnsFields.m_col_sequence);
 
183
}
 
184
 
 
185
LayoutItem_GroupBy::type_list_sort_fields Dialog_GroupBy_SortFields::get_fields() const
 
186
{
 
187
  LayoutItem_GroupBy::type_list_sort_fields result;
 
188
 
 
189
  guint field_sequence = 1; //0 means no sequence
 
190
  for(Gtk::TreeModel::iterator iterFields = m_model_fields->children().begin(); iterFields != m_model_fields->children().end(); ++iterFields)
 
191
  {
 
192
    Gtk::TreeModel::Row row = *iterFields;
 
193
 
 
194
    sharedptr<const LayoutItem_Field> item = row[m_ColumnsFields.m_col_layout_item];
 
195
    const Glib::ustring field_name = item->get_name();
 
196
    if(!field_name.empty())
 
197
    {
 
198
      sharedptr<LayoutItem_Field> field_copy = glom_sharedptr_clone(item);
 
199
 
 
200
      const bool ascending = row[m_ColumnsFields.m_col_ascending];
 
201
      result.push_back( LayoutItem_GroupBy::type_pair_sort_field(field_copy, ascending) );
 
202
 
 
203
      ++field_sequence;
 
204
    }
 
205
  }
 
206
 
 
207
  return result;
 
208
}
 
209
 
 
210
void Dialog_GroupBy_SortFields::on_treeview_fields_selection_changed()
 
211
{
 
212
  enable_buttons();
 
213
}
 
214
 
 
215
void Dialog_GroupBy_SortFields::on_button_add_field()
 
216
{
 
217
  //Get the chosen fields:
 
218
  type_list_field_items fields_list = offer_field_list(m_table_name, this);
 
219
  for(type_list_field_items::iterator iter_chosen = fields_list.begin(); iter_chosen != fields_list.end(); iter_chosen++) 
 
220
  {
 
221
 
 
222
    sharedptr<LayoutItem_Field> field = *iter_chosen;
 
223
    if(!field)
 
224
      continue;
 
225
 
 
226
    //Add the field details to the layout treeview:
 
227
    Gtk::TreeModel::iterator iter =  m_model_fields->append();
 
228
 
 
229
    if(iter)
 
230
    {
 
231
      Gtk::TreeModel::Row row = *iter;
 
232
      row[m_ColumnsFields.m_col_layout_item] = field;
 
233
      row[m_ColumnsFields.m_col_ascending] = true; //Default to this so that alphabetical searches go from A to Z by default.
 
234
 
 
235
      //Scroll to, and select, the new row:
 
236
      Glib::RefPtr<Gtk::TreeView::Selection> refTreeSelection = m_treeview_fields->get_selection();
 
237
      if(refTreeSelection)
 
238
        refTreeSelection->select(iter);
 
239
 
 
240
      m_treeview_fields->scroll_to_row( Gtk::TreeModel::Path(iter) );
 
241
 
 
242
      treeview_fill_sequences(m_model_fields, m_ColumnsFields.m_col_sequence); //The document should have checked this already, but it does not hurt to check again.
 
243
    }
 
244
  }
 
245
}
 
246
 
 
247
void Dialog_GroupBy_SortFields::on_button_delete()
 
248
{
 
249
  Glib::RefPtr<Gtk::TreeView::Selection> refTreeSelection = m_treeview_fields->get_selection();
 
250
  if(refTreeSelection)
 
251
  {
 
252
    //TODO: Handle multiple-selection:
 
253
    Gtk::TreeModel::iterator iter = refTreeSelection->get_selected();
 
254
    if(iter)
 
255
    {
 
256
      m_model_fields->erase(iter);
 
257
 
 
258
      m_modified = true;
 
259
    }
 
260
  }
 
261
}
 
262
 
 
263
 
 
264
void Dialog_GroupBy_SortFields::on_cell_data_name(Gtk::CellRenderer* renderer, const Gtk::TreeModel::iterator& iter)
 
265
{
 
266
  //Set the view's cell properties depending on the model's data:
 
267
  Gtk::CellRendererText* renderer_text = dynamic_cast<Gtk::CellRendererText*>(renderer);
 
268
  if(renderer_text)
 
269
  {
 
270
    if(iter)
 
271
    {
 
272
      Gtk::TreeModel::Row row = *iter;
 
273
 
 
274
      sharedptr<const LayoutItem_Field> item = row[m_ColumnsFields.m_col_layout_item]; //TODO_performance: Reduce copying.
 
275
      renderer_text->property_markup() = item->get_layout_display_name();
 
276
      renderer_text->property_editable() = false; //Names can never be edited.
 
277
    }
 
278
  }
 
279
}
 
280
 
 
281
 
 
282
void Dialog_GroupBy_SortFields::on_button_edit_field()
 
283
{
 
284
  Glib::RefPtr<Gtk::TreeView::Selection> refTreeSelection = m_treeview_fields->get_selection();
 
285
  if(refTreeSelection)
 
286
  {
 
287
    //TODO: Handle multiple-selection:
 
288
    Gtk::TreeModel::iterator iter = refTreeSelection->get_selected();
 
289
    if(iter)
 
290
    {
 
291
      Gtk::TreeModel::Row row = *iter;
 
292
      sharedptr<const LayoutItem_Field> field = row[m_ColumnsFields.m_col_layout_item];
 
293
 
 
294
      //Get the chosen field:
 
295
      sharedptr<LayoutItem_Field> field_chosen = 
 
296
        offer_field_list_select_one_field(field, m_table_name, this);
 
297
      if(field_chosen)
 
298
 
 
299
      //Set the field details in the layout treeview:
 
300
 
 
301
      row[m_ColumnsFields.m_col_layout_item] = field_chosen;
 
302
 
 
303
      //Scroll to, and select, the new row:
 
304
      /*
 
305
      Glib::RefPtr<Gtk::TreeView::Selection> refTreeSelection = m_treeview_fields->get_selection();
 
306
      if(refTreeSelection)
 
307
        refTreeSelection->select(iter);
 
308
 
 
309
      m_treeview_fields->scroll_to_row( Gtk::TreeModel::Path(iter) );
 
310
 
 
311
      treeview_fill_sequences(m_model_fields, m_ColumnsFields.m_col_sequence); //The document should have checked this already, but it does not hurt to check again.
 
312
      */
 
313
    }
 
314
  }
 
315
}
 
316
 
 
317
} //namespace Glom
 
318
 
 
319